1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Core
.Resource
18 using System
.Globalization
;
20 using System
.Reflection
;
21 using System
.Resources
;
24 public class AssemblyBundleResource
: AbstractResource
26 private readonly CustomUri resource
;
27 private readonly CultureInfo ci
;
29 public AssemblyBundleResource(CustomUri resource
) : this(resource
, CultureInfo
.InvariantCulture
)
33 public AssemblyBundleResource(CustomUri resource
, CultureInfo ci
)
35 this.resource
= resource
;
39 public override TextReader
GetStreamReader()
41 Assembly assembly
= ObtainAssembly(resource
.Host
);
44 string[] paths
= resource
.Path
.Split(new char[] { '/' }
).FindAll(s
=> !string.IsNullOrEmpty(s
));
46 string[] paths
= resource
.Path
.Split(new char[] { '/' }
, StringSplitOptions
.RemoveEmptyEntries
);
49 if (paths
.Length
!= 2)
51 throw new ResourceException("AssemblyBundleResource does not support paths with more than 2 levels in depth. See " + resource
.Path
);
54 ResourceManager rm
= new ResourceManager(paths
[0], assembly
);
56 return new StringReader(rm
.GetString(paths
[1]));
59 public override TextReader
GetStreamReader(Encoding encoding
)
61 return GetStreamReader();
64 public override IResource
CreateRelative(string relativePath
)
66 throw new System
.NotImplementedException();
69 public override void Dispose()
73 private Assembly
ObtainAssembly(string assemblyName
)
77 return Assembly
.Load(assemblyName
);
81 String message
= String
.Format("The assembly {0} could not be loaded", assemblyName
);
82 throw new ResourceException(message
, ex
);