protected override void StartButtonClicked(object parameters) { if (!PBS.Util.Utility.IsValidFilename(Output)) { MessageBox.Show(App.Current.FindResource("msgOutputPathError").ToString(), App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (File.Exists(Output)) { if (MessageBox.Show(App.Current.FindResource("msgOverwrite").ToString(), App.Current.FindResource("msgWarning").ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } else { try { File.Delete(Output); } catch (Exception e) { MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } try { string version = null; if (SelectedDatasourceType == "BaiduSate" || SelectedDatasourceType == "BaiduBase") { version = "009"; } else if (SelectedDatasourceType == "BaiduPanoMark") { version = BaiDuMapManager.inst.streetudt; } else { version = BaiDuMapManager.inst.cp.getLastVersion(); } Datasource = new DataSourceBaiduOnlineMap(SelectedDatasourceType) { OutputFileName = Output, Version = version, autoCorrectCoord = true }; (Datasource as DataSourceBaiduOnlineMap).ConvertCompleted += (s, a) => { if (a.Successful) { if (!AutoConfirm) { string str = App.Current.FindResource("msgConvertComplete").ToString(); if (DoCompact) { str += "\r\n" + App.Current.FindResource("msgCompactResult").ToString() + (Datasource.ConvertingStatus.SizeBeforeCompact / 1024).ToString("N0") + "KB --> " + (Datasource.ConvertingStatus.SizeAfterCompact / 1024).ToString("N0") + "KB"; } MessageBox.Show(str, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } DataSourceAdjustCoord transferSource = new DataSourceAdjustCoord(Output); Datasource = transferSource; (transferSource as DataSourceAdjustCoord).ConvertCompleted += (s1, a1) => { string str1 = App.Current.FindResource("msgAdjustComplete").ToString(); MessageBox.Show(str1, "", MessageBoxButtons.OK, MessageBoxIcon.Information); }; transferSource.ConvertToMBTiles(Output, "", "", "", Levels, null, false); } }; Datasource.ConvertCancelled += (s, a) => { }; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, a) => { IsIdle = false; App.Current.Dispatcher.Invoke(new Action(() => { (CMDClickStartButton as DelegateCommand).RaiseCanExecuteChanged(); })); ESRI.ArcGIS.Client.Geometry.Envelope extent = (ESRI.ArcGIS.Client.Geometry.Envelope)_webMercator.FromGeographic(DownloadExtent); try { PBS.Util.Geometry g = _downloadPolygon == null ? (PBS.Util.Geometry) new PBS.Util.Envelope(DownloadExtent.XMin, DownloadExtent.YMin, DownloadExtent.XMax, DownloadExtent.YMax) : _downloadPolygon; if (_downloadPolygon != null) { MessageBox.Show(App.Current.FindResource("msgDownloadByPolygonIntro").ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information); } Datasource.ConvertToMBTiles(Output, Name, Description, Attribution, Levels, g, DoCompact); } catch (Exception e) { MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } IsIdle = true; App.Current.Dispatcher.Invoke(new Action(() => { (CMDClickStartButton as DelegateCommand).RaiseCanExecuteChanged(); })); }; bw.RunWorkerAsync(); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void StartButtonClicked(object parameters) { string param = parameters.ToString(); if (param == "START") { DataSourceAdjustCoord transferSource = new DataSourceAdjustCoord(DateToFetch, FileToCorrect); Datasource = transferSource; ConvertingStatus = transferSource.ConvertingStatus; NotifyPropertyChanged(p => p.ConvertingStatus); (transferSource as DataSourceAdjustCoord).ConvertCompleted += (s1, a1) => { string str1 = App.Current.FindResource("msgAdjustComplete").ToString(); MessageBox.Show(str1, "", MessageBoxButtons.OK, MessageBoxIcon.Information); }; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, a) => { transferSource.ConvertToMBTiles(FileToCorrect, "", "", "", new int[] { 18, 19 }, null, false); }; bw.RunWorkerAsync(); } else if (param == "MERGE") { IsMergeButtonEnable = false; BackgroundWorker bw = new BackgroundWorker(); bw.RunWorkerCompleted += (s, a) => { MessageBox.Show("转换完成", "", MessageBoxButtons.OK, MessageBoxIcon.Information); }; bw.DoWork += (s, a) => { Datasource = new MockDataSource(); ConvertingStatus = new ConvertStatus(); ((MockDataSource)Datasource).ConvertingStatus = ConvertingStatus; NotifyPropertyChanged(p => p.ConvertingStatus); List <int> levels = new List <int>(); int recordCount = 0; int totalCount = 0; string boundA = "", boundB = ""; SQLiteConnection _outputconn = new SQLiteConnection("Data source = " + FileToCorrect); _outputconn.Open(); SQLiteConnection _inputconn = new SQLiteConnection("Data source = " + DateToFetch); _inputconn.Open(); ConvertingStatus.IsInProgress = true; using (SQLiteTransaction writeTran = _outputconn.BeginTransaction()) { SQLiteCommand readCommand = new SQLiteCommand(_inputconn); SQLiteCommand writeCommand = new SQLiteCommand(_outputconn); readCommand.CommandText = "select value from metadata where name = 'bounds'"; SQLiteDataReader reader = readCommand.ExecuteReader(); if (reader.Read()) { boundA = reader.GetString(0); } reader.Close(); writeCommand.CommandText = "select value from metadata where name = 'bounds'"; reader = writeCommand.ExecuteReader(); if (reader.Read()) { boundB = reader.GetString(0); } reader.Close(); readCommand.CommandText = "select count(*) from tiles"; reader = readCommand.ExecuteReader(); if (reader.Read()) { totalCount = reader.GetInt32(0); } ConvertingStatus.TotalCount = totalCount; reader.Close(); readCommand.CommandText = "select distinct(zoom_level) from tiles order by zoom_level"; reader = readCommand.ExecuteReader(); while (reader.Read()) { levels.Add(reader.GetInt32(0)); } reader.Close(); foreach (int level in levels) { readCommand.CommandText = "select count(*) from tiles where zoom_level = " + level; reader = readCommand.ExecuteReader(); reader.Read(); int levelCount = reader.GetInt32(0); int levelCompleted = 0; ConvertingStatus.Level = level; ConvertingStatus.LevelTotalCount = levelCount; ConvertingStatus.LevelCompleteCount = ConvertingStatus.LevelErrorCount = 0; reader.Close(); readCommand.CommandText = "select zoom_level, tile_column, tile_row, tile_data from tiles where zoom_level = " + level; reader = readCommand.ExecuteReader(); while (reader.Read()) { int col = reader.GetInt32(1); int row = reader.GetInt32(2); byte[] data = (byte[])reader.GetValue(3); try { WriteTilesToSqlite(level, col, row, data, writeCommand); } catch (Exception e) { } finally { levelCompleted++; recordCount++; ConvertingStatus.LevelCompleteCount = levelCompleted; ConvertingStatus.CompleteCount = recordCount; TotalPercent = ConvertingStatus.CompletePercent; } } reader.Close(); } writeCommand.CommandText = "update metadata set value = @bound where name = 'bounds'"; writeCommand.Parameters.AddWithValue("bound", mergeBounds(boundA, boundB)); writeCommand.ExecuteNonQuery(); writeTran.Commit(); writeTran.Dispose(); } ConvertingStatus.IsInProgress = false; _inputconn.Close(); _inputconn.Dispose(); _outputconn.Close(); _outputconn.Dispose(); }; bw.RunWorkerAsync(); } }