ArcGISPortalManager: Get a portal and Sign In, Set it Active
//Find the portal to sign in with using its Uri...varportal=ArcGISPortalManager.Current.GetPortal(newUri(uri,UriKind.Absolute));if(!portal.IsSignedOn()){//Calling "SignIn" will trigger the OAuth popup if your credentials are//not cached (eg from a previous sign in in the session)if(portal.SignIn().success){//Set this portal as my active portalArcGISPortalManager.Current.SetActivePortal(portal);}}
Portal: Get the "online" portal view for the current user
//If no-one is signed in, this will be the default view for//the anonymous user.varonline=ArcGISPortalManager.Current.GetPortal(newUri("http://www.arcgis.com"));varportalInfo=awaitonline.GetPortalInfoAsync();
Portal: Get the portal view of online for the current user
//If no-one is signed in, this will be the default view for//the anonymous user.varonline=ArcGISPortalManager.Current.GetPortal(newUri("http://www.arcgis.com"));varportalInfo=awaitonline.GetPortalInfoAsync();
Portal: Get the organization id for the current user
Portal: Get the user content for the active user from the active portal
varportal=ArcGISPortalManager.Current.GetActivePortal();varowner=portal.GetSignOnUsername();varuserContent=awaitportal.GetUserContentAsync(owner);//Get content for a specific folder (identified by its folder id)//var userContent = await portal.GetUserContentAsync(owner, folderId);//Get all the foldersforeach(varpfinuserContent.PortalFolders){//Do something with the folders}//Get all the content itemsforeach(varpiinuserContent.PortalItems){//Do something with the portal items}
Portal: Download any package items in the user content
//elsewhere...//var owner = portal.GetSignOnUsername();vargroups=awaitportal.GetGroupsFromUserAsync(owner);foreach(vargroupingroups){//Do something with the portal groups}
Portal: Execute a portal search
varportal=ArcGISPortalManager.Current.GetPortal(portalUri);varowner=portal.GetSignOnUsername();varportalInfo=awaitportal.GetPortalInfoAsync();//1. Get all web mapsvarquery1=PortalQueryParameters.CreateForItemsOfType(PortalItemType.WebMap);//2. Get all web maps and map services - include user, organization// and "usa" in the titlevarquery2=PortalQueryParameters.CreateForItemsOfTypes(newList<PortalItemType>(){PortalItemType.WebMap,PortalItemType.MapService},owner,"","title:usa");query2.OrganizationId=portalInfo.OrganizationId;//retrieve in batches of up to a 100 each timequery2.Limit=100;//Loop until donevarportalItems=newList<PortalItem>();while(query2!=null){//run the searchPortalQueryResultSet<PortalItem>results=awaitportal.SearchForContentAsync(query2);portalItems.AddRange(results.Results);query2=results.NextQueryParameters;}//process resultsforeach(varpiinportalItems){//Do something with the portal items}
EsriHttpClient: Get the Current signed on User
//Reference Newtonsoft - Json.Net//Reference System.Net.HttpUriBuilderselfURL=newUriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri){Path="sharing/rest/portals/self",Query="f=json"};EsriHttpResponseMessageresponse=newEsriHttpClient().Get(selfURL.Uri.ToString());dynamicportalSelf=JObject.Parse(awaitresponse.Content.ReadAsStringAsync());// if the response doesn't contain the user information then it is essentially// an anonymous request against the portalif(portalSelf.user==null)return;stringuserName=portalSelf.user.username;
Get the Groups for the Current Signed on User
//Assume that you have executed the "Get the Current signed on User" snippet and have 'userName'UriBuildergroupsURL=newUriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri){Path=String.Format("sharing/rest/community/users/{0}",userName),Query="f=json"};vargroupResponse=newEsriHttpClient().Get(groupsURL.Uri.ToString());dynamicportalGroups=JObject.Parse(awaitgroupResponse.Content.ReadAsStringAsync());stringgroups=portalGroups.groups.ToString();
EsriHttpClient: Query for esri content on the active Portal
//http://www.arcgis.com/sharing/search?q=owner:esri&f=jsonUriBuildersearchURL=newUriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri){Path="sharing/rest/search",Query="q=owner:esri&f=json"};EsriHttpClienthttpClient=newEsriHttpClient();varsearchResponse=httpClient.Get(searchURL.Uri.ToString());dynamicresultItems=JObject.Parse(awaitsearchResponse.Content.ReadAsStringAsync());longnumberOfTotalItems=resultItems.total.Value;longcurrentCount=0;List<dynamic>resultItemList=newList<dynamic>();// store the first results in the listresultItemList.AddRange(resultItems.results);currentCount=currentCount+resultItems.num.Value;//Up to 50while(currentCount<numberOfTotalItems&¤tCount<=50){searchURL.Query=String.Format("q=owner:esri&start={0}&f=json",resultItems.nextStart.Value);searchResponse=httpClient.Get(searchURL.Uri.ToString());resultItems=JObject.Parse(awaitsearchResponse.Content.ReadAsStringAsync());resultItemList.AddRange(resultItems.results);currentCount=currentCount+resultItems.num.Value;}
EsriHttpClient: Get a Web Map for the Current User and Add it to Pro
UriBuildersearchURL=newUriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri){Path="sharing/rest/portals/self",Query="f=json"};EsriHttpClienthttpClient=newEsriHttpClient();EsriHttpResponseMessageresponse=httpClient.Get(searchURL.Uri.ToString());dynamicportalSelf=JObject.Parse(awaitresponse.Content.ReadAsStringAsync());// if the response doesn't contain the user information then it is essentially// an anonymous request against the portalif(portalSelf.user==null)return;stringuserName=portalSelf.user.username;searchURL.Path="sharing/rest/search";stringwebMaps="(type:\"Web Map\" OR type:\"Explorer Map\" OR type:\"Web Mapping Application\" OR type:\"Online Map\")";searchURL.Query=string.Format("q=owner:{0} {1}&f=json",userName,webMaps);varsearchResponse=httpClient.Get(searchURL.Uri.ToString());dynamicresultItems=JObject.Parse(awaitsearchResponse.Content.ReadAsStringAsync());longnumberOfTotalItems=resultItems.total.Value;if(numberOfTotalItems==0)return;List<dynamic>resultItemList=newList<dynamic>();resultItemList.AddRange(resultItems.results);//get the first resultdynamicitem=resultItemList[0];stringitemID=item.id;ItemcurrentItem=ItemFactory.Instance.Create(itemID,ItemFactory.ItemType.PortalItem);if(MapFactory.Instance.CanCreateMapFrom(currentItem)){MapnewMap=MapFactory.Instance.CreateMapFromItem(currentItem);awaitProApp.Panes.CreateMapPaneAsync(newMap);}
EsriHttpClient: Get a Service Layer and Add it to Pro
UriBuildersearchURL=newUriBuilder(ArcGISPortalManager.Current.GetActivePortal().PortalUri){Path="sharing/rest/search"};stringlayers="(type:\"Map Service\" OR type:\"Image Service\" OR type:\"Feature Service\" OR type:\"WMS\" OR type:\"KML\")";//any public layer contentsearchURL.Query=string.Format("q={0}&f=json",layers);EsriHttpClienthttpClient=newEsriHttpClient();varsearchResponse=httpClient.Get(searchURL.Uri.ToString());dynamicresultItems=JObject.Parse(awaitsearchResponse.Content.ReadAsStringAsync());longnumberOfTotalItems=resultItems.total.Value;if(numberOfTotalItems==0)return;List<dynamic>resultItemList=newList<dynamic>();resultItemList.AddRange(resultItems.results);//get the first resultdynamicitem=resultItemList[0];stringitemID=item.id;ItemcurrentItem=ItemFactory.Instance.Create(itemID,ItemFactory.ItemType.PortalItem);awaitQueuedTask.Run(()=>{// if we have an item that can be turned into a layer// add it to the mapif(LayerFactory.Instance.CanCreateLayerFrom(currentItem))LayerFactory.Instance.CreateLayer(currentItem,MapView.Active.Map);});