Represents a resource configuration associated with a controller.
		/// <summary>
		/// Creates an implementation of <see cref="IResource"/>
		/// based on the descriptor.
		/// <seealso cref="ResourceManager"/>
		/// <seealso cref="ResourceFacade"/>
		/// </summary>
		/// <param name="descriptor"></param>
		/// <param name="appAssembly"></param>
		/// <returns></returns>
		public IResource Create(ResourceDescriptor descriptor, Assembly appAssembly)
		{
			Assembly assembly = this.ResolveAssembly(descriptor.AssemblyName, appAssembly);
			CultureInfo cultureInfo = this.ResolveCulture(descriptor.CultureName);

			if (logger.IsDebugEnabled)
			{
				logger.DebugFormat("Creating resource name {0}, assembly {1}, resource {2}", 
				                   descriptor.Name, descriptor.AssemblyName, descriptor.ResourceName);
			}

			ResourceManager manager = new ResourceManager(descriptor.ResourceName, assembly, descriptor.ResourceType);
			return new ResourceFacade(manager, cultureInfo);
		}
示例#2
0
		/// <summary>
		/// Creates the resources and adds them to the <see cref="IControllerContext.Resources"/>.
		/// </summary>
		/// <param name="resources">The resources.</param>
		protected virtual void CreateResources(ResourceDescriptor[] resources)
		{
			if (resources == null || resources.Length == 0)
			{
				return;
			}

			Assembly typeAssembly = GetType().Assembly;

			IResourceFactory resourceFactory = engineContext.Services.ResourceFactory;

			foreach(ResourceDescriptor resDesc in resources)
			{
				if (ControllerContext.Resources.ContainsKey(resDesc.Name))
				{
					throw new MonoRailException("There is a duplicated entry on the resource dictionary. Resource entry name: " +
					                            resDesc.Name);
				}

				ControllerContext.Resources.Add(resDesc.Name, resourceFactory.Create(resDesc, typeAssembly));
			}
		}