Пример #1
0
		public void TriggerSyncOfflineMapEvent(OfflineMapItem offlineMapItem)
		{
			SyncOfflineMap(offlineMapItem);
		}
Пример #2
0
		public void TriggerLoadOfflineMapEvent(OfflineMapItem offlineMapItem)
		{
			LoadOfflineMap(offlineMapItem);
		}
Пример #3
0
		public void TriggerDeleteOfflineMapEvent(OfflineMapItem offlineMapItem)
		{
			DeleteOfflineMap(offlineMapItem);
		}
        private ObservableCollection<OfflineMapListBoxItem> CreateOfflineMapItems()
        {
            var offlineMapListBoxItems = new ObservableCollection<OfflineMapListBoxItem>();
            var webMapdirectories = GetWebMapdirectories();

            foreach (var webMapDirectory in webMapdirectories)
            {
                var portalItemJson = GetPortalItemJson(webMapDirectory);
                if (portalItemJson == null)
                {
                    continue;
                }

                var directories = Directory.GetDirectories(webMapDirectory);
                foreach (var directory in directories)
                {
                    var offlineMapName = directory.Split('\\').Last();
                    var offlineMapItem = new OfflineMapItem(portalItemJson, offlineMapName, Path.GetFullPath(directory));

                    var offlineMapListBoxItem = new OfflineMapListBoxItem(offlineMapItem, LoadOfflineMapCommand, SyncOfflineMapCommand,
                        DeleteOfflineMapCommand);
                    offlineMapListBoxItems.Add(offlineMapListBoxItem);
                }
            }

            return offlineMapListBoxItems;
        }
		private async Task Reset()
		{
			CurrentEsriMapView = null;
			_model.SetSyncState(CheckSyncState(true));
			_currentOfflineMapItem = null;
			await CreateToc();
			IsInProgress = false;
		}
		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);
		}
		private async Task SyncOfflineMap(OfflineMapItem offlineMapItem)
		{
			var gdbFiles = Directory.GetFiles(offlineMapItem.OfflineMapPath,
				string.Format("*{0}", OfflineMapItem.GeodatabaseFilenameExtension));
			foreach (var gdbFile in gdbFiles)
			{
				var gdbPath = gdbFile.Replace("/", @"\");
				var geodatabase = await Geodatabase.OpenAsync(gdbPath);
				if (!geodatabase.FeatureTables.Any(table => table.HasEdits))
				{
					// nothing to sync..
					continue;
				}

				_model.SetMessageInfo("Sync geodatabase...");
				var serviceUri = geodatabase.GetServiceUri();
				var geodatabaseSyncTask = new GeodatabaseSyncTask(serviceUri);
				var statusCallback =
					new Progress<GeodatabaseStatusInfo>(
						statusInfo => _model.SetMessageInfo(string.Format("Current Status: {0}", statusInfo.Status)));

				var tcs = new TaskCompletionSource<GeodatabaseStatusInfo>();

				try
				{
					// At this point, we are submitting a job. Therefore, the await returns pretty fast.
					await geodatabaseSyncTask.SyncGeodatabaseAsync(
						new SyncGeodatabaseParameters
						{
							RollbackOnFailure = true,
							SyncDirection = SyncDirection.Upload,
							UnregisterGeodatabase = false
						},
						geodatabase,
						(geodatabaseStatusInfo, exc) =>
						{
							if (geodatabaseStatusInfo != null)
							{
								tcs.SetResult(geodatabaseStatusInfo);
							}
							if (exc != null)
							{
								tcs.SetException(exc);
							}
						},
						uploadResult => { _model.SetMessageInfo(string.Format("UploadResult: {0}", uploadResult.Success)); },
						TimeSpan.FromSeconds(5),
						statusCallback,
						CancellationToken.None);

					// This is the call we are really waiting for..
					await tcs.Task;
					_model.SetMessageInfo(string.Format("Finished Status: {0}", tcs.Task.Result.Status));
				}
				catch (Exception exc)
				{
					_model.SetMessageInfo(string.Format("Executing SyncGeodatabaseAsync failed: {0}", exc.Message));
				}
				_model.SetMessageInfo("...done syncing geodatabase");
			}
		}
		private async Task LoadOfflineMap(OfflineMapItem offlineMapItem)
		{
			_currentOfflineMapItem = offlineMapItem;
			var basemapName = GetBasemapNameFromDirectory(offlineMapItem.OfflineMapPath);
			var arcGisLocalTiledLayer =
				new ArcGISLocalTiledLayer(string.Format("{0}\\{1}{2}", offlineMapItem.OfflineMapPath, basemapName,
					OfflineMapItem.BasemapFilenameExtension));
			arcGisLocalTiledLayer.DisplayName = basemapName;
			var offlineMap = new Map();
			offlineMap.Layers.Add(arcGisLocalTiledLayer);

			var files = Directory.GetFiles(offlineMapItem.OfflineMapPath,
				string.Format("*{0}", OfflineMapItem.GeodatabaseFilenameExtension));
			foreach (var file in files)
			{
				var gdbFile = file.Replace("/", @"\");
				var featureLayerList = await CreateOfflineFeatureLayersAsync(gdbFile);

				foreach (var featureLayer in featureLayerList)
				{
					var geodatabaseFeatureTable = featureLayer.FeatureTable as GeodatabaseFeatureTable;
					featureLayer.DisplayName = geodatabaseFeatureTable.ServiceInfo.Name;
					featureLayer.IsVisible = geodatabaseFeatureTable.ServiceInfo.DefaultVisibility;
					offlineMap.Layers.Add(featureLayer);
				}

				break;
			}

			var mapView = new MapView {Map = offlineMap};
			CurrentEsriMapView = mapView;
			CurrentEsriMapView.MapViewTapped += CurrentEsriMapViewTapped;
			await Task.Delay(TimeSpan.FromSeconds(2));
		}