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();
        }
Ejemplo n.º 2
0
        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()
        {
            // 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();
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        /**
         * 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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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));
                }
            }
        }