示例#1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SectionData"/> class
        ///     from a previous instance of <see cref="SectionData"/>.
        /// </summary>
        /// <remarks>
        ///     Data is deeply copied
        /// </remarks>
        /// <param name="ori">
        ///     The instance of the <see cref="SectionData"/> class 
        ///     used to create the new instance.
        /// </param>
        /// <param name="searchComparer">
        ///     Search comparer.
        /// </param>
        public SectionData(SectionData ori, IEqualityComparer<string> searchComparer = null)
        {
            SectionName = ori.SectionName;

            _searchComparer = searchComparer;
            _leadingComments = new List<string>(ori._leadingComments);
            _keyDataCollection = new KeyDataCollection(ori._keyDataCollection, searchComparer ?? ori._searchComparer);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SectionData"/> class.
        /// </summary>
        public SectionData(string sectionName)
        {
            if (string.IsNullOrEmpty(sectionName))
                throw new ArgumentException("section name can not be empty");

            _leadingComments = new List<string>();
            _keyDataCollection = new KeyDataCollection();
            SectionName = sectionName;
        }
示例#3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SectionData"/> class.
        /// </summary>
        public SectionData(string sectionName, IEqualityComparer<string> searchComparer)
        {
            _searchComparer = searchComparer;

            if (string.IsNullOrEmpty(sectionName))
                throw new ArgumentException("section name can not be empty");

            _leadingComments = new List<string>();
            _keyDataCollection = new KeyDataCollection(_searchComparer);
            SectionName = sectionName;
        }
示例#4
0
        public void Load(KeyDataCollection collection)
        {
            if (collection.ContainsKey("force") == false)
            {
                return;
            }

            // load suppressed channels from the line
            string[] channels = collection["force"].Split(',');

            this.EnableChannels.AddRange(channels);
        }
示例#5
0
        public static string[] ParseLetter(string letterName)
        {
            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadFile(@"Conf\Letters.ini", Encoding.UTF8);
            KeyDataCollection letter = data[letterName];

            string[] values = new string[3];
            values[0] = letter["to"];
            values[1] = letter["subject"];
            values[2] = letter["body"].Replace("\\n\\r", "\n\r");
            return(values);
        }
示例#6
0
    private KnyttWorldInfo getWorldInfo(byte[] ini_bin, KeyDataCollection merge_to = null)
    {
        string           ini   = GDKnyttAssetManager.loadTextFile(ini_bin);
        GDKnyttWorldImpl world = new GDKnyttWorldImpl();

        world.loadWorldConfig(ini);
        if (merge_to != null)
        {
            merge_to.Merge(world.INIData["World"]);
        }
        return(world.Info);
    }
示例#7
0
 /// <summary>
 ///     Abstract Method that decides what to do in case we are trying to add a duplicated key to a section
 /// </summary>
 protected virtual void HandleDuplicatedKeyInCollection(string key, string value,
                                                        KeyDataCollection keyDataCollection, string sectionName)
 {
     if (!Configuration.AllowDuplicateKeys)
     {
         throw new ParsingException(
                   string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
     }
     if (Configuration.OverrideDuplicateKeys)
     {
         keyDataCollection[key] = value;
     }
 }
        public static CommandList FromIniSection(IniData ini, string sectionName, Configuration config)
        {
            KeyDataCollection sectionData = ini.Sections[sectionName];
            CommandList       list        = new CommandList();

            if (sectionData != null)
            {
                foreach (KeyData key in sectionData)
                {
                    string value = key.Value.Trim();
                    if (value.Length == 0)
                    {
                        Trace.TraceInformation("Ignore empty command '{0}'", key.KeyName);
                        continue;
                    }
                    Grammar grammar;
                    if (value[0] == '@')
                    {
                        string path = config.ResolveFilePath(value.Substring(1));
                        if (path == null)
                        {
                            Trace.TraceError("Cannot find the SRGS XML file '{0}', key: {1}", value.Substring(1), key.KeyName);
                            continue;
                        }

                        // load a SRGS XML file
                        XmlDocument doc = new XmlDocument();
                        doc.Load(path);

                        // If xml:lang in the file does not match the DSN's locale, the grammar cannot be loaded.
                        XmlAttribute xmlLang = doc.CreateAttribute("xml:lang");
                        xmlLang.Value = config.GetLocale().Name;
                        doc.DocumentElement.SetAttributeNode(xmlLang);

                        MemoryStream xmlStream = new MemoryStream();
                        doc.Save(xmlStream);
                        xmlStream.Flush(); //Adjust this if you want read your data
                        xmlStream.Position = 0;

                        grammar = new Grammar(xmlStream);
                    }
                    else
                    {
                        grammar = Phrases.createGrammar(Phrases.normalize(key.KeyName, config), config);
                    }
                    grammar.Name = key.KeyName;
                    list.commandsByPhrase[grammar] = value;
                }
            }
            return(list);
        }
示例#9
0
        static string LoadOrGetInput(KeyDataCollection section, string request)
        {
            var key = EscapeString(request);
            var x   = section[key];

            if (x != null)
            {
                return(x);
            }

            x            = GetInput(request);
            section[key] = x;
            return(x);
        }
示例#10
0
 private static bool BottlesExist(KeyDataCollection bottles, out int bottleCount)
 {
     bottleCount = 0;
     if (bottles["COUNT"] == null)
     {
         return(false);
     }
     if (!int.TryParse(bottles["COUNT"], out var parseResult))
     {
         return(false);
     }
     bottleCount = parseResult;
     return(bottleCount != 0);
 }
示例#11
0
 private static void SetValuesToAllBottles(KeyDataCollection bottlesInformation, int containerCounter, out List <Container> containerList)
 {
     containerList = new List <Container>();
     for (var counter = 1; counter <= containerCounter; counter++)
     {
         var iniKey       = "BOTTLE" + counter;
         var newContainer = new Container()
         {
             ContainerId    = counter,
             ContainerValue = bottlesInformation[iniKey]
         };
         containerList.Add(newContainer);
     }
 }
示例#12
0
        public AsteriskProvider(KeyDataCollection data) : base(data)
        {
            string host   = data["host"];
            int    port   = int.Parse(data["port"]);
            string user   = data["username"];
            string secret = data["secret"];
            string app    = data["app"];

            Client = new AriClient(new StasisEndpoint(host, port, user, secret), app);
            Client.OnConnectionStateChanged += Client_OnConnectionStateChanged;

            Client.OnStasisStartEvent += Client_OnStasisStartEvent;
            Client.OnStasisEndEvent   += Client_OnStasisEndEvent;
        }
示例#13
0
 private void DeleteIconFile(KeyDataCollection section)
 {
     if (section.ContainsKey("IconResource"))
     {
         var oldIcon = section["IconResource"];
         var imgPath = oldIcon.Split(',')[0];
         if (Path.GetExtension(imgPath) == ".ico")
         {
             var folderPath = Path.GetDirectoryName(filePath);
             File.Delete(Path.Combine(folderPath, imgPath));
         }
         section.RemoveKey("IconResource");
     }
 }
示例#14
0
文件: ListView.cs 项目: zy1911/JxqyHD
        public ListView(GuiItem parent,
                        Vector2 position,
                        Vector2 scrollBarPosition,
                        int width,
                        int height,
                        Texture baseTexture,
                        int rowCouunts,
                        KeyDataCollection config,
                        int slideBarWidth,
                        int slideBarHeight,
                        string slideButtonImage,
                        bool useTopLeftText = true)
            : base(parent, position, width, height, baseTexture)
        {
            _config = config;
            InitializeItems(useTopLeftText);
            var slideTexture       = Utils.GetAsf(null, slideButtonImage);
            var slideBaseTexture   = new Texture(slideTexture);
            var slideClikedTexture = new Texture(slideTexture, 0, 1);
            var slideButton        = new GuiItem(this,
                                                 Vector2.Zero,
                                                 slideBaseTexture.Width,
                                                 slideBaseTexture.Height,
                                                 slideBaseTexture,
                                                 null,
                                                 slideClikedTexture,
                                                 null,
                                                 Utils.GetSoundEffect("界-大按钮.wav"));

            _scrollBar = new ScrollBar(this,
                                       slideBarWidth,
                                       slideBarHeight,
                                       null,
                                       ScrollBar.ScrollBarType.Vertical,
                                       slideButton,
                                       scrollBarPosition,
                                       0,
                                       rowCouunts - 1 - 2,
                                       0);
            _scrollBar.Scrolled += delegate(object arg1, ScrollBar.ScrolledEvent arg2)
            {
                if (Scrolled != null)
                {
                    Scrolled(this, new ListScrollEvent(arg2.Value));
                }
            };

            MouseScrollUp   += (arg1, arg2) => _scrollBar.Value -= 1;
            MouseScrollDown += (arg1, arg2) => _scrollBar.Value += 1;
        }
示例#15
0
 public void LoadIniData(KeyDataCollection keys)
 {
     foreach (var data in keys)
     {
         if (elementDict.TryGetValue(data.KeyName, out var element))
         {
             element.SetValue(element.Options.Parser.ParseObject(data.Value));
         }
         else
         {
             Debug.LogWarning($"Unknown key {data.KeyName} in section! Ignoring...");
         }
     }
 }
        private void WriteKeyValueData(KeyDataCollection keyDataCollection, StringBuilder sb)
        {
            foreach (KeyData keyData in keyDataCollection)
            {
                // Add a blank line if the key value pair has comments
                if (keyData.Comments.Count > 0) sb.AppendLine();

                // Write key comments
                WriteComments(keyData.Comments, sb);

                //Write key and value
                sb.AppendLine(string.Format("{0}{3}{1}{3}{2}", keyData.KeyName, Configuration.KeyValueAssigmentChar, keyData.Value, Configuration.AssigmentSpacer));
            }
        }
示例#17
0
        private void SetItem(string section, string key, string s)
        {
            KeyDataCollection keys = _data.Sections[section];

            if (keys == null)
            {
                SectionData secData = new SectionData(section);
                secData.Keys[key] = s;
                _data.Sections.Add(secData);
            }
            else
            {
                keys[key] = s;
            }
        }
示例#18
0
        public PinballXSystem(KeyDataCollection data, ISettingsManager settingsManager)
            : this(settingsManager)
        {
            var systemType = data["SystemType"];
            if ("0".Equals(systemType)) {
                Type = Platform.PlatformType.Custom;
            } else if ("1".Equals(systemType)) {
                Type = Platform.PlatformType.VP;
            } else if ("2".Equals(systemType)) {
                Type = Platform.PlatformType.FP;
            }
            Name = data["Name"];

            SetByData(data);
        }
示例#19
0
        public static bool GetBool(this KeyDataCollection settings, string keyName, bool defaultVal = false)
        {
            if (!settings.ContainsKey(keyName))
            {
                settings.AddKey(CreateKeyData(keyName, defaultVal.ToString()));
                Write();
            }
            bool successful = StrToBool(settings[keyName], out bool result, defaultVal);

            if (!successful)
            {
                Logger.Warning($"Unable to parse {keyName} with value {settings[keyName]} as a boolean, using default value of {defaultVal} instead.");
            }
            return(result);
        }
示例#20
0
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            bool flag = keyDataCollection.ContainsKey(key);

            if (flag)
            {
                this.HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                keyDataCollection.AddKey(key, value);
            }
            keyDataCollection.GetKeyData(key).Comments = this._currentCommentListTemp;
            this._currentCommentListTemp.Clear();
        }
示例#21
0
 protected override void loadFromINI(KeyDataCollection data)
 {
     base.loadFromINI(data);
     FormattedArea     = new KnyttPoint(getIntINIValue(data, "XMap"), getIntINIValue(data, "YMap"));
     FormattedPosition = new KnyttPoint(getIntINIValue(data, "XPos"), getIntINIValue(data, "YPos"));
     Save      = getBoolINIValue(data, "Save", false);
     StopMusic = getBoolINIValue(data, "StopMusic", true);
     Quantize  = getBoolINIValue(data, "Quantize", true);
     StopMusic = getBoolINIValue(data, "StopMusic", false);
     Cutscene  = getStringINIValue(data, "Cutscene");
     FlagOn    = JuniValues.Flag.Parse(getStringINIValue(data, "FlagOn"));
     FlagOff   = JuniValues.Flag.Parse(getStringINIValue(data, "FlagOff"));
     Coin      = getIntINIValue(data, "Coin");
     Delay     = getIntINIValue(data, "Time");
 }
示例#22
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection" /> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData" /> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection" /> is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
示例#23
0
        /// <summary>
        /// Creates config file and set default values.
        /// </summary>
        public static void InitConfig()
        {
            if (!File.Exists(file))
            {
                var               parser  = new FileIniDataParser();
                IniData           newData = new IniData();
                KeyDataCollection kdc     = newData[section];

                kdc["autosave"]       = "disabled";
                kdc["gameDir"]        = @"C:\Program Files (x86)\Steam\steamapps\common\Guns of Icarus Online\";
                kdc["minimizeToTray"] = "false";

                parser.WriteFile(file, newData);
                Debug.WriteLine("Config.InitConfig(): New config with default values.");
            }
        }
        public static CommandList FromIniSection(IniData ini, string sectionName)
        {
            KeyDataCollection sectionData = ini.Sections[sectionName];
            CommandList       list        = new CommandList();

            if (sectionData != null)
            {
                foreach (KeyData key in sectionData)
                {
                    Grammar grammar = new Grammar(new GrammarBuilder(key.KeyName));
                    grammar.Name = key.KeyName;
                    list.commandsByPhrase[grammar] = key.Value.Trim();
                }
            }
            return(list);
        }
示例#25
0
        public void LoadConfiguration()
        {
            var     parser = new FileIniDataParser();
            IniData data   = parser.ReadFile("config.ini");

            KeyDataCollection keyValue = data["UTCOffset"];

            TimeZone = keyValue["timezone"];

            keyValue = data["Position"];
            Left     = TryParseDouble(keyValue["left"]) ?? 0;
            Top      = TryParseDouble(keyValue["top"]) ?? 0;

            keyValue = data["Color"];
            Color    = (Color)ColorConverter.ConvertFromString(keyValue["color"]);
        }
示例#26
0
 internal static IEnumerable <string> ReadValues(this KeyDataCollection collection, string target)
 {
     if (collection == null)
     {
         return(new List <string>());
     }
     try
     {
         var raw = collection[target];
         return(raw?.Split(',').Select(s => s.Trim().TrimEnd(',')) ?? new List <string>());
     }
     catch
     {
         return(new List <string>());
     }
 }
示例#27
0
        /// <summary>
        /// Get value from user settings.
        /// </summary>
        private string GetValue(string section, string name)
        {
            KeyDataCollection keyDataCollection = userSettings[section];

            if (keyDataCollection != null)
            {
                string key = keyDataCollection[name];
                if (key != null)
                {
                    return(key);
                }
            }

            Debug.LogErrorFormat("Failed to get ({0},{1}) for mod {2}.", section, name, mod.Title);
            return(null);
        }
示例#28
0
        private string GetValue(string section, string key)
        {
            if (!_data.Sections.ContainsSection(section))
            {
                throw new SectionNotFoundException(section);
            }

            KeyDataCollection keyMap = _data[section];;

            if (!keyMap.ContainsKey(key))
            {
                throw new KeyNotFoundException(key);
            }

            return(keyMap[key]);
        }
示例#29
0
        public void ReadConfig()
        {
            var               parser    = new FileIniDataParser();
            IniData           ini       = parser.ReadFile("config.ini");
            KeyDataCollection getRemove = ini["WindowsFetch_Remove"];
            int               i         = 0;

            foreach (KeyData _getRemove in getRemove)
            {
                remove[i] = Int32.Parse(_getRemove.Value);
                i++;
            }
            _default = Boolean.Parse(ini["WindowsFetch"]["default"]);
            picture  = ini["WindowsFetch"]["picture"];
            domain   = Boolean.Parse(ini["WindowsFetch"]["remove_domain"]);
        }
示例#30
0
    /// <summary>
    /// Method to prevent leaking KeyDataCollection to calling code
    /// </summary>
    /// <returns>The dictionary converted from a KeyDataCollection.</returns>
    /// <param name="keyDataCollection">Key data collection.</param>
    private KeyDataCollection DictionaryToKeyDataCollection(IDictionary <string, string> data)
    {
        if (data == null)
        {
            return(null);
        }

        KeyDataCollection result = new KeyDataCollection();

        foreach (KeyValuePair <string, string> kvp in data)
        {
            result.AddKey(kvp.Key, kvp.Value);
        }

        return(result);
    }
示例#31
0
    /// <summary>
    /// Method to prevent leaking KeyDataCollection to calling code
    /// </summary>
    /// <returns>The dictionary converted from a KeyDataCollection.</returns>
    /// <param name="keyDataCollection">Key data collection.</param>
    private IDictionary <string, string> KeyDataCollectionToDictionary(KeyDataCollection keyDataCollection)
    {
        if (keyDataCollection == null)
        {
            return(null);
        }

        IDictionary <string, string> result = new Dictionary <string, string>(keyDataCollection.Count);

        foreach (KeyData keyData in keyDataCollection)
        {
            result[keyData.KeyName] = keyData.Value;
        }

        return(result);
    }
示例#32
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
示例#33
0
        private void WriteKeyValueData(KeyDataCollection keyDataCollection, StringBuilder sb)
        {
            foreach (KeyData keyData in keyDataCollection)
            {
                // Add a blank line if the key value pair has comments
                if (keyData.Comments.Count > 0)
                {
                    sb.AppendLine();
                }

                // Write key comments
                WriteComments(keyData.Comments, sb);

                //Write key and value
                sb.AppendLine(string.Format("{0}{3}{1}{3}{2}", keyData.KeyName, Configuration.KeyValueAssigmentChar, keyData.Value, Configuration.AssigmentSpacer));
            }
        }
示例#34
0
        public void RemoveSectionValue(string SectionName, string val)
        {
            KeyDataCollection SectionCollection = GetConfigSection(SectionName);

            if (SectionCollection == null)
            {
                return;
            }
            //iterate through all the index card names
            foreach (KeyData key in SectionCollection)
            {
                if (key.Value == val)
                {
                    SectionCollection.RemoveKey(key.KeyName);
                }
            }
        }
示例#35
0
        private static void InitConfig()
        {
            if (!File.Exists(filename))
            {
                var               parser  = new FileIniDataParser();
                IniData           newData = new IniData();
                KeyDataCollection kdc     = newData[section];

                kdc["start_in_tray"]   = "true";
                kdc["notify_startup"]  = "true";
                kdc["notify_autosave"] = "true";
                kdc["autosave_limit"]  = "40";

                parser.WriteFile(filename, newData);
                Debug.WriteLine("Config.InitConfig(): New config with default values.");
            }
        }
示例#36
0
        public void check_merge_keys()
        {
            var keys1 = new KeyDataCollection();
            keys1.AddKey( "key1", "value1");
            keys1.AddKey( "key2", "value2");
            keys1.AddKey( "key3", "value3");

            var keys2 = new KeyDataCollection();
            keys2.AddKey("key1", "value11");
            keys2.AddKey("key4", "value4");

            keys1.Merge(keys2);

            Assert.That(keys1["key1"], Is.EqualTo("value11"));
            Assert.That(keys1["key2"], Is.EqualTo("value2"));
            Assert.That(keys1["key3"], Is.EqualTo("value3"));
            Assert.That(keys1["key4"], Is.EqualTo("value4"));
        }
示例#37
0
        public void test()
        {
            var col = new KeyDataCollection();
            col.AddKey("key1");

            Assert.That(col["key1"], Is.Empty);


            col.AddKey("key2", "value2");

            Assert.That(col["key2"], Is.EqualTo("value2"));

            var keyData = new KeyData("key3");
            keyData.Value = "value3";
            col.AddKey(keyData);

            Assert.That(col["key3"], Is.EqualTo("value3"));
        }
示例#38
0
 public PinballXSystem(Platform.PlatformType type, KeyDataCollection data, ISettingsManager settingsManager)
     : this(settingsManager)
 {
     Type = type;
     switch (type) {
         case Platform.PlatformType.VP:
             Name = "Visual Pinball";
             break;
         case Platform.PlatformType.FP:
             Name = "Future Pinball";
             break;
         case Platform.PlatformType.Custom:
             Name = "Custom";
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(type), type, null);
     }
     SetByData(data);
 }
示例#39
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="section"></param>
		void Download ( BuildContext context, KeyDataCollection section, BuildResult result )
		{
			Log.Message("Downloading...");

			foreach ( var keyValue in section ) {

				if (Path.IsPathRooted(keyValue.KeyName)) {
					throw new BuildException(string.Format("Rooted paths are not allowed: {0}", keyValue.KeyName));
				}
				
				var fullPath	=	Path.Combine( context.Options.FullInputDirectory, keyValue.KeyName );
				var urlName		=	keyValue.Value;

				Log.Message("  {0} -> {1}", urlName, keyValue.KeyName);

				try {
					
					DownloadIfModified( urlName, fullPath);
					 
				} catch ( WebException wex ) {
					Log.Error("{0} : {1}", keyValue.KeyName, wex.Message );
					result.Failed++;
				}
			}
		}
示例#40
0
        private void WriteKeyValueData(KeyDataCollection keyDataCollection, StringBuilder sb)
        {


            foreach (KeyData keyData in keyDataCollection)
            {
                //Write key comments
                WriteComments(keyData.Comments, sb);

                //Write key and value
                sb.AppendLine(string.Format("{0} {1} {2}", keyData.KeyName, Configuration.KeyValueAssigmentChar, keyData.Value));
            }
        }
示例#41
0
		public SectionData(SectionData ori) {
			mComments = new List<string>(ori.mComments);
			mKeyDataCollection = new KeyDataCollection(ori.mKeyDataCollection);
		}
示例#42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SectionData"/> class.
 /// </summary>
 public SectionData(string sectionName)
 {
     _comments = new List<string>();
     _keyDataCollection = new KeyDataCollection();
     SectionName = sectionName;
 }
示例#43
0
 /// <summary>
 ///     Abstract Method that decides what to do in case we are trying to add a duplicated key to a section
 /// </summary>
 protected virtual void HandleDuplicatedKeyInCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
 {
     if (!Configuration.AllowDuplicateKeys)
     {
         throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
     }
     else if(Configuration.OverrideDuplicateKeys)
     {
         keyDataCollection[key] = value;
     }
 }
示例#44
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained. 
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
示例#45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SectionData"/> class
 /// from a previous instance of <see cref="SectionData"/>.
 /// </summary>
 /// <remarks>
 /// Data is deeply copied
 /// </remarks>
 /// <param name="ori">
 /// The instance of the <see cref="SectionData"/> class 
 /// used to create the new instance.</param>
 public SectionData(SectionData ori)
 {
     _leadingComments = new List<string>(ori._leadingComments);
     _keyDataCollection = new KeyDataCollection(ori._keyDataCollection);
 }
示例#46
0
 /// <summary>
 ///     Initializes a new IniData instance using a previous
 ///     <see cref="SectionDataCollection"/>.
 /// </summary>
 /// <param name="sdc">
 ///     <see cref="SectionDataCollection"/> object containing the
 ///     data with the sections of the file
 /// </param>
 public IniData(SectionDataCollection sdc)
 {
     _sections = (SectionDataCollection)sdc.Clone();
     Global = new KeyDataCollection();
     SectionKeySeparator = '.';
 }
示例#47
0
 /// <summary>
 ///     Initializes a new IniData instance using a previous
 ///     <see cref="SectionDataCollection"/>.
 /// </summary>
 /// <param name="sdc">
 ///     <see cref="SectionDataCollection"/> object containing the
 ///     data with the sections of the file
 /// </param>
 public IniData(SectionDataCollection sdc)
 {
     _sections = (SectionDataCollection)sdc.Clone();
     Global = new KeyDataCollection();
 }
示例#48
0
 /// <summary>
 ///     Merges the given global values into this globals by overwriting existing values.
 /// </summary>
 private void MergeGlobal(KeyDataCollection globals)
 {
     foreach(var globalValue in globals)
     {
         Global[globalValue.KeyName] = globalValue.Value;
     }
 }
示例#49
0
		private static string iniValue(KeyDataCollection sec, string key) {
			return sec[key];
		}
示例#50
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained. 
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section

                if (!Configuration.AllowDuplicateKeys)
                {
                    throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
                }
                else if(Configuration.OverrideDuplicateKeys)
                {
                    keyDataCollection[key] = value;
                }
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
 protected override void HandleDuplicatedKeyInCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
 {
     keyDataCollection[key] += Configuration.ConcatenateSeparator + value;
 }