Added RedirectUsingNamedRoute
[castle.git] / Core / Castle.Core / Resource / AssemblyBundleResource.cs
blobbf1b0865dad0bc2114a891fa312637c1c79645c3
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Globalization;
19 using System.IO;
20 using System.Reflection;
21 using System.Resources;
22 using System.Text;
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;
36 this.ci = ci;
39 public override TextReader GetStreamReader()
41 Assembly assembly = ObtainAssembly(resource.Host);
43 string[] paths = resource.Path.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
45 if (paths.Length != 2)
47 throw new ResourceException("AssemblyBundleResource does not support paths with more than 2 levels in depth. See " + resource.Path);
50 ResourceManager rm = new ResourceManager(paths[0], assembly);
52 return new StringReader(rm.GetString(paths[1]));
55 public override TextReader GetStreamReader(Encoding encoding)
57 return GetStreamReader();
60 public override IResource CreateRelative(string relativePath)
62 throw new System.NotImplementedException();
65 public override void Dispose()
69 private Assembly ObtainAssembly(string assemblyName)
71 try
73 return Assembly.Load(assemblyName);
75 catch(Exception ex)
77 String message = String.Format("The assembly {0} could not be loaded", assemblyName);
78 throw new ResourceException(message, ex);