1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2016 Esri.//// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific// language governing permissions and limitations under the License.using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespaceArcGIS.WPF.Samples.ListGeodatabaseVersions{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "List geodatabase versions",
category: "Geoprocessing",
description: "Connect to a service and list versions of the geodatabase.",
instructions: "When the sample loads, a list of geodatabase versions and their properties will be displayed.",
tags: new[] { "conflict resolution", "data management", "database", "multi-user", "sync", "version" })]
publicpartialclassListGeodatabaseVersions {
// Url to used geoprocessing serviceprivateconststring ListVersionsUrl =
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions";
publicListGeodatabaseVersions() {
InitializeComponent();
// Create the UI, setup the control references and execute initialization _ = Initialize();
}
privateasync Task Initialize() {
// Set the UI to indicate that the geoprocessing is running SetBusy(true);
try {
// Get versions from a geodatabase IFeatureSet versionsFeatureSet = await GetGeodatabaseVersionsAsync();
// Continue if we got a valid geoprocessing resultif (versionsFeatureSet != null)
{
// Create a string builder to hold all of the information from the geoprocessing// task to display in the UI StringBuilder myStringBuilder = new StringBuilder();
// Loop through each Feature in the FeatureSetforeach (Feature version in versionsFeatureSet)
{
// Get the attributes (a dictionary of <key,value> pairs) from the Feature IDictionary<string, object> myDictionary = version.Attributes;
// Loop through each attribute (a <key,value> pair)foreach (KeyValuePair<string, object> attribute in myDictionary)
{
// Add the key and value strings to the string builder myStringBuilder.AppendLine(attribute.Key + ": " + attribute.Value);
}
// Add a blank line after each Feature (the listing of geodatabase versions) myStringBuilder.AppendLine();
}
// Display the result in the textbox ResultView.Text = myStringBuilder.ToString();
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error");
}
// Set the UI to indicate that the geoprocessing is not running SetBusy(false);
}
privateasync Task<IFeatureSet> GetGeodatabaseVersionsAsync() {
// Results will be returned as a feature set IFeatureSet results = null;
// Create new geoprocessing task GeoprocessingTask listVersionsTask = await GeoprocessingTask.CreateAsync(new Uri(ListVersionsUrl));
// Create default parameters that are passed to the geoprocessing task GeoprocessingParameters listVersionsParameters = await listVersionsTask.CreateDefaultParametersAsync();
// Create job that handles the communication between the application and the geoprocessing task GeoprocessingJob listVersionsJob = listVersionsTask.CreateJob(listVersionsParameters);
try {
// Execute analysis and wait for the results GeoprocessingResult analysisResult = await listVersionsJob.GetResultAsync();
// Get results from the outputs GeoprocessingFeatures listVersionsResults = (GeoprocessingFeatures)analysisResult.Outputs["Versions"];
// Set results results = listVersionsResults.Features;
}
catch (Exception ex)
{
// Error handling if something goes wrongif (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null)
MessageBox.Show("Executing geoprocessing failed. " + listVersionsJob.Error.Message, "Geoprocessing error");
else MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error");
}
finally {
// Set the UI to indicate that the geoprocessing is not running SetBusy(false);
}
return results;
}
privatevoidSetBusy(bool isBusy = true) {
if (isBusy)
{
// Change UI to indicate that the geoprocessing is running BusyOverlay.Visibility = Visibility.Visible;
Progress.IsIndeterminate = true;
}
else {
// Change UI to indicate that the geoprocessing is not running BusyOverlay.Visibility = Visibility.Collapsed;
Progress.IsIndeterminate = false;
}
}
}
}