コード例 #1
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);
        }
コード例 #2
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;
            }
        }
コード例 #3
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;
            }
        }