Exemplo n.º 1
0
		public IPhpConfiguration Global;   // can be null

		/// <summary>
		/// Creates a configuration context.
		/// </summary>
		/// <param name="local">Local configuration record or a <B>null</B> reference.</param>
		/// <param name="global">Local configuration record or a <B>null</B> reference.</param>
		public ConfigContextBase(IPhpConfiguration local, IPhpConfiguration global)
		{
			this.Local = local;
			this.Global = global;
		}
Exemplo n.º 2
0
		internal void SetConfigurations(IPhpConfiguration[]/*!*/ configurations)
		{
			Debug.Assert(!IsConfigurationLoaded && configurations != null);
			this._configurations = configurations;
		}
Exemplo n.º 3
0
        /// <summary>
		/// Finishes and validates the configuration. 
		/// Creates an array of library configurations and stores it to local and global config records.
		/// The first validated configuration is the global one, local ones follows in the order in which 
		/// the respective libraries has been loaded.
		/// </summary>
		/// <exception cref="ConfigurationErrorsException">Configuration is invalid.</exception>
		internal void ValidateNoLock()
		{
			List<PhpLibraryAssembly> libraries = new List<PhpLibraryAssembly>(applicationContext.GetLoadedLibraries());

			Debug.WriteLine("CONFIG", "Context.Validate: #desc = {0}", libraries.Count);

			// request can use only some of the libraries but we need to allocate space for all to allow
			// indexing by unique indices:
			IPhpConfiguration[] local_configs = new IPhpConfiguration[libraries.Count];
			IPhpConfiguration[] global_configs = new IPhpConfiguration[libraries.Count];

			if (!this.applicationContext.AssemblyLoader.ReflectionOnly)
			{
				foreach (PhpLibraryAssembly library in libraries)
				{
					PhpLibraryDescriptor descriptor = library.Descriptor;
					ConfigContextBase cfg_context;

					if (descriptor.ConfigurationSectionName != null)
					{
						Debug.Assert(sections.ContainsKey(descriptor.ConfigurationSectionName));
						cfg_context = sections[descriptor.ConfigurationSectionName].UserContext;
					}
					else
					{
						// creates a configuration records with default values or 
						// empty context if the library doesn't use configuration:
						cfg_context = descriptor.CreateConfigContext();
					}

					descriptor.Validate(cfg_context);

					local_configs[descriptor.UniqueIndex] = cfg_context.Local;
					global_configs[descriptor.UniqueIndex] = cfg_context.Global;
				}
			}
			
			global.Library.SetConfigurations(global_configs);
			local.Library.SetConfigurations(local_configs);

			global.Validate();
			local.Validate();
		}
Exemplo n.º 4
0
        /// <summary>
        /// Writes core configuration to given output.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <remarks>
        /// Configuration is traversed by reflection methods and all fields and its values are formatted to table.
        /// </remarks>
        private static void WriteConfiguration(TextWriter /*!*/ output)
        {
            ApplicationContext app_context = ScriptContext.CurrentContext.ApplicationContext;

            Debug.Assert(!app_context.AssemblyLoader.ReflectionOnly);

            string directive = CoreResources.GetString("info_directive");

            // script dependent configuration //

            output.Write(htmlSectionCaption, CoreResources.GetString("info_script_dependent"));
            output.Write(htmlTableStart);
            output.Write(HtmlEntireRowHeader("Core", 3));
            output.Write(HtmlHeaderRow(directive, CoreResources.GetString("info_script_value"), CoreResources.GetString("info_master_value")));

            // core:
            ReflectConfigSection(output, "", typeof(LocalConfiguration), Configuration.Local, Configuration.DefaultLocal);

            // libraries:
            foreach (PhpLibraryAssembly lib_assembly in app_context.GetLoadedLibraries())
            {
                IPhpConfiguration local    = Configuration.Local.GetLibraryConfig(lib_assembly.Descriptor);
                IPhpConfiguration @default = Configuration.DefaultLocal.GetLibraryConfig(lib_assembly.Descriptor);

                if (local != null)
                {
                    if (!local.GetType().IsDefined(typeof(NoPhpInfoAttribute), false))
                    {
                        output.Write(HtmlEntireRowHeader(HttpUtility.HtmlEncode(lib_assembly.Properties.Name), 3));
                        output.Write(HtmlHeaderRow(directive, CoreResources.GetString("info_script_value"), CoreResources.GetString("info_master_value")));
                        ReflectConfigSection(output, "", local.GetType(), local, @default);
                    }
                }
            }

            output.Write(htmlTableEnd);

            // script independent configuration //

            output.Write(htmlSectionCaption, CoreResources.GetString("info_shared"));
            output.Write(htmlTableStart);
            output.Write(HtmlEntireRowHeader("Core", 2));
            output.Write(HtmlHeaderRow(directive, CoreResources.GetString("info_value")));

            // core:
            ReflectConfigSection(output, "", typeof(GlobalConfiguration), Configuration.Global, null);

            // libraries:
            foreach (PhpLibraryAssembly lib_assembly in app_context.GetLoadedLibraries())
            {
                object config = Configuration.Global.GetLibraryConfig(lib_assembly.Descriptor);

                if (config != null)
                {
                    if (!config.GetType().IsDefined(typeof(NoPhpInfoAttribute), false))
                    {
                        output.Write(HtmlEntireRowHeader(HttpUtility.HtmlEncode(lib_assembly.Properties.Name), 2));
                        output.Write(HtmlHeaderRow(directive, CoreResources.GetString("info_value")));
                        ReflectConfigSection(output, "", config.GetType(), config, null);
                    }
                }
            }

            output.Write(htmlTableEnd);
        }