Visual Basic (Declaration) | |
---|---|
Public Sub UnshareAsync( _ ByVal groupIds As IEnumerable(Of String), _ ByVal callback As Action(Of IEnumerable(Of String),Exception) _ ) |
C# | |
---|---|
public void UnshareAsync( IEnumerable<string> groupIds, Action<IEnumerable<string>,Exception> callback ) |
In order to use the ArcGISPortalItem.UnshareAsync Method, a user must be logged into the ArcGIS Online or ArcGIS Portal site with proper credentials. One way for a user to log into the portal site is via code using the IdentityManager Class.
The individual who is authenticated and logged into the portal site that desires to use the ArcGISPortalItem.UnshareAsync Method to remove which Groups (via their ArcGISPortalGroup.Id values) the ArcGISPortalItem is currently shared MUST meet one of the following criteria:
- The authenticated user is the owner of the ArcGISPortalItem.
- The authenticated user is the Administrator of the Organization to which the ArcGISPortalItem belongs.
- The ArcGISPortalItem has its PortalAccess value of Public and the authenticated user is the owner of the Group. Note: the ArcGISPortalItem may not have been created/owned by the authenticated user; it is only important that the ArcGISPortalItem be Public, no matter who created/owns the ArcGISPortalItem.
- The ArcGISPortalItem has its PortalAccess value of Public and the authenticated user is the Administrator of the Organization to which Group belongs. Note: the ArcGISPortalItem may not have been created/owned by the authenticated user; it is only important that the ArcGISPortalItem be Public, no matter who created/owns the ArcGISPortalItem.
Parameters
- groupIds
- The IEnumerable (aka. a collection) of Group Ids (obtained via ArcGISPortalGroup.Id values) that you want to stop sharing the item with.
- callback
- The callback executed when the result is available. The first argument of the callback is the IEnumerable (aka. a collection) of Groups to which the item could not be unshared from.
How to use:
Edit the Member (i.e. Global) variables in the code-behind before running this sample. You need to supply Urls for an ArcGIS Online or ArcGIS Portal to get information about ArcGISPortalItems. It is required to supply the username and password for a user that can access the portal. - When the application loads, click on an ArcGISPortalItem in the ListBox to display information in the other controls. Choose the various access level radio buttons and then click the button to update the ArcGISPortalItem. The radio buttons are mutually exclusive. If the Shared RadioButton is chosen, you can also specify one or more Groups (via CheckBoxes) to associate with the ArcGISPortalItem.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | ![]() |
---|---|
<Grid x:Name="LayoutRoot" Background="White"> <!-- Display the ArcGISPortalItems in a ListBox. The user can click on items in the ListBox and see information about the ArcGISPortalItem in the other controls. --> <TextBlock Height="23" HorizontalAlignment="Left" Margin="2,124,0,0" Name="TextBlock1" Text="ArcGISPortalItems:" VerticalAlignment="Top" /> <ListBox Height="455" HorizontalAlignment="Left" Margin="0,145,0,0" Name="ListBox_Results" VerticalAlignment="Top" Width="384" SelectionChanged="ListBox_Results_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding Title, StringFormat='Title: {0}'}"/> <Image Source="{Binding ThumbnailUri}" Stretch="None" HorizontalAlignment="Left"/> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <TextBox Height="318" HorizontalAlignment="Left" Margin="390,270,0,0" Name="TextBox1" VerticalAlignment="Top" Width="410" Background="Aquamarine" /> <!-- Controls the user can manipulate to change the PortalAccess level and Groups associated with the selected ArcGISPortalItem. --> <RadioButton Content="Private" Height="16" HorizontalAlignment="Left" Margin="461,101,0,0" Name="RadioButton_Private" VerticalAlignment="Top" Click="RadioButton_XXX_Click"/> <RadioButton Content="Organization" Height="16" HorizontalAlignment="Left" Margin="526,101,0,0" Name="RadioButton_Organization" VerticalAlignment="Top" Click="RadioButton_XXX_Click"/> <RadioButton Content="Public" Height="16" HorizontalAlignment="Left" Margin="390,101,0,0" Name="RadioButton_Public" VerticalAlignment="Top" Click="RadioButton_XXX_Click"/> <RadioButton Content="Shared (aka. Groups)" Height="16" HorizontalAlignment="Left" Margin="390,125,0,0" Name="RadioButton_Shared" VerticalAlignment="Top" Click="RadioButton_Shared_Click"/> <ListBox Height="90" HorizontalAlignment="Left" Margin="390,145,0,0" Name="ListBox_GroupsOwned" VerticalAlignment="Top" Width="410" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <CheckBox IsChecked="{Binding Selected, Mode=TwoWay}" Content="{Binding Item.Title}" Tag="{Binding Item.Id}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <!-- Display the credential information for the user specified in the code-behind Member variables. --> <TextBlock Height="22" Margin="581,126,0,0" Name="TextBlock2" VerticalAlignment="Top" Text="Current User:" HorizontalAlignment="Left" Width="73" /> <TextBlock Height="22" HorizontalAlignment="Left" Margin="660,125,0,0" Name="TextBlock_CurrentUser" VerticalAlignment="Top" Width="140" /> <!-- Update the access level and Groups for the selected ArcGISPortalItem. --> <Button Content="ArcGISPortalItem.ShareAsync (ver1)" Height="23" HorizontalAlignment="Left" Margin="390,241,0,0" VerticalAlignment="Top" Width="410" Name="Button_ArcGISPortalItem_ShareAsync_Ver1" Click="Button_ArcGISPortalItem_ShareAsync_Ver1_Click"/> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="95" HorizontalAlignment="Left" Name="TextBlock_Instructions" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" Text="Edit the Member (i.e. Global) variables in the code-behind before running this sample. You need to supply Urls for an ArcGIS Online or ArcGIS Portal to get information about ArcGISPortalItems. It is required to supply the username and password for a user that can access the portal. - When the application loads, click on an ArcGISPortalItem in the ListBox to display information in the other controls. Choose the various access level radio buttons and then click the button to update the ArcGISPortalItem. The radio buttons are mutually exclusive. If the Shared RadioButton is chosen, you can also specify one or more Groups (via CheckBoxes) to associate with the ArcGISPortalItem." /> </Grid> |
C# | ![]() |
---|---|
public partial class MainPage : UserControl { // ========================================================================================== // TODO: MODIFY THE FOLLOWING MEMBER (i.e. GLOBAL) VARIABLES THAT WORK FOR YOUR ORGANIZATION! // Specify the root location of ArcGIS Online or your ArcGIS Portal for testing. private const string _DefaultServerUrl = "http://www.YourArcGISPortal.com/sharing/rest"; // Specify the location of ArcGIS Online or your ArcGIS Portal for generating a token for accessing secured services. private const string _DefaultTokenUrl = "https://www.YourArcGISPortal.com/sharing/generateToken"; // Specify the UserName of the account in ArcGIS Online or your ArcGIS Portal. private const string _Username = "YourUserName"; // Specify the Password of the account in ArcGIS Online or your ArcGIS Portal. private const string _Password = "YourPassword"; // ========================================================================================== // Other Member (aka. Global) variables used in the application. (NO NEED TO MODIFY) private ESRI.ArcGIS.Client.Portal.ArcGISPortal _MyArcGISPortal = new ESRI.ArcGIS.Client.Portal.ArcGISPortal() { Url = _DefaultServerUrl }; private ESRI.ArcGIS.Client.Portal.ArcGISPortalUser _MyArcGISPortalUser; private List<ArcGISPortalGroupExtended> _MyListOfArcGISPortalGroupExtended = new List<ArcGISPortalGroupExtended>(); private ESRI.ArcGIS.Client.Portal.ArcGISPortalItem _MyArcGISPortalItem; public MainPage() { InitializeComponent(); // Create a new instance of the IdentityManager.ServerInfos collection. System.Collections.Generic.List<ESRI.ArcGIS.Client.IdentityManager.ServerInfo> myServerInfos = null; myServerInfos = new System.Collections.Generic.List<ESRI.ArcGIS.Client.IdentityManager.ServerInfo>(); // Create a new instance of a single IdentityManager.ServerInfo object. Using the user supplied Member variables defined // above set the ServerInfo.ServerUrl and ServerInfo.TokenServiceUrl Properties. ESRI.ArcGIS.Client.IdentityManager.ServerInfo myServerInfo = new ESRI.ArcGIS.Client.IdentityManager.ServerInfo(); myServerInfo.ServerUrl = _DefaultServerUrl; myServerInfo.TokenServiceUrl = _DefaultTokenUrl; // Add the ServerInfo object to the ServerInfos collection. myServerInfos.Add(myServerInfo); // Determine the location of secure server and token endpoint. ESRI.ArcGIS.Client.IdentityManager.Current.RegisterServers(myServerInfos); // Define the function to challenge for credentials. ESRI.ArcGIS.Client.IdentityManager.Current.ChallengeMethod = CALLBACK_IdentityManager_ChallengeMethod; // Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = null; // Disable being able to select Groups. Once the user has selected the RadioButton_Shared they can check on various Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = false; // Get the credential object that will be used to access secured token based services. ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(_DefaultServerUrl, _Username, _Password, CALLBACK_IdentityManager_GenerateCredentialAsync); } private void CALLBACK_IdentityManager_ChallengeMethod(string url, Action<ESRI.ArcGIS.Client.IdentityManager.Credential, Exception> callback, ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions options) { // Activate the IdentityManager. callback(null, new NotImplementedException()); } private void CALLBACK_IdentityManager_GenerateCredentialAsync(ESRI.ArcGIS.Client.IdentityManager.Credential crd, System.Exception ex) { // The callback that obtains the credential object. if (crd != null) { // We got a valid credential user token object. // Add the credential user token to the IdentityManager for accessing resources. ESRI.ArcGIS.Client.IdentityManager.Current.AddCredential(crd); // Begin the process of accessing ArcGIS Online/ArcGIS Portal using the user specified Member variables defined above. _MyArcGISPortal.InitializeAsync(_DefaultServerUrl, CALLBACK_ArcGISPortal_InitializeAsync); } else { // We had a problem generating the credentialed user token. Notify the user of the problem. MessageBox.Show("Could not log in. Please check credentials."); } } private void CALLBACK_ArcGISPortal_InitializeAsync(ESRI.ArcGIS.Client.Portal.ArcGISPortal credential, System.Exception exception) { // The callback that establishes valid communication with ArcGIS Online/ArcGIS Portal. if (credential != null && credential.CurrentUser != null) { // We have valid credentials. // Set the Member variable for the ArcGISPortalUser to the user credential that was found using the IdentityManager. _MyArcGISPortalUser = credential.CurrentUser; // Display the FullName of the credentialed user in the TextBlock. TextBlock_CurrentUser.Text = string.Format(credential.CurrentUser.FullName); // Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = null; // Set the ArcGISPortal.Url to the user defined Member variable. if (string.IsNullOrEmpty(_MyArcGISPortal.Url)) { _MyArcGISPortal.Url = _DefaultServerUrl; } // Get the ArcGISPortalItems for the credentialed user. _MyArcGISPortalUser.GetItemsAsync(CALLBACK_ArcGISPortalUser_GetItemsAsync); // Get the Groups that an ArcGISPortalUser belongs to. _MyArcGISPortalUser.GetGroupsAsync(CALLBACK_ArcGISPortalUser_GetGroupsAsync); } } private void CALLBACK_ArcGISPortalUser_GetGroupsAsync(IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup> grps, System.Exception err) { // Add the Groups the credentialed user has to the ArcGISPortalGroupExtended collection. _MyListOfArcGISPortalGroupExtended.AddRange( from g in grps select new ArcGISPortalGroupExtended(g)); // Add the ArcGISPortalGroupExtended objects to the ListBox. ListBox_GroupsOwned.ItemsSource = _MyListOfArcGISPortalGroupExtended; } private void CALLBACK_ArcGISPortalUser_GetItemsAsync(System.Collections.Generic.IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalItem> userItems, System.Exception ex) { // Add the ArcGISPortalItems to the ListBox. ListBox_Results.ItemsSource = userItems; } private void Button_ArcGISPortalItem_ShareAsync_Ver1_Click(object sender, System.Windows.RoutedEventArgs e) { // Executes when the user clicks the Button. Changes the access level permissions for the selected ArcGISPortalItem. // Get the ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = ListBox_Results.SelectedItem as ESRI.ArcGIS.Client.Portal.ArcGISPortalItem; // Warn the user that before they can change an access level on an ArcGISPortalItem, that they must first select it. if (_MyArcGISPortalItem == null) { MessageBox.Show("Select an ArcGISPortalItem from the ListBox before trying to change access level permissions."); return; } // Get the list of all the Groups the user can set for an ArcGISPortalItem. System.Collections.Generic.List<string> my_GroupIDs_ALL = new System.Collections.Generic.List<string>(); foreach (ArcGISPortalGroupExtended myArcGISPortalGroupExtended in _MyListOfArcGISPortalGroupExtended) { ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup myArcGISPortalGroup = myArcGISPortalGroupExtended.Item; my_GroupIDs_ALL.Add(myArcGISPortalGroup.Id); } //------------------------------------------ if (RadioButton_Public.IsChecked == true) { // The user has chosen to make the ArcGISPortalItem Public. In this code example we will make sure that all other PortalAccess // levels are turned off and clear out any Groups to which the ArcGISPortalItem may belong to. // NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, (result, err) => { // Display any error messages if any. if (err != null) { MessageBox.Show(err.Message); } // Now set the PortalAccess level for everyone (i.e. Public). _MyArcGISPortalItem.ShareAsync(null, true, false, CALLBACK_ArcGISPortalItem_ShareAsync); }); } //------------------------------------------ if (RadioButton_Organization.IsChecked == true) { // The user has chosen to make the ArcGISPortalItem open to the Organization. In this code example we will make sure that all other // PortalAccess levels are turned off and clear out any Groups to which the ArcGISPortalItem may belong to. // NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, (result, err) => { // Display any error messages if any. if (err != null) { MessageBox.Show(err.Message); } // Now set the PortalAccess level for all users in the Organization. _MyArcGISPortalItem.ShareAsync(null, false, true, CALLBACK_ArcGISPortalItem_ShareAsync); }); } //------------------------------------------ if (RadioButton_Private.IsChecked == true) { // The user has chosen to keep the ArcGISPortalItem Private (i.e. just to the credentialed user). In this code example we will make // sure that all other PortalAccess levels are turned off and clear out any Groups to which the ArcGISPortalItem may belong to. // NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, (result, err) => { // Display any error messages if any. if (err != null) { MessageBox.Show(err.Message); } // Now set the PortalAccess level to be just the credentialed user (i.e. Private). _MyArcGISPortalItem.ShareAsync(null, false, false, CALLBACK_ArcGISPortalItem_ShareAsync); }); } //------------------------------------------ if (RadioButton_Shared.IsChecked == true) { // The user has chosen to share the ArcGISPortalItem with one or more Groups. Get the selected Groups from the CheckBoxes // that were checked On and put the Group ID values in a List. // NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. System.Collections.Generic.List<string> mySelectedGroupIDs = new System.Collections.Generic.List<string>(); foreach (ArcGISPortalGroupExtended myArcGISPortalGroupExtended in _MyListOfArcGISPortalGroupExtended) { if (myArcGISPortalGroupExtended.Selected) { ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup myArcGISPortalGroup = myArcGISPortalGroupExtended.Item; mySelectedGroupIDs.Add(myArcGISPortalGroup.Id); } } // Make sure that at least one Group is chosen. if (mySelectedGroupIDs.Count == 0) { MessageBox.Show("At least one Group must be checked on in order to set Shared access level permissions."); return; } // Now set the PortalAccess level to be Shared and specify which Groups will have access to the ArcGISPortalItem. _MyArcGISPortalItem.ShareAsync(mySelectedGroupIDs, false, false, CALLBACK_ArcGISPortalItem_ShareAsync); } //------------------------------------------ } private void CALLBACK_ArcGISPortalItem_ShareAsync(System.Collections.Generic.IEnumerable<string> result, System.Exception err) { // This function executes when the changing of the ArcGISPortalItem access level changes. // Display an error messages. if (err != null) { MessageBox.Show(err.Message); } else { // Get the selected ArcGISPortalItem in the ListBox. _MyArcGISPortalItem = ListBox_Results.SelectedItem as ESRI.ArcGIS.Client.Portal.ArcGISPortalItem; // Make sure we have a valid ArcGISPortalItem. if (_MyArcGISPortalItem == null) { return; } // Call the ArcGISPortalItem.GetSharingInfoAsync which will update the RadioButton and CheckBox controls with the most // current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(CALLBACK_ArcGISPortalItem_GetSharingInfoAsync); } } private void CALLBACK_ArcGISPortalItem_GetSharingInfoAsync(ESRI.ArcGIS.Client.Portal.ArcGISPortalSharingInfo sharinginfo, System.Exception ex) { // This function will display the access level and other information about the ArcGISPortalItem. // ----------------------------------- // Display various information in the TextBox. Add more as you feel. System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder(); ESRI.ArcGIS.Client.Portal.ArcGISPortalItem myPortalItem = sharinginfo.ArcGISPortalItem; myStringBuilder.Append("ArcGISPortalItem.Title = " + myPortalItem.Title + Environment.NewLine); myStringBuilder.Append("ArcGISPortalItem.AvgRating: " + myPortalItem.AvgRating.ToString() + Environment.NewLine); myStringBuilder.Append("ArcGISPortalItem.Type: " + myPortalItem.Type.ToString() + Environment.NewLine); myStringBuilder.Append("ArcGISPortalItem.Snippet: " + myPortalItem.Snippet + Environment.NewLine); myStringBuilder.Append("---------------------------------------------------" + Environment.NewLine); ESRI.ArcGIS.Client.Portal.PortalAccess myPortalAccess = sharinginfo.Access; myStringBuilder.Append("ArcGISPortalItem.PortalAccess = " + myPortalAccess.ToString() + Environment.NewLine); System.Collections.Generic.IEnumerable<string> myGroupIds = sharinginfo.GroupIds; foreach (string oneGroupId in myGroupIds) { myStringBuilder.Append("ArcGISPortalItem.GroupId = " + oneGroupId + Environment.NewLine); } TextBox1.Text = myStringBuilder.ToString(); // ----------------------------------- // Update the RadioButtons that represent the ArcGISPortalItem PortalAccess Enumerations. Also check on any // Group CheckBoxes that are available for the Shared PortalAccess level. if (_MyArcGISPortalItem.Owner != null && _MyArcGISPortalItem.Owner == _MyArcGISPortalUser.UserName) { if (sharinginfo.Access == ESRI.ArcGIS.Client.Portal.PortalAccess.Public) { // The access to the ArcGISPortalItem is Public. RadioButton_Public.IsChecked = true; // Uncheck all of the Shared (i.e. Group) CheckBoxes foreach (var m in _MyListOfArcGISPortalGroupExtended) { m.Selected = false; } } if (sharinginfo.Access == ESRI.ArcGIS.Client.Portal.PortalAccess.Organization) { // The access to the ArcGISPortalItem is the Organization. RadioButton_Organization.IsChecked = true; // Uncheck all of the Shared (i.e. Group) CheckBoxes foreach (var m in _MyListOfArcGISPortalGroupExtended) { m.Selected = false; } } if (sharinginfo.Access == ESRI.ArcGIS.Client.Portal.PortalAccess.Private) { // The access to the ArcGISPortalItem is Private. RadioButton_Private.IsChecked = true; // Uncheck all of the Shared (i.e. Group) CheckBoxes foreach (var m in _MyListOfArcGISPortalGroupExtended) { m.Selected = false; } } if (sharinginfo.Access == ESRI.ArcGIS.Client.Portal.PortalAccess.Shared) { // The access to the ArcGISPortalItem is Shared (i.e. there are Groups). RadioButton_Shared.IsChecked = true; // The user can check on various Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = true; // Check on the Group CheckBoxes that are part of the Shared access. if (sharinginfo.GroupIds.Count() != 0) { var x = from g in _MyListOfArcGISPortalGroupExtended where sharinginfo.GroupIds.Any((r) => r == g.Item.Id) select g; foreach (var m in x) { m.Selected = true; } } else { foreach (var m in _MyListOfArcGISPortalGroupExtended) { m.Selected = false; } } } } } private void RadioButton_XXX_Click(object sender, System.Windows.RoutedEventArgs e) { // The user clicked either the Public, Organization or Private RadioButtons. // Unselect all of the Group CheckBoxes. if (RadioButton_Public.IsChecked == true) { foreach (var m in _MyListOfArcGISPortalGroupExtended) { m.Selected = false; } } // Disable being able to turn on Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = false; } private void RadioButton_Shared_Click(object sender, System.Windows.RoutedEventArgs e) { // The user selected the Share (i.e. Group) RadioButton. // Enable the user to be able to check on various Groups. ListBox_GroupsOwned.IsEnabled = true; } private void ListBox_Results_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { // Disable being able to select Groups. Once the user has selected the RadioButton_Shared they can check on various Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = false; // Get the currently selected ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = ListBox_Results.SelectedItem as ESRI.ArcGIS.Client.Portal.ArcGISPortalItem; // Make sure we have a valid ArcGISPortalItem. if (_MyArcGISPortalItem == null) { return; } // Call the ArcGISPortalItem.GetSharingInfoAsync which will update the RadioButton and CheckBox controls with the most // current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(CALLBACK_ArcGISPortalItem_GetSharingInfoAsync); } } // A helper class to aid with setting up binding to the controls in XAML. It basically helps track the updating of the // ArcGISPortalGroup with the CheckBoxes. public class ArcGISPortalGroupExtended : System.ComponentModel.INotifyPropertyChanged { private bool selected_Renamed; public bool Selected { get { return selected_Renamed; } set { if (selected_Renamed != value) { selected_Renamed = value; OnPropertyChanged("Selected"); } } } private ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup item_Renamed; public ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup Item { get { return item_Renamed; } set { if (item_Renamed != value) { item_Renamed = value; OnPropertyChanged("Item"); } } } public ArcGISPortalGroupExtended(ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup item) { this.Item = item; } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string property) { if (PropertyChanged != null) PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(property)); } } |
VB.NET | ![]() |
---|---|
Partial Public Class MainPage Inherits UserControl ' ========================================================================================== ' TODO: MODIFY THE FOLLOWING MEMBER (i.e. GLOBAL) VARIABLES THAT WORK FOR YOUR ORGANIZATION! ' Specify the root location of ArcGIS Online or your ArcGIS Portal for testing. Private Const _DefaultServerUrl As String = "http://www.YourArcGISPortal.com/sharing/rest" ' Specify the location of ArcGIS Online or your ArcGIS Portal for generating a token for accessing secured services. Private Const _DefaultTokenUrl As String = "https://www.YourArcGISPortal.com/sharing/generateToken" ' Specify the UserName of the account in ArcGIS Online or your ArcGIS Portal. Private Const _Username As String = "YourUserName" ' Specify the Password of the account in ArcGIS Online or your ArcGIS Portal. Private Const _Password As String = "YourPassword" ' ========================================================================================== ' Other Member (aka. Global) variables used in the application. (NO NEED TO MODIFY) Private _MyArcGISPortal As New ESRI.ArcGIS.Client.Portal.ArcGISPortal() With {.Url = _DefaultServerUrl} Private _MyArcGISPortalUser As ESRI.ArcGIS.Client.Portal.ArcGISPortalUser Private _MyListOfArcGISPortalGroupExtended As New List(Of ArcGISPortalGroupExtended)() Private _MyArcGISPortalItem As ESRI.ArcGIS.Client.Portal.ArcGISPortalItem Public Sub New() InitializeComponent() ' Create a new instance of the IdentityManager.ServerInfos collection. Dim myServerInfos As System.Collections.Generic.List(Of ESRI.ArcGIS.Client.IdentityManager.ServerInfo) myServerInfos = New System.Collections.Generic.List(Of ESRI.ArcGIS.Client.IdentityManager.ServerInfo) ' Create a new instance of a single IdentityManager.ServerInfo object. Using the user supplied Member variables defined ' above set the ServerInfo.ServerUrl and ServerInfo.TokenServiceUrl Properties. Dim myServerInfo As ESRI.ArcGIS.Client.IdentityManager.ServerInfo = New ESRI.ArcGIS.Client.IdentityManager.ServerInfo myServerInfo.ServerUrl = _DefaultServerUrl myServerInfo.TokenServiceUrl = _DefaultTokenUrl ' Add the ServerInfo object to the ServerInfos collection. myServerInfos.Add(myServerInfo) ' Determine the location of secure server and token endpoint. ESRI.ArcGIS.Client.IdentityManager.Current.RegisterServers(myServerInfos) ' Define the function to challenge for credentials. ESRI.ArcGIS.Client.IdentityManager.Current.ChallengeMethod = AddressOf CALLBACK_IdentityManager_ChallengeMethod ' Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = Nothing ' Disable being able to select Groups. Once the user has selected the RadioButton_Shared they can check on various Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = False ' Get the credential object that will be used to access secured token based services. ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(_DefaultServerUrl, _Username, _Password, AddressOf CALLBACK_IdentityManager_GenerateCredentialAsync) End Sub Private Sub CALLBACK_IdentityManager_ChallengeMethod(ByVal url As String, ByVal callback As Action(Of ESRI.ArcGIS.Client.IdentityManager.Credential, Exception), ByVal options As ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions) ' Activate the IdentityManager. callback(Nothing, New NotImplementedException()) End Sub Private Sub CALLBACK_IdentityManager_GenerateCredentialAsync(crd As ESRI.ArcGIS.Client.IdentityManager.Credential, ex As System.Exception) ' The callback that obtains the credential object. If crd IsNot Nothing Then ' We got a valid credential user token object. ' Add the credential user token to the IdentityManager for accessing resources. ESRI.ArcGIS.Client.IdentityManager.Current.AddCredential(crd) ' Begin the process of accessing ArcGIS Online/ArcGIS Portal using the user specified Member variables defined above. _MyArcGISPortal.InitializeAsync(_DefaultServerUrl, AddressOf CALLBACK_ArcGISPortal_InitializeAsync) Else ' We had a problem generating the credentialed user token. Notify the user of the problem. MessageBox.Show("Could not log in. Please check credentials.") End If End Sub Private Sub CALLBACK_ArcGISPortal_InitializeAsync(credential As ESRI.ArcGIS.Client.Portal.ArcGISPortal, exception As System.Exception) ' The callback that establishes valid communication with ArcGIS Online/ArcGIS Portal. If credential IsNot Nothing AndAlso credential.CurrentUser IsNot Nothing Then ' We have valid credentials. ' Set the Member variable for the ArcGISPortalUser to the user credential that was found using the IdentityManager. _MyArcGISPortalUser = credential.CurrentUser ' Display the FullName of the credentialed user in the TextBlock. TextBlock_CurrentUser.Text = String.Format(credential.CurrentUser.FullName) ' Clear out any existing ArcGISPortalGroupExtended objects from the ListBox. ListBox_Results.ItemsSource = Nothing ' Set the ArcGISPortal.Url to the user defined Member variable. If String.IsNullOrEmpty(_MyArcGISPortal.Url) Then _MyArcGISPortal.Url = _DefaultServerUrl End If ' Get the ArcGISPortalItems for the credentialed user. _MyArcGISPortalUser.GetItemsAsync(AddressOf CALLBACK_ArcGISPortalUser_GetItemsAsync) ' Get the Groups that an ArcGISPortalUser belongs to. _MyArcGISPortalUser.GetGroupsAsync(AddressOf CALLBACK_ArcGISPortalUser_GetGroupsAsync) End If End Sub Private Sub CALLBACK_ArcGISPortalUser_GetGroupsAsync(grps As IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup), err As System.Exception) ' Add the Groups the credentialed user has to the ArcGISPortalGroupExtended collection. _MyListOfArcGISPortalGroupExtended.AddRange( From g In grps Select New ArcGISPortalGroupExtended(g)) ' Add the ArcGISPortalGroupExtended objects to the ListBox. ListBox_GroupsOwned.ItemsSource = _MyListOfArcGISPortalGroupExtended End Sub Private Sub CALLBACK_ArcGISPortalUser_GetItemsAsync(userItems As System.Collections.Generic.IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalItem), ex As System.Exception) ' Add the ArcGISPortalItems to the ListBox. ListBox_Results.ItemsSource = userItems End Sub Private Sub Button_ArcGISPortalItem_ShareAsync_Ver1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' Executes when the user clicks the Button. Changes the access level permissions for the selected ArcGISPortalItem. ' Get the ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = TryCast(ListBox_Results.SelectedItem, ESRI.ArcGIS.Client.Portal.ArcGISPortalItem) ' Warn the user that before they can change an access level on an ArcGISPortalItem, that they must first select it. If _MyArcGISPortalItem Is Nothing Then MessageBox.Show("Select an ArcGISPortalItem from the ListBox before trying to change access level permissions.") Return End If ' Get the list of all the Groups the user can set for an ArcGISPortalItem. Dim my_GroupIDs_ALL As New System.Collections.Generic.List(Of String) For Each myArcGISPortalGroupExtended As ArcGISPortalGroupExtended In _MyListOfArcGISPortalGroupExtended Dim myArcGISPortalGroup As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup = myArcGISPortalGroupExtended.Item my_GroupIDs_ALL.Add(myArcGISPortalGroup.Id) Next '------------------------------------------ If RadioButton_Public.IsChecked = True Then ' The user has chosen to make the ArcGISPortalItem Public. In this code example we will make sure that all other PortalAccess ' levels are turned off and clear out any Groups to which the ArcGISPortalItem may belong to. ' NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, Sub(result, err) ' Display any error messages if any. If err IsNot Nothing Then MessageBox.Show(err.Message) End If ' Now set the PortalAccess level for everyone (i.e. Public). _MyArcGISPortalItem.ShareAsync(Nothing, True, False, AddressOf CALLBACK_ArcGISPortalItem_ShareAsync) End Sub) End If '------------------------------------------ If RadioButton_Organization.IsChecked = True Then ' The user has chosen to make the ArcGISPortalItem open to the Organization. In this code example we will make sure that all other ' PortalAccess levels are turned off and clear out any Groups to which the ArcGISPortalItem may belong to. ' NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, Sub(result, err) ' Display any error messages if any. If err IsNot Nothing Then MessageBox.Show(err.Message) End If ' Now set the PortalAccess level for all users in the Organization. _MyArcGISPortalItem.ShareAsync(Nothing, False, True, AddressOf CALLBACK_ArcGISPortalItem_ShareAsync) End Sub) End If '------------------------------------------ If RadioButton_Private.IsChecked = True Then ' The user has chosen to keep the ArcGISPortalItem Private (i.e. just to the credentialed user). In this code example we will make ' sure that all other PortalAccess levels are turned off and clear out any Groups to which the ArcGISPortalItem may belong to. ' NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. _MyArcGISPortalItem.UnshareAsync(my_GroupIDs_ALL, Sub(result, err) ' Display any error messages if any. If err IsNot Nothing Then MessageBox.Show(err.Message) End If ' Now set the PortalAccess level to be just the credentialed user (i.e. Private). _MyArcGISPortalItem.ShareAsync(Nothing, False, False, AddressOf CALLBACK_ArcGISPortalItem_ShareAsync) End Sub) End If '------------------------------------------ If RadioButton_Shared.IsChecked = True Then ' The user has chosen to share the ArcGISPortalItem with one or more Groups. Get the selected Groups from the CheckBoxes ' that were checked On and put the Group ID values in a List. ' NOTE: it is possible to have multiple PortalAccess levels and Groups specified, it is just not shown in this example. Dim mySelectedGroupIDs As New System.Collections.Generic.List(Of String) For Each myArcGISPortalGroupExtended As ArcGISPortalGroupExtended In _MyListOfArcGISPortalGroupExtended If (myArcGISPortalGroupExtended.Selected) Then Dim myArcGISPortalGroup As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup = myArcGISPortalGroupExtended.Item mySelectedGroupIDs.Add(myArcGISPortalGroup.Id) End If Next ' Make sure that at least one Group is chosen. If mySelectedGroupIDs.Count = 0 Then MessageBox.Show("At least one Group must be checked on in order to set Shared access level permissions.") Return End If ' Now set the PortalAccess level to be Shared and specify which Groups will have access to the ArcGISPortalItem. _MyArcGISPortalItem.ShareAsync(mySelectedGroupIDs, False, False, AddressOf CALLBACK_ArcGISPortalItem_ShareAsync) End If '------------------------------------------ End Sub Private Sub CALLBACK_ArcGISPortalItem_ShareAsync(result As System.Collections.Generic.IEnumerable(Of String), err As System.Exception) ' This function executes when the changing of the ArcGISPortalItem access level changes. ' Display an error messages. If err IsNot Nothing Then MessageBox.Show(err.Message) Else ' Get the selected ArcGISPortalItem in the ListBox. _MyArcGISPortalItem = TryCast(ListBox_Results.SelectedItem, ESRI.ArcGIS.Client.Portal.ArcGISPortalItem) ' Make sure we have a valid ArcGISPortalItem. If _MyArcGISPortalItem Is Nothing Then Return End If ' Call the ArcGISPortalItem.GetSharingInfoAsync which will update the RadioButton and CheckBox controls with the most ' current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(AddressOf CALLBACK_ArcGISPortalItem_GetSharingInfoAsync) End If End Sub Private Sub CALLBACK_ArcGISPortalItem_GetSharingInfoAsync(sharinginfo As ESRI.ArcGIS.Client.Portal.ArcGISPortalSharingInfo, ex As System.Exception) ' This function will display the access level and other information about the ArcGISPortalItem. ' ----------------------------------- ' Display various information in the TextBox. Add more as you feel. Dim myStringBuilder As New Text.StringBuilder Dim myPortalItem As ESRI.ArcGIS.Client.Portal.ArcGISPortalItem = sharinginfo.ArcGISPortalItem myStringBuilder.Append("ArcGISPortalItem.Title = " + myPortalItem.Title + vbCrLf) myStringBuilder.Append("ArcGISPortalItem.AvgRating: " + myPortalItem.AvgRating.ToString + vbCrLf) myStringBuilder.Append("ArcGISPortalItem.Type: " + myPortalItem.Type.ToString + vbCrLf) myStringBuilder.Append("ArcGISPortalItem.Snippet: " + myPortalItem.Snippet + vbCrLf) myStringBuilder.Append("---------------------------------------------------" + vbCrLf) Dim myPortalAccess As ESRI.ArcGIS.Client.Portal.PortalAccess = sharinginfo.Access myStringBuilder.Append("ArcGISPortalItem.PortalAccess = " + myPortalAccess.ToString + vbCrLf) Dim myGroupIds As System.Collections.Generic.IEnumerable(Of String) = sharinginfo.GroupIds For Each oneGroupId As String In myGroupIds myStringBuilder.Append("ArcGISPortalItem.GroupId = " + oneGroupId + vbCrLf) Next TextBox1.Text = myStringBuilder.ToString ' ----------------------------------- ' Update the RadioButtons that represent the ArcGISPortalItem PortalAccess Enumerations. Also check on any ' Group CheckBoxes that are available for the Shared PortalAccess level. If _MyArcGISPortalItem.Owner IsNot Nothing AndAlso _MyArcGISPortalItem.Owner = _MyArcGISPortalUser.UserName Then If sharinginfo.Access = ESRI.ArcGIS.Client.Portal.PortalAccess.Public Then ' The access to the ArcGISPortalItem is Public. RadioButton_Public.IsChecked = True ' Uncheck all of the Shared (i.e. Group) CheckBoxes For Each m In _MyListOfArcGISPortalGroupExtended m.Selected = False Next m End If If sharinginfo.Access = ESRI.ArcGIS.Client.Portal.PortalAccess.Organization Then ' The access to the ArcGISPortalItem is the Organization. RadioButton_Organization.IsChecked = True ' Uncheck all of the Shared (i.e. Group) CheckBoxes For Each m In _MyListOfArcGISPortalGroupExtended m.Selected = False Next m End If If sharinginfo.Access = ESRI.ArcGIS.Client.Portal.PortalAccess.Private Then ' The access to the ArcGISPortalItem is Private. RadioButton_Private.IsChecked = True ' Uncheck all of the Shared (i.e. Group) CheckBoxes For Each m In _MyListOfArcGISPortalGroupExtended m.Selected = False Next m End If If sharinginfo.Access = ESRI.ArcGIS.Client.Portal.PortalAccess.Shared Then ' The access to the ArcGISPortalItem is Shared (i.e. there are Groups). RadioButton_Shared.IsChecked = True ' The user can check on various Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = True ' Check on the Group CheckBoxes that are part of the Shared access. If sharinginfo.GroupIds.Count() <> 0 Then Dim x = From g In _MyListOfArcGISPortalGroupExtended Where sharinginfo.GroupIds.Any(Function(r) r = g.Item.Id) Select g For Each m In x m.Selected = True Next m Else For Each m In _MyListOfArcGISPortalGroupExtended m.Selected = False Next m End If End If End If End Sub Private Sub RadioButton_XXX_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' The user clicked either the Public, Organization or Private RadioButtons. ' Unselect all of the Group CheckBoxes. If RadioButton_Public.IsChecked = True Then For Each m In _MyListOfArcGISPortalGroupExtended m.Selected = False Next m End If ' Disable being able to turn on Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = False End Sub Private Sub RadioButton_Shared_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' The user selected the Share (i.e. Group) RadioButton. ' Enable the user to be able to check on various Groups. ListBox_GroupsOwned.IsEnabled = True End Sub Private Sub ListBox_Results_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) ' Disable being able to select Groups. Once the user has selected the RadioButton_Shared they can check on various Group CheckBoxes. ListBox_GroupsOwned.IsEnabled = False ' Get the currently selected ArcGISPortalItem from the ListBox. _MyArcGISPortalItem = TryCast(ListBox_Results.SelectedItem, ESRI.ArcGIS.Client.Portal.ArcGISPortalItem) ' Make sure we have a valid ArcGISPortalItem. If _MyArcGISPortalItem Is Nothing Then Return End If ' Call the ArcGISPortalItem.GetSharingInfoAsync which will update the RadioButton and CheckBox controls with the most ' current access level information. _MyArcGISPortalItem.GetSharingInfoAsync(AddressOf CALLBACK_ArcGISPortalItem_GetSharingInfoAsync) End Sub End Class ' A helper class to aid with setting up binding to the controls in XAML. It basically helps track the updating of the ' ArcGISPortalGroup with the CheckBoxes. Public Class ArcGISPortalGroupExtended Implements System.ComponentModel.INotifyPropertyChanged Private selected_Renamed As Boolean Public Property Selected() As Boolean Get Return selected_Renamed End Get Set(ByVal value As Boolean) If selected_Renamed <> value Then selected_Renamed = value OnPropertyChanged("Selected") End If End Set End Property Private item_Renamed As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup Public Property Item() As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup Get Return item_Renamed End Get Set(ByVal value As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup) If item_Renamed IsNot value Then item_Renamed = value OnPropertyChanged("Item") End If End Set End Property Public Sub New(ByVal item As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup) Me.Item = item End Sub Public Event PropertyChanged As System.ComponentModel.PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged Private Sub OnPropertyChanged(ByVal [property] As String) RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs([property])) End Sub End Class |
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7