示例#1
0
        void DBTranslateFactory_TaskFinished()
        {
            this.Dispatcher.Invoke(new Action(delegate
            {
                SpeedLabel.Content = "Complete";
                start.Content      = "Start";
                DBTranslateFactory.configFinished = 0;
                DBTranslateFactory.configSucceed  = 0;
                if (timeCount != null)
                {
                    timeCount.Stop();
                }
                try
                {
                    //config = SharpConfig.Configuration.LoadFromFile("Config.ini");
                    if (config != null && config.Contains("Record") && config["Record"].SettingCount == 13)
                    {
                        config["Record"]["NowTileNum"].SetValue <ulong>(tConfig.NowTileNum);
                        config["Record"]["SuccessNum"].SetValue <ulong>(tConfig.SuccessNum);
                        config["Record"]["minLon"].SetValue <double>(tConfig.minLon);
                        config["Record"]["minLat"].SetValue <double>(tConfig.minLat);
                        config["Record"]["maxLon"].SetValue <double>(tConfig.maxLon);
                        config["Record"]["maxLat"].SetValue <double>(tConfig.maxLat);
                        config["Record"]["sLevel"].SetValue <int>(tConfig.sLevel);
                        config["Record"]["eLevel"].SetValue <int>(tConfig.eLevel);
                        config["Record"]["OperateFunction"].SetValue <string>(tConfig.OperateFunction);
                        config["Record"]["StartTime"].SetValue <string>(tConfig.StartTime);
                        config["Record"]["LastTime"].SetValue <string>(tConfig.LastTime);
                        config["Record"]["TotalTilesNum"].SetValue <ulong>(tConfig.TotalTilesNum);
                        config.Save("Config.ini");
                    }

                    if (CheckExport.IsChecked != null && CheckExport.IsChecked == true)
                    {
                        this.GetExportEXE();
                        this.ExportDB();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }));
        }
示例#2
0
    /// <summary>
    /// Tries the get named section or returns null.
    /// </summary>
    /// <returns>The get.</returns>
    /// <param name="config">Config.</param>
    /// <param name="section">Section.</param>
    public static SharpConfig.Section TryGet(this SharpConfig.Configuration config, string section)
    {
        Debug.Assert(config != null);
        Debug.Assert(!string.IsNullOrEmpty(section));

        if (config.Contains(section))
        {
            return(config[section]);
        }
        return(null);
    }
示例#3
0
        /// <summary>
        /// Checks if the given section/setting combination exists in this configuration.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="loggingLevel"></param>
        /// <returns></returns>
        public static bool Exists(this SharpConfig.Configuration config, string section, string key, Logging.Level loggingLevel = Logging.Level.Error)
        {
            var exists = config.Contains(section) && config[section].Contains(key);

            if (!exists)
            {
                Logging.Log(config, "Could not find [" + section + "] [" + key + "]", Logging.Level.Warning, loggingLevel);
            }

            return(exists);
        }
示例#4
0
        // Parses a configuration from a source string.
        // This is the core parsing function.
        private static Configuration Parse(string source)
        {
            // Reset temporary fields.
            mLineNumber = 0;

            Configuration config         = new Configuration();
            Section       currentSection = null;
            var           preComments    = new List <Comment>();

            using (var reader = new StringReader(source))
            {
                string line = null;

                // Read until EOF.
                while ((line = reader.ReadLine()) != null)
                {
                    mLineNumber++;

                    // Remove all leading / trailing white-spaces.
                    line = line.Trim();

                    // Empty line? If so, skip.
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    int commentIndex = 0;
                    var comment      = ParseComment(line, out commentIndex);

                    if (!IgnorePreComments && commentIndex == 0)
                    {
                        // This is a comment line (pre-comment).
                        // Add it to the list of pre-comments.
                        preComments.Add(comment.Value);
                        continue;
                    }
                    else if (!IgnoreInlineComments && commentIndex > 0)
                    {
                        // Strip away the comments of this line.
                        line = line.Remove(commentIndex).Trim();
                    }

                    // Sections start with a '['.
                    if (line.StartsWith("["))
                    {
                        currentSection = ParseSection(line);

                        if (!IgnoreInlineComments)
                        {
                            currentSection.Comment = comment;
                        }

                        if (config.Contains(currentSection.Name))
                        {
                            if (IgnoreDuplicateSections)
                            {
                                continue;
                            }

                            throw new ParserException(string.Format(
                                                          "The section '{0}' was already declared in the configuration.",
                                                          currentSection.Name), mLineNumber);
                        }

                        if (!IgnorePreComments && preComments.Count > 0)
                        {
                            currentSection.mPreComments = new List <Comment>(preComments);
                            preComments.Clear();
                        }

                        config.mSections.Add(currentSection);
                    }
                    else
                    {
                        Setting setting = ParseSetting(line);

                        if (!IgnoreInlineComments)
                        {
                            setting.Comment = comment;
                        }

                        if (currentSection == null)
                        {
                            throw new ParserException(string.Format(
                                                          "The setting '{0}' has to be in a section.",
                                                          setting.Name), mLineNumber);
                        }

                        if (currentSection.Contains(setting.Name))
                        {
                            if (IgnoreDuplicateSettings)
                            {
                                continue;
                            }

                            throw new ParserException(string.Format(
                                                          "The setting '{0}' was already declared in the section.",
                                                          setting.Name), mLineNumber);
                        }

                        if (!IgnorePreComments && preComments.Count > 0)
                        {
                            setting.mPreComments = new List <Comment>(preComments);
                            preComments.Clear();
                        }

                        currentSection.Add(setting);
                    }
                }
            }

            return(config);
        }
        // Parses a configuration from a source string.
        // This is the core parsing function.
        private static Configuration Parse(string source)
        {
            // Reset temporary fields.
            mLineNumber = 0;

            Configuration config = new Configuration();
            Section currentSection = null;
            var preComments = new List<Comment>();

            using (var reader = new StringReader(source))
            {
                string line = null;

                // Read until EOF.
                while ((line = reader.ReadLine()) != null)
                {
                    mLineNumber++;

                    // Remove all leading / trailing white-spaces.
                    line = line.Trim();

                    // Empty line? If so, skip.
                    if (string.IsNullOrEmpty(line))
                        continue;

                    int commentIndex = 0;
                    var comment = ParseComment(line, out commentIndex);

                    if (!IgnorePreComments && commentIndex == 0)
                    {
                        // This is a comment line (pre-comment).
                        // Add it to the list of pre-comments.
                        preComments.Add(comment.Value);
                        continue;
                    }
                    else if (!IgnoreInlineComments && commentIndex > 0)
                    {
                        // Strip away the comments of this line.
                        line = line.Remove(commentIndex).Trim();
                    }

                    // Sections start with a '['.
                    if (line.StartsWith("["))
                    {
                        currentSection = ParseSection(line);

                        if (!IgnoreInlineComments)
                            currentSection.Comment = comment;

                        if (config.Contains(currentSection.Name))
                        {
                            if (IgnoreDuplicateSections)
                            {
                                continue;
                            }

                            throw new ParserException(string.Format(
                                "The section '{0}' was already declared in the configuration.",
                                currentSection.Name), mLineNumber);
                        }

                        if (!IgnorePreComments && preComments.Count > 0)
                        {
                            currentSection.mPreComments = new List<Comment>(preComments);
                            preComments.Clear();
                        }

                        config.mSections.Add(currentSection);
                    }
                    else
                    {
                        Setting setting = ParseSetting(line);

                        if (!IgnoreInlineComments)
                            setting.Comment = comment;

                        if (currentSection == null)
                        {
                            throw new ParserException(string.Format(
                                "The setting '{0}' has to be in a section.",
                                setting.Name), mLineNumber);
                        }

                        if (currentSection.Contains(setting.Name))
                        {
                            if (IgnoreDuplicateSettings)
                            {
                                continue;
                            }

                            throw new ParserException(string.Format(
                                "The setting '{0}' was already declared in the section.",
                                setting.Name), mLineNumber);
                        }

                        if (!IgnorePreComments && preComments.Count > 0)
                        {
                            setting.mPreComments = new List<Comment>(preComments);
                            preComments.Clear();
                        }

                        currentSection.Add(setting);
                    }

                }
            }

            return config;
        }
示例#6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string configPath = "";

            System.Windows.Forms.OpenFileDialog odlg = new OpenFileDialog();
            odlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
            odlg.Filter           = "config files (*.ini)|*.ini";
            if (odlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                configPath = odlg.FileName;
            }
            else
            {
                return;
            }

            tConfig = new TransformConfigion();

            try
            {
                SharpConfig.Configuration configi = SharpConfig.Configuration.LoadFromFile(configPath);
                if (configi != null && configi.Contains("Record") && configi["Record"].SettingCount == 13)
                {
                    tConfig = configi["Record"].CreateObject <TransformConfigion>();
                    if (tConfig != null)
                    {
                        SUM_MinX.Text = tConfig.minLon.ToString();
                        SUM_MinY.Text = tConfig.minLat.ToString();
                        SUM_MaxX.Text = tConfig.maxLon.ToString();
                        SUM_MaxY.Text = tConfig.maxLat.ToString();

                        StartLevel.Text = tConfig.sLevel.ToString();
                        EndLevel.Text   = tConfig.eLevel.ToString();
                        foreach (ComboBoxItem s in this.CBOX.Items)
                        {
                            if (tConfig.OperateFunction == s.Content as string)
                            {
                                this.CBOX.SelectedItem = s;
                            }
                        }

                        List <string> item = new List <string>();
                        item.Add(string.Format("Min Longitude: {0}", tConfig.minLon));
                        item.Add(string.Format("Max Longitude: {0}", tConfig.maxLon));
                        item.Add(string.Format("Min Latitude: {0}", tConfig.minLat));
                        item.Add(string.Format("Max Latitude: {0}", tConfig.maxLat));
                        item.Add(string.Format("Start Level: {0}", tConfig.sLevel));
                        item.Add(string.Format("End Level: {0}", tConfig.eLevel));
                        item.Add(string.Format("Function: {0}", tConfig.OperateFunction));
                        item.Add(string.Format("Start Time: {0}", tConfig.StartTime));
                        item.Add(string.Format("Last Time: {0}", tConfig.LastTime));
                        item.Add(string.Format("Tiles Amount: {0}", tConfig.TotalTilesNum));
                        item.Add(string.Format("Tiles Finished: {0}", tConfig.NowTileNum));
                        item.Add(string.Format("Tiles Succeed: {0}", tConfig.SuccessNum));
                        item.Add(string.Format("Save Path: {0}", tConfig.SavePath));
                        listBoxConfig.ItemsSource = item;

                        DBTranslateFactory.configSucceed  = tConfig.SuccessNum;
                        DBTranslateFactory.configFinished = tConfig.NowTileNum;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
示例#7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string ServiceAdress  = null;
            string ServiceAdress2 = null;

            if (ConfigurationManager.AppSettings["ServiceAdressSource"] != null)
            {
                ServiceAdress = ConfigurationManager.AppSettings["ServiceAdressSource"];
            }
            else
            {
                ServiceAdress = "mongodb://192.168.1.103:27017";
            }
            if (ConfigurationManager.AppSettings["ServiceAdressTarget"] != null)
            {
                ServiceAdress2 = ConfigurationManager.AppSettings["ServiceAdressTarget"];
            }
            else
            {
                ServiceAdress2 = "mongodb://localhost:27017";
            }
            Console.WriteLine("serverAdress: " + ServiceAdress);
            //string ServiceAdress = "mongodb://192.168.1.103:27017";

            DBTranslateFactory.DBReaderHelper = new MongoDBReaderHelper();
            if (!DBTranslateFactory.DBReaderHelper.InitMongoDB(ServiceAdress, ServiceAdress2))
            {
                System.Windows.Forms.MessageBox.Show("数据库连接失败", "Error");
                this.Close();
            }
            DBTranslateFactory.statusChanged   += DBTranslateFactory_statusChanged;
            DBTranslateFactory.ProgressChanged += DBTranslateFactory_ProgressChanged;
            DBTranslateFactory.TaskFinished    += DBTranslateFactory_TaskFinished;
            if (DBTranslateFactory.DBReaderHelper.DBNames != null)
            {
                listBoxSourceDB.ItemsSource = DBTranslateFactory.DBReaderHelper.DBNames;
            }
            if (DBTranslateFactory.DBReaderHelper.DBNamesTarget != null)
            {
                listBoxTargetDB.ItemsSource = DBTranslateFactory.DBReaderHelper.DBNamesTarget;
            }
            themes.ItemsSource = ThemeManager.GetThemes();
            try
            {
                config = SharpConfig.Configuration.LoadFromFile("Config.ini");
                if (config != null && config.Contains("Record") && config["Record"].SettingCount == 13)
                {
                    TransformConfigion tConfig = config["Record"].CreateObject <TransformConfigion>();
                    if (tConfig != null)
                    {
                        //SUM_MinX.Text = tConfig.minLon.ToString();
                        //SUM_MinY.Text = tConfig.minLat.ToString();
                        //SUM_MaxX.Text = tConfig.maxLon.ToString();
                        //SUM_MaxY.Text = tConfig.maxLat.ToString();

                        //StartLevel.Text = tConfig.sLevel.ToString();
                        //EndLevel.Text = tConfig.eLevel.ToString();
                        //foreach (ComboBoxItem s in this.CBOX.Items)
                        //{
                        //    if (tConfig.OperateFunction == s.Content as string)
                        //    {
                        //        this.CBOX.SelectedItem = s;
                        //    }
                        //}

                        List <string> item = new List <string>();
                        item.Add(string.Format("Min Longitude: {0}", tConfig.minLon));
                        item.Add(string.Format("Max Longitude: {0}", tConfig.maxLon));
                        item.Add(string.Format("Min Latitude: {0}", tConfig.minLat));
                        item.Add(string.Format("Max Latitude: {0}", tConfig.maxLat));
                        item.Add(string.Format("Start Level: {0}", tConfig.sLevel));
                        item.Add(string.Format("End Level: {0}", tConfig.eLevel));
                        item.Add(string.Format("Function: {0}", tConfig.OperateFunction));
                        item.Add(string.Format("Start Time: {0}", tConfig.StartTime));
                        item.Add(string.Format("Last Time: {0}", tConfig.LastTime));
                        item.Add(string.Format("Tiles Amount: {0}", tConfig.TotalTilesNum));
                        item.Add(string.Format("Tiles Finished: {0}", tConfig.NowTileNum));
                        item.Add(string.Format("Tiles Succeed: {0}", tConfig.SuccessNum));
                        item.Add(string.Format("Save Path: {0}", tConfig.SavePath));
                        listBoxConfig.ItemsSource = item;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }


            SpeedChanged += MainWindow_SpeedChanged;
            load          = true;

            this.UpdateTree();


            //SpeedLabel.Content = "fgfgfgfgfgfgfgfgfgfgfgfgfgfg";
            //SpeedLabel1.Content = "fgfgfgfgfgf";
            //int x = 123, y = 321, z = 113;
            //ProgressLabel.Content = string.Format("Complete\r\n{0}/{1}\r\n{2:f2}% ", x, y, (double)x / (double)y * 100);
            //ProgressLabel1.Content = string.Format("Successed\r\n{1}/{0}\r\n{2:f2}%", x, z, (double)z / (double)x * 100);
        }
示例#8
0
        /// <summary>
        /// according to the longitude latitude box and level range insert tile data to kq database file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void start_Click(object sender, RoutedEventArgs e)
        {
            if (start.Content.ToString() == "Start" || start.Content.ToString() == "Config")
            {
                if (start.Content.ToString() == "Config")
                {
                    string configPath = "";
                    System.Windows.Forms.OpenFileDialog odlg = new OpenFileDialog();
                    odlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
                    odlg.Filter           = "config files (*.ini)|*.ini";
                    if (odlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        configPath = odlg.FileName;
                    }
                    else
                    {
                        return;
                    }

                    tConfig = new TransformConfigion();

                    try
                    {
                        SharpConfig.Configuration configi = SharpConfig.Configuration.LoadFromFile(configPath);
                        if (configi != null && configi.Contains("Record") && configi["Record"].SettingCount == 13)
                        {
                            tConfig = configi["Record"].CreateObject <TransformConfigion>();
                            if (tConfig != null)
                            {
                                SUM_MinX.Text = tConfig.minLon.ToString();
                                SUM_MinY.Text = tConfig.minLat.ToString();
                                SUM_MaxX.Text = tConfig.maxLon.ToString();
                                SUM_MaxY.Text = tConfig.maxLat.ToString();

                                StartLevel.Text = tConfig.sLevel.ToString();
                                EndLevel.Text   = tConfig.eLevel.ToString();
                                foreach (ComboBoxItem s in this.CBOX.Items)
                                {
                                    if (tConfig.OperateFunction == s.Content as string)
                                    {
                                        this.CBOX.SelectedItem = s;
                                    }
                                }

                                List <string> item = new List <string>();
                                item.Add(string.Format("Min Longitude :{0}", tConfig.minLon));
                                item.Add(string.Format("Max Longitude :{0}", tConfig.maxLon));
                                item.Add(string.Format("Min Latitude :{0}", tConfig.minLat));
                                item.Add(string.Format("Max Latitude :{0}", tConfig.maxLat));
                                item.Add(string.Format("Start Level :{0}", tConfig.sLevel));
                                item.Add(string.Format("End   Level :{0}", tConfig.eLevel));
                                item.Add(string.Format("Function :{0}", tConfig.OperateFunction));
                                item.Add(string.Format("Start Time :{0}", tConfig.StartTime));
                                item.Add(string.Format("Last  Time :{0}", tConfig.LastTime));
                                item.Add(string.Format("Tiles Amount :{0}", tConfig.TotalTilesNum));
                                item.Add(string.Format("Tiles Finished :{0}", tConfig.NowTileNum));
                                item.Add(string.Format("Tiles Succeed :{0}", tConfig.SuccessNum));
                                item.Add(string.Format("Save Path :{0}", tConfig.SavePath));
                                listBoxConfig.ItemsSource = item;

                                DBTranslateFactory.configSucceed  = tConfig.SuccessNum;
                                DBTranslateFactory.configFinished = tConfig.NowTileNum;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }

                double minX = 0, minY = 0, maxX = 0, maxY = 0;
                int    sLevel = 0, eLevel = 0, threatNum = 0;

                string func = this.CBOX.SelectionBoxItem as string;

                if (!(double.TryParse(SUM_MinX.Text, out minX)) || !(double.TryParse(SUM_MinY.Text, out minY)) || !(double.TryParse(SUM_MaxX.Text, out maxX)) || !(double.TryParse(SUM_MaxY.Text, out maxY)))
                {
                    StatusLable.Content = "Try to enter anther valuable longitude and latitude range.";
                    return;
                }
                if (!(int.TryParse(StartLevel.Text, out sLevel)) || !(int.TryParse(EndLevel.Text, out eLevel)) || !(int.TryParse(ThreatNum.Text, out threatNum)))
                {
                    StatusLable.Content = "Try to enter anther valuable StartLevel and EndLevel , Threat Number.";
                    return;
                }

                if (minX > maxX || minY > maxY || minX < -180 || minY < -90 || maxX > 180 || maxY > 90)
                {
                    StatusLable.Content = "Try to enter anther valuable longitude and latitude range.";
                    return;
                }

                if (sLevel < 0 || sLevel > 21 || eLevel < 0 || eLevel > 21 || sLevel > eLevel || threatNum < 1 || threatNum > 25)
                {
                    StatusLable.Content = "Try to enter anther valuable StartLevel and EndLevel.";
                    return;
                }

                imagebox.Visibility    = Visibility.Hidden;
                bigiamgebox.Visibility = Visibility.Hidden;
                KQLable.Visibility     = Visibility.Hidden;
                GoogleLbel.Visibility  = Visibility.Hidden;

                ProgressInfo.Visibility = Visibility.Visible;

                //start.IsEnabled = false;

                tConfig = new TransformConfigion();

                tConfig.sLevel          = sLevel;
                tConfig.eLevel          = eLevel;
                tConfig.minLat          = minY;
                tConfig.minLon          = minX;
                tConfig.maxLat          = maxY;
                tConfig.maxLon          = maxX;
                tConfig.TotalTilesNum   = 0;
                tConfig.NowTileNum      = 0;
                tConfig.SuccessNum      = 0;
                tConfig.OperateFunction = func;
                tConfig.StartTime       = DateTime.Now.ToString();
                tConfig.LastTime        = DateTime.Now.ToString();
                tConfig.SavePath        = DBTranslateFactory.kqpath;

                tileAmount   = 0;
                tileFinished = 0;
                tileSucceed  = 0;
                lastFinished = 0;

                StatusLable.Content = "Transformation is beginning.";

                bool result = false;
                if (func == "MongoDB To KQDB")
                {
                    if (DBTranslateFactory.InsertOperationByMultiThreading(threatNum, sLevel, eLevel, maxX, maxY, minX, minY))
                    {
                        result = true;
                        StatusLable.Content = "Transformation has launched successfully.";
                    }
                }

                if (func == "MongoDB To File")
                {
                    if (DBTranslateFactory.CreatGoogleFileByMultiThreading(threatNum, sLevel, eLevel, maxX, maxY, minX, minY))
                    {
                        result = true;
                        StatusLable.Content = "Transformation has launched successfully.";
                    }
                }

                if (func == "Get Partial MongoDB")
                {
                    if (DBTranslateFactory.CreatPartialMongoDB(threatNum, sLevel, eLevel, maxX, maxY, minX, minY))
                    {
                        result = true;
                        StatusLable.Content = "Transformation has launched successfully.";
                    }
                }
                //DBTranslateFactory.InsertKQImageByLonLatRange(6, 115, 25, 110, 20);
                if (!result)
                {
                    return;
                }
                timeCount          = new System.Windows.Forms.Timer();
                timeCount.Tick    += timeCount_Tick;
                timeCount.Enabled  = true;
                timeCount.Interval = 1000;
                timeCount.Start();

                start.Content = "Pause";
                if (config != null && config.Contains("Record") && config["Record"].SettingCount == 13)
                {
                    config["Record"]["NowTileNum"].SetValue <ulong>(tConfig.NowTileNum);
                    config["Record"]["SuccessNum"].SetValue <ulong>(tConfig.SuccessNum);
                    config["Record"]["minLon"].SetValue <double>(tConfig.minLon);
                    config["Record"]["minLat"].SetValue <double>(tConfig.minLat);
                    config["Record"]["maxLon"].SetValue <double>(tConfig.maxLon);
                    config["Record"]["maxLat"].SetValue <double>(tConfig.maxLat);
                    config["Record"]["sLevel"].SetValue <int>(tConfig.sLevel);
                    config["Record"]["eLevel"].SetValue <int>(tConfig.eLevel);
                    config["Record"]["OperateFunction"].SetValue <string>(tConfig.OperateFunction);
                    config["Record"]["StartTime"].SetValue <string>(tConfig.StartTime);
                    config["Record"]["LastTime"].SetValue <string>(tConfig.LastTime);
                    config["Record"]["TotalTilesNum"].SetValue <ulong>(tConfig.TotalTilesNum);
                    config["Record"]["SavePath"].SetValue <string>(tConfig.SavePath);
                    config.Save("Config.ini");
                }

                return;
            }
            else if (start.Content.ToString() == "Pause")
            {
                DBTranslateFactory.Pause = true;
                timeCount.Stop();
                start.Content = "Continue";
                return;
            }

            else if (start.Content.ToString() == "Continue")
            {
                DBTranslateFactory.Pause = false;
                timeCount.Start();
                start.Content = "Pause";
                return;
            }
        }
示例#9
0
        //根据字符串解析配置文件,核心的解析函数
        private static Configuration Parse(string source)
        {
            //重置临时字段
            mLineNumber = 0;

            Configuration config         = new Configuration();
            Section       currentSection = null;
            var           preComments    = new List <Comment>();

            using (var reader = new StringReader(source))
            {
                string line = null;

                // 读取一行,直到结尾(Read until EOF.)
                while ((line = reader.ReadLine()) != null)
                {
                    mLineNumber++;
                    //删除前后空白字符
                    line = line.Trim();

                    //这里扩展核心的换行支持,使用 3个 ... 开头,说明是上一个设置的换行
                    //每一次行都读取下一行试一下,如果有...,就添加
                    if (line.StartsWith("..."))
                    {
                        var text = "\r\n" + line.Substring(3);
                        currentSection[currentSection.SettingCount - 1].Value += text;
                        continue;
                    }
                    //如果是空行跳过
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    int commentIndex = 0;
                    var comment      = ParseComment(line, out commentIndex);

                    if (!mIgnorePreComments && commentIndex == 0)
                    {
                        // 解析注释行,添加到 注释列表中去
                        preComments.Add(comment);
                        continue;
                    }
                    else if (!mIgnoreInlineComments && commentIndex > 0)
                    {
                        // 去掉这一行的注释
                        line = line.Remove(commentIndex).Trim();
                    }

                    //如果开始字符是 [ ,说明是 节(Sections)
                    if (line.StartsWith("["))
                    {
                        #region 节解析
                        currentSection = ParseSection(line);

                        if (!mIgnoreInlineComments)
                        {
                            currentSection.Comment = comment;
                        }

                        if (config.Contains(currentSection.Name))
                        {
                            throw new ParserException(string.Format(
                                                          "The section '{0}' was already declared in the configuration.",
                                                          currentSection.Name), mLineNumber);
                        }

                        if (!mIgnorePreComments && preComments.Count > 0)
                        {
                            currentSection.mPreComments = new List <Comment>(preComments);
                            preComments.Clear();
                        }

                        config.mSections.Add(currentSection);
                        #endregion
                    }
                    else  //否则就是键值设置行
                    {
                        //解析设置行
                        Setting setting = ParseSetting(line);

                        if (!mIgnoreInlineComments)
                        {
                            setting.Comment = comment;
                        }

                        if (currentSection == null)
                        {
                            throw new ParserException(string.Format("The setting '{0}' has to be in a section.", setting.Name), mLineNumber);
                        }

                        if (currentSection.Contains(setting.Name))
                        {
                            throw new ParserException(string.Format("The setting '{0}' was already declared in the section.", setting.Name), mLineNumber);
                        }

                        if (!mIgnorePreComments && preComments.Count > 0)
                        {
                            setting.mPreComments = new List <Comment>(preComments);
                            preComments.Clear();
                        }
                        currentSection.Add(setting);
                    }
                }
            }
            return(config);
        }