List geodatabase versions

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Connect to a service and list versions of the geodatabase.

Image of list geodatabase versions

Use case

As part of a multi-user editing scenario, you can check with the server to see how many versions of the geodatabase are outstanding before syncing.

How to use the sample

When the sample loads, a list of geodatabase versions and their properties will be displayed.

How it works

  1. Create a geoprocessing task referring to a GPServer with a ListVersions task.
  2. Use the task to create default parameters.
  3. Use the created parameters to create a job.
  4. Run the job to get a GeoprocessingResult.
  5. Get a list of geoprocessing features from the Versions output parameter of the results.
  6. Format the geodatabase versions for display.

Relevant API

  • GeoprocessingFeatures
  • GeoprocessingFeatures.Features
  • GeoprocessingJob
  • GeoprocessingJob.GetResultAsync
  • GeoprocessingParameters
  • GeoprocessingResult
  • GeoprocessingResult.Outputs
  • GeoprocessingTask
  • GeoprocessingTask.CreateDefaultParametersAsync
  • GeoprocessingTask.CreateJob

About the data

The sample uses a sample geoprocessing service hosted on ArcGIS Online.

Additional information

ArcGIS Server does not include a geoprocessing service for listing geodatabase versions. You must configure one using the steps defined in Geoprocessing service example: list, create, and delete geodatabase versions in the ArcMap documentation.

Tags

conflict resolution, data management, database, multi-user, sync, version

Sample Code

ListGeodatabaseVersions.cs
Use dark colors for code blocksCopy
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright 2017 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 System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using Foundation;
using UIKit;

namespace ArcGISRuntime.Samples.ListGeodatabaseVersions
{
    [Register("ListGeodatabaseVersions")]
    [ArcGISRuntime.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" })]
    public class ListGeodatabaseVersions : UIViewController
    {
        // Hold references to UI controls.
        private UIActivityIndicatorView _progressBar;
        private UITextView _geodatabaseListField;

        // URL pointing to the service.
        private readonly Uri _listVersionsUrl =
            new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions");

        public ListGeodatabaseVersions()
        {
            Title = "List geodatabase versions";
        }

        private async void Initialize()
        {
            try
            {
                // Get versions from a geodatabase.
                IFeatureSet versionsFeatureSet = await GetGeodatabaseVersionsAsync();

                // Continue if there is a valid geoprocessing result.
                if (versionsFeatureSet != null)
                {
                    // Create a string builder to hold all of the information from the geoprocessing
                    // task to display in the UI.
                    StringBuilder stringBuilder = new StringBuilder();

                    // Loop through each Feature in the FeatureSet.
                    foreach (Feature version in versionsFeatureSet)
                    {
                        // Loop through each attribute (a <key,value> pair).
                        foreach (KeyValuePair<string, object> attribute in version.Attributes)
                        {
                            // Add the key and value strings to the string builder.
                            stringBuilder.AppendLine(attribute.Key + ": " + attribute.Value);
                        }

                        // Add a blank line after each Feature (the listing of geodatabase versions).
                        stringBuilder.AppendLine();
                    }

                    // Display the results to the user.
                    _geodatabaseListField.Text = stringBuilder.ToString();
                }
            }
            catch (Exception e)
            {
                new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate) null, "OK", null).Show();
            }
        }

        private async Task<IFeatureSet> GetGeodatabaseVersionsAsync()
        {
            // Start animating the activity indicator.
            _progressBar.StartAnimating();

            // Results will be returned as a feature set.
            IFeatureSet results = null;

            // Create new geoprocessing task.
            GeoprocessingTask listVersionsTask = await GeoprocessingTask.CreateAsync(_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 wrong.
                if (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null)
                {
                    UIAlertController alert = new UIAlertController
                    {
                        Message = "Executing geoprocessing failed. " + listVersionsJob.Error.Message
                    };
                    alert.ShowViewController(this, this);
                }
                else
                {
                    UIAlertController alert = new UIAlertController
                    {
                        Message = "An error occurred. " + ex
                    };
                    alert.ShowViewController(this, this);
                }
            }
            finally
            {
                // Stop the activity animation.
                _progressBar.StopAnimating();
            }

            return results;
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Initialize();
        }

        public override void LoadView()
        {
            // Create the views.
            View = new UIView {BackgroundColor = ApplicationTheme.BackgroundColor};

            _progressBar = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
            _progressBar.TranslatesAutoresizingMaskIntoConstraints = false;
            _progressBar.BackgroundColor = UIColor.FromWhiteAlpha(.3f, .8f);
            _progressBar.HidesWhenStopped = true;

            _geodatabaseListField = new UITextView();
            _geodatabaseListField.TranslatesAutoresizingMaskIntoConstraints = false;

            // Add the views.
            View.AddSubviews(_geodatabaseListField, _progressBar);

            // Lay out the views.
            NSLayoutConstraint.ActivateConstraints(new[]
            {
                _geodatabaseListField.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                _geodatabaseListField.LeadingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.LeadingAnchor),
                _geodatabaseListField.TrailingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TrailingAnchor),
                _geodatabaseListField.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor),

                _progressBar.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                _progressBar.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _progressBar.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _progressBar.BottomAnchor.ConstraintEqualTo(View.BottomAnchor)
            });
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.