Beispiel #1
0
        // provide a callback to execute when the GeodatabaseSyncTask completes (successfully or with an exception)
        private async void GdbCompleteCallback(Esri.ArcGISRuntime.Tasks.Offline.GeodatabaseStatusInfo statusInfo, Exception ex)
        {
            // if unsuccessful, report the exception and return
            if (ex != null)
            {
                Console.WriteLine("An exception occured: " + ex.Message);
                //this.ReportStatus("An exception occured: " + ex.Message);
                return;
            }

            // if successful, read the generated geodatabase from the server
            var client    = new ArcGISHttpClient();
            var gdbStream = client.GetOrPostAsync(statusInfo.ResultUri, null);

            var geodatabasePath = System.IO.Path.Combine(@"C:\Temp\10_2_7Demo", "WildlifeLocal.geodatabase");

            // create a local path for the geodatabase, if it doesn't already exist
            if (!System.IO.Directory.Exists(@"C:\Temp\10_2_7Demo"))
            {
                System.IO.Directory.CreateDirectory(@"C:\Temp\10_2_7Demo");
            }

            // write geodatabase to local location
            await Task.Factory.StartNew(async delegate
            {
                using (var stream = System.IO.File.Create(geodatabasePath))
                {
                    await gdbStream.Result.Content.CopyToAsync(stream);
                }
                MessageBox.Show("Offline database created at " + geodatabasePath);
            });
        }
        // provide a callback to execute when the GeodatabaseSyncTask completes (successfully or with an exception)
        private async void GdbCompleteCallback(Esri.ArcGISRuntime.Tasks.Offline.GeodatabaseStatusInfo statusInfo, Exception ex)
        {
            // if unsuccessful, report the exception and return
            if (ex != null)
            {
                this.Dispatcher.Invoke(() => this.SyncStatusTextBlock.Text = "An exception occured: " + ex.Message);
                return;
            }

            // if successful, read the generated geodatabase from the server
            var client    = new ArcGISHttpClient();
            var gdbStream = client.GetOrPostAsync(statusInfo.ResultUri, null);

            var geodatabasePath = System.IO.Path.Combine(@"C:\Temp\Cache", "PoiLocal.geodatabase");

            // create a local path for the geodatabase, if it doesn't already exist
            if (!System.IO.Directory.Exists(@"C:\Temp\Cache"))
            {
                System.IO.Directory.CreateDirectory(@"C:\Temp\Cache");
            }

            await Task.Factory.StartNew(async delegate
            {
                using (var stream = System.IO.File.Create(geodatabasePath))
                {
                    await gdbStream.Result.Content.CopyToAsync(stream);
                }
                this.Dispatcher.Invoke(() => this.LocalDataPathTextBlock.Text  = geodatabasePath);
                this.Dispatcher.Invoke(() => this.SyncProgressBar.Visibility   = System.Windows.Visibility.Hidden);
                this.Dispatcher.Invoke(() => this.SyncStatusPanel.Visibility   = System.Windows.Visibility.Collapsed);
                this.Dispatcher.Invoke(() => this.UseLocalDataOption.IsEnabled = true);
            });
        }