public void SaveBindings(string filename)
        {
            if (_bindingsFile == null)
                _bindingsFile = new FullFileBuffer(filename);
            else
                _bindingsFile.Filename = filename;

            const string pattern = "^{0}";
            foreach (var bindingName in _bindings.GetValuesType1())
            {
                var binding = SerializeBiding(bindingName);

                //Replace existing line instead of duplicating declaration
                var lineno = _bindingsFile.LineMatching(pattern.format(bindingName));
                if (lineno < 0)
                    _bindingsFile.Append(binding);
                else
                    _bindingsFile.WriteLine(binding, lineno);
            }
            _bindingsFile.SaveToFile();
        }
 public void LoadBindings(string filename)
 {
     ClearAllBindings();
     foreach (var line in new StreamReader(filename).ReadLines())
     {
         string bindingName;
         var key = DeserializeBinding(line, out bindingName);
         if (key != null) AddBinding(bindingName, key);
     }
     _bindingsFile = new FullFileBuffer(filename);
 }
 public void SaveToFile()
 {
     var buffer = new FullFileBuffer(_filename);
     if (_map.ContainsKey("")) WriteSection("", buffer); // Settings without a section
     _map.Keys.Where(header => header != "").Each(header => WriteSection(header, buffer));
     buffer.SaveToFile();
 }
 private void WriteSection(string header, FullFileBuffer buffer)
 {
     if (header == null) return;
     if(!String.IsNullOrEmpty(header))
         buffer.Append("[{0}]".format(header));
     var section = _map[header];
     if(section == null) return;
     foreach (var key in section.Keys)
     {
         var value = section[key];
         buffer.Append("{0}{1}{2}".format(key, _delim, value));
     }
     buffer.Append("");
 }
        public void LoadFromFile()
        {
            Clear();
            var headerRegex = new Regex(HeaderPattern);
            var _buffer = new FullFileBuffer(_filename);

            var header = "";
            foreach (var line in _buffer)
            {
                if (headerRegex.HasNamedCapture(line, "header"))
                    header = headerRegex.GetNamedCapture(line, "header");
                else
                {
                    var keyvalue = line.Split(_delim, 2);

                    if (header == null) continue;
                    if (keyvalue.Length != 2) continue; // Poorly formed line

                    if (_trimWhitespace) keyvalue = keyvalue.Trim();
                    this[header, keyvalue[0]] = keyvalue[1];
                }
            }
        }