| Visual Basic (Declaration) | |
|---|---|
Public Sub SearchGroupsAsync( _ ByVal searchParameters As SearchParameters, _ ByVal callback As Action(Of SearchResultInfo(Of ArcGISPortalGroup),Exception) _ ) | |
| C# | |
|---|---|
public void SearchGroupsAsync( SearchParameters searchParameters, Action<SearchResultInfo<ArcGISPortalGroup>,Exception> callback ) | |
This method obtains a Portal.SearchResultInfo<T> object that contains Portal.ArcGISPortalGroup objects. Use the Portal.SearchResultInfo<T>.Results Property to get the IEnumberable collection of Portal.ArcGISPortalGroup objects.
Portal.ArcGISPortalGroup objects are collections (aka. groups) of items, usually related to a specific area of interest such as maps (aka. WebMap), applications, and tools. Groups allow members to contribute items as a useful way to collaborate. The Portal.ArcGISPortal.SearchGroupsAsync Method allows searching for specific groups within ArcGIS Online (AGOL) or ArcGIS Portal. The Portal.ArcGISPortal.SearchGroupsAsync Method requires providing specific Portal.SearchParameters to limit the scope of which groups are returned.
You can call this method before calling the Portal.ArcGISPortal.InitializeAsync Method and obtain Portal.ArcGISPortalGroup information BUT the Portal.ArcGISPortalGroup.ArcGISPortal Property will not be populated with valid information (i.e. its value will be Nothing/null). It is a recommended best practice to call the Portal.ArcGISPortal.InitializeAsync Method before calling the Portal.ArcGISPortal.SearchGroupsAsync Method so that all of the properties in the Portal.ArcGISPortal.ArcGISPortalGroup will contain valid data.
You do not have to be a logged in user using the IdentityManager to get information from the Portal.ArcGISPortal.SearchGroupsAsync Method. You can gain this information from anonymous access. However, to obtain information about groups in your organization that have a Portal.PortalAccess level of Private you need to use the IdentityManager by supplying the appropriate username/password credentials. As AGOL and ArcGIS Portal require the use of long term tokens to access secured information (i.e. information that is Private) you should remember to set the IdentityManager.TokenGenerationReferer Property to the correct string required by your development platform.
By default the Portal.SearchParameters.QueryString Property that is used in the Portal.ArcGISPortal.SearchGroupsAsync Method uses a default set of high performance index fields when providing simple keyword string(s) for the search. As of AGOL/ArcGIS Portal v2.1, these fields are: id, title, description, snippet, tags, and owner. For more advanced searches, developers can preface their simple keyword strings with a more exhaustive set of REST named fields followed by a colon (:). These advanced searches can also take advantage of Boolean operators (AND, NOT, OR, +), wildcard operators (* and ?), as well as other techniques to more fully utilize the AGOL/ArcGIS Portal search capabilities. Comprehensive details on using the advanced search strings that follow the REST specification can be found in the Search Reference document in the ArcGIS Portal API.
The following are a few advanced REST search scenarios with example strings that you might consider using for the Portal.SearchParameters.QueryString Property:
To find one specific ArcGISPortalGroup by it's Id: "id:1db70a32f5f84ea9a88f5f460f22557b"
To find all Private ArcGISPortalGroups with the word 'federal' in the Title field: "title:federal AND access:private"
To find all ArcGISPortalGroupds with the word 'federal' in the Title field and the word 'restricted' in the Description field: "title:federal AND description:restricted"
To find all ArcGISPortalGroups with the word 'state' in the Title field and not have the word 'restricted' in the Description field: "title:state NOT description:restricted"
NOTE: It is not required to use the advanced REST search syntax to find ArcGISPortalGroups with this Method. Simple string syntax for the Portal.SearchParameters.QueryString Property such as: "federal" will find all occurrences of that string in the default high performance index fields.
Parameters
- searchParameters
- The search parameters.
- callback
- The callback executed when the result is available.
How to use:
Set the correct values for the example code initialization variables in the code-behind (the user needs to provide the ArcGIS Online (AGOL) or ArcGIS Portal base Url, credentials via username/password if wanting to access secured services, and at least one keyword to search for ArcGIS Portal Groups). Once the user information is provided, click the button to make Asynchronous calls to the AGOL/ArcGIS Portal server to retrieve information for display.
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 | Copy Code |
|---|---|
<Grid x:Name="LayoutRoot" Background="White"> <!-- Information the user needs to supply. --> <!-- Get the ArcGIS Online/ArcGIS Portal base Url. --> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,83,0,0" Name="Label_ArcGISPortalBaseUrl" VerticalAlignment="Top" Width="231" Content="ArcGIS Online or ArcGIS Portal base Url:"/> <TextBox Height="23" HorizontalAlignment="Left" Margin="239,79,0,0" Name="TextBox_ArcGISPortalBaseUrl" VerticalAlignment="Top" Width="536" /> <!-- Use Anonymous access or IdentityManager with user credentials to access the information about ArcGISPortalGroups. --> <CheckBox Content="Use Anynomous Access" Height="16" Margin="12,113,0,0" Name="CheckBox_UseAnonymousAccess" VerticalAlignment="Top" HorizontalAlignment="Left" Width="165" Click="CheckBox_UseAnonymousAccess_Click" /> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="222,113,0,0" Name="Label_UserName" VerticalAlignment="Top" Width="70" Content="UserName:"/> <TextBox Height="23" HorizontalAlignment="Left" Margin="287,109,0,0" Name="TextBox_UserName" VerticalAlignment="Top" Width="210" /> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="506,110,0,0" Name="Label_Password" VerticalAlignment="Top" Width="56" Content="Password:"/> <TextBox Height="23" HorizontalAlignment="Left" Margin="565,109,0,0" Name="TextBox_Password" VerticalAlignment="Top" Width="210" /> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,144,0,0" Name="Label_SearchKeywords" VerticalAlignment="Top" Width="231" Content="Search for Groups using the keyword(s):"/> <TextBox Height="23" HorizontalAlignment="Left" Margin="239,140,0,0" Name="TextBox_SearchKeywords" VerticalAlignment="Top" Width="536" /> <!-- Button to invoke searching for Groups on ArcGIS Online/ArcGIS Portal--> <Button Content="Get ArcGIS Portal Groups Information" Height="23" HorizontalAlignment="Left" Margin="12,172,0,0" Name="Button1" VerticalAlignment="Top" Width="763" Click="Button1_Click" /> <!-- Display the results to the user. --> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,203,0,0" Name="Label_GenericInfo" VerticalAlignment="Top" Width="202" Content="Generic ArcGIS Portal Information:"/> <TextBlock Height="362" HorizontalAlignment="Left" Margin="12,226,0,0" Name="TextBlock_GenericInfo" Text="TextBlock_GenericInfo" VerticalAlignment="Top" Width="314" /> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="331,203,0,0" Name="Label_GroupInfo" VerticalAlignment="Top" Width="194" Content="ArcGIS Portal Group Information:"/> <ListBox Height="362" HorizontalAlignment="Left" Margin="331,226,0,0" Name="ListBox_GroupInfo" VerticalAlignment="Top" Width="444" /> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="73" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" Text="Set the correct values for the example code initialization variables in the code-behind (the user needs to provide the ArcGIS Online (AGOL) or ArcGIS Portal base Url, credentials via username/password if wanting to access secured services, and at least one keyword to search for ArcGIS Portal Groups). Once the user information is provided, click the button to make Asynchronous calls to the AGOL/ArcGIS Portal server to retrieve information for display." /> </Grid> | |
| C# | Copy Code |
|---|---|
public MainPage() { InitializeComponent(); // TODO: Provide your default values to run the example code. // ========================================================== // Provide the Url to ArcGIS OnLine (AGOL) or your ArcGIS Portal. TextBox_ArcGISPortalBaseUrl.Text = "http://www.arcgis.com"; // If gaining access to secured services on AGOL/Portal provide Username/Password information. TextBox_UserName.Text = "YourUserName"; TextBox_Password.Text = "YourPassword"; // Provide default keyword(s) to search for ArcGISPortalGroups in AGOL/Portal. TextBox_SearchKeywords.Text = "federal"; } private void Button1_Click(object sender, System.Windows.RoutedEventArgs e) { // This sub-routine executes when the user clicks the Button. The purpose is to get general information about the // AGOL/Portal service (including user information if trying to access a secured service). Additionally, information // about ArcGISPortalGroups is returned based upon a keyword(s) search. // Clear out any existing results before proceeding. TextBlock_GenericInfo.Text = ""; ListBox_GroupInfo.Items.Clear(); // Set the referer string of the IdentityManager using the .TokenGenrationReferer Property. // This will establish the referer string that is part of the Http WebRequest Header. // FYI: You can view the 'Referer' header information in freeware/shareware applications like 'Fiddler'. // NOTE: // For WPF this value could be any string. Ex: "http://www.MyWebSite.com", "http", "h", "Whatever". // For Silverlight this value should point to the .xap file, but any sub-string will do. Ex: "http://localhost:65121/ClientBin/SL-App.xap", // "http", "h". // For Windows Phone this value should point to the application install location on the device, but any sub-string will do. Ex: // "file://Applications/Install/868A84BA-237D-4980-BF51-74E193CECCF1/Install/", "file", "f". ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions myGenerateTokenOptions = null; myGenerateTokenOptions = new ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions(); myGenerateTokenOptions.Referer = "h"; // Get the base Url for AGOL/Portal. string myArcGISPortalBaseUrl = TextBox_ArcGISPortalBaseUrl.Text; // Get the Username/Password for accessing secured AGOL/Portal services. string myUserName = TextBox_UserName.Text; string myPassword = TextBox_Password.Text; // Use IdentityManager to access secured AGOL/Portal services. This will cause an asynchronous call to the // sub-routine called CALLBACK_IdentityManager_GenerateCredentialAsync. ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(myArcGISPortalBaseUrl, myUserName, myPassword, CALLBACK_IdentityManager_GenerateCredentialAsync, myGenerateTokenOptions); } private void CALLBACK_IdentityManager_GenerateCredentialAsync(ESRI.ArcGIS.Client.IdentityManager.Credential myCredential, System.Exception ex) { // This sub-routine executes as a result of the IdentityManager.GenerateCredentialAsync Method. // Ensure there was not a problem in the returned results. if (ex == null) { // Create a new instance of the ArcGISPortal Class. ESRI.ArcGIS.Client.Portal.ArcGISPortal myArcGISPortal = new ESRI.ArcGIS.Client.Portal.ArcGISPortal(); // Determine if we are going to really use the IdentityManager result to get information from AGOL/Portal. if (CheckBox_UseAnonymousAccess.IsChecked == false) { // The user wants to use their username/password to access secured AGOL/Portal services. Using this option will // display Private Groups to which the logged in user belongs or is the administrator of. // Set the ArcGISPortal.Token Property to the IdentityManager.Credential long term token. // Long term tokens are necessary to access secured AGOL/Portal services. myArcGISPortal.Token = myCredential.Token; } else { // The user wants to access publically available information from AGOL/Portal services. Private Groups will not // be displayed using this option. // The need to use the ArcGISPortal.Token is NOT necessary. } // Get the base Url of the AGOL/portal site. string myArcGISPortalBaseUrl = TextBox_ArcGISPortalBaseUrl.Text; // Add the other necessary parts to the base Url string so that information can be accessed on AGOL/Portal. string myArcGISPortalEnhancedUrl = myArcGISPortalBaseUrl + "/sharing/rest"; // Make an asynchronous call to obtain information from AGOL/Portal. Upon successful completion of this call // you can then gain access to deeper levels of information using other ArcGISPortal asynchronous calls like: // .SearchGroupsAsync, .SearchItemsAsnyc, and .SearchUsersAsync. myArcGISPortal.InitializeAsync(myArcGISPortalEnhancedUrl, CALLBACK_Portal_InitializeAsync); } else { // There was some problem with the IdentityManager.GenerateCredentialAsync call. Display the message to the user. MessageBox.Show("Could not log in. Please check credentials."); } } private void CALLBACK_Portal_InitializeAsync(ESRI.ArcGIS.Client.Portal.ArcGISPortal myArcGISPortal, System.Exception ex) { // This sub-routine executes as a result of the ArcGISPortal.InitializeAsync Method. // Ensure there was not a problem in the returned results. if (ex == null) { // Get the ArcGISPortalInfo object from ArcGISPortal. ESRI.ArcGIS.Client.Portal.ArcGISPortalInfo myArcGISPortalInfo = myArcGISPortal.ArcGISPortalInfo; // Get the ArcGISPortalInfo.PortalHostname information. string myPortalHostName = ""; if (myArcGISPortalInfo != null) { myPortalHostName = myArcGISPortalInfo.PortalHostname; } // Get the ArcGISPortal.CurrentUser object. Initialize some string variables for the username and email of the // CurrentUser. If we have a valid CurrentUser get that information. If the user tries to get information using // anonymous access the default string values of "[NOT AVAILABLE]" are provided. ESRI.ArcGIS.Client.Portal.ArcGISPortalUser myCurrentUser = myArcGISPortal.CurrentUser; string myUserName = "[NOT AVAILABLE]"; string myEmail = "[NOT AVAILABLE]"; if (myCurrentUser != null) { myUserName = myCurrentUser.UserName; myEmail = myCurrentUser.Email; } // Get the CurrentVerion of the AGOL/Portal server. string myCurrentVersion = myArcGISPortal.CurrentVersion; // Get the Url of the AGOL/Portal server. string myUrl = myArcGISPortal.Url; // Create a StringBuilder class to hold information obtained from the AGOL/Portal service. System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder(); myStringBuilder.Append("ArcGISPortalInfo.PortalHostName: " + myPortalHostName + Environment.NewLine); myStringBuilder.Append("ArcGISPortal.CurrentVersion: " + myCurrentVersion + Environment.NewLine); myStringBuilder.Append("ArcGISPortal.Url: " + myUrl + Environment.NewLine); myStringBuilder.Append("CurrentUser.UserName: " + myUserName + Environment.NewLine); myStringBuilder.Append("CurrentUser.Email: " + myEmail + Environment.NewLine); // Display the information about the AGOL/Portal server to the user. TextBlock_GenericInfo.Text = myStringBuilder.ToString(); //---------------------------------------------------------------- // Now that the ArcGISPortal.InitializeAsync has successfully been invoked, we can now get more detailed information // about ArcGISPortalGroup's. // Create a new SearchParameters object. ESRI.ArcGIS.Client.Portal.SearchParameters mySearchParameters = new ESRI.ArcGIS.Client.Portal.SearchParameters(); // Get the search keyword(s) for finding Groups in the AGOL/Portal server. string mySearchKeywords = TextBox_SearchKeywords.Text; // Add the search keyword(s) to the SearchParameters. mySearchParameters.QueryString = mySearchKeywords; // Allow lots of Groups to be returned. mySearchParameters.Limit = 1000; // Use the ArcGISPortal object to access Group information in AGOL/Portal services. This will cause an asynchronous call to the // sub-routine called CALLBACK_ArcGISPortal_SearchGroupsAsync. myArcGISPortal.SearchGroupsAsync(mySearchParameters, CALLBACK_ArcGISPortal_SearchGroupsAsync); } else { // There was some problem with the ArcGISPortal.InitializeAsync call. Display the message to the user. MessageBox.Show("Failed to initialize" + ex.Message.ToString()); } } private void CALLBACK_ArcGISPortal_SearchGroupsAsync(ESRI.ArcGIS.Client.Portal.SearchResultInfo<ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup> sri, System.Exception ex) { // This sub-routine executes as a result of the ArcGISPortal.SearchGroupsAsync Method. // Create a StringBuilder class to hold Group information obtained from the AGOL/Portal service. Display the // number of Groups found in the ListBox. System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder(); myStringBuilder.Append("Number of ArcGIS Portal Groups: " + sri.TotalCount.ToString() + Environment.NewLine); ListBox_GroupInfo.Items.Add(myStringBuilder.ToString()); // Get the results (an IEnumerable of ArcGISPortalGroup objects) from the SearchResultInfo object. IEnumerable<ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup> myResults = sri.Results; // Loop through each ArcGISPortalGroup object. foreach (ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup myArcGISPortalGroup in myResults) { // Get various ArcGISPortalGroup Property information. Like: the image logo for the Group, the access level // of the Group (Private, Public, etc.), the brief description (i.e. Snippet) of what the Group does, the // owner username of the Group, and the title (e.g. the name) of the Group. Uri myImageUri = myArcGISPortalGroup.ThumbnailUri; ESRI.ArcGIS.Client.Portal.PortalAccess myAccess = (ESRI.ArcGIS.Client.Portal.PortalAccess)myArcGISPortalGroup.Access; string mySnippet = myArcGISPortalGroup.Snippet; string myOwner = myArcGISPortalGroup.Owner; string myTitle = myArcGISPortalGroup.Title; // Create a new StackPanel to house the information that will be displayed to the user about each Group found. StackPanel myStackPanel = new StackPanel(); myStackPanel.Orientation = Orientation.Vertical; if (myImageUri != null) { // If the Group has an image logo, display it to the user. // Create a new Image object, define its size and set the Uri of the Image to that for the Group. Image myImage = new Image(); myImage.Width = 50; myImage.Height = 50; myImage.Source = new System.Windows.Media.Imaging.BitmapImage(myImageUri); // Silverlight has issues with .gif format images! // Display the image on the left in the ListBox. StackPanel myStackPanel2 = new StackPanel(); myStackPanel2.Orientation = Orientation.Horizontal; myStackPanel2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; myStackPanel2.Children.Add(myImage); myStackPanel.Children.Add(myStackPanel2); } else { // The Group does not have an image logo defined. // Inform the use that no image logo is available for display. TextBlock myTextBlock_ArcGISPortalGroup_ThumbnailImage = new TextBlock(); myTextBlock_ArcGISPortalGroup_ThumbnailImage.Text = "[NO THUMBNAIL IMAGE AVAILABLE]"; myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_ThumbnailImage); } // Display the AGOL/Portal Group access level (i.e. Public, Private, etc.). TextBlock myTextBlock_ArcGISPortalGroup_Access = new TextBlock(); myTextBlock_ArcGISPortalGroup_Access.Text = "ArcGISPortalGroup.Access: " + myAccess.ToString(); myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Access); // Display the snippet (aka. brief description) of what the Group is about. if (mySnippet != null) // Some Snippets have no value! { TextBlock myTextBlock_ArcGISPortalGroup_Snippet = new TextBlock(); myTextBlock_ArcGISPortalGroup_Snippet.Text = "ArcGISPortalGroup.Snippet: " + mySnippet.ToString(); myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Snippet); } // Display the owner of the Group. TextBlock myTextBlock_ArcGISPortalGroup_Owner = new TextBlock(); myTextBlock_ArcGISPortalGroup_Owner.Text = "ArcGISPortalGroup.Owner: " + myOwner.ToString(); myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Owner); // Display the title of the Group. TextBlock myTextBlock_ArcGISPortalGroup_Title = new TextBlock(); myTextBlock_ArcGISPortalGroup_Title.Text = "ArcGISPortalGroup.Title: " + myTitle.ToString(); myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Title); // Add the various display objects about the Group in the ListBox. ListBox_GroupInfo.Items.Add(myStackPanel); } } private void CheckBox_UseAnonymousAccess_Click(object sender, System.Windows.RoutedEventArgs e) { // This sub-routine execute when the user checks on/off the ability to get information about AGOL/Portal // using anonymous access or via the IdentityManager with a username/password for secured web services. if (CheckBox_UseAnonymousAccess.IsChecked == true) { // The user wants to have anonymous access to get AGOL/Portal information. // Hide the username/password controls. Label_Password.Visibility = System.Windows.Visibility.Collapsed; Label_UserName.Visibility = System.Windows.Visibility.Collapsed; TextBox_Password.Visibility = System.Windows.Visibility.Collapsed; TextBox_UserName.Visibility = System.Windows.Visibility.Collapsed; } else { // The user wants to have IdentityManager with a username/password access to get AGOL/Portal information. // Show the username/password controls. Label_Password.Visibility = System.Windows.Visibility.Visible; Label_UserName.Visibility = System.Windows.Visibility.Visible; TextBox_Password.Visibility = System.Windows.Visibility.Visible; TextBox_UserName.Visibility = System.Windows.Visibility.Visible; } } | |
| VB.NET | Copy Code |
|---|---|
Public Sub New() InitializeComponent() ' TODO: Provide your default values to run the example code. ' ========================================================== ' Provide the Url to ArcGIS OnLine (AGOL) or your ArcGIS Portal. TextBox_ArcGISPortalBaseUrl.Text = "http://www.arcgis.com" ' If gaining access to secured services on AGOL/Portal provide Username/Password information. TextBox_UserName.Text = "dkemlage_agol" TextBox_Password.Text = "dkemlage_agol" ' Provide default keyword(s) to search for ArcGISPortalGroups in AGOL/Portal. TextBox_SearchKeywords.Text = "federal" End Sub Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' This sub-routine executes when the user clicks the Button. The purpose is to get general information about the ' AGOL/Portal service (including user information if trying to access a secured service). Additionally, information ' about ArcGISPortalGroups is returned based upon a keyword(s) search. ' Clear out any existing results before proceeding. TextBlock_GenericInfo.Text = "" ListBox_GroupInfo.Items.Clear() ' Set the referer string of the IdentityManager using the .TokenGenrationReferer Property. ' This will establish the referer string that is part of the Http WebRequest Header. ' FYI: You can view the 'Referer' header information in freeware/shareware applications like 'Fiddler'. ' NOTE: ' For WPF this value could be any string. Ex: "http://www.MyWebSite.com", "http", "h", "Whatever". ' For Silverlight this value should point to the .xap file, but any sub-string will do. Ex: "http://localhost:65121/ClientBin/SL-App.xap", ' "http", "h". ' For Windows Phone this value should point to the application install location on the device, but any sub-string will do. Ex: ' "file://Applications/Install/868A84BA-237D-4980-BF51-74E193CECCF1/Install/", "file", "f". Dim myGenerateTokenOptions As ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions myGenerateTokenOptions = New ESRI.ArcGIS.Client.IdentityManager.GenerateTokenOptions myGenerateTokenOptions.Referer = "h" ' Get the base Url for AGOL/Portal. Dim myArcGISPortalBaseUrl As String = TextBox_ArcGISPortalBaseUrl.Text ' Get the Username/Password for accessing secured AGOL/Portal services. Dim myUserName As String = TextBox_UserName.Text Dim myPassword As String = TextBox_Password.Text ' Use IdentityManager to access secured AGOL/Portal services. This will cause an asynchronous call to the ' sub-routine called CALLBACK_IdentityManager_GenerateCredentialAsync. ESRI.ArcGIS.Client.IdentityManager.Current.GenerateCredentialAsync(myArcGISPortalBaseUrl, myUserName, myPassword, AddressOf CALLBACK_IdentityManager_GenerateCredentialAsync, myGenerateTokenOptions) End Sub Private Sub CALLBACK_IdentityManager_GenerateCredentialAsync(myCredential As ESRI.ArcGIS.Client.IdentityManager.Credential, ex As System.Exception) ' This sub-routine executes as a result of the IdentityManager.GenerateCredentialAsync Method. ' Ensure there was not a problem in the returned results. If ex Is Nothing Then ' Create a new instance of the ArcGISPortal Class. Dim myArcGISPortal As ESRI.ArcGIS.Client.Portal.ArcGISPortal = New ESRI.ArcGIS.Client.Portal.ArcGISPortal ' Determine if we are going to really use the IdentityManager result to get information from AGOL/Portal. If CheckBox_UseAnonymousAccess.IsChecked = False Then ' The user wants to use their username/password to access secured AGOL/Portal services. Using this option will ' display Private Groups to which the logged in user belongs or is the administrator of. ' Set the ArcGISPortal.Token Property to the IdentityManager.Credential long term token. ' Long term tokens are necessary to access secured AGOL/Portal services. myArcGISPortal.Token = myCredential.Token Else ' The user wants to access publically available information from AGOL/Portal services. Private Groups will not ' be displayed using this option. ' The need to use the ArcGISPortal.Token is NOT necessary. End If ' Get the base Url of the AGOL/portal site. Dim myArcGISPortalBaseUrl As String = TextBox_ArcGISPortalBaseUrl.Text ' Add the other necessary parts to the base Url string so that information can be accessed on AGOL/Portal. Dim myArcGISPortalEnhancedUrl As String = myArcGISPortalBaseUrl + "/sharing/rest" ' Make an asynchronous call to obtain information from AGOL/Portal. Upon successful completion of this call ' you can then gain access to deeper levels of information using other ArcGISPortal asynchronous calls like: ' .SearchGroupsAsync, .SearchItemsAsnyc, and .SearchUsersAsync. myArcGISPortal.InitializeAsync(myArcGISPortalEnhancedUrl, AddressOf CALLBACK_Portal_InitializeAsync) Else ' There was some problem with the IdentityManager.GenerateCredentialAsync call. Display the message to the user. MessageBox.Show("Could not log in. Please check credentials.") End If End Sub Private Sub CALLBACK_Portal_InitializeAsync(myArcGISPortal As ESRI.ArcGIS.Client.Portal.ArcGISPortal, ex As System.Exception) ' This sub-routine executes as a result of the ArcGISPortal.InitializeAsync Method. ' Ensure there was not a problem in the returned results. If ex Is Nothing Then ' Get the ArcGISPortalInfo object from ArcGISPortal. Dim myArcGISPortalInfo As ESRI.ArcGIS.Client.Portal.ArcGISPortalInfo = myArcGISPortal.ArcGISPortalInfo ' Get the ArcGISPortalInfo.PortalHostname information. Dim myPortalHostName As String = "" If myArcGISPortalInfo IsNot Nothing Then myPortalHostName = myArcGISPortalInfo.PortalHostname End If ' Get the ArcGISPortal.CurrentUser object. Initialize some string variables for the username and email of the ' CurrentUser. If we have a valid CurrentUser get that information. If the user tries to get information using ' anonymous access the default string values of "[NOT AVAILABLE]" are provided. Dim myCurrentUser As ESRI.ArcGIS.Client.Portal.ArcGISPortalUser = myArcGISPortal.CurrentUser Dim myUserName As String = "[NOT AVAILABLE]" Dim myEmail As String = "[NOT AVAILABLE]" If myCurrentUser IsNot Nothing Then myUserName = myCurrentUser.UserName myEmail = myCurrentUser.Email End If ' Get the CurrentVerion of the AGOL/Portal server. Dim myCurrentVersion As String = myArcGISPortal.CurrentVersion ' Get the Url of the AGOL/Portal server. Dim myUrl As String = myArcGISPortal.Url ' Create a StringBuilder class to hold information obtained from the AGOL/Portal service. Dim myStringBuilder As New Text.StringBuilder myStringBuilder.Append("ArcGISPortalInfo.PortalHostName: " + myPortalHostName + vbCrLf) myStringBuilder.Append("ArcGISPortal.CurrentVersion: " + myCurrentVersion + vbCrLf) myStringBuilder.Append("ArcGISPortal.Url: " + myUrl + vbCrLf) myStringBuilder.Append("CurrentUser.UserName: " + myUserName + vbCrLf) myStringBuilder.Append("CurrentUser.Email: " + myEmail + vbCrLf) ' Display the information about the AGOL/Portal server to the user. TextBlock_GenericInfo.Text = myStringBuilder.ToString '---------------------------------------------------------------- ' Now that the ArcGISPortal.InitializeAsync has successfully been invoked, we can now get more detailed information ' about ArcGISPortalGroup's. ' Create a new SearchParameters object. Dim mySearchParameters As ESRI.ArcGIS.Client.Portal.SearchParameters = New ESRI.ArcGIS.Client.Portal.SearchParameters ' Get the search keyword(s) for finding Groups in the AGOL/Portal server. Dim mySearchKeywords As String = TextBox_SearchKeywords.Text ' Add the search keyword(s) to the SearchParameters. mySearchParameters.QueryString = mySearchKeywords ' Allow lots of Groups to be returned. mySearchParameters.Limit = 1000 ' Use the ArcGISPortal object to access Group information in AGOL/Portal services. This will cause an asynchronous call to the ' sub-routine called CALLBACK_ArcGISPortal_SearchGroupsAsync. myArcGISPortal.SearchGroupsAsync(mySearchParameters, AddressOf CALLBACK_ArcGISPortal_SearchGroupsAsync) Else ' There was some problem with the ArcGISPortal.InitializeAsync call. Display the message to the user. MessageBox.Show("Failed to initialize" & ex.Message.ToString()) End If End Sub Private Sub CALLBACK_ArcGISPortal_SearchGroupsAsync(sri As ESRI.ArcGIS.Client.Portal.SearchResultInfo(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup), ex As System.Exception) ' This sub-routine executes as a result of the ArcGISPortal.SearchGroupsAsync Method. ' Create a StringBuilder class to hold Group information obtained from the AGOL/Portal service. Display the ' number of Groups found in the ListBox. Dim myStringBuilder As New Text.StringBuilder myStringBuilder.Append("Number of ArcGIS Portal Groups: " + sri.TotalCount.ToString + vbCrLf) ListBox_GroupInfo.Items.Add(myStringBuilder.ToString) ' Get the results (an IEnumerable of ArcGISPortalGroup objects) from the SearchResultInfo object. Dim myResults As IEnumerable(Of ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup) = sri.Results ' Loop through each ArcGISPortalGroup object. For Each myArcGISPortalGroup As ESRI.ArcGIS.Client.Portal.ArcGISPortalGroup In myResults ' Get various ArcGISPortalGroup Property information. Like: the image logo for the Group, the access level ' of the Group (Private, Public, etc.), the brief description (i.e. Snippet) of what the Group does, the ' owner username of the Group, and the title (e.g. the name) of the Group. Dim myImageUri As Uri = myArcGISPortalGroup.ThumbnailUri Dim myAccess As ESRI.ArcGIS.Client.Portal.PortalAccess = myArcGISPortalGroup.Access Dim mySnippet As String = myArcGISPortalGroup.Snippet Dim myOwner As String = myArcGISPortalGroup.Owner Dim myTitle As String = myArcGISPortalGroup.Title ' Create a new StackPanel to house the information that will be displayed to the user about each Group found. Dim myStackPanel As New StackPanel myStackPanel.Orientation = Orientation.Vertical If myImageUri IsNot Nothing Then ' If the Group has an image logo, display it to the user. ' Create a new Image object, define its size and set the Uri of the Image to that for the Group. Dim myImage As New Image myImage.Width = 50 myImage.Height = 50 myImage.Source = New Imaging.BitmapImage(myImageUri) ' Silverlight has issues with .gif format images! ' Display the image on the left in the ListBox. Dim myStackPanel2 As New StackPanel myStackPanel2.Orientation = Orientation.Horizontal myStackPanel2.HorizontalAlignment = Windows.HorizontalAlignment.Left myStackPanel2.Children.Add(myImage) myStackPanel.Children.Add(myStackPanel2) Else ' The Group does not have an image logo defined. ' Inform the use that no image logo is available for display. Dim myTextBlock_ArcGISPortalGroup_ThumbnailImage As New TextBlock myTextBlock_ArcGISPortalGroup_ThumbnailImage.Text = "[NO THUMBNAIL IMAGE AVAILABLE]" myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_ThumbnailImage) End If ' Display the AGOL/Portal Group access level (i.e. Public, Private, etc.). Dim myTextBlock_ArcGISPortalGroup_Access As New TextBlock myTextBlock_ArcGISPortalGroup_Access.Text = "ArcGISPortalGroup.Access: " + myAccess.ToString myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Access) ' Display the snippet (aka. brief description) of what the Group is about. If Not (mySnippet Is Nothing) Then ' Some Snippets have no value! Dim myTextBlock_ArcGISPortalGroup_Snippet As New TextBlock myTextBlock_ArcGISPortalGroup_Snippet.Text = "ArcGISPortalGroup.Snippet: " + mySnippet.ToString myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Snippet) End If ' Display the owner of the Group. Dim myTextBlock_ArcGISPortalGroup_Owner As New TextBlock myTextBlock_ArcGISPortalGroup_Owner.Text = "ArcGISPortalGroup.Owner: " + myOwner.ToString myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Owner) ' Display the title of the Group. Dim myTextBlock_ArcGISPortalGroup_Title As New TextBlock myTextBlock_ArcGISPortalGroup_Title.Text = "ArcGISPortalGroup.Title: " + myTitle.ToString myStackPanel.Children.Add(myTextBlock_ArcGISPortalGroup_Title) ' Add the various display objects about the Group in the ListBox. ListBox_GroupInfo.Items.Add(myStackPanel) Next End Sub Private Sub CheckBox_UseAnonymousAccess_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' This sub-routine execute when the user checks on/off the ability to get information about AGOL/Portal ' using anonymous access or via the IdentityManager with a username/password for secured web services. If CheckBox_UseAnonymousAccess.IsChecked = True Then ' The user wants to have anonymous access to get AGOL/Portal information. ' Hide the username/password controls. Label_Password.Visibility = Windows.Visibility.Collapsed Label_UserName.Visibility = Windows.Visibility.Collapsed TextBox_Password.Visibility = Windows.Visibility.Collapsed TextBox_UserName.Visibility = Windows.Visibility.Collapsed Else ' The user wants to have IdentityManager with a username/password access to get AGOL/Portal information. ' Show the username/password controls. Label_Password.Visibility = Windows.Visibility.Visible Label_UserName.Visibility = Windows.Visibility.Visible TextBox_Password.Visibility = Windows.Visibility.Visible TextBox_UserName.Visibility = Windows.Visibility.Visible End If End Sub | |
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8