private async void HandleGenerationCompleted(GenerateGeodatabaseJob job) { JobStatus status = job.Status; // If the job completed successfully, add the geodatabase data to the map. if (status == JobStatus.Succeeded) { // Clear out the existing layers. myMapView.Map.OperationalLayers.Clear(); // Loop through all feature tables in the geodatabase and add a new layer to the map. foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables) { // Skip non-point tables. await table.LoadAsync(); if (table.GeometryType != GeometryType.Point) { continue; } // Create a new feature layer for the table. FeatureLayer layer = new FeatureLayer(table); // Add the new layer to the map. myMapView.Map.OperationalLayers.Add(layer); } // Enable editing features. _readyForEdits = EditState.Ready; // Update the help label. myHelpLabel.Text = "2. Tap a point feature to select"; } // See if the job failed. if (status == JobStatus.Failed) { // Create a message to show the user. string message = "Generate geodatabase job failed"; // Show an error message (if there is one). if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job. foreach (JobMessage m in job.Messages) { // Get the text from the JobMessage and add it to the output string. message += "\n" + m.Message; } } // Show the message. ShowStatusMessage(message); } }
private async Task StartGeodatabaseGeneration() { // Create a task for generating a geodatabase (GeodatabaseSyncTask). _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the current extent of the red preview box. Envelope extent = MyMapView.GraphicsOverlays.First().Graphics.First().Geometry as Envelope; // Get the default parameters for the generate geodatabase task. GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job. _generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Handle the progress changed event (to show progress bar). _generateGdbJob.ProgressChanged += (sender, e) => { UpdateProgressBar(); }; // Show the progress bar. MyProgressBar.Visibility = Visibility.Visible; // Start the job. _generateGdbJob.Start(); // Get the result. Geodatabase resultGdb = await _generateGdbJob.GetResultAsync(); // Hide the progress bar. MyProgressBar.Visibility = Visibility.Hidden; // Do the rest of the work. await HandleGenerationCompleted(resultGdb); }
private async Task StartGeodatabaseGeneration() { // Update geodatabase path. _gdbPath = $"{Path.GetTempFileName()}.geodatabase"; // Create a task for generating a geodatabase (GeodatabaseSyncTask). _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the current extent of the red preview box. Envelope extent = _myMapView.GraphicsOverlays.First().Graphics.First().Geometry as Envelope; // Get the default parameters for the generate geodatabase task. GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job. _generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Handle the progress changed event (to show progress bar). _generateGdbJob.ProgressChanged += GenerateGdbJob_ProgressChanged; // Start the job. _generateGdbJob.Start(); // Get the result. Geodatabase resultGdb = await _generateGdbJob.GetResultAsync(); // Do the rest of the work. await HandleGenerationStatusChange(_generateGdbJob, resultGdb); }
private async void StartGeodatabaseGeneration() { // Create a task for generating a geodatabase (GeodatabaseSyncTask) _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the (only) graphic in the map view GraphicsOverlay redPreviewBox = myMapView.GraphicsOverlays.FirstOrDefault(); // Get the current extent of the red preview box Envelope extent = redPreviewBox.Extent as Envelope; // Get the default parameters for the generate geodatabase task GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job GenerateGeodatabaseJob generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Handle the job changed event generateGdbJob.JobChanged += GenerateGdbJobChanged; // Handle the progress changed event with an inline (lambda) function to show the progress bar generateGdbJob.ProgressChanged += ((object sender, EventArgs e) => { // Get the job GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // Update the progress bar UpdateProgressBar(job.Progress); }); // Start the job generateGdbJob.Start(); }
private async void StartGeodatabaseGeneration() { // Update the geodatabase path _gdbPath = GetGdbPath(); // Create a task for generating a geodatabase (GeodatabaseSyncTask) _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the current extent of the red preview box Envelope extent = MyMapView.GraphicsOverlays.First().Graphics.First().Geometry as Envelope; // Get the default parameters for the generate geodatabase task GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job _generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Handle the job changed event _generateGdbJob.JobChanged += GenerateGdbJobChanged; // Handle the progress changed event (to show progress bar) _generateGdbJob.ProgressChanged += ((sender, e) => { UpdateProgressBar(); }); // Start the job _generateGdbJob.Start(); }
private async void StartGeodatabaseGeneration() { // 同期させたいレイヤーで ジオデータベースタスク オブジェクトを作成する (GeodatabaseSyncTask) _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(FEATURELAYER_SERVICE_URL); // ジオデータベース作成のためのパラメータを取得する Envelope extent = myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry as Envelope; // ジオデータベース作成 タスクオブジェクトのデフォルトパラメータを取得する GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // ジオデータベースの作成ジョブオブジェクトを作成する GenerateGeodatabaseJob generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // ジョブ変更イベントを処理する generateGdbJob.JobChanged += GenerateGdbJobChanged; //進行状況を変更したイベントをインライン(ラムダ)関数で処理してプログレスバーを表示する generateGdbJob.ProgressChanged += ((object sender, EventArgs e) => { // ジョブを取得 GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // プログレスバーの更新 UpdateProgressBar(job.Progress); }); // ジオデータベース作成のジョブをスタートする generateGdbJob.Start(); }
private async void HandleGenerationCompleted(GenerateGeodatabaseJob job) { // Hide the progress bar. _progressBar.Hidden = true; switch (job.Status) { // If the job completed successfully, add the geodatabase data to the map. case JobStatus.Succeeded: // Clear out the existing layers. _myMapView.Map.OperationalLayers.Clear(); // Loop through all feature tables in the geodatabase and add a new layer to the map. foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables) { // Skip non-point tables. await table.LoadAsync(); if (table.GeometryType != GeometryType.Point) { continue; } // Create a new feature layer for the table. FeatureLayer layer = new FeatureLayer(table); // Add the new layer to the map. _myMapView.Map.OperationalLayers.Add(layer); } // Enable editing features. _readyForEdits = EditState.Ready; // Update the help label. _helpLabel.Text = "2. Tap a point feature to select."; break; // See if the job failed. case JobStatus.Failed: // Create a message to show the user. string message = "Generate geodatabase job failed"; // Show an error message (if there is one). if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job. message = job.Messages.Aggregate(message, (current, m) => current + "\n" + m.Message); } // Show the message. ShowStatusMessage(message); break; } }
private async void HandleGenerationStatusChange(GenerateGeodatabaseJob job) { JobStatus status = job.Status; // If the job completed successfully, add the geodatabase data to the map if (status == JobStatus.Succeeded) { // Clear out the existing layers myMapView.Map.OperationalLayers.Clear(); // Get the new geodatabase Geodatabase resultGdb = await job.GetResultAsync(); // Loop through all feature tables in the geodatabase and add a new layer to the map foreach (GeodatabaseFeatureTable table in resultGdb.GeodatabaseFeatureTables) { // Create a new feature layer for the table FeatureLayer _layer = new FeatureLayer(table); // Add the new layer to the map myMapView.Map.OperationalLayers.Add(_layer); } // Best practice is to unregister the geodatabase await _gdbSyncTask.UnregisterGeodatabaseAsync(resultGdb); // Tell the user that the geodatabase was unregistered ShowStatusMessage("Since no edits will be made, the local geodatabase has been unregistered per best practice."); // Re-enable the generate button myGenerateButton.Enabled = true; } // See if the job failed if (status == JobStatus.Failed) { // Create a message to show the user string message = "Generate geodatabase job failed"; // Show an error message (if there is one) if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job var m = from msg in job.Messages select msg.Message; message += ": " + string.Join <string>("\n", m); } // Show error message ShowStatusMessage(message); // Re-enable the generate button myGenerateButton.Enabled = true; } }
private async Task HandleGenerationStatusChange(GenerateGeodatabaseJob job, Geodatabase resultGdb) { switch (job.Status) { // If the job completed successfully, add the geodatabase data to the map. case JobStatus.Succeeded: // Clear out the existing layers. _myMapView.Map.OperationalLayers.Clear(); // Loop through all feature tables in the geodatabase and add a new layer to the map. foreach (GeodatabaseFeatureTable table in resultGdb.GeodatabaseFeatureTables) { // Create a new feature layer for the table. FeatureLayer layer = new FeatureLayer(table); // Add the new layer to the map. _myMapView.Map.OperationalLayers.Add(layer); } // Best practice is to unregister the geodatabase. await _gdbSyncTask.UnregisterGeodatabaseAsync(resultGdb); // Tell the user that the geodatabase was unregistered. ShowStatusMessage("Since no edits will be made, the local geodatabase has been unregistered per best practice."); // Re-enable the generate button. _generateButton.Enabled = true; break; // See if the job failed. case JobStatus.Failed: // Create a message to show the user. string message = "Generate geodatabase job failed"; // Show an error message (if there is one). if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job. IEnumerable <string> m = from msg in job.Messages select msg.Message; message += ": " + string.Join("\n", m); } ShowStatusMessage(message); // Re-enable the generate button. _generateButton.Enabled = true; break; } // Hide the progress bar. _progressBar.RemoveFromSuperview(); }
private async void HandleGenerationStatusChange(GenerateGeodatabaseJob job) { JobStatus status = job.Status; // If the job completed successfully, add the geodatabase data to the map if (status == JobStatus.Succeeded) { // Clear out the existing layers MyMapView.Map.OperationalLayers.Clear(); // Get the new geodatabase _resultGdb = await job.GetResultAsync(); // Loop through all feature tables in the geodatabase and add a new layer to the map foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables) { // Create a new feature layer for the table FeatureLayer layer = new FeatureLayer(table); // Add the new layer to the map MyMapView.Map.OperationalLayers.Add(layer); } // Enable editing features _readyForEdits = EditState.Ready; // Update help label MyHelpLabel.Content = "2. Tap a point feature to select"; } // See if the job failed if (status == JobStatus.Failed) { // Create a message to show the user string message = "Generate geodatabase job failed"; // Show an error message (if there is one) if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job foreach (JobMessage m in job.Messages) { // Get the text from the JobMessage and add it to the output string message += "\n" + m.Message; } } // Show the message ShowStatusMessage(message); } }
// Handler for the job changed event private void GenerateGdbJobChanged(object sender, EventArgs e) { // Get the job object; will be passed to HandleGenerationStatusChange GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // Due to the nature of the threading implementation, // the dispatcher needs to be used to interact with the UI InvokeOnMainThread(() => { // Do the remainder of the job status changed work HandleGenerationStatusChange(job); }); }
private async void HandleGenerationStatusChange(GenerateGeodatabaseJob job) { JobStatus status = job.Status; // Job が成功したら作成した ローカル ジオデータベース をマップに追加する if (status == JobStatus.Succeeded) { // 既存のレイヤーをクリア //myMapView.Map.OperationalLayers.Clear(); myMapView.Map.OperationalLayers.RemoveAt(0); // 新しいローカル ジオデータベース を取得 _resultGdb = await job.GetResultAsync(); mGdbFeatureTable = _resultGdb.GeodatabaseFeatureTables.FirstOrDefault(); // テーブから新しいフィーチャ レイヤを作成する FeatureLayer layer = new FeatureLayer(mGdbFeatureTable); // 新しいレイヤーをマップに追加する myMapView.Map.OperationalLayers.Add(layer); // 編集機能を有効にする _readyForEdits = EditState.Ready; } // ジオデータベースの作成ジョブに失敗した時 if (status == JobStatus.Failed) { // エラーメッセージの作成 string message = "ジオデータベースの作成に失敗"; // エラーメッセージを表示する(存在する場合) if (job.Error != null) { message += ": " + job.Error.Message; } else { // エラーがなければ、ジョブからのメッセージを表示する foreach (JobMessage m in job.Messages) { // JobMessage からテキストを取得し、出力文字列に追加します message += "\n" + m.Message; } } // メッセージを表示する ShowStatusMessage(message); } }
private void HandleGenerationStatusChange(GenerateGeodatabaseJob job) { // If the job completed successfully, add the geodatabase data to the map. if (job.Status == JobStatus.Succeeded) { // Clear out the existing layers. myMapView.Map.OperationalLayers.Clear(); // Loop through all feature tables in the geodatabase and add a new layer to the map. foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables) { // Create a new feature layer for the table. FeatureLayer layer = new FeatureLayer(table); // Add the new layer to the map. myMapView.Map.OperationalLayers.Add(layer); } // Enable editing features. _readyForEdits = EditState.Ready; // Update the help label. MyHelpLabel.Text = "2. Tap a point feature to select"; } // See if the job failed. else if (job.Status == JobStatus.Failed) { // Create a message to show the user. string message = "Generate geodatabase job failed"; // Show an error message (if there is one). if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job. foreach (JobMessage m in job.Messages) { // Get the text from the JobMessage and add it to the output string. message += "\n" + m.Message; } } // Show the message. ((Page)Parent).DisplayAlert("Error", message, "OK"); } }
private async Task HandleGenerationStatusChange(GenerateGeodatabaseJob job, Geodatabase resultGdb) { // If the job completed successfully, add the geodatabase data to the map. if (job.Status == JobStatus.Succeeded) { // Clear out the existing layers. myMapView.Map.OperationalLayers.Clear(); // Loop through all feature tables in the geodatabase and add a new layer to the map. foreach (GeodatabaseFeatureTable table in resultGdb.GeodatabaseFeatureTables) { // Create a new feature layer for the table. FeatureLayer _layer = new FeatureLayer(table); // Add the new layer to the map. myMapView.Map.OperationalLayers.Add(_layer); } // Best practice is to unregister the geodatabase. await _gdbSyncTask.UnregisterGeodatabaseAsync(resultGdb); // Tell the user that the geodatabase was unregistered. await Application.Current.MainPage.DisplayAlert("Alert", "Since no edits will be made, the local geodatabase has been unregistered per best practice.", "OK"); // Re-enable generate button. myGenerateButton.IsEnabled = true; } // See if the job failed. if (job.Status == JobStatus.Failed) { // Create a message to show the user. string message = "Generate geodatabase job failed"; // Show an error message (if there is one). if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job. message += ": " + String.Join("\n", job.Messages.Select(m => m.Message)); } await Application.Current.MainPage.DisplayAlert("Alert", message, "OK"); } }
/** * GeoDatabaseを新規に作成する * ③ 同期させたいArcGIS Online の Feature Layer でローカル geodatabase を作成する **/ private void generateGeodatabase() { // TODO geodatabaseファイル作成ジョブオブヘジェクトを作成する generateJob = geodatabaseSyncTask.GenerateGeodatabase(generateParams, mGeodatabasePath); // JobChanged イベントを処理してジョブのステータスをチェックする generateJob.JobChanged += (s, e) => { // report error (if any) if (generateJob.Error != null) { Console.WriteLine("Error creating geodatabase: " + generateJob.Error.Message); return; } // check the job status if (generateJob.Status == JobStatus.Succeeded) { // ジョブが成功した場合はローカルデータをマップに追加する readGeoDatabase(); } else if (generateJob.Status == JobStatus.Failed) { // report failure Console.WriteLine("Unable to create local geodatabase."); } else { // job is still running, report last message Console.WriteLine(generateJob.Messages[generateJob.Messages.Count - 1].Message); } }; generateJob.ProgressChanged += ((object sender, EventArgs e) => { this.Dispatcher.Invoke(() => { MyProgressBar.Value = generateJob.Progress / 1.0; }); }); // ジョブを開始し、ジョブIDをコンソール上に表示 generateJob.Start(); Console.WriteLine("Submitted job #" + generateJob.ServerJobId + " to create local geodatabase"); }
private async Task StartGeodatabaseGeneration() { // Update the geodatabase path. _gdbPath = $"{Path.GetTempFileName()}.geodatabase"; // Create a task for generating a geodatabase (GeodatabaseSyncTask). _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the (only) graphic in the map view. Graphic redPreviewBox = myMapView.GraphicsOverlays.First().Graphics.First(); // Get the current extent of the red preview box. Envelope extent = redPreviewBox.Geometry as Envelope; // Get the default parameters for the generate geodatabase task. GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job. GenerateGeodatabaseJob generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Show the progress bar. myProgressBar.IsVisible = true; // Handle the progress changed event with an inline (lambda) function to show the progress bar. generateGdbJob.ProgressChanged += (sender, e) => { // Get the job. GenerateGeodatabaseJob job = (GenerateGeodatabaseJob)sender; // Update the progress bar. UpdateProgressBar(job.Progress); }; // Start the job. generateGdbJob.Start(); // Get the result. _resultGdb = await generateGdbJob.GetResultAsync(); // Hide the progress bar. myProgressBar.IsVisible = false; // Handle the job completion. HandleGenerationStatusChange(generateGdbJob); }
// Handler for the job changed event private void GenerateGdbJobChanged(object sender, EventArgs e) { // Get the job object; will be passed to HandleGenerationStatusChange GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // Due to the nature of the threading implementation, // the dispatcher needs to be used to interact with the UI RunOnUiThread(() => { // Update progress bar visibility if (job.Status == JobStatus.Started) { myProgressBar.Visibility = Android.Views.ViewStates.Visible; } else { myProgressBar.Visibility = Android.Views.ViewStates.Gone; } // Do the remainder of the job status changed work HandleGenerationStatusChange(job); }); }
private async Task StartGeodatabaseGeneration() { // Create a task for generating a geodatabase (GeodatabaseSyncTask). _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the (only) graphic in the map view. Graphic redPreviewBox = MyMapView.GraphicsOverlays.First().Graphics.First(); // Get the current extent of the red preview box. Envelope extent = redPreviewBox.Geometry as Envelope; // Get the default parameters for the generate geodatabase task. GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job. GenerateGeodatabaseJob generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Handle the progress changed event with an inline (lambda) function to show the progress bar. generateGdbJob.ProgressChanged += (sender, e) => { // Update the progress bar. UpdateProgressBar(generateGdbJob.Progress); }; // Show the progress bar. MyProgressBar.Visibility = Visibility.Visible; // Start the job. generateGdbJob.Start(); // Get the result of the job. _resultGdb = await generateGdbJob.GetResultAsync(); // Hide the progress bar. MyProgressBar.Visibility = Visibility.Collapsed; // Do the rest of the work. HandleGenerationCompleted(generateGdbJob); }
// Handler for the job changed event private void GenerateGdbJobChanged(object sender, EventArgs e) { //ジョブオブジェクトを取得します。 HandleGenerationStatusChangeに渡されます。 GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // スレッド化された実装の性質上、 // UI と対話するためにディスパッチャを使用する必要がある Device.BeginInvokeOnMainThread(() => { // ジョブが終了したらプログレスバーを非表示にする if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed) { myProgressBar.IsVisible = false; } else { myProgressBar.IsVisible = true; } // ジョブステータスの残りの部分を変更 HandleGenerationStatusChange(job); }); }
// Handler for the job changed event private async void GenerateGdbJobChanged(object sender, EventArgs e) { // Get the job object; will be passed to HandleGenerationStatusChange GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // Due to the nature of the threading implementation, // the dispatcher needs to be used to interact with the UI await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Hide the progress bar if the job is finished if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed) { MyProgressBar.Visibility = Visibility.Collapsed; } else // Show it otherwise { MyProgressBar.Visibility = Visibility.Visible; } // Do the remainder of the job status changed work HandleGenerationStatusChange(job); }); }
// Handler for the job changed event private void GenerateGdbJobChanged(object sender, EventArgs e) { // Get the job object; will be passed to HandleGenerationStatusChange GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // Due to the nature of the threading implementation, // the dispatcher needs to be used to interact with the UI Device.BeginInvokeOnMainThread(() => { // Hide the progress bar if the job is finished if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed) { myProgressBar.IsVisible = false; } else // Show it otherwise { myProgressBar.IsVisible = true; } // Do the remainder of the job status changed work HandleGenerationStatusChange(job); }); }
private async Task StartGeodatabaseGeneration() { _generateButton.Enabled = false; // Update geodatabase path. _gdbPath = $"{Path.GetTempFileName()}.geodatabase"; // Create a task for generating a geodatabase (GeodatabaseSyncTask). _gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri); // Get the (only) graphic in the map view. Graphic redPreviewBox = _myMapView.GraphicsOverlays.First().Graphics.First(); // Get the current extent of the red preview box. Envelope extent = redPreviewBox.Geometry as Envelope; // Get the default parameters for the generate geodatabase task. GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent); // Create a generate geodatabase job. _gdbGenJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath); // Handle the progress changed event. _gdbGenJob.ProgressChanged += GenerateGdbJob_ProgressChanged; // Show the progress bar. _progressBar.Hidden = false; // Start the job. _gdbGenJob.Start(); // Get the result. _resultGdb = await _gdbGenJob.GetResultAsync(); // Do the rest of the work. HandleGenerationCompleted(_gdbGenJob); }
// Handler for the job changed event private void GenerateGdbJobChanged(object sender, EventArgs e) { // Get the job object; will be passed to HandleGenerationStatusChange GenerateGeodatabaseJob job = sender as GenerateGeodatabaseJob; // Due to the nature of the threading implementation, // the dispatcher needs to be used to interact with the UI // The dispatcher takes an Action, provided here as a lambda function Dispatcher.Invoke(() => { // Hide the progress bar if the job is finished if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed) { MyProgressBar.Visibility = Visibility.Collapsed; } else // Show it otherwise { MyProgressBar.Visibility = Visibility.Visible; } // Do the remainder of the job status changed work HandleGenerationStatusChange(job); }); }
private async Task GetLocalGeodatabase() { // Get the path to the local geodatabase for this platform (temp directory, for example) string localGeodatabasePath = GetGdbPath(); try { // See if the geodatabase file is already present if (File.Exists(localGeodatabasePath)) { // If the geodatabase is already available, open it, hide the progress control, and update the message _localGeodatabase = await Geodatabase.OpenAsync(localGeodatabasePath); _progressBar.Visibility = Android.Views.ViewStates.Gone; _messageTextBlock.Text = "Using local geodatabase from '" + _localGeodatabase.Path + "'"; } else { // Create a new GeodatabaseSyncTask with the uri of the feature server to pull from GeodatabaseSyncTask gdbTask = await GeodatabaseSyncTask.CreateAsync(new Uri(SyncServiceUrl)); // Create parameters for the task: layers and extent to include, out spatial reference, and sync model GenerateGeodatabaseParameters gdbParams = await gdbTask.CreateDefaultGenerateGeodatabaseParametersAsync(_extent); gdbParams.OutSpatialReference = _mapView.SpatialReference; gdbParams.SyncModel = SyncModel.Layer; gdbParams.LayerOptions.Clear(); gdbParams.LayerOptions.Add(new GenerateLayerOption(0)); gdbParams.LayerOptions.Add(new GenerateLayerOption(1)); // Create a geodatabase job that generates the geodatabase GenerateGeodatabaseJob generateGdbJob = gdbTask.GenerateGeodatabase(gdbParams, localGeodatabasePath); // Handle the job changed event and check the status of the job; store the geodatabase when it's ready generateGdbJob.JobChanged += (s, e) => { // Call a function to update the progress bar RunOnUiThread(() => UpdateProgressBar(generateGdbJob.Progress)); // See if the job succeeded if (generateGdbJob.Status == JobStatus.Succeeded) { RunOnUiThread(() => { // Hide the progress control and update the message _progressBar.Visibility = Android.Views.ViewStates.Gone; _messageTextBlock.Text = "Created local geodatabase"; }); } else if (generateGdbJob.Status == JobStatus.Failed) { RunOnUiThread(() => { // Hide the progress control and report the exception _progressBar.Visibility = Android.Views.ViewStates.Gone; _messageTextBlock.Text = "Unable to create local geodatabase: " + generateGdbJob.Error.Message; }); } }; // Start the generate geodatabase job _localGeodatabase = await generateGdbJob.GetResultAsync(); } } catch (Exception ex) { // Show a message for the exception encountered RunOnUiThread(() => { ShowStatusMessage("Generate Geodatabase", "Unable to create offline database: " + ex.Message); }); } }
private async Task GetLocalGeodatabase() { string localGeodatabasePath = GetGdbPath(); try { // See if the geodatabase file is already present. if (File.Exists(localGeodatabasePath)) { // If the geodatabase is already available, open it, hide the progress control, and update the message. _localGeodatabase = await Geodatabase.OpenAsync(localGeodatabasePath); _progressBar.Hidden = true; _statusLabel.Text = "Using local geodatabase."; } else { // Create a new GeodatabaseSyncTask with the URI of the feature server to pull from. Uri uri = new Uri(SyncServiceUrl); GeodatabaseSyncTask gdbTask = await GeodatabaseSyncTask.CreateAsync(uri); // Create parameters for the task: layers and extent to include, out spatial reference, and sync model. GenerateGeodatabaseParameters gdbParams = await gdbTask.CreateDefaultGenerateGeodatabaseParametersAsync(_extent); gdbParams.OutSpatialReference = _mapView.SpatialReference; gdbParams.SyncModel = SyncModel.Layer; gdbParams.LayerOptions.Clear(); gdbParams.LayerOptions.Add(new GenerateLayerOption(0)); gdbParams.LayerOptions.Add(new GenerateLayerOption(1)); // Create a geodatabase job that generates the geodatabase. GenerateGeodatabaseJob generateGdbJob = gdbTask.GenerateGeodatabase(gdbParams, localGeodatabasePath); // Handle the job changed event and check the status of the job; store the geodatabase when it's ready. generateGdbJob.JobChanged += (s, e) => { // Call a function to update the progress bar. InvokeOnMainThread(() => UpdateProgressBar(generateGdbJob.Progress)); switch (generateGdbJob.Status) { // See if the job succeeded. case JobStatus.Succeeded: InvokeOnMainThread(() => { // Hide the progress control and update the message. _progressBar.Hidden = true; _statusLabel.Text = "Created local geodatabase"; }); break; case JobStatus.Failed: InvokeOnMainThread(() => { // Hide the progress control and report the exception. _progressBar.Hidden = true; _statusLabel.Text = "Unable to create local geodatabase: " + generateGdbJob.Error.Message; }); break; } }; // Start the generate geodatabase job. _localGeodatabase = await generateGdbJob.GetResultAsync(); } } catch (Exception ex) { // Show a message for the exception encountered. InvokeOnMainThread(() => { ShowMessage("Generate Geodatabase", "Unable to create offline database: " + ex.Message, "OK"); }); } }
private async Task GetLocalGeodatabase() { // Get the path to the local geodatabase for this platform (temp directory, for example) var localGeodatabasePath = GetGdbPath(); try { // See if the geodatabase file is already present if (File.Exists(localGeodatabasePath)) { // If the geodatabase is already available, open it, hide the progress control, and update the message _localGeodatabase = await Geodatabase.OpenAsync(localGeodatabasePath); LoadingProgressBar.Visibility = Visibility.Collapsed; MessageTextBlock.Text = "Using local geodatabase from '" + _localGeodatabase.Path + "'"; } else { // Create a new GeodatabaseSyncTask with the uri of the feature server to pull from var uri = new Uri(SyncServiceUrl); var gdbTask = await GeodatabaseSyncTask.CreateAsync(uri); // Create parameters for the task: layers and extent to include, out spatial reference, and sync model var gdbParams = await gdbTask.CreateDefaultGenerateGeodatabaseParametersAsync(_extent); gdbParams.OutSpatialReference = MyMapView.SpatialReference; gdbParams.SyncModel = SyncModel.Layer; gdbParams.LayerOptions.Clear(); gdbParams.LayerOptions.Add(new GenerateLayerOption(0)); gdbParams.LayerOptions.Add(new GenerateLayerOption(1)); // Create a geodatabase job that generates the geodatabase GenerateGeodatabaseJob generateGdbJob = gdbTask.GenerateGeodatabase(gdbParams, localGeodatabasePath); // Handle the job changed event and check the status of the job; store the geodatabase when it's ready generateGdbJob.JobChanged += (s, e) => { // See if the job succeeded if (generateGdbJob.Status == JobStatus.Succeeded) { this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Hide the progress control and update the message LoadingProgressBar.Visibility = Visibility.Collapsed; MessageTextBlock.Text = "Created local geodatabase"; }); } else if (generateGdbJob.Status == JobStatus.Failed) { this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Hide the progress control and report the exception LoadingProgressBar.Visibility = Visibility.Collapsed; MessageTextBlock.Text = "Unable to create local geodatabase: " + generateGdbJob.Error.Message; }); } }; // Start the generate geodatabase job _localGeodatabase = await generateGdbJob.GetResultAsync(); } } catch (Exception ex) { // Show a message for the exception encountered this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MessageDialog dialog = new MessageDialog("Unable to create offline database: " + ex.Message); dialog.ShowAsync(); }); } }
public static async void LoadCache(CacheSettings cache) { Logging.LogMethodCall(MethodBase.GetCurrentMethod().DeclaringType.Name, () => new Dictionary <String, Object> { { nameof(cache), cache } }); if (cache == null) { throw new ArgumentNullException("cache"); } try { if (File.Exists(CacheFilePath(cache.IsBaseMap, cache.Name, false, true))) { if (File.Exists(CacheFilePath(cache.IsBaseMap, cache.Name, true, true))) { File.Delete(CacheFilePath(cache.IsBaseMap, cache.Name, true, true)); } if (cache.IsBaseMap || true)//handle not purge on sync { File.Move(CacheFilePath(cache.IsBaseMap, cache.Name, false, true), CacheFilePath(cache.IsBaseMap, cache.Name, true, true)); } else { File.Copy(CacheFilePath(cache.IsBaseMap, cache.Name, false, true), CacheFilePath(cache.IsBaseMap, cache.Name, true, true)); } } if (File.Exists(CacheFilePath(cache.IsBaseMap, cache.Name, true, true))) { try { if (cache.IsBaseMap) { TileCacheLoaded.Invoke(null, new TileCacheLoadedEventArgs(cache.Name, new TileCache(CacheFilePath(cache.IsBaseMap, cache.Name, true, true)), null)); } else { GeodatabaseLoaded.Invoke(null, new GeodatabaseLoadedEventArgs(cache.Name, await Geodatabase.OpenAsync(CacheFilePath(cache.IsBaseMap, cache.Name, true, true)), null)); } } catch (Exception ex) { if (cache.IsBaseMap) { TileCacheLoaded.Invoke(null, new TileCacheLoadedEventArgs(cache.Name, null, ex)); } else { GeodatabaseLoaded.Invoke(null, new GeodatabaseLoadedEventArgs(cache.Name, null, ex)); } } if (cache.SyncType == CacheSyncTypes.AdminSync && File.GetLastWriteTime(CacheFilePath(cache.IsBaseMap, cache.Name, true, true)) >= cache.LastUpdate) { return; } } if (cache.SyncType == CacheSyncTypes.NeverSync) { return; } if (cache.IsBaseMap) { // Create a task for generating a geodatabase (GeodatabaseSyncTask) var etcTask = await ExportTileCacheTask.CreateAsync(new Uri(cache.URL)); // Get the default parameters for the generate geodatabase task var etcParams = await etcTask.CreateDefaultExportTileCacheParametersAsync(etcTask.ServiceInfo.FullExtent, etcTask.ServiceInfo.MinScale, etcTask.ServiceInfo.MaxScale); // Create a generate geodatabase job var etcJob = etcTask.ExportTileCache(etcParams, CacheFilePath(cache.IsBaseMap, cache.Name, false, false)); // Handle the job changed event etcJob.JobChanged += (object sender, EventArgs e) => { JobStatus status = etcJob.Status; // If the job completed successfully, add the geodatabase data to the map if (status == JobStatus.Succeeded) { File.Move(CacheFilePath(cache.IsBaseMap, cache.Name, false, false), CacheFilePath(cache.IsBaseMap, cache.Name, false, true)); TileCacheLoaded.Invoke(null, new TileCacheLoadedEventArgs(cache.Name, new TileCache(CacheFilePath(cache.IsBaseMap, cache.Name, false, true)), null)); } // See if the job failed if (status == JobStatus.Failed) { // Create a message to show the user string message = "Generate tile cache job failed"; // Show an error message (if there is one) if (etcJob.Error != null) { message += ": " + etcJob.Error.Message; } else { // If no error, show messages from the job var m = from msg in etcJob.Messages select msg.Message; message += ": " + string.Join <string>("\n", m); } TileCacheLoaded.Invoke(null, new TileCacheLoadedEventArgs(cache.Name, null, new Exception(message))); } }; // Handle the progress changed event (to show progress bar) etcJob.ProgressChanged += ((object sender, EventArgs e) => { String message = String.Format("Loading {0}", cache.Name); CacheUpdating.Invoke(null, new CacheUpdatingEventArgs(message, etcJob.Progress, 100)); }); // Start the job etcJob.Start(); } else { // Create a task for generating a geodatabase (GeodatabaseSyncTask) var gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(cache.URL)); // Get the default parameters for the generate geodatabase task GenerateGeodatabaseParameters generateParams = await gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(gdbSyncTask.ServiceInfo.FullExtent); // Create a generate geodatabase job gdbJob = gdbSyncTask.GenerateGeodatabase(generateParams, CacheFilePath(cache.IsBaseMap, cache.Name, false, false)); // Handle the job changed event gdbJob.JobChanged += (async(object sender, EventArgs e) => { var job = sender as GenerateGeodatabaseJob; // See if the job failed if (job.Status == JobStatus.Failed) { // Create a message to show the user string message = "Generate geodatabase job failed"; // Show an error message (if there is one) if (job.Error != null) { message += ": " + job.Error.Message; } else { // If no error, show messages from the job var m = from msg in job.Messages select msg.Message; message += ": " + string.Join <string>("\n", m); } GeodatabaseLoaded.Invoke(null, new GeodatabaseLoadedEventArgs(cache.Name, null, new Exception(message))); } if (job.Status == JobStatus.Succeeded) { // Get the new geodatabase var _currentGeodatabase = await job.GetResultAsync(); // Best practice is to unregister the geodatabase await gdbSyncTask.UnregisterGeodatabaseAsync(_currentGeodatabase); _currentGeodatabase.Close(); File.Move(CacheFilePath(cache.IsBaseMap, cache.Name, false, false), CacheFilePath(cache.IsBaseMap, cache.Name, false, true)); var old = await Geodatabase.OpenAsync(CacheFilePath(cache.IsBaseMap, cache.Name, false, true)); GeodatabaseLoaded.Invoke(null, new GeodatabaseLoadedEventArgs(cache.Name, old, null)); } }); // Handle the progress changed event (to show progress bar) gdbJob.ProgressChanged += ((object sender, EventArgs e) => { String message = String.Format("Loading {0}", cache.Name); CacheUpdating.Invoke(null, new CacheUpdatingEventArgs(message, gdbJob.Progress, 100)); }); // Start the job gdbJob.Start(); } } catch (Exception ex) { if (cache.IsBaseMap) { TileCacheLoaded.Invoke(null, new TileCacheLoadedEventArgs(cache.Name, null, ex)); } else { GeodatabaseLoaded.Invoke(null, new GeodatabaseLoadedEventArgs(cache.Name, null, ex)); } } }