// Generate / download and display layers from a generated geodatabase private async void GenerateGeodatabaseButton_Click(object sender, RoutedEventArgs e) { try { panelUI.IsEnabled = false; panelStatus.Visibility = Visibility.Visible; ReportStatus("Creating GeodatabaseSyncTask..."); var syncTask = new GeodatabaseSyncTask(new Uri(BASE_URL)); // Get current viewpoints extent from the MapView var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); var viewpointExtent = currentViewpoint.TargetGeometry.Extent; var options = new GenerateGeodatabaseParameters(new int[] { 0, 1, 2 }, viewpointExtent) { GeodatabasePrefixName = GDB_PREFIX, ReturnAttachments = false, OutSpatialReference = MyMapView.SpatialReference, SyncModel = SyncModel.PerLayer }; var tcs = new TaskCompletionSource <GeodatabaseStatusInfo>(); Action <GeodatabaseStatusInfo, Exception> completionAction = (info, ex) => { if (ex != null) { tcs.SetException(ex); } tcs.SetResult(info); }; var generationProgress = new Progress <GeodatabaseStatusInfo>(); generationProgress.ProgressChanged += (sndr, sts) => { ReportStatus(sts.Status.ToString()); }; ReportStatus("Starting GenerateGeodatabase..."); var result = await syncTask.GenerateGeodatabaseAsync(options, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); ReportStatus("Waiting on geodatabase from server..."); var statusResult = await tcs.Task; ReportStatus("Downloading Geodatabase..."); var gdbPath = await DownloadGeodatabase(statusResult); ReportStatus("Create local feature layers..."); await CreateFeatureLayersAsync(gdbPath); MyMapView.Map.Layers["wildfireGroup"].IsVisible = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } finally { panelStatus.Visibility = Visibility.Collapsed; panelUI.IsEnabled = true; } }
// Generate / download and display layers from a generated geodatabase private async void GenerateGeodatabaseButton_Click(object sender, RoutedEventArgs e) { try { panelUI.IsEnabled = false; panelStatus.Visibility = Visibility.Visible; ReportStatus("Creating GeodatabaseSyncTask..."); var syncTask = new GeodatabaseSyncTask(new Uri(BASE_URL)); // Get current viewpoints extent from the MapView var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); var viewpointExtent = currentViewpoint.TargetGeometry.Extent; var options = new GenerateGeodatabaseParameters(new int[] { 0, 1, 2 }, viewpointExtent) { GeodatabasePrefixName = GDB_PREFIX, ReturnAttachments = false, OutSpatialReference = MyMapView.SpatialReference, SyncModel = SyncModel.PerLayer }; var tcs = new TaskCompletionSource<GeodatabaseStatusInfo>(); Action<GeodatabaseStatusInfo, Exception> completionAction = (info, ex) => { if (ex != null) tcs.SetException(ex); tcs.SetResult(info); }; var generationProgress = new Progress<GeodatabaseStatusInfo>(); generationProgress.ProgressChanged += (sndr, sts) => { ReportStatus(sts.Status.ToString()); }; ReportStatus("Starting GenerateGeodatabase..."); var result = await syncTask.GenerateGeodatabaseAsync(options, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); ReportStatus("Waiting on geodatabase from server..."); var statusResult = await tcs.Task; ReportStatus("Downloading Geodatabase..."); var gdbPath = await DownloadGeodatabase(statusResult); ReportStatus("Create local feature layers..."); await CreateFeatureLayersAsync(gdbPath); MyMapView.Map.Layers["wildfireGroup"].IsVisible = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } finally { panelStatus.Visibility = Visibility.Collapsed; panelUI.IsEnabled = true; } }
// Generate / download and display layers from a generated geodatabase private async Task GenerateLocalGeodatabaseAsync(Envelope extent) { try { IsBusy = true; ReportStatus("Creating GeodatabaseSyncTask..."); var syncTask = new GeodatabaseSyncTask(new Uri(BASE_URL)); var options = new GenerateGeodatabaseParameters(new int[] { 1 }, extent) { GeodatabasePrefixName = GDB_PREFIX, ReturnAttachments = false, OutSpatialReference = extent.SpatialReference, SyncModel = SyncModel.PerLayer }; var tcs = new TaskCompletionSource <GeodatabaseStatusInfo>(); Action <GeodatabaseStatusInfo, Exception> completionAction = (info, ex) => { if (ex != null) { tcs.SetException(ex); } tcs.SetResult(info); }; var generationProgress = new Progress <GeodatabaseStatusInfo>(); generationProgress.ProgressChanged += (sndr, sts) => { SecondaryStatus = sts.Status.ToString(); }; ReportStatus("Starting GenerateGeodatabase..."); var result = await syncTask.GenerateGeodatabaseAsync(options, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); ReportStatus("Waiting on geodatabase from server..."); var statusResult = await tcs.Task; ReportStatus("Downloading Geodatabase..."); await DownloadGeodatabaseAsync(statusResult); ReportStatus("Opening Geodatabase..."); var gdb = await Geodatabase.OpenAsync(_gdbPath); ReportStatus("Create local feature layers..."); await CreateFeatureLayers(gdb); _onlineBirdsLayer.IsVisible = false; } finally { IsBusy = false; } }
// call GenerateGeodatabaseAsync from a button click private async void GetDataButton_Click(object sender, RoutedEventArgs e) { try { // cancel if an earlier call was made if (_syncCancellationTokenSource != null) { _syncCancellationTokenSource.Cancel(); } // get a cancellation token _syncCancellationTokenSource = new CancellationTokenSource(); var cancelToken = _syncCancellationTokenSource.Token; // create a new GeodatabaseSyncTask with the uri of the feature server to pull from var serverUrl = this.featureLayerServiceUrl.Substring(0, this.featureLayerServiceUrl.LastIndexOf('/')); var uri = new Uri(serverUrl); var gdbTask = new GeodatabaseSyncTask(uri); // create parameters for the task: layers and extent to include, out spatial reference, and sync model var layers = new List <int>(new int[1] { 0 }); var extent = MyMapView.Extent; var gdbParams = new GenerateGeodatabaseParameters(layers, extent) { OutSpatialReference = MyMapView.SpatialReference, SyncModel = SyncModel.PerLayer }; // Create a System.Progress<T> object to report status as the task executes var progress = new Progress <GeodatabaseStatusInfo>(); progress.ProgressChanged += (s, info) => { this.SyncStatusTextBlock.Text = "Generate GDB: " + info.Status; this.SyncProgressBar.Visibility = System.Windows.Visibility.Visible; }; // call GenerateGeodatabaseAsync, pass in the parameters and the callback to execute when it's complete this.SyncProgressBar.Visibility = System.Windows.Visibility.Visible; this.SyncStatusTextBlock.Text = "Generate GDB: Job submitted ..."; // show progress bar and label this.SyncStatusPanel.Visibility = System.Windows.Visibility.Visible; // generate the database var gdbResult = await gdbTask.GenerateGeodatabaseAsync(gdbParams, GdbCompleteCallback, new TimeSpan(0, 0, 3), progress, cancelToken); } catch (Exception ex) { this.Dispatcher.Invoke(() => this.SyncStatusTextBlock.Text = "Unable to create offline database: " + ex.Message); } }
private async void Download_Click(object sender, RoutedEventArgs e) { try { // cancel if an earlier call was made if (_syncCancellationTokenSource != null) { _syncCancellationTokenSource.Cancel(); } // get a cancellation token _syncCancellationTokenSource = new CancellationTokenSource(); var cancelToken = _syncCancellationTokenSource.Token; // create a new GeodatabaseSyncTask with the uri of the feature server to pull from var uri = new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/SaveTheBaySync/FeatureServer"); var gdbTask = new GeodatabaseSyncTask(uri); // create parameters for the task: layers and extent to include, out spatial reference, and sync model var layers = new List <int>(new int[3] { 0, 1, 2 }); var extent = MyMapView.Extent; var gdbParams = new GenerateGeodatabaseParameters(layers, extent) { OutSpatialReference = MyMapView.SpatialReference, SyncModel = SyncModel.PerLayer, ReturnAttachments = true }; // Create a System.Progress<T> object to report status as the task executes var progress = new Progress <GeodatabaseStatusInfo>(); progress.ProgressChanged += (s, info) => { //ShowStatus(info.Status); Console.WriteLine(info.Status); }; // call GenerateGeodatabaseAsync, pass in the parameters and the callback to execute when it's complete var gdbResult = await gdbTask.GenerateGeodatabaseAsync(gdbParams, GdbCompleteCallback, new TimeSpan(0, 1, 0), progress, cancelToken); } catch (Exception ex) { MessageBox.Show("Unable to create offline database: " + ex.Message); } }
// Generate / download and display layers from a generated geodatabase private async Task GenerateLocalGeodatabaseAsync(Envelope extent) { try { IsBusy = true; ReportStatus("Creating GeodatabaseSyncTask..."); var syncTask = new GeodatabaseSyncTask(new Uri(BASE_URL)); var options = new GenerateGeodatabaseParameters(new int[] { 1 }, extent) { GeodatabasePrefixName = GDB_PREFIX, ReturnAttachments = false, OutSpatialReference = extent.SpatialReference, SyncModel = SyncModel.PerLayer }; var tcs = new TaskCompletionSource<GeodatabaseStatusInfo>(); Action<GeodatabaseStatusInfo, Exception> completionAction = (info, ex) => { if (ex != null) tcs.SetException(ex); tcs.SetResult(info); }; var generationProgress = new Progress<GeodatabaseStatusInfo>(); generationProgress.ProgressChanged += (sndr, sts) => { SecondaryStatus = sts.Status.ToString(); }; ReportStatus("Starting GenerateGeodatabase..."); var result = await syncTask.GenerateGeodatabaseAsync(options, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); ReportStatus("Waiting on geodatabase from server..."); var statusResult = await tcs.Task; ReportStatus("Downloading Geodatabase..."); await DownloadGeodatabaseAsync(statusResult); ReportStatus("Opening Geodatabase..."); var gdb = await Geodatabase.OpenAsync(_gdbPath); ReportStatus("Create local feature layers..."); await CreateFeatureLayers(gdb); _onlineBirdsLayer.IsVisible = false; } finally { IsBusy = false; } }
private async void GetFeatures(object sender, RoutedEventArgs e) { try { StatusPanel.Visibility = Visibility.Visible; StatusMessagesList.Items.Add("Submitting generate geodatabase job ..."); StatusProgressBar.IsIndeterminate = true; StatusProgressBar.IsEnabled = true; // cancel if an erliear call was made if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } // get a cancellation token cancellationTokenSource = new CancellationTokenSource(); var cancelToken = cancellationTokenSource.Token; // create a new GeodatabaseSncTask with the uri of the feature service to pull from var serverUrl = operationalUrl.Substring(0, operationalUrl.LastIndexOf('/')); var uri = new Uri(serverUrl); var getFeaturesTask = new GeodatabaseSyncTask(uri); // crate parameters for the task: layers and extent to include, out spation reference and sync model var layers = new List<int>(new int[1] { 0 }); //just get the first layer var extent = MyMapView.Extent; var getFeaturesParams = new GenerateGeodatabaseParameters(layers, extent) { OutSpatialReference = MyMapView.SpatialReference, SyncModel = SyncModel.PerLayer }; // check progress every two seconds var checkInterval = TimeSpan.FromSeconds(2); var creationProgress = new Progress<GeodatabaseStatusInfo>(p => { this.StatusMessagesList.Items.Add(DateTime.Now.ToShortTimeString() + ": " + p.Status); }); // call GenerateGeodatabaseAsync, the GenerateFeautresCompleteCallback callback will execute when it's complete var gdbResults = await getFeaturesTask.GenerateGeodatabaseAsync(getFeaturesParams, GenerateFeatuersCompleteCallback, checkInterval, creationProgress, cancelToken); } catch (Exception ex) { StatusMessagesList.Items.Add("Unable to create offline database: " + ex.Message); StatusProgressBar.IsIndeterminate = false; } }
private async Task DoExportGeodataBase(List<FeatureLayer> featureLayerList) { try { Uri featureServerUri = null; var layerIdList = new List<int>(); foreach (var featureLayer in featureLayerList) { var geodatabaseFeatureServiceTable = featureLayer.FeatureTable as ServiceFeatureTable; if (geodatabaseFeatureServiceTable == null) return; var featureServiceUri = new Uri(geodatabaseFeatureServiceTable.ServiceUri); if (featureServerUri == null) { var newSegments = featureServiceUri.Segments.Take(featureServiceUri.Segments.Length - 1).ToArray(); newSegments[newSegments.Length - 1] = newSegments[newSegments.Length - 1].TrimEnd('/'); var uriBuilder = new UriBuilder(featureServiceUri) {Path = string.Concat(newSegments)}; featureServerUri = uriBuilder.Uri; } if (featureServiceUri.ToString().Contains(featureServerUri.ToString())) { var layerId = int.Parse(featureServiceUri.Segments.Last()); layerIdList.Add(layerId); } } _model.SetMessageInfo("Creating GeodatabaseSyncTask..."); var geodatabaseSyncTask = new GeodatabaseSyncTask(featureServerUri); var generateGeodatabaseParameters = new GenerateGeodatabaseParameters(layerIdList, _areaToExportGraphic.Geometry) { GeodatabasePrefixName = "EsriDE.Samples", // ReturnAttachments = true, OutSpatialReference = CurrentEsriMapView.SpatialReference, SyncModel = SyncModel.PerGeodatabase }; var taskCompletionSource = new TaskCompletionSource<GeodatabaseStatusInfo>(); Action<GeodatabaseStatusInfo, Exception> completionAction = (info, ex) => { if (ex != null) taskCompletionSource.SetException(ex); taskCompletionSource.SetResult(info); }; var generationProgress = new Progress<GeodatabaseStatusInfo>(); generationProgress.ProgressChanged += (sndr, sts) => { _model.SetMessageInfo(string.Format("{0}: {1}", sts.Status.ToString(), sts.LastUpdatedTime)); }; _model.SetMessageInfo("Starting Generate Geodatabase..."); var result = await geodatabaseSyncTask.GenerateGeodatabaseAsync(generateGeodatabaseParameters, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); _model.SetMessageInfo("Waiting on geodatabase from server..."); var statusResult = await taskCompletionSource.Task; _model.SetMessageInfo("Downloading Geodatabase..."); var gdbPath = await DownloadGeodatabase(statusResult, GetServiceNameByUrl(featureServerUri)); _model.SetMessageInfo(string.Format("Download completed : {0}", gdbPath)); } catch (Exception ex) { _model.SetMessageInfo(ex.Message); } }
private async Task GenerateGeodatabase() { var syncTask = new GeodatabaseSyncTask(new Uri(_url)); var serviceInfo = await syncTask.GetServiceInfoAsync(); var syncModel = serviceInfo.SyncCapabilities.SupportsPerLayerSync ? SyncModel.PerLayer : SyncModel.PerGeodatabase; var layerNumList = await Helpers.GetLayersIdList(_url); var options = new GenerateGeodatabaseParameters(layerNumList, serviceInfo.FullExtent) { ReturnAttachments = false, OutSpatialReference = serviceInfo.SpatialReference, SyncModel = syncModel }; var tcs = new TaskCompletionSource<GeodatabaseStatusInfo>(); Action<GeodatabaseStatusInfo, Exception> completionAction = (statusInfo, ex) => { try { if (ex != null) { tcs.SetException(ex); return; } tcs.SetResult(statusInfo); } catch (Exception) { } }; var generationProgress = new Progress<GeodatabaseStatusInfo>(); var result = await syncTask.GenerateGeodatabaseAsync(options, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); var statusResult = await tcs.Task; if (statusResult.Status == GeodatabaseSyncStatus.Failed) throw new ApplicationException("Map Download Failed, try again later."); await DownloadGeodatabase(statusResult, GDB_PATH); }