当前位置: 首页>>代码示例>>C#>>正文


C# IniConfigSource.Merge方法代码示例

本文整理汇总了C#中Nini.Config.IniConfigSource.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# IniConfigSource.Merge方法的具体用法?C# IniConfigSource.Merge怎么用?C# IniConfigSource.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nini.Config.IniConfigSource的用法示例。


在下文中一共展示了IniConfigSource.Merge方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeAndSave

		public void MergeAndSave ()
		{
			string fileName = "NiniConfig.ini";

			StreamWriter fileWriter = new StreamWriter (fileName);
			fileWriter.WriteLine ("[Pets]");
			fileWriter.WriteLine ("cat = Muffy"); // overwrite
			fileWriter.WriteLine ("dog = Rover"); // new
			fileWriter.WriteLine ("bird = Tweety");
			fileWriter.Close ();
			
			StringWriter writer = new StringWriter ();
			writer.WriteLine ("[Pets]");
			writer.WriteLine ("cat = Becky"); // overwrite
			writer.WriteLine ("lizard = Saurus"); // new
			writer.WriteLine ("[People]");
			writer.WriteLine (" woman = Jane");
			writer.WriteLine (" man = John");
			IniConfigSource iniSource = new IniConfigSource 
									(new StringReader (writer.ToString ()));

			IniConfigSource source = new IniConfigSource (fileName);

			source.Merge (iniSource);
			
			IConfig config = source.Configs["Pets"];
			Assert.AreEqual (4, config.GetKeys ().Length);
			Assert.AreEqual ("Becky", config.Get ("cat"));
			Assert.AreEqual ("Rover", config.Get ("dog"));
			Assert.AreEqual ("Saurus", config.Get ("lizard"));
		
			config = source.Configs["People"];
			Assert.AreEqual (2, config.GetKeys ().Length);
			Assert.AreEqual ("Jane", config.Get ("woman"));
			Assert.AreEqual ("John", config.Get ("man"));
			
			config.Set ("woman", "Tara");
			config.Set ("man", "Quentin");
			
			source.Save ();
			
			source = new IniConfigSource (fileName);
			
			config = source.Configs["Pets"];
			Assert.AreEqual (4, config.GetKeys ().Length);
			Assert.AreEqual ("Becky", config.Get ("cat"));
			Assert.AreEqual ("Rover", config.Get ("dog"));
			Assert.AreEqual ("Saurus", config.Get ("lizard"));
			
			config = source.Configs["People"];
			Assert.AreEqual (2, config.GetKeys ().Length);
			Assert.AreEqual ("Tara", config.Get ("woman"));
			Assert.AreEqual ("Quentin", config.Get ("man"));
			
			File.Delete  (fileName);
		}
开发者ID:JeffreyZksun,项目名称:gpstranslator,代码行数:56,代码来源:IniConfigSourceTests.cs

示例2: MergeItself

		public void MergeItself ()
		{
			StringWriter writer = new StringWriter ();
			writer.WriteLine ("[People]");
			writer.WriteLine (" woman = Jane");
			writer.WriteLine (" man = John");
			IniConfigSource iniSource = 
					new IniConfigSource (new StringReader (writer.ToString ()));
			
			iniSource.Merge (iniSource); // exception
		}
开发者ID:JeffreyZksun,项目名称:gpstranslator,代码行数:11,代码来源:ConfigSourceBaseTests.cs

示例3: BaseConfig

        public BaseConfig(string iniFileName)
        {
            source = new IniConfigSource(iniFileName);

            string mergedPath = string.Format("{0}.local", iniFileName);

            if (File.Exists(mergedPath))
            {
                var forMerge = new IniConfigSource(mergedPath);
                source.Merge(forMerge);
            }
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:12,代码来源:BaseConfig.cs

示例4: GetConfig

        // We call this from our plugin module to get our configuration
        public IConfig GetConfig()
        { 
            IConfig config = null;
            config = ServerUtils.GetConfig(ConfigFile, ConfigName);

            // Our file is not here? We can get one to bootstrap our plugin module
            if ( config == null )
            {
                IConfigSource remotesource = GetConfigSource();

                if (remotesource != null)
                {
                    IniConfigSource initialconfig = new IniConfigSource();
                    initialconfig.Merge (remotesource);
                    initialconfig.Save(ConfigFile);
                }

                config = remotesource.Configs[ConfigName];
            }

            return config;
        }
开发者ID:BogusCurry,项目名称:arribasim-dev,代码行数:23,代码来源:ServerConnector.cs

示例5: LoadConfig

        private IniConfigSource LoadConfig(string location)
        {
            IniConfigSource currentConfig = new IniConfigSource();
            List<string> currentConfigLines = new List<string>();
            string[] configLines = null;

            if (IsUrl(location))
            {
                // Web-based loading
                string responseStr;
                if (WebUtil.TryGetUrl(location, out responseStr))
                {
                    configLines = responseStr.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    m_log.Error("Failed to load web config file " + location + ": " + responseStr);
                }
            }
            else
            {
                // Local file loading
                try
                {
                    configLines = new List<string>(File.ReadAllLines(location)).ToArray();
                }
                catch (Exception ex)
                {
                    m_log.Error("Failed to load config file " + location + ": " + ex.Message);
                }
            }

            if (configLines != null)
            {
                for (int i = 0; i < configLines.Length; i++)
                {
                    string line = configLines[i].Trim();

                    if (line.StartsWith("Include "))
                    {
                        // Compile the current config lines, compile the included config file, and combine them
                        currentConfig.Merge(CompileConfig(currentConfigLines));
                        currentConfigLines.Clear();

                        string includeLocation = line.Substring(8).Trim().Trim(new char[] { '"' });

                        if (IsUrl(includeLocation))
                        {
                            IniConfigSource includeConfig = LoadConfig(includeLocation);
                            currentConfig.Merge(includeConfig);
                        }
                        else
                        {
                            string basepath = Path.GetFullPath(Util.configDir());

                            // Resolve relative paths with wildcards
                            string chunkWithoutWildcards = includeLocation;
                            string chunkWithWildcards = string.Empty;
                            int wildcardIndex = includeLocation.IndexOfAny(new char[] { '*', '?' });
                            if (wildcardIndex != -1)
                            {
                                chunkWithoutWildcards = includeLocation.Substring(0, wildcardIndex);
                                chunkWithWildcards = includeLocation.Substring(wildcardIndex);
                            }
                            string path = Path.Combine(basepath, chunkWithoutWildcards);
                            path = Path.GetFullPath(path) + chunkWithWildcards;
                            
                            string[] paths = Util.Glob(path);
                            foreach (string p in paths)
                            {
                                IniConfigSource includeConfig = LoadConfig(p);
                                currentConfig.Merge(includeConfig);
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(line) && !line.StartsWith(";"))
                    {
                        currentConfigLines.Add(line);
                    }
                }

                currentConfig.Merge(CompileConfig(currentConfigLines));
            }

            return currentConfig;
        }
开发者ID:openmetaversefoundation,项目名称:fortis-opensim,代码行数:86,代码来源:ConfigurationLoader.cs

示例6: LoadConfigSettings


//.........这里部分代码省略.........
                    secondaryIniFileName = startupConfig.GetString("secondaryIniFileName", secondaryIniFileName);
                }
            }

            if (!oldoptions)
            {
                if (mainIniDirectory != "")
                    basePath = mainIniDirectory;
                if (mainIniFileName != "")
                {
                    if (IsUri(mainIniFileName))
                    {
                        if (!sources.Contains(mainIniFileName))
                            sources.Add(mainIniFileName);
                    }
                    else
                    {
                        string mainIniFilePath = Path.Combine(mainIniDirectory, mainIniFileName);
                        if (!sources.Contains(mainIniFilePath))
                            sources.Add(mainIniFilePath);
                    }
                }

                if (secondaryIniFileName != "")
                {
                    if (IsUri(secondaryIniFileName))
                    {
                        if (!sources.Contains(secondaryIniFileName))
                            sources.Add(secondaryIniFileName);
                    }
                    else
                    {
                        string secondaryIniFilePath = Path.Combine(mainIniDirectory, secondaryIniFileName);
                        if (!sources.Contains(secondaryIniFilePath))
                            sources.Add(secondaryIniFilePath);
                    }
                }
            }

            IConfigSource m_config = new IniConfigSource();
            IConfigSource m_fakeconfig = new IniConfigSource();

            if (sources.Count == 0)
            {
                Console.WriteLine(string.Format("[CONFIG]: Could not load any configuration"));
                Console.WriteLine(
                    string.Format("[CONFIG]: Did you copy the " + defaultIniFile + ".example file to " + defaultIniFile +
                                  "?"));
                throw new NotSupportedException();
            }

            List<string> triedPaths = new List<string>();
            for (int i = 0; i < sources.Count; i++)
            {
                //Read all non .example files first, then read all the example ones

                if (File.Exists(sources[i]) &&
                    ReadConfig(sources[i], i, m_fakeconfig))
                    iniFileExists = true;
                else if (File.Exists(sources[i] + ".example") &&
                         ReadConfig(sources[i] + ".example", i, m_fakeconfig))
                    iniFileExists = true;
                AddIncludes(sources, basePath, ref i, ref triedPaths, m_fakeconfig);
            }

            //
            sources.Reverse();
            for (int i = 0; i < sources.Count; i++)
            {
                //Read all non .example files first, then read all the example ones

                if (File.Exists(sources[i]))
                    ReadConfig(sources[i], i, m_config);
                else if (File.Exists(sources[i] + ".example"))
                    ReadConfig(sources[i] + ".example", i, m_config);
            }

            // add override paramteres if they exist ONLY for standalone operation
            if (! mainIniFileName.Contains("GridServer"))
            {
                string  worldIniFilePath = Path.Combine(mainIniDirectory, worldIniFileName);
                if (File.Exists(worldIniFilePath))
                    ReadConfig(worldIniFilePath, 0, m_config);
            }

            FixDefines(ref m_config);

            if (!iniFileExists)
            {
                Console.WriteLine(string.Format("[CONFIG]: Could not load any configuration"));
                Console.WriteLine(string.Format("[CONFIG]: .. or Configuration possibly exists, but there was an error loading it!"));
                Console.WriteLine(string.Format("[CONFIG]: Configuration : " + mainIniDirectory+", "+mainIniFileName));
                throw new NotSupportedException();
            }
            // Make sure command line options take precedence
            if (argvSource != null)
                m_config.Merge(argvSource);

            return m_config;
        }
开发者ID:emperorstarfinder,项目名称:Virtual-Universe,代码行数:101,代码来源:ConfigurationLoader.cs

示例7: Main

        static int Main(string[] args)
        {
            ResultCode resultCode = 0;

            // use a configuration file to list all the sites you want to check
            // provide SMTP server information too

            var version = Assembly.GetEntryAssembly().GetName().Version;
            string startup = "LINKCHECKER " + version + " (c) Ian Mercer 2010 http://blog.abodit.com";

            Console.WriteLine(startup);
            Console.WriteLine("".PadLeft(startup.Length, '-'));
            Console.WriteLine();

            if (!File.Exists("LinkChecker.ini"))
            {
                Console.WriteLine("Please reinstall, you need both the .EXE and the .INI file");
                Console.WriteLine("See http://blog.abodit.com");
            }

            IConfigSource mainSource = new IniConfigSource("LinkChecker.ini");

            ArgvConfigSource argSource = new ArgvConfigSource(args);
            //argSource.AddSwitch("SMTP", "Server", "smtp");
            //argSource.AddSwitch("SMTP", "Port", "port");
            //argSource.AddSwitch("SMTP", "Username", "user");
            //argSource.AddSwitch("SMTP", "Password", "password");

            argSource.AddSwitch("Settings", "Domain", "d");                // a single domain

            argSource.AddSwitch("Settings", "Delay", "de");             //

            argSource.AddSwitch("Settings", "IncludeSelectors", "is");     // Exclude pages option
            argSource.AddSwitch("Settings", "ExcludeSelectors", "xs");     // Exclude pages option

            argSource.AddSwitch("Settings", "ExcludePages", "xp");         // Exclude pages option
            argSource.AddSwitch("Settings", "All", "a");                 //
            argSource.AddSwitch("Settings", "Pages", "pa");             //
            argSource.AddSwitch("Settings", "Seo", "s");                 //
            argSource.AddSwitch("Settings", "Changes", "c");         //
            argSource.AddSwitch("Settings", "Limit", "li");             //
            argSource.AddSwitch("Settings", "Dump", "du");               //  dump all text found
            argSource.AddSwitch("Settings", "Suggestions", "su");

            mainSource.Merge(argSource);

            //var SMTPConfig = mainSource.Configs["SMTP"];
            var config = mainSource.Configs["Settings"];

            //string SMTPServer = SMTPConfig.GetString("Server", "");
            //int SMTPPort = SMTPConfig.GetInt("Port", 25);
            //string SMTPUsername = SMTPConfig.GetString("Username", "");
            //string SMTPPassword = SMTPConfig.GetString("Password", "");

            //SMTPConfig.Set("Server", SMTPServer);
            //SMTPConfig.Set("Port", SMTPPort);
            //SMTPConfig.Set("Username", SMTPUsername);
            //SMTPConfig.Set("Password", SMTPPassword);

            int delayBetween = config.GetInt("Delay", 10);
            config.Set("Delay", delayBetween);

            string excludedPathSetting = config.GetString("ExcludePages", ""); //"");       // common duplicate pages / comments
            string excludedPaths = excludedPathSetting;
            config.Set("ExcludePages", excludedPaths);

            string includeSelector = config.GetString("IncludeSelectors", "head title,body");
            string excludeSelector = config.GetString("ExcludeSelectors", ".pageHeader,#header,.header,#footer,.footer,#sidebar,.sidebar," +                                                                        "#feedbackTab,#feedback,.feedback,#feedbackdialog," +
                                            "#smalltype,.share-links-footer,block-ec_blogs");
            config.Set("IncludeSelector", includeSelector);
            config.Set("ExcludeSelector", excludeSelector);

            string listPages = config.GetString("Pages", "").ToLower();
            if (listPages != "none" && listPages != "list") listPages = "error";
            config.Set("Pages", listPages);

            string seo = config.GetString("Seo", "").ToLower();
            if (seo != "none" && seo != "list") seo = "error";
            config.Set("Seo", seo);

            string changes = config.GetString("Changes", "").ToLower();
            if (changes != "none" && changes != "error") changes = "list";
            config.Set("Changes", changes);

            int limit = config.GetInt("Limit", 3000);               // 3000 pages limit by default

            string dumpFilePath = config.GetString("Dump");
            if (dumpFilePath != null)
                config.Set("Dump", dumpFilePath);

            bool showSuggestedLinks = !string.IsNullOrWhiteSpace(config.Get("Suggestions", ""));
            config.Set("Suggestions", showSuggestedLinks);

            string domainSingle = config.GetString("Domain", "");

            // Save any changes back to the config file
            // Don't do this because then they affect everyone after that ...
            //mainSource.Save();

            if (string.IsNullOrWhiteSpace(domainSingle))
//.........这里部分代码省略.........
开发者ID:tsunli,项目名称:LinkChecker,代码行数:101,代码来源:Program.cs

示例8: ExpandKeyValuesMerge

        public void ExpandKeyValuesMerge()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[web]");
            writer.WriteLine (" protocol = http");
            writer.WriteLine ("[server]");
            writer.WriteLine (" domain1 = ${web|protocol}://nini.sf.net/");
            IniConfigSource source = new IniConfigSource
                                    (new StringReader (writer.ToString ()));

            StringWriter newWriter = new StringWriter ();
            newWriter.WriteLine ("[web]");
            newWriter.WriteLine (" apache = Apache implements ${protocol}");
            newWriter.WriteLine ("[server]");
            newWriter.WriteLine (" domain2 = ${web|protocol}://nini.sf.net/");
            IniConfigSource newSource = new IniConfigSource
                                    (new StringReader (newWriter.ToString ()));
            source.Merge (newSource);
            source.ExpandKeyValues ();

            IConfig config = source.Configs["web"];
            Assert.AreEqual ("http", config.Get ("protocol"));
            Assert.AreEqual ("Apache implements http", config.Get ("apache"));
            config = source.Configs["server"];
            Assert.AreEqual ("http://nini.sf.net/", config.Get ("domain1"));
            Assert.AreEqual ("http://nini.sf.net/", config.Get ("domain2"));
        }
开发者ID:rwhitworth,项目名称:nini,代码行数:27,代码来源:ConfigSourceBaseTests.cs

示例9: LoadConfigValues

        /// <summary>
        /// Load in all the configuration values from the XMRM section of various configuration sources.
        /// 
        /// The order is:
        /// 1 - the Opensim application config file.
        /// 2 - opensim.ini
        /// 3 - The parameters passed in in the body of the text are parsed
        /// [4] - any application config file pointed to by one of the previous 3 configs.
        /// 
        /// Each set of config values overrides the previous so if "ShadowCopy" is set to "true" in the opensim config file, opensim.ini and
        /// in the script but "false" in the config file the final value will be false.
        /// </summary>
        /// <param name="script">The script to parse for information.</param>
        /// <returns>A config object with the values taken from the script.</returns>
        private IConfig LoadConfigValues(out string[] scriptArguments)
        {
            //Load in the arguments as command line arguments
            CommandLineConfig argConfig = new CommandLineConfig(ScriptText, true, "\n", " ");

            argConfig.AddSetting(XMRM, CONFIG_FILE, "f");
            argConfig.AddSetting(XMRM, CONFIG_FILE, "F");

            argConfig.AddSetting(XMRM, ASSEMBLY, "a");
            argConfig.AddSetting(XMRM, ASSEMBLY, "A");

            argConfig.AddSetting(XMRM, CLASS, "c");
            argConfig.AddSetting(XMRM, CLASS, "C");

            argConfig.AddSetting(XMRM, BASE_FOLDER, "b");
            argConfig.AddSetting(XMRM, BASE_FOLDER, "B");

            argConfig.AddFlag(XMRM, SHADOW_COPY, "s", false);
            argConfig.AddFlag(XMRM, SHADOW_COPY, "S", false);

            argConfig.AddFlag(XMRM, GOD, "g", false);
            argConfig.AddFlag(XMRM, GOD, "G", false);

            scriptArguments = argConfig.Argument.Length == 0 ? new string[0] : argConfig.Argument.Split(' ', '\n');

            //Merge the three guaranteed config sources
            IConfigSource config = new IniConfigSource();
            config.Merge(m_appConfig);
            config.Merge(m_config);
            config.Merge(argConfig);

            IConfig mrmConfig = config.Configs[XMRM];

            //If a config file is specified merge those values in
            if (mrmConfig.Contains(CONFIG_FILE)) {
                try {
                    IConfigSource fileSource = new DotNetConfigSource(mrmConfig.Get(CONFIG_FILE));
                    config.Merge(fileSource);
                } catch (Exception e) {
                    ErrorString = ("Unable to load config file from '" + mrmConfig.Get(CONFIG_FILE) + "'. " + e.Message);
                }
            }
            return config.Configs[XMRM];
        }
开发者ID:JohnMcCaffery,项目名称:XMRM,代码行数:58,代码来源:ScriptXMRM.cs

示例10: LoadConfig

        private static IniConfigSource LoadConfig(string location)
        {
            IniConfigSource currentConfig = new IniConfigSource();
            List<string> currentConfigLines = new List<string>();
            string[] configLines = null;

            if (IsUrl(location))
            {
                // Web-based loading
                string responseStr;
                if (WebUtil.TryGetUrl(location, out responseStr))
                {
                    configLines = responseStr.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    m_log.Error("Failed to load web config file " + location + ": " + responseStr);
                }
            }
            else
            {
                // Local file loading
                try
                {
                    configLines = new List<string>(File.ReadAllLines(location)).ToArray();
                }
                catch (Exception ex)
                {
                    m_log.Error("Failed to load config file " + location + ": " + ex.Message);
                }
            }

            if (configLines != null)
            {
                for (int i = 0; i < configLines.Length; i++)
                {
                    string line = configLines[i].Trim();

                    if (line.StartsWith("Include "))
                    {
                        // Compile the current config lines, compile the included config file, and combine them
                        currentConfig.Merge(CompileConfig(currentConfigLines));
                        currentConfigLines.Clear();

                        // Compile the included config file
                        string includeFilename = GetConfigPath(line.Substring(8).Trim());
                        IniConfigSource includeConfig = LoadConfig(includeFilename);

                        // Merge the included config with the curent config
                        currentConfig.Merge(includeConfig);
                    }
                    else if (!String.IsNullOrEmpty(line) && !line.StartsWith(";"))
                    {
                        currentConfigLines.Add(line);
                    }
                }

                currentConfig.Merge(CompileConfig(currentConfigLines));
            }

            return currentConfig;
        }
开发者ID:thoys,项目名称:simian,代码行数:62,代码来源:ConfigurationLoader.cs

示例11: migrate

        /// <summary>
        /// Applies any migrational changes from older to newer versions
        /// </summary>
        void migrate()
        {
            var newConfigSource = new IniConfigSource();
            newConfigSource.Merge(UserSettings);

            // For when user setting names were forced to lowercase
            foreach (IConfig config in newConfigSource.Configs)
                UserSettings.Configs[config.Name].Name = config.Name.ToLower();
        }
开发者ID:edwinr,项目名称:VPServices,代码行数:12,代码来源:VPS.Users.cs

示例12: StartGui

        /*
        public static Form StartGui(IConfig config, ViewerProxy form, Func<Form> createForm) {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) {
                Form f = createForm();
                StartProxyClient(config, form, f);
                f.ShowDialog();
                return f;
            } else {
                object createLock = new object();
                Form f = null;
                bool started = false;
                Thread t = new Thread(() => {
                    f = createForm();
                    lock (createLock)
                        MonitorChanged.PulseAll(createLock);
                    started = true;
                    StartProxyClient(config, form, f);
                    f.ShowDialog();
                });
                t.SetApartmentState(ApartmentState.STA);
                t.Begin();
                if (!started)
                    lock (createLock)
                        MonitorChanged.Wait(createLock);
                return f;
            }
        }

        private static void StartProxyClient(IConfig config, ViewerProxy form, Form f) {
            f.VisibleChanged += (source, args) => {
                if (!f.Visible)
                    return;
                bool autostartProxy = Get(config, "AutoStartProxy", false);
                bool autostartClient = Get(config, "AutoStartClient", false);

                if (autostartProxy || autostartClient)
                    while (!form.StartProxy())
                        form.ProxyConfig.ProxyPort++;
                if (autostartClient)
                    form.StartClient();
            };
        }
        */
        public static IConfigSource AddFile(IConfigSource config, string file)
        {
            if (File.Exists(file) && Path.GetExtension(file).ToUpper().Equals(".CONFIG")) {
                try {
                    DotNetConfigSource dotnet = new DotNetConfigSource(file);
                    //config.Merge(dotnet);
                    dotnet.Merge(config);
                    return dotnet;
                } catch (Exception e) {
                    Logger.Warn("Unable to load app configuration file " + file + "'." + e.Message + ".\n" + e.StackTrace);
                }
            } else if (File.Exists(file) && Path.GetExtension(file).ToUpper().Equals(".INI")) {
                try {
                    IniDocument doc = new IniDocument(file, IniFileType.WindowsStyle);
                    IniConfigSource ini = new IniConfigSource(doc);
                    //config.Merge(ini);
                    ini.Merge(config);
                    return ini;
                } catch (Exception e) {
                    Logger.Warn("Unable to load ini configuration file " + file + "'." + e.Message + ".\n" + e.StackTrace);
                }
            }
            return config;
        }
开发者ID:JohnMcCaffery,项目名称:ChimeraClean,代码行数:67,代码来源:Init.cs


注:本文中的Nini.Config.IniConfigSource.Merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。