示例#1
0
        public void SambaLoadAsStandard()
        {
            IniDocument doc = new IniDocument();

            Assert.Throws <IniException>(() =>
            {
                var filePath = "Save.ini";
                var stream   = new FileStream(filePath, FileMode.Create);

                // Create a new document and save to stream
                doc.FileType = IniFileType.SambaStyle;
                var section  = new IniSection("Pets");
                section.Set("my comment");
                section.Set("dog", "rover");
                doc.Sections.Add(section);
                doc.Save(stream);
                stream.Close();

                var iniDoc = new IniDocument {
                    FileType = IniFileType.Standard
                };
                iniDoc.Load(filePath);

                File.Delete(filePath);
            });
        }
示例#2
0
        public void SaveAsMysqlStyle()
        {
            string     filePath = "Save.ini";
            FileStream stream   = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();

            doc.FileType = IniFileType.MysqlStyle;
            IniSection section = new IniSection("Pets");

            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            StringWriter writer = new StringWriter();

            writer.WriteLine("[Pets]");
            writer.WriteLine("# my comment");
            writer.WriteLine("dog = rover");

            StreamReader reader = new StreamReader(filePath);

            Assert.AreEqual(writer.ToString(), reader.ReadToEnd());
            reader.Close();

            IniDocument iniDoc = new IniDocument();

            iniDoc.FileType = IniFileType.MysqlStyle;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
示例#3
0
        static void Main(string[] args)
        {
            // Create a new instance of IniDocument
            IniDocument document = new IniDocument();

            document.Load("Sample.ini");

            // Make some changes
            document.Sections["First"].Parameters.Add(
                new IniParameter("Property3", 512)
                );

            // Change syntax and formatting settings
            document.SyntaxDefinition = new IniSyntaxDefinition()
            {
                CommentStartChar = '#'
            };

            // Write out
            document.Save(Console.Out, new IniWriterFormattingSettings {
                SortParameters = true
            });

            // Wait for a key
            Console.ReadLine();
        }
示例#4
0
文件: AppConfig.cs 项目: sgryjp/azuki
        /// <summary>
        /// Loads application config file.
        /// </summary>
        public static void Load()
        {
            int width, height;

            try
            {
                using (var file = new StreamReader(IniFilePath, Encoding.UTF8))
                    Ini.Load(file);

                int    fontSize = Ini.GetInt("Default", "FontSize", 1, Int32.MaxValue, FontInfo.Size);
                string fontName = Ini.Get("Default", "Font", FontInfo.Name);
                width  = Ini.GetInt("Default", "WindowWidth", 100, Int32.MaxValue, WindowSize.Width);
                height = Ini.GetInt("Default", "WindowHeight", 100, Int32.MaxValue, WindowSize.Height);

                AppConfig.FontInfo                      = new FontInfo(fontName, fontSize, FontStyle.Regular);
                AppConfig.WindowSize                    = new Size(width, height);
                AppConfig.WindowMaximized               = Ini.Get("Default", "WindowMaximized", false);
                AppConfig.TabPanelEnabled               = Ini.Get("Default", "TabPanelEnabled", false);
                AppConfig.UseScreenLineNumber           = Ini.Get("Default", "UseScreenLineNumber", false);
                AppConfig.DrawsEolCode                  = Ini.Get("Default", "DrawsEolCode", true);
                AppConfig.DrawsFullWidthSpace           = Ini.Get("Default", "DrawsFullWidthSpace", true);
                AppConfig.DrawsSpace                    = Ini.Get("Default", "DrawsSpace", true);
                AppConfig.DrawsTab                      = Ini.Get("Default", "DrawsTab", true);
                AppConfig.DrawsEofMark                  = Ini.Get("Default", "DrawsEofMark", false);
                AppConfig.HighlightsCurrentLine         = Ini.Get("Default", "HighlightsCurrentLine", true);
                AppConfig.HighlightsMatchedBracket      = Ini.Get("Default", "HighlightsMatchedBracket", true);
                AppConfig.ShowsLineNumber               = Ini.Get("Default", "ShowsLineNumber", true);
                AppConfig.ShowsHRuler                   = Ini.Get("Default", "ShowsHRuler", false);
                AppConfig.ShowsDirtBar                  = Ini.Get("Default", "ShowsDirtBar", false);
                AppConfig.TabWidth                      = Ini.GetInt("Default", "TabWidth", 0, 100, 8);
                AppConfig.LinePadding                   = Ini.GetInt("Default", "LinePadding", 1, 100, 1);
                AppConfig.LeftMargin                    = Ini.GetInt("Default", "LeftMargin", 0, 100, 1);
                AppConfig.TopMargin                     = Ini.GetInt("Default", "TopMargin", 0, 100, 1);
                AppConfig.ViewType                      = Ini.Get("Default", "ViewType", ViewType.Proportional);
                AppConfig.UsesTabForIndent              = Ini.Get("Default", "UsesTabForIndent", true);
                AppConfig.UnindentsWithBackspace        = Ini.Get("Default", "UnindentsWithBackspace", false);
                AppConfig.ConvertsFullWidthSpaceToSpace = Ini.Get("Default", "ConvertsFullWidthSpaceToSpace", false);
                AppConfig.HRulerIndicatorType           = Ini.Get("Default", "HRulerIndicatorType", HRulerIndicatorType.Segment);
                AppConfig.ScrollsBeyondLastLine         = Ini.Get("Default", "ScrollsBeyondLastLine", true);
                AppConfig.MruFiles.Load(Ini.Get("Default", "Mru", ""));

                UserPref.Antialias               = Ini.Get("Default", "Antialias", UserPref.Antialias);
                UserPref.AutoScrollMargin        = Ini.Get("Default", "AutoScrollMargin", UserPref.AutoScrollMargin);
                UserPref.CopyLineWhenNoSelection = Ini.Get("Default", "CopyLineWhenNoSelection", UserPref.CopyLineWhenNoSelection);
                UserPref.UseTextForEofMark       = Ini.Get("Default", "UseTextForEofMark", UserPref.UseTextForEofMark);
            }
            catch
            {}
        }
示例#5
0
        private void Load(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                if (File.Exists(fileName) == false)
                {
                    Assembly         assembly  = this.GetType().Assembly;
                    System.IO.Stream smEmbeded = assembly.GetManifestResourceStream("ConfigManager.Config.记录曲线.rhhcfg");


                    byte[] data = new byte[smEmbeded.Length];

                    smEmbeded.Read(data, 0, data.Length);


                    //建立目录

                    string dir = Path.GetDirectoryName(fileName);
                    if (Directory.Exists(dir) == false)
                    {
                        Directory.CreateDirectory(dir);
                    }


                    File.WriteAllBytes(fileName, data);


                    smEmbeded.Close();
                }
            }
            IniDocument ini = new IniDocument();

            ini.Load(fileName);
            int num = ini.GetInt("记录曲线类型", "数目", 0);

            for (int i = 0; i < num; i++)
            {
                CurveGroup grp = new CurveGroup(ini, i);
                if (grp.IsValid == false)
                {
                    continue;
                }

                if (dicCurveGrp.ContainsKey(grp.Name) == false)
                {
                    dicCurveGrp.Add(grp.Name, grp);
                }
            }
        }
示例#6
0
 private void LoadLauncherConfig()
 {
     if (File.Exists(ProjectManager.Instance.ThisProject.LauncherIni) && new FileInfo(ProjectManager.Instance.ThisProject.LauncherIni).Length > 0L)
     {
         foreach (Section section in IniDocument.Load(File.ReadLines(ProjectManager.Instance.ThisProject.LauncherIni)).get_Sections())
         {
             this._buttons.PopulateUserControls(section);
         }
         int num = (int)MessageBox.Show("Project loading completed.", "Success.");
     }
     else
     {
         int num1 = (int)MessageBox.Show("The editor was set to defaults.", "This app is not in PAL format.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
示例#7
0
        private void Load(string fileName)
        {
            if (File.Exists(fileName) == false)
             {
                 if (File.Exists(fileName) == false)
                 {
                     Assembly assembly = this.GetType().Assembly;
                     System.IO.Stream smEmbeded = assembly.GetManifestResourceStream("ConfigManager.Config.记录曲线.rhhcfg");

                     byte[] data = new byte[smEmbeded.Length];

                     smEmbeded.Read(data, 0, data.Length);

                     //建立目录

                     string dir = Path.GetDirectoryName(fileName);
                     if (Directory.Exists(dir) == false)
                     {
                         Directory.CreateDirectory(dir);
                     }

                     File.WriteAllBytes(fileName, data);

                     smEmbeded.Close();
                 }
             }
             IniDocument ini = new IniDocument();
             ini.Load(fileName);
             int num = ini.GetInt("记录曲线类型", "数目", 0);
             for (int i = 0; i < num; i++)
             {
                 CurveGroup grp = new CurveGroup(ini, i);
                 if (grp.IsValid == false) continue;

                 if (dicCurveGrp.ContainsKey(grp.Name) == false)
                 {
                     dicCurveGrp.Add(grp.Name, grp);
                 }
             }
        }
示例#8
0
        static void Main(string[] args)
        {
            // Create a new instance of IniDocument
            IniDocument document = new IniDocument();
            document.Load("Sample.ini");

            // Make some changes
            document.Sections["First"].Parameters.Add(
                new IniParameter("Property3", 512)
            );

            // Change syntax and formatting settings
            document.SyntaxDefinition = new IniSyntaxDefinition() {
                CommentStartChar = '#'
            };

            // Write out
            document.Save(Console.Out);

            // Wait for a key
            Console.ReadLine();
        }
示例#9
0
        private static IReadOnlyDictionary <string, string> ReadAsDictionary(string fileName)
        {
            IniDocument doc = IniDocument.Load(File.ReadLines(fileName));

            Dictionary <string, string> result = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (var section in doc.Sections)
            {
                foreach (var record in section.Records)
                {
                    if (result.ContainsKey(record.Name))
                    {
                        result[record.Name] = record.Value;
                    }
                    else
                    {
                        result.Add(record.Name, record.Value);
                    }
                }
            }

            return(result);
        }
示例#10
0
        public void SambaLoadAsStandard()
        {
            string     filePath = "Save.ini";
            FileStream stream   = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();

            doc.FileType = IniFileType.SambaStyle;
            IniSection section = new IniSection("Pets");

            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            IniDocument iniDoc = new IniDocument();

            iniDoc.FileType = IniFileType.Standard;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
示例#11
0
        private void Load(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                if (File.Exists(fileName) == false)
                {
                    Assembly         assembly  = this.GetType().Assembly;
                    System.IO.Stream smEmbeded = assembly.GetManifestResourceStream("ConfigManager.Config.设备.rhhcfg");


                    byte[] data = new byte[smEmbeded.Length];

                    smEmbeded.Read(data, 0, data.Length);


                    //建立目录

                    string dir = Path.GetDirectoryName(fileName);
                    if (Directory.Exists(dir) == false)
                    {
                        Directory.CreateDirectory(dir);
                    }


                    File.WriteAllBytes(fileName, data);


                    smEmbeded.Close();
                }
            }
            IniDocument ini = new IniDocument();

            ini.Load(fileName);
            int num = ini.GetInt("设备", "数目", 0);

            for (int i = 0; i < num; i++)
            {
                HHDeviceGrp devGrp = new HHDeviceGrp(ini, i);
                if (devGrp.IsValid)
                {
                    listGrp.Add(devGrp);
                }
            }

            //区间轨道电路

            List <HHDeviceGrp> grpsQJ = new List <HHDeviceGrp>();
            HHDeviceGrp        grpQJ  = null;

            List <HHDeviceGrp> grpsZN = new List <HHDeviceGrp>();
            HHDeviceGrp        grpZN  = null;

            for (int i = 0; i < listGrp.Count; i++)
            {
                int devType = listGrp[i].DevType;
                switch (devType)
                {
                case 8:     //区间轨道电路
                    grpQJ = listGrp[i];
                    listGrpSort.Add(grpQJ);
                    break;

                case 10:     //无绝缘移频
                    grpsQJ.Add(listGrp[i]);
                    break;

                case 30:     //有绝缘移频
                    grpsQJ.Add(listGrp[i]);
                    break;

                case 208:     //ZPW2000
                    grpsQJ.Add(listGrp[i]);
                    break;

                case 4:     //站内轨道电路
                    grpZN = listGrp[i];
                    listGrpSort.Add(grpZN);
                    break;

                case 11:     //25HZ轨道电路
                    grpsZN.Add(listGrp[i]);
                    break;

                case 16:     //480轨道电路
                    grpsZN.Add(listGrp[i]);
                    break;

                case 17:     //高压不对称
                    grpsZN.Add(listGrp[i]);
                    break;

                case 25:     //驼峰
                    grpsZN.Add(listGrp[i]);
                    break;

                default:
                    listGrpSort.Add(listGrp[i]);
                    break;
                }
                if (devType != 4 && devType != 8)
                {
                    listGrpUnsort.Add(listGrp[i]);
                }
            }

            if (grpQJ != null)
            {
                grpQJ.AddGrp(grpsQJ);
            }
            else
            {
                listGrpSort.AddRange(grpsQJ);
            }
            if (grpZN != null)
            {
                grpZN.AddGrp(grpsZN);
            }
            else
            {
                listGrpSort.AddRange(grpsZN);
            }
        }
示例#12
0
        private void Load(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                if (File.Exists(fileName) == false)
                {
                    Assembly assembly = this.GetType().Assembly;
                    System.IO.Stream smEmbeded = assembly.GetManifestResourceStream("ConfigManager.Config.设备.rhhcfg");

                    byte[] data = new byte[smEmbeded.Length];

                    smEmbeded.Read(data, 0, data.Length);

                    //建立目录

                    string dir = Path.GetDirectoryName(fileName);
                    if (Directory.Exists(dir) == false)
                    {
                        Directory.CreateDirectory(dir);
                    }

                    File.WriteAllBytes(fileName, data);

                    smEmbeded.Close();
                }
            }
            IniDocument ini = new IniDocument();
            ini.Load(fileName);
            int num = ini.GetInt("设备", "数目", 0);

            for (int i = 0; i < num; i++)
            {
                HHDeviceGrp devGrp = new HHDeviceGrp(ini,i);
                if (devGrp.IsValid)
                {
                    listGrp.Add(devGrp);
                }
            }

            //区间轨道电路

            List<HHDeviceGrp> grpsQJ = new List<HHDeviceGrp>();
            HHDeviceGrp grpQJ = null;

            List<HHDeviceGrp> grpsZN = new List<HHDeviceGrp>();
            HHDeviceGrp grpZN = null;

            for (int i = 0; i < listGrp.Count; i++)
            {
                int devType=listGrp[i].DevType;
                switch (devType)
                {
                    case 8: //区间轨道电路
                        grpQJ = listGrp[i];
                        listGrpSort.Add(grpQJ);
                        break;
                    case 10: //无绝缘移频
                        grpsQJ.Add(listGrp[i]);
                        break;
                    case 30: //有绝缘移频
                        grpsQJ.Add(listGrp[i]);
                        break;
                    case 208: //ZPW2000
                        grpsQJ.Add(listGrp[i]);
                        break;
                    case 4: //站内轨道电路
                        grpZN = listGrp[i];
                        listGrpSort.Add(grpZN);
                        break;
                    case 11: //25HZ轨道电路
                        grpsZN.Add(listGrp[i]);
                        break;
                    case 16: //480轨道电路
                        grpsZN.Add(listGrp[i]);
                        break;
                    case 17: //高压不对称
                        grpsZN.Add(listGrp[i]);
                        break;
                    case 25: //驼峰
                        grpsZN.Add(listGrp[i]);
                        break;
                    default:
                        listGrpSort.Add(listGrp[i]);
                        break;

                }
                if (devType != 4 && devType != 8)
                {
                    listGrpUnsort.Add(listGrp[i]);
                }

            }

            if (grpQJ != null)
            {
                grpQJ.AddGrp(grpsQJ);
            }
            else
            {
                listGrpSort.AddRange(grpsQJ);
            }
            if (grpZN != null)
            {
                grpZN.AddGrp(grpsZN);
            }
            else
            {
                listGrpSort.AddRange(grpsZN);
            }
        }