// Unregister local geodatabase from the online service private async void UnregisterButton_Click(object sender, RoutedEventArgs e) { try { IsBusy = true; ReportStatus("Unregistering Geodatabase..."); if (LocalBirdsLayer != null) { var gdbTable = LocalBirdsLayer.FeatureTable as GeodatabaseFeatureTable; await _syncTask.UnregisterGeodatabaseAsync(gdbTable.Geodatabase); MyMapView.Map.Layers.Remove(LocalBirdsLayer); LocalBirdFeatures = null; LocalBirdsLayer = null; } CanSync = CanUnregister = false; CanGenerate = true; } catch (Exception ex) { HandleException(ex); } finally { IsBusy = false; } }
private async Task UnregisterAndRemoveMobileMapPackage(MobileMapPackage mobileMapPackage) { // Unregister all geodatabases from all maps that are part of the mobile map package. // Offline areas that are downloaded by using OfflineMapTask will contain a single // map in them but it is a good practice to handle the case of multiple maps. foreach (Map map in mobileMapPackage.Maps) { // Find all geodatabases from the used map. List <Geodatabase> geodatabasesToUnregister = new List <Geodatabase>(); // Add all geodatabases used in the feature layers. foreach (FeatureLayer featureLayer in map.OperationalLayers.OfType <FeatureLayer>()) { GeodatabaseFeatureTable geodatabaseFeatureTable = featureLayer.FeatureTable as GeodatabaseFeatureTable; if (geodatabaseFeatureTable == null) { continue; } // Add the geodatabase feature table if it isn't already in the list. if (geodatabasesToUnregister.All(x => x.Path != geodatabaseFeatureTable.Geodatabase.Path)) { geodatabasesToUnregister.Add(geodatabaseFeatureTable.Geodatabase); } } // Add all geodatabases used in a table. foreach (FeatureTable featureTable in map.Tables) { GeodatabaseFeatureTable geodatabaseFeatureTable = featureTable as GeodatabaseFeatureTable; if (geodatabaseFeatureTable == null) { continue; } // Add the geodatabase feature table if it isn't already in the list. if (geodatabasesToUnregister.All(x => x.Path != geodatabaseFeatureTable.Geodatabase.Path)) { geodatabasesToUnregister.Add(geodatabaseFeatureTable.Geodatabase); } } // Unregister geodatabases that were used. foreach (Geodatabase geodatabaseToUnregister in geodatabasesToUnregister) { GeodatabaseSyncTask geodatabaSyncTask = await GeodatabaseSyncTask.CreateAsync(geodatabaseToUnregister.Source); await geodatabaSyncTask.UnregisterGeodatabaseAsync(geodatabaseToUnregister); } // Make sure that all geodatabases are closed and locks released. foreach (Geodatabase geodatabase in geodatabasesToUnregister) { geodatabase.Close(); } } // Remove package. Directory.Delete(mobileMapPackage.Path, true); }
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 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"); } }
private async Task HandleGenerationCompleted(Geodatabase resultGdb) { // If the job completed successfully, add the geodatabase data to the map, // removing the version from the service. if (_generateGdbJob.Status == JobStatus.Succeeded) { 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. MessageBox.Show("Since no edits will be made, the local geodatabase has been unregistered per best practice."); } else { // Create a message to show the user. string message = "Generate geodatabase job failed"; // Show an error message (if there is one). if (_generateGdbJob.Error != null) { message += ": " + _generateGdbJob.Error.Message; } else { // If no error, show messages from the _generateGdbJob. var m = from msg in _generateGdbJob.Messages select msg.Message; message += ": " + string.Join <string>("\n", m); } MessageBox.Show(message); } }
private async Task DeleteOfflineMap(OfflineMapItem offlineMapItem) { // TODO Ensure, map isn't loaded // TODO Ensure, user is logged on _model.SetMessageInfo(string.Format("Unregister Geodatabases...")); var gdbFiles = Directory.GetFiles(offlineMapItem.OfflineMapPath, string.Format("*{0}", OfflineMapItem.GeodatabaseFilenameExtension)); foreach (var gdbFile in gdbFiles) { _model.SetMessageInfo(string.Format("\tUnregister Geodatabase '{0}'...", gdbFile)); var gdbPath = gdbFile.Replace("/", @"\"); var geodatabase = await Geodatabase.OpenAsync(gdbPath); var serviceUri = geodatabase.GetServiceUri(); var geodatabaseSyncTask = new GeodatabaseSyncTask(serviceUri); var result = await geodatabaseSyncTask.UnregisterGeodatabaseAsync(geodatabase); _model.SetMessageInfo(string.Format("\t...Geodatabase {0} {1}successfully unregistered", gdbFile, result.Success ? "" : "NOT ")); // Workaround to release file handle, as Geodatabase does not implement IDisposable geodatabase = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); File.Delete(gdbFile); } // delete directory, including basemap Directory.Delete(offlineMapItem.OfflineMapPath, true); }