This sample demonstrates tracking the identity of users who make edits (adds, updates) to a feature class. IdentityManager is used to prompt the user to log in. IdentityManager sets the FeatureLayer.EditUserName which is used to tell the service who is editing the features. To use the sample enter one of the username and password below: username=user1, password=user1 or username=user2, password=user2. Use the tools to add new features, select features, and delete features. Update features using the FeatureDataGrid.
Download Sample Application
< UserControl x:Class = " ArcGISWPFSDK.EditorTracking "
xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "
xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:esri = " http://schemas.esri.com/arcgis/client/2009 " >
< Grid x:Name = " LayoutRoot " >
< Grid.Resources >
< esri : Editor x:Key = " MyEditor "
GeometryServiceUrl = " http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer "
ContinuousMode = " True " />
</ Grid.Resources >
< Grid.RowDefinitions >
< RowDefinition Height = " * " />
< RowDefinition Height = " 5 " />
< RowDefinition Height = " 150 " />
</ Grid.RowDefinitions >
< esri : Map Name = " MyMap "
Extent = " -13724204.479703,5317475.93669291,-13400488.4812798,5450378.64389627 "
WrapAround = " True " >
< esri : ArcGISTiledMapServiceLayer ID = " Street Map "
Url = " http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer " />
< esri : FeatureLayer ID = " WildfireLayer "
DisplayName = " Wildfire Layer "
Url = " http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer/0 "
MouseLeftButtonDown = " FeatureLayer_MouseLeftButtonDown "
InitializationFailed = " FeatureLayer_InitializationFailed "
OutFields = " description,eventdate,eventtype,created_user,created_date,last_edited_user,last_edited_date "
Mode = " OnDemand " />
</ esri : Map >
< Grid Name = " LoggedInGrid "
HorizontalAlignment = " Right "
VerticalAlignment = " Top "
Margin = " 0,15,15,0 "
Visibility = " Collapsed " >
< Rectangle Stroke = " Gray "
RadiusX = " 10 "
RadiusY = " 10 "
Fill = " LightGray "
Margin = " -10 " >
< Rectangle.Effect >
< DropShadowEffect />
</ Rectangle.Effect >
</ Rectangle >
< Grid >
< Grid.ColumnDefinitions >
< ColumnDefinition />
< ColumnDefinition />
</ Grid.ColumnDefinitions >
< Grid.RowDefinitions >
< RowDefinition />
< RowDefinition />
< RowDefinition />
</ Grid.RowDefinitions >
< TextBlock Grid.Row = " 0 "
Grid.ColumnSpan = " 2 "
Text = " {Binding ElementName=MyMap,Path=Layers[WildfireLayer].DisplayName} " />
< TextBlock Text = " Logged in as: "
Grid.Column = " 0 "
Grid.Row = " 1 "
Margin = " 2 "
VerticalAlignment = " Center " />
< TextBlock Name = " LoggedInUserTextBlock "
FontWeight = " Bold "
HorizontalAlignment = " Left "
Margin = " 2 "
Grid.Column = " 1 "
Grid.Row = " 1 "
TextAlignment = " Left " />
< Button Name = " ChangeUserButton "
Content = " Sign Out "
Width = " 140 "
Margin = " 0,5,0,5 "
HorizontalAlignment = " Center "
Grid.Row = " 2 "
Grid.ColumnSpan = " 2 "
Click = " SignOut_Click " />
</ Grid >
</ Grid >
< Border Name = " ToolBorder "
Background = " LightGray "
Visibility = " Collapsed "
BorderThickness = " 1 "
CornerRadius = " 5 "
HorizontalAlignment = " Left "
VerticalAlignment = " Top "
Padding = " 5 "
BorderBrush = " Black "
Margin = " 5 " >
< Border.Effect >
< DropShadowEffect />
</ Border.Effect >
< StackPanel Orientation = " Vertical " >
< esri : TemplatePicker Map = " {Binding ElementName=MyMap, Mode=OneWay} "
LayerIDs = " WildfireLayer " />
< StackPanel DataContext = " {StaticResource MyEditor} "
Orientation = " Vertical " >
< StackPanel Orientation = " Horizontal " >
< Button Command = " {Binding ClearSelection} "
Margin = " 2 " >
< TextBlock > Clear< LineBreak /> Selection</ TextBlock >
</ Button >
< Button Command = " {Binding DeleteSelected} "
Margin = " 2 " >
< TextBlock > Delete< LineBreak /> Selected</ TextBlock >
</ Button >
</ StackPanel >
</ StackPanel >
</ StackPanel >
</ Border >
< esri : FeatureDataGrid Grid.Row = " 2 "
x:Name = " MyDataGrid "
Map = " {Binding ElementName=MyMap} "
SelectionMode = " Single "
GraphicsLayer = " {Binding ElementName=MyMap, Path=Layers.[WildfireLayer]} " />
</ Grid >
</ UserControl >
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Toolkit;
namespace ArcGISWPFSDK
{
public partial class EditorTracking : UserControl
{
public EditorTracking()
{
InitializeComponent();
ESRI.ArcGIS.Client.Editor myEditor = LayoutRoot.Resources["MyEditor" ] as ESRI.ArcGIS.Client.Editor;
myEditor.Map = MyMap;
IdentityManager.Current.ChallengeMethod = Challenge;
}
private void Challenge(string url,
Action<IdentityManager.Credential, Exception> callback, IdentityManager.GenerateTokenOptions options)
{
SignInDialog.DoSignIn(url, (credential, error) =>
{
if (error == null )
{
ToolBorder.Visibility = System.Windows.Visibility.Visible;
LoggedInGrid.Visibility = System.Windows.Visibility.Visible;
LoggedInUserTextBlock.Text = credential.UserName;
}
callback(credential, error);
}
, options);
}
private void FeatureLayer_InitializationFailed(object sender, EventArgs e)
{ }
private void SignOut_Click(object sender, RoutedEventArgs e)
{
SignOut();
}
private void SignOut()
{
var featureLayer = MyMap.Layers["WildfireLayer" ] as FeatureLayer;
var credential = IdentityManager.Current.FindCredential(featureLayer.Url, LoggedInUserTextBlock.Text);
if (credential == null ) return ;
ToolBorder.Visibility = System.Windows.Visibility.Collapsed;
LoggedInGrid.Visibility = System.Windows.Visibility.Collapsed;
IdentityManager.Current.RemoveCredential(credential);
MyMap.Layers.Remove(featureLayer);
featureLayer = new FeatureLayer()
{
ID = "WildfireLayer" ,
DisplayName = "Wildfire Layer" ,
Url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer/0" ,
Mode = FeatureLayer.QueryMode.OnDemand
};
featureLayer.OutFields.Add("*" );
featureLayer.MouseLeftButtonDown += FeatureLayer_MouseLeftButtonDown;
featureLayer.InitializationFailed += FeatureLayer_InitializationFailed;
MyMap.Layers.Add(featureLayer);
}
private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
{
if (e.Graphic != null && !e.Graphic.Selected && (sender as FeatureLayer).IsUpdateAllowed(e.Graphic))
{
Editor editor = LayoutRoot.Resources["MyEditor" ] as Editor;
if ((sender as FeatureLayer).IsUpdateAllowed(e.Graphic))
{
if (editor.EditVertices.CanExecute(null ))
editor.EditVertices.Execute(null );
}
else
if (editor.CancelActive.CanExecute(null ))
editor.CancelActive.Execute(null );
}
(sender as FeatureLayer).ClearSelection();
e.Graphic.Select();
MyDataGrid.ScrollIntoView(e.Graphic, null );
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry
Imports ESRI.ArcGIS.Client.Toolkit
Namespace ArcGISWPFSDK
Partial Public Class EditorTracking
Inherits UserControl
Public Sub New ()
InitializeComponent()
Dim myEditor As ESRI.ArcGIS.Client.Editor = TryCast(LayoutRoot.Resources("MyEditor" ), ESRI.ArcGIS.Client.Editor)
myEditor.Map = MyMap
IdentityManager.Current.ChallengeMethod = AddressOf Challenge
End Sub
Private Sub Challenge(url As String , callback As Action(Of IdentityManager.Credential, Exception), options As IdentityManager.GenerateTokenOptions)
SignInDialog.DoSignIn(url, Function (credential, [error ])
If [error ] Is Nothing Then
ToolBorder.Visibility = System.Windows.Visibility.Visible
LoggedInGrid.Visibility = System.Windows.Visibility.Visible
LoggedInUserTextBlock.Text = credential.UserName
End If
callback(credential, [error ])
End Function , options)
End Sub
Private Sub FeatureLayer_InitializationFailed(sender As Object , e As EventArgs)
End Sub
Private Sub SignOut_Click(sender As Object , e As RoutedEventArgs)
SignOut()
End Sub
Private Sub SignOut()
Dim featureLayer = TryCast(MyMap.Layers("WildfireLayer" ), FeatureLayer)
Dim credential = IdentityManager.Current.FindCredential(featureLayer.Url, LoggedInUserTextBlock.Text)
If credential Is Nothing Then
Return
End If
ToolBorder.Visibility = System.Windows.Visibility.Collapsed
LoggedInGrid.Visibility = System.Windows.Visibility.Collapsed
IdentityManager.Current.RemoveCredential(credential)
MyMap.Layers.Remove(featureLayer)
featureLayer = New FeatureLayer() With { _
.ID = "WildfireLayer" , _
.DisplayName = "Wildfire Layer" , _
.Url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/FeatureServer/0" , _
.Mode = featureLayer.QueryMode.OnDemand _
}
featureLayer.OutFields.Add("*" )
MyMap.Layers.Add(featureLayer)
End Sub
Private Sub FeatureLayer_MouseLeftButtonDown(sender As Object , e As GraphicMouseButtonEventArgs)
If e.Graphic IsNot Nothing AndAlso Not e.Graphic.Selected AndAlso TryCast(sender, FeatureLayer).IsUpdateAllowed(e.Graphic) Then
Dim editor As Editor = TryCast(LayoutRoot.Resources("MyEditor" ), Editor)
If TryCast(sender, FeatureLayer).IsUpdateAllowed(e.Graphic) Then
If editor.EditVertices.CanExecute(Nothing ) Then
editor.EditVertices.Execute(Nothing )
End If
ElseIf editor.CancelActive.CanExecute(Nothing ) Then
editor.CancelActive.Execute(Nothing )
End If
End If
TryCast(sender, FeatureLayer).ClearSelection()
e.Graphic.[Select ]()
MyDataGrid.ScrollIntoView(e.Graphic, Nothing )
End Sub
End Class
End Namespace
5/16/2014