This sample illustrates a simple way of querying the Portal metadata/properties and retrieving featuredItems using the Portal API. To use the sample, Click on Initialize button to initialize the portal. Once the portal is initialized , the portal metadata is displayed.
Download Sample Application
< UserControl x:Class = " ArcGISWPFSDK.PortalMetadata "
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 " Background = " White " >
< Grid.Resources >
< DataTemplate x:Key = " PortalGroupTemplate " >
< StackPanel Margin = " 2 " >
< TextBlock Text = " {Binding Title, StringFormat='Title: {0}'} " FontWeight = " Bold " />
< TextBlock Text = " {Binding Snippet, StringFormat='Snippet: {0}'} " TextWrapping = " Wrap " Width = " 500 " />
< TextBlock Text = " {Binding Owner, StringFormat='Owner: {0}'} " />
< TextBlock Text = " {Binding CreationDate, StringFormat='Creation Date: {0}'} " />
</ StackPanel >
</ DataTemplate >
</ Grid.Resources >
< Grid.ColumnDefinitions >
< ColumnDefinition />
< ColumnDefinition />
</ Grid.ColumnDefinitions >
< Grid.RowDefinitions >
< RowDefinition Height = " 35 " />
< RowDefinition Height = " * " />
</ Grid.RowDefinitions >
< StackPanel Orientation = " Horizontal " Grid.Row = " 0 " Grid.ColumnSpan = " 2 " >
< TextBlock Text = " Portal Url: " Margin = " 10,5,5,5 " VerticalAlignment = " Center " HorizontalAlignment = " Center " />
< TextBox x:Name = " PortalUrltextbox " Text = " http://www.arcgis.com/sharing/rest "
HorizontalAlignment = " Left " VerticalAlignment = " Center " Width = " 250 " Margin = " 5 " />
< Button Content = " Initialize " Click = " LoadPortalInfo_Click " Height = " 25 " />
</ StackPanel >
< Grid Margin = " 2 " Grid.Row = " 1 " Grid.Column = " 0 " >
< TextBlock HorizontalAlignment = " Left " Text = " Portal Details "
VerticalAlignment = " Top " Margin = " 15,10,0,0 " FontSize = " 12 "
FontWeight = " Bold " />
< ListBox x:Name = " PropertiesListBox " Margin = " 5,35,5,5 " />
</ Grid >
< Grid Margin = " 2 " Grid.Row = " 1 " Grid.Column = " 1 " >
< TextBlock HorizontalAlignment = " Left " Text = " Featured Maps "
VerticalAlignment = " Top " Margin = " 15,10,0,0 " FontSize = " 12 "
FontWeight = " Bold " />
< ListBox x:Name = " FeaturedMapsList " Margin = " 5,35,5,5 " >
< ListBox.ItemTemplate >
< DataTemplate >
< StackPanel Orientation = " Horizontal " >
< Image Source = " {Binding ThumbnailUri} " Margin = " 5 " Stretch = " None " />
< StackPanel Orientation = " Vertical " >
< TextBlock Text = " {Binding Title, StringFormat='Title: {0}'} " />
< TextBlock Text = " {Binding Type, StringFormat='Type: {0}'} " />
< TextBlock Text = " {Binding Owner, StringFormat='Owner: {0}'} " />
< TextBlock Text = " {Binding CreationDate, StringFormat='Creation Date: {0}'} " />
</ StackPanel >
</ StackPanel >
</ DataTemplate >
</ ListBox.ItemTemplate >
</ ListBox >
</ Grid >
</ Grid >
</ UserControl >
using System.Windows.Controls;
using System.Text;
using ESRI.ArcGIS.Client.Portal;
using System.Collections.Generic;
using ESRI.ArcGIS.Client.WebMap;
using ESRI.ArcGIS.Client;
using System.Windows;
using System;
using System.Windows.Navigation;
using System.Diagnostics;
namespace ArcGISWPFSDK
{
public partial class PortalMetadata : UserControl
{
public PortalMetadata()
{
InitializeComponent();
}
private void LoadPortalInfo_Click(object sender, RoutedEventArgs e)
{
PropertiesListBox.Items.Clear();
if (String.IsNullOrEmpty(PortalUrltextbox.Text))
return ;
InitializePortal(PortalUrltextbox.Text);
}
public void InitializePortal(string PortalUrl)
{
ArcGISPortal arcgisPortal = new ArcGISPortal();
arcgisPortal.InitializeAsync(PortalUrl, (p, ex) =>
{
if (ex == null )
{
ArcGISPortalInfo portalInfo = p.ArcGISPortalInfo;
if (portalInfo == null )
{
MessageBox.Show("Portal Information could not be retrieved" );
return ;
}
PropertiesListBox.Items.Add(string .Format("Current Version: {0}" , p.CurrentVersion));
PropertiesListBox.Items.Add(string .Format("Access: {0}" , portalInfo.Access));
PropertiesListBox.Items.Add(string .Format("Host Name: {0}" , portalInfo.PortalHostname));
PropertiesListBox.Items.Add(string .Format("Name: {0}" , portalInfo.PortalName));
PropertiesListBox.Items.Add(string .Format("Mode: {0}" , portalInfo.PortalMode));
ESRI.ArcGIS.Client.WebMap.BaseMap basemap = portalInfo.DefaultBaseMap;
PropertiesListBox.Items.Add(string .Format("Default BaseMap Title: {0}" , basemap.Title));
PropertiesListBox.Items.Add(string .Format("WebMap Layers ({0}):" , basemap.Layers.Count));
foreach (WebMapLayer webmapLayer in basemap.Layers)
{
PropertiesListBox.Items.Add(webmapLayer.Url);
}
portalInfo.GetFeaturedGroupsAsync((portalgroup, exp) =>
{
if (exp == null )
{
PropertiesListBox.Items.Add("Groups:" );
ListBox listGroups = new ListBox();
listGroups.ItemTemplate = LayoutRoot.Resources["PortalGroupTemplate" ] as DataTemplate;
listGroups.ItemsSource = portalgroup;
PropertiesListBox.Items.Add(listGroups);
}
});
portalInfo.SearchFeaturedItemsAsync(new SearchParameters() { Limit = 15 }, (result, err) =>
{
if (err == null )
{
FeaturedMapsList.ItemsSource = result.Results;
}
});
}
else
MessageBox.Show("Failed to initialize" + ex.Message.ToString());
});
}
}
}
Imports System.Windows.Controls
Imports System.Text
Imports ESRI.ArcGIS.Client.Portal
Imports System.Collections.Generic
Imports ESRI.ArcGIS.Client.WebMap
Imports ESRI.ArcGIS.Client
Imports System.Windows
Imports System
Imports System.Windows.Navigation
Imports System.Diagnostics
Namespace ArcGISWPFSDK
Partial Public Class PortalMetadata
Inherits UserControl
Public Sub New ()
InitializeComponent()
End Sub
Private Sub LoadPortalInfo_Click(ByVal sender As Object , ByVal e As RoutedEventArgs)
PropertiesListBox.Items.Clear()
If String .IsNullOrEmpty(PortalUrltextbox.Text) Then
Return
End If
InitializePortal(PortalUrltextbox.Text)
End Sub
Public Sub InitializePortal(ByVal PortalUrl As String )
Dim arcgisPortal As New ArcGISPortal()
arcgisPortal.InitializeAsync(
PortalUrl,
Sub (p, ex)
If ex Is Nothing Then
Dim portalInfo As ArcGISPortalInfo = p.ArcGISPortalInfo
If portalInfo Is Nothing Then
MessageBox.Show("Portal Information could not be retrieved" )
Exit Sub
End If
PropertiesListBox.Items.Add(String .Format("Current Version: {0}" , p.CurrentVersion))
PropertiesListBox.Items.Add(String .Format("Access: {0}" , portalInfo.Access))
PropertiesListBox.Items.Add(String .Format("Host Name: {0}" , portalInfo.PortalHostname))
PropertiesListBox.Items.Add(String .Format("Name: {0}" , portalInfo.PortalName))
PropertiesListBox.Items.Add(String .Format("Mode: {0}" , portalInfo.PortalMode))
Dim basemap As ESRI.ArcGIS.Client.WebMap.BaseMap = portalInfo.DefaultBaseMap
PropertiesListBox.Items.Add(String .Format("Default BaseMap Title: {0}" , basemap.Title))
PropertiesListBox.Items.Add(String .Format("WebMap Layers ({0}):" , basemap.Layers.Count ))
For Each webmapLayer As WebMapLayer In basemap.Layers
PropertiesListBox.Items.Add(webmapLayer.Url)
Next webmapLayer
portalInfo.GetFeaturedGroupsAsync(
Sub (portalgroup, exp)
If exp Is Nothing Then
PropertiesListBox.Items.Add("Groups:" )
Dim listGroups As New ListBox()
listGroups.ItemTemplate = TryCast(LayoutRoot.Resources("PortalGroupTemplate" ), DataTemplate)
listGroups.ItemsSource = portalgroup
PropertiesListBox.Items.Add(listGroups)
End If
End Sub )
portalInfo.SearchFeaturedItemsAsync(
New SearchParameters() _
With {.Limit = 15},
Sub (result, err)
If err Is Nothing Then
FeaturedMapsList.ItemsSource = result.Results
End If
End Sub )
Else
MessageBox.Show("Failed to initialize" & ex.Message.ToString())
End If
End Sub )
End Sub
Private Sub Hyperlink_RequestNavigate(sender As Object , e As RoutedEventArgs)
Dim btn As Button = TryCast(sender, Button)
Process.Start(New ProcessStartInfo(btn.Content.ToString()))
e.Handled = True
End Sub
End Class
End Namespace
5/16/2014