예제 #1
0
        void IConfigurationSystem.Init()
        {
            lock (this)
            {
                if (_application == null)
                {
                    ConfigurationRecord machineConfig = null;
                    string machineConfigFilename      = MachineConfigurationFilePath;
                    _application = machineConfig = new ConfigurationRecord();
                    bool machineConfigExists = machineConfig.Load(machineConfigFilename);

                    if (!machineConfigExists)
                    {
                        // Load machine.config from embedded resource
                        System.Resources.ResourceManager resMgr = new System.Resources.ResourceManager("OpenNETCF.Configuration.machineconfig", System.Reflection.Assembly.GetExecutingAssembly());
                        string machineConfigXml    = resMgr.GetString("machine.config");
                        bool   machineConfigLoaded = machineConfig.LoadXml(machineConfigXml);
                    }

                    Uri appConfigFilename = AppConfigPath;

                    // test to see if a unit test config exists first
                    string unitTestConfig = appConfigFilename.LocalPath + UnitTestExtension;

                    if (File.Exists(unitTestConfig))
                    {
                        appConfigFilename = new Uri("file://" + unitTestConfig);
                    }

                    // Only load the app.config is machine.config exists
                    if (appConfigFilename != null)
                    {
                        _application = new ConfigurationRecord(machineConfig);
                        //jsm - Bug 80 - need to throw exception if app.config file doesn't exist
                        if (!_application.Load(appConfigFilename.ToString()))
                        {
                            throw new ConfigurationException("Unable to load application configuration file");
                        }
                    }
                }
            }
        }
        void IConfigurationSystem.Init()
        {
            lock (this)
            {
                if (_application == null)
                {
                    ConfigurationRecord machineConfig = null;
                    string machineConfigFilename      = MachineConfigurationFilePath;
                    Uri    appConfigFilename          = AppConfigPath;
                    _application = machineConfig = new ConfigurationRecord();
                    bool machineConfigExists = machineConfig.Load(machineConfigFilename);

                    // Only load the app.config is machine.config exists
                    if (machineConfigExists && appConfigFilename != null)
                    {
                        _application = new ConfigurationRecord(machineConfig);
                        _application.Load(appConfigFilename.ToString());
                    }
                }
            }
        }
		public ConfigurationRecord(ConfigurationRecord Parent)
		{
			results = new Hashtable();
			parent = Parent;
		}
예제 #4
0
 public ConfigurationRecord(ConfigurationRecord Parent)
 {
     results = new Hashtable();
     parent  = Parent;
 }
예제 #5
0
        private void ScanFactoriesRecursive(XmlTextReader reader, string configKey)
        {
            int depth = reader.Depth;

            StrictReadToNextElement(reader);
            while (reader.Depth == depth + 1)
            {
                switch (reader.Name)
                {
                case "sectionGroup":
                {
                    // Get the name of the current sectionGroup
                    string tagName = null;
                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name != "name")
                            {
                                ThrowUnrecognizedAttribute(reader);
                            }
                            tagName = reader.Value;
                        }
                        reader.MoveToElement();
                    }
                    // sectionGroup name attribute must have a value
                    CheckRequiredAttribute(tagName, "name", reader);
                    // Check the validity of the section name
                    VerifySectionName(tagName, reader);

                    // Add the current sectionGroup to the hashtable and process it
                    string tagKey = TagKey(configKey, tagName);
                    if (HaveFactoryEnum.Section == HaveFactory(tagName))
                    {
                        throw BuildConfigError("Tag name already defined", reader);
                    }
                    EnsureFactories[tagKey] = GroupSingleton;
                    ScanFactoriesRecursive(reader, tagKey);
                    continue;
                }

                case "section":
                {
                    string tagName  = null;
                    string typeName = null;

                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case "name":
                                tagName = reader.Value;
                                break;

                            case "type":
                                typeName = reader.Value;
                                break;

                            case "allowLocation":
                            case "allowDefinition":
                                break;

                            default:
                                ThrowUnrecognizedAttribute(reader);
                                break;
                            }
                        }
                        reader.MoveToElement();
                    }
                    CheckRequiredAttribute(tagName, "name", reader);
                    CheckRequiredAttribute(typeName, "type", reader);
                    VerifySectionName(tagName, reader);
                    string tagKey = TagKey(configKey, tagName);
                    if (HaveFactory(tagKey) != HaveFactoryEnum.NotFound)
                    {
                        throw BuildConfigError("Tag name already defined", reader);
                    }
                    EnsureFactories[tagKey] = typeName;
                    break;
                }

                case "remove":
                {
                    string tagName = null;
                    // Schema defines that <remove /> elements must have a name attribute
                    // so check to see if we have one and retrieve its value
                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name != "name")
                            {
                                ThrowUnrecognizedAttribute(reader);
                            }
                            tagName = reader.Value;
                        }
                        reader.MoveToElement();
                    }
                    // Enforce schema definition of remove element
                    if (tagName == null)
                    {
                        this.ThrowRequiredAttribute(reader, "name");
                    }
                    // Does the remove element have a valid name?
                    this.VerifySectionName(tagName, reader);

                    // If so, add it to the hashtable
                    string tagKey = ConfigurationRecord.TagKey(configKey, tagName);
                    if (HaveFactory(tagKey) != HaveFactoryEnum.Section)
                    {
                        throw BuildConfigError("Could not remove section handler", reader);
                    }
                    EnsureFactories[tagName] = RemovedFactorySingleton;
                    break;
                }

                case "clear":
                {
                    // Config schema definition states that clear element has no attributes
                    CheckForUnrecognizedAttributes(reader);
                    // Reset factories hashtable
                    factories          = null;
                    factoriesNoInherit = true;
                    break;
                }

                default:
                    ThrowUnrecognizedElement(reader);
                    break;
                }

                this.StrictReadToNextElement(reader);
                // Unrecognized children are not allowed
                if (reader.Depth > depth + 1)
                {
                    ThrowUnrecognizedElement(reader);
                }
            }
        }