Consuming Windows Azure DataMarket with SharePoint 2010 via Business Connectivity Services

Windows Azure MarketPlace DataMarket is a service that provides a single consistent marketplace and delivery channel for high quality information as cloud services. It provides high quality Statistical and Research data across many business domains from financial to Health Care.. You can read more about it here

How do we consume this content in an enterprise scenario? In this post we are going to look at how to integrate Azure Marketplace Datamarket with SharePoint 2010 via Business Connectivity Services via .NET Connector as a external list. This enable us to surface Azure DataMarket data through SharePoint 2010 lists which opens up world of possibilities including going offline with SharePoint workspace and participation with workflows, enterprise search etc..

Let’s first start with Azure Datamarket. Logon to https://datamarket.azure.com with your live id and subscribe to a dataset that that you are interested in. I selected European Greenhouse Gas Emissions DataSet. Also note down your account key in the Account Keys tab as we will need this information later on.

Untitled1

The Dataset details give you the input parameters and results as follows.

Untitled

You can navigate to the Data set link with your browser and view the oData feed. We are going to consume this oData feed with WCF Data Services. This allows us to use Linq to filter the data.

LinqPad is a nifty tool to develop and test LINQ Query Expressions. It allows you to connect to Windows Azure DataMarket Datasets and develop the queries against the data as shown below.

clip_image006

Now lets move on to VS2010 and create a BCS Model project as shown below.

 

image

Rename the Default Entity in the BDC Model designer and set the properties that you want to expose as the external content type

image

Once all properties are set DBC Explorer displays my model as shown below.

image

Now our BDC model is ready. Now lets implement ReadList and ReadItem BDC operations.

First Add a Service Reference to your project. Set the Address to the location of your Azure DataMarket

Dataset and Discover the oData Feed as shown below.

image

After the service reference is added , we can implement the ReadItem method as shown below.

 

image

Note that Service Reference Context requires your live ID and account Id pass as credentials in to the service call.

image

Once all operations are implemented Click F5 to build and Deploy your BDC model  into SharePoint. Once deployed

log on to Central Administration and go to Manage Service Applications and select Business Connectivity Services

and view the Details of EmissionStat Content Type being Deployed. You might wanted to permissions for this content

type at this point.

image

Now the external content type is defined all we need is a external List based on this content type. Fire up SharePoint

Designer and Create an external list referencing the new External content type just created

image

Once the list is created navigate to the list in the portal. Note that Windows Azure market place Data Market content

now surfaced through SharePoint 2010 list as shown below. The VS2010 solution associated with this post can be download here

image

Viewing item details shows full item details using our ReadItem BCS operation.

image

Integrating Structured data (Azure) with Unstructured content (Collaborative Data) in SharePoint allows you  to create high business valued

composites for informed decision making purposes at all levels in your organisations. Happy Cloud Collaboration!


WSS Search: Your search cannot be completed because this site is not assigned to an indexer

I’ve noticed that this issue came up few times in different environments where Team foundation server 2010 configured with out of the box SharePoint (WSS) installation. I thought of writing this post that might help someone having the same issue.

The Problem: SharePoint search was not working in the current production environment and when you search you get a error message saying

Your search cannot be completed because this site is not assigned to an indexer. Contact your administrator for more information’.

You also notice that the SharePoint search service is running as a windows service in the service console but not visible under farm services in the Central Administration.

 

The cause:  Search services not properly configured registered in the SharePoint farm level.

The resolution steps:

1.      Go to Central Admin as login as the farm Administrator

2.      Go to Application Management tab

3.      Select SharePoint Web Application Management heading | Content databases

4.      Ensure your web application is the one selected

5.      Select your content database name

6.      Under Search Server – select your server (if your search server drop down is disabled please follow the additional steps below)

7.      Go to 12 hive folder and open stsadm.exe utility

8.      Run the following command psconfig.exe -cmd services -install

9.      Then run stsadm -o spsearch -action start (specify the farm account if required)

This process will register the search services within the SharePoint (WSS) farm and search service will now appear under central administration. Now you can click the service service and create a indexing schedule. After indexing job is completed for the given web application you will notice that search results appear as expected.


Leverage and Extend Claims based identity in SharePoint 2010

Windows Identity Foundation (WIF) is the platform on which SharePoint 2010 claims authentication is based. WIF, which is fully supported in SharePoint 2010, ADFS 2.0, ASP.NET, Windows Communication Foundation (WCF), and any other .NET application you care to develop, provides the infrastructure necessary to generate, transmit, and process claims-based identity in a simple and straightforward manner. It removes the roadblocks imposed by legacy authentication schemes like NTLM and Kerberos and puts control directly into the hands of developers, users, and IT security professionals. long story short, it’s a framework written to help solve identity issues common in the of cloud computing and service-oriented architecture.

The idea of claims based identity is one that many people are willing to try. Getting accurate information out there to the public though does take time.

The important point is this is based on industry standards.  Many different entities are on board along with Microsoft in this matter. The digital world continues to give us new opportunities and those involved believe that this will help all of us to get the most out of it. There is a strong foundation in place to continue building upon. The use of AD FS v2, CardSpace, and Windows Identity Foundation are all important pieces of this puzzle.

As a demonstration of these capabilities, I’ll show how SharePoint 2010, WCF,and WIF can be put together to solve the identity delegation problem. In this demo session part 1 I start establishing the trust relationship between ADFS 2.0 and SharePoint with PowerShell and demonstrate how the claims get into SharePoint.Then we build and deploy a claims viewer Webpart with WIF programming model. In part 2 We start with a web service that is front-ending line-of-business information stored in a SQL database. Then, we’ll configure it to use WIF to request the calling user’s claims from SharePoint and process the token so that authorization decisions can be made. we’ll surface this information in SharePoint 2010 as an External Content Type using Business Connectivity Services (BCS).

This session was presented in SharePoint Saturday Melbourne 2010  in Oct 2010  and MOSSIG user group Nov 2010.

images

Click here to view a recorded screencast of this session. 

The slide deck of this session is shared here

The SharePoint Claims Viewer Visual WebPart VS2010 solution,  Claims based WCF Service VS2010 solution and necesssary powershell scripts to add and remove identity provider in SharePoint 2010 can be downloaded from here.
 
I encourage you to look at following links for further information about this topic

I am Speaking at SharePoint Saturday Melbourne |Topic: “A Lap around Claims based Authentication in SharePoint 2010”

SharePointSat314x116_Melbourne

Session Abstract: “The industry it moving towards identity standards. In this session Nalaka will explore    how SharePoint 2010 has undergone a shift in identity and access control by adopting the claims-based object model offered by Windows Identity Foundation (WIF). We will discuss how SharePoint 2010 implements the extensibility points of WIF and achieves a standards based identity solution that is designed for heterogeneous identity environments for both sign-in and services (SOA)”  

Also have look at other great session line up here


Building an interactive dashboard with SharePoint 2010 RESTful Services

REST (or Representational State Transfer) is an easy way to easily get or post items to a server-side web service.  It is used in situations where you would use a web service but do not want the overhead and tightly-coupled nature of SOAP.   Technically, REST is not a protocol, but an architectural style. It complies to Open Data Protocol (OData), a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today.

SharePoint 2010, being based on WCF in the .NET 3.5 Framework, has built-in RESTful web services which allow us to take advantage of this simplicity in custom applications we write..

The RESTful service can be accessed via  http://<site collection url>_vti_bin/ListData.svc

This blog post is based on my Demo #2 last week at MOSSIG user group meeting in Melbourne.

 

uuo

 

The Data for this dashboard is sourced from 2 custom lists “Products” and “Sales”  The two lists has parent-child relationship.

aas

 

Sales List

aas2

Edit Sale Item.

aas5

 

Any given list can be accessed via the RESTFul service. This demo application is using  WCF Data Services to read/write to sharepoint  list Data, then, WCF Data Services  was the first Microsoft technology to support the Open Data Protocol. It provides developers with client libraries for .NET, Silverlight, AJAX etc..

image

Once the service proxy is created from ListData.svc you will have typed access to all the list data with LINQ support.  The following code segment in the ViewModel  shows how sales data is obtained from the service along with corresponding product details and register for Unit of Work tracking when property change.

 

private void GetSalesData() { // Set up the data context if it hasn't been done already if (_dataContext ==null) { _dataContext = new HomeDataContext( new Uri("http://spdemo/_vti_bin/ListData.svc")); } Sales = new ObservableCollection<SalesItem>(); //Prepare REST service request var query = (from s in _dataContext.Sales.Expand("ProductCode") select s ) as DataServiceQuery<SalesItem>; query.BeginExecute( (ar) => { IEnumerable<SalesItem> _salesItems = query.EndExecute(ar); foreach (SalesItem item in _salesItems) { item.PropertyChanged += ((sender, e) => { var entity = (SalesItem)sender; //track changes to entities _dataContext.UpdateObject(entity); }); Sales.Add(item); } NotifyPropertyChanged("LineValue"); }, null) ; }

The viewModel implements INotifyPropertyChanged event for the purpose of Notifying the view of Data changes and visa versa. The ViewModel exposes two properties LineValue (bound to the slider) and ObservableCollection of SalesItems. These 2 properties are declaratively bound to both chart types (bar and pie). I am using few charting controls  from Silverlight Toolkit (http://silverlight.codeplex.com/)  with XAML Declarative bindings as shown below.  

 

            <TextBlock x:Name="ScoreTextBlock" Text="{Binding LineValue}" />
            <chart:Chart Height="200" LegendTitle="Item" Title="No of Units Sold By Product" 
                         x:Name="MyBarChart" Width="562" DataContext="{Binding}">
            <chart:ColumnSeries x:Name="MySalesChartData" Title="Sales of Products" 
                    ItemsSource="{Binding Sales}"
                    IndependentValueBinding="{Binding ProductCode.ProductName}"
                    DependentValueBinding="{Binding NoofUnits}"/>
            </chart:Chart>
            <chart:Chart Height="230" Title="Sales Distribution" x:Name="MyPieChart" Width="562" Margin="4,0">
                <chart:PieSeries ItemsSource="{Binding Sales}" 
                    IndependentValueBinding="{Binding ProductCode.ProductName}"
                    DependentValueBinding="{Binding NoofUnits}" Background="#FF2B1515" />
            </chart:Chart>

The VS2010  solution that contains source code for this demo is uploaded here.

Enjoy!


SharePoint 2010 Live Image Capturing WebPart packaged as a Sandbox solution

It was great speaking and networking with fellow members at MOSSIG July meeting in Melbourne last week. I presented a session on Effective use of SilverLight 4 with SharePoint 2010.  The Slide deck is uploaded here. I demoed a SilverLight 4 WebPart  taking a snapshot on demand and with the help of  client object model  automatically save the captured snapshot to SharePoint picture library.

This demo solution was created to showcase effective use of SilverLight 4  in SharePoint 2010 as well as to show how MVVM (Model-View-ViewModel)  pattern pattern is used in designed and developing maintainable and testable SilverLight applications with powerful declarative Data binding capabilities

I thought of writing a little elaborative blog post about this solution and here we go…

First lets have a look at the outcome.

Final Result:

Untitled3

By the way this is my little boy Bryan. He enjoyed this a lot  🙂

The picture library to be used for storing the captured images can be configured by the user as shown below as a WebPart property.

Untitled1

 

Solution Type:

This  is sandbox solution. Therefore as site collection administrator you can add this solution to your solution gallery and try out its functionality with minimal impact on your farm as compared to a classic farm solution. SharePoint perform resource monitoring of your sand box solutions  as shown below. If it doesn’t behave properly it will be kicked out by SharePoint before you even know about it at times . How cool is that ?

This is a great model for ISV’s to distribute their apps and Farm/Site Collection Administrators to trial out third-party solutions with minimum risk.

image

 

Solution architecture:

The basic solution archtecture is shown below.  The viewmodel is decorating the model/Repository  and sits between your model(domain objects) and the view.  MVVM is targeted at modern UI development platforms (WPF and Silverlight). You can read more about this simple pattern  here

Untitled44

The VS2010 solution structure for this application is as follows.

Untitled4 

SandBox WebPart properties:

One of the limitation with running in the sandbox is that all web parts must inherit from “System.Web.UI.WebControls.WebParts.WebPart” instead of “Microsoft.SharePoint.WebPartPages” (which is not allowed)  when running in the sandbox.  This means the traditional means of creating custom Web Part Properties using the ToolPart object in SharePoint is not available.  Thus one must now rely on how these custom properties are created when dealing with ASP.Net Web parts.  Which by the way (as is obvious in the sandbox restriction) is now the preferred way to create web parts.  ASP.Net Web Parts have an equivalent class to the “ToolPart” class called the “EditorPart”. So I’ve created my webpart property editor inheriting from EditorPart as shown below.

// Create a custom EditorPart to edit the WebPart control.
 [AspNetHostingPermission(SecurityAction.Demand,
     Level = AspNetHostingPermissionLevel.Minimal)]
 public class SLWebCamEditorPart : EditorPart
 {
     private DropDownList _partTargetLibrary;

     public SLWebCamEditorPart()
     {
         Title = "Image capture webpart settings";
     }

     private DropDownList PartTargetLibrary
     {
         get
         {
             EnsureChildControls();
             return _partTargetLibrary;
         }
     }

 
 
Passing initialize parameters into Silverlight from Sharepoint:
 
The CreateChildControls Method in the hosting webpart injects SilverLight host control  into the WebPart as shown below.  In this case we are injecting the current site URL and target picture library name as ‘initparams’ into the SilverLight host control.
NOTE: It is important to inject the current site URL in order to guarantee the ClientContext (in SharePoint client OM ) is not NULL during  runtime execution.
[Personalizable, WebBrowsable(false)]
public String PictureLibraryName { get; set; }

protected override void CreateChildControls() { var width = "400"; var height = "600"; base.CreateChildControls(); string source = SPContext.Current.Site.Url + "/_catalogs/masterpage/SLWebCam.xap"; Controls.Add(new LiteralControl( "<div>" + " <object data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"" + width + "\" height=\"" + height + "\">" + " <param name=\"source\" value=\"" + source + "\"/>" + " <param name=\"onerror\" value=\"onSilverlightError\" />" + " <param name=\"background\" value=\"white\" />" + " <param name=\"minRuntimeVersion\" value=\"4.0.50401.0\" />" + " <param name=\"autoUpgrade\" value=\"true\" />" + " <param name=\"initParams\" value=\"MS.SP.url=" + SPContext.Current.Site.Url + ",PictureLibraryName=" + PictureLibraryName +     

…..Continue..

The injected initparam  values in the serverside can be extracted from the client side and stored as application resource as shown below.

private void Application_Startup(object sender, StartupEventArgs e)
{   // Extract init params and inject into application resource dictionary
    foreach (var resource in e.InitParams)
    {
        Application.Current.Resources.Add(resource.Key,resource.Value);
    }
    this.RootVisual = new MainPage();
}

Declarative DataBinding:

The XAML based view was created using VS2010 enhanced UI designer. The ViewModel exposes the necessary bindable properties and bindable commands (using command pattern). In other words ViewModel is the datacontext for the View

ie: XAML markup for showing the live web cam video uses a Rectangle bound to a property named VideoBrush in the ViewModel as shown below.

<Rectangle Fill="{Binding VideoBrush}" Height="138" Width="170" />

private VideoBrush videoBrush;
public VideoBrush VideoBrush
{
    get { return videoBrush; }
    set
    {
        videoBrush = value;
        FirePropertyChanged("VideoBrush");
    }
}

The view Model implements INotifyPropertyChange interface. Notifies clients that a property value has changed. The snapshots taken are exposed as a ObservableCollection of Writable bitmaps from the ViewModel and bound to a ListBox with  a DataTemplate as shown below. ObservableCollection  Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.

public ObservableCollection<WriteableBitmap> Images { get; set; }
   public ICommand StartCaptureCommand { get; set; }
   public ICommand StopCaptureCommand { get; set; }
   public ICommand TakeSnapshotCommand { get; set; }
   public ICommand SaveSnapshotCommand { get; set; }

<ListBox x:Name="Snapshots" ItemTemplate="{StaticResource SnapshotDataTemplate}" ItemsPanel="{StaticResource SnapshotItemsPanelTemplate}" ItemsSource="{Binding Images}" SelectedItem="{Binding SelectedSnapshot, Mode=TwoWay}" Height="123"

Width="356" />

Saving the Captured Image to the Sharepoint picture Library:
In order to use sharepoint client OM all you need is referencing the following 2 assemblies from SP root folder. Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin  and use the following namespace from silveright.

image
using Microsoft.SharePoint.Client;
I am also using SilverLight Image manipulation library “ImageTools” from   http://imagetools.codeplex.com/ for handing bitmap processing in the client side.

When the user select a snapshot and click the save button ClientContext is initiated and List information is obtained from the server via Client OM as a Asynchronous operation.  On the successful callback FileCreationInformation object is created with the image content , add the new file  to the list of files and commit is performed as a another asynchronous call to the server.
 
/// <summary>
 /// Obtain list instance with required minimum information via Client OM
 /// </summary>
 private void GetSpTargetListInfo(string listname)
 {
     //first build the workload 
     _targetlist = _ctx.Web.Lists.GetByTitle(listname);
     _ctx.Load(_targetlist, l => l.RootFolder.ServerRelativeUrl);
     //now execute it as a on single batch  
     _ctx.ExecuteQueryAsync(ListloadSucceeded, ListloadFailed);
 }

private void ListloadSucceeded(object sender, ClientRequestSucceededEventArgs e) { if (_img == null) return; using (Stream fs = _img.ToStream()) { var fileContent = new byte[fs.Length]; fs.Read(fileContent, 0, fileContent.Length); //create file object var file = new FileCreationInformation { Content = fileContent, Url = ApplicationContext.Current.Url + 

_targetlist.RootFolder.ServerRelativeUrl + "/" + Guid.NewGuid() + ".png" }; //add the new file to the target list var files = _targetlist.RootFolder.Files; files.Add(file); //Now execute the workload _ctx.ExecuteQueryAsync(UploadRequestSucceeded, UploadRequestFailed); } }

 

If you want to play with the webcam webpart a packaged Sandbox solution (SpImageCapture.wsp) can be downloaded here.  When activating this solution Silverlight .XAP file named SLWebCam.xap will be created in the site masterpage gallery and a hosting WebPart will be added to your WebPart gallery named SLWebCamWebPart.webpart  Drag this WebPart to your page and configure its web part properties by specifying a picture library to use for storing the images and you are done.   I’ve also uploaded the  full VS2010 solution here if you are interested in the code.

Enjoy!


Australian SharePoint Conference 2010 takeaways

Last week we had a fantastic SharePoint conference and thought of putting up a link list of few tips and tricks picked up. Great mix of technical/business sessions covering all pillars of SharePoint 2010.

On the technical Track =>

  • Deep dive into feature versioning and upgrade support in SharePoint 2010 by Jeremy Thake was great with full of content of how you upgrade solutions declarative and imperative paths. VS 2010 F5 during dev time do not help much in really testing your upgrade code in practice. Build the .wsp in vs2010 and use Powershell ISE for the rest.
  • Use splimitedwebpartmanager for adding a web part to a site imperatively and setting web part properties.
  • Great white paper on  SharePoint Content & Application Lifecycle Management Guidance from Jeremy. Check it out here
  • It was great catching up with Todd Bleeker. CKS Development Tools http://cksdev.codeplex.com/  provide nice feature upgrade enhancements and few more dev productivity tools.
  • Checkout SharePoint 2010 Extensibility Projects which extends VS2010  with following templates.

                  1. Silverlight and SharePoint project template
                  2. SharePoint Ribbon project template
                  3. OBA Deployment project template

  • SharePoint 2010 Word Services, combined with the OpenXML SDK rocks. Great session by Andrew Coates
  • Remoteblobstorage in sp 2010  for very large file storage including any steaming media for better performance and ease of database file size management.

On the business/end user track =>

  • Sharepoint 2010 is a single unified platform for supporting entire organizational information architecture with  knowledge management, content management, document management and record management. Enjoyed the information architecture session by Gayan Peiris and Rai Umair. Metadata navigation,Document ID, Document Sets are great brand new new features of SP2010 . Specially liked ability to define record management policies on content types too.

On the IT Pro track =>

  • Migrate and upgrade to SharePoint 2010 with restructure in mind. In place upgrade is largely theoretical. Database attach upgrade is recommended for most scenarios. Think about the possibilities of virtualizes some of SP2010 farm environment roles except database role. 

Had an awesome time at #auspc, meet lots of awesome people and big thank you for the organizers.

  

 

.