Learn More About the Best Practices SharePoint Conference

How to Write Custom Code Against the MashPoint Runtime Object Model

Blogs

    MashPoint - A Breakthrough in SharePoint Data Integration
  • Home
  • Contact

News Flash

Download MashPoint Now!

MashPoint - Data Integration for SharePointDownload the official MashPoint release, available as of November 7th, 2008.

Jonas Nilsson Q&A

In this post I'm going to describe how you write code that uses the MashPoint runtime object model. But before we dive in to the samples we need to get an idea of how MashPoint works.

The MashPoint API can run in two modes:

  1. Utilizing the MashPoint implementation.
  2. Utilizing the MOSS BDC.

No matter what runtime you will target, you can use the MashPoint APIs. This gives you the benefit of being able to run your code both on MOSS BDC and on Bamboo MashPoint. A company with both MOSS Enterprise farms and WSS farms can now deploy the same Web Parts in both environments if you use the MashPoint APIs instead of the Microsoft specific APIs.

This is accomplished by exposing an interface-based API. When you work with MashPoint, you only use interfaces. We have created interfaces for all public classes in the ApplicationRegistry namespace. When you run on top of the BDC, we wrap all objects coming from the BDC so that you get the MashPoint interface to work with.

image

 

The picture above shows the different layers. At the top you have the client code (your code). This code only has a reference to the Bamboo.Portal.dll. During runtime, the Bamboo.Portal layer decides if it's going to use the BDC or MashPoint. If you write a Web Part, the decision is made based on the context.

If the Web Part is running in a Web Application that is associated with a Bamboo Shared Service you will use the MashPoint implementation, otherwise you will use the BDC if it's available and an association exists. If you are writing a console application you have to specify what Shared Service to use. If you specify a Bamboo Shared Service you will use the MashPoint implementation.

 

 

Comparison of the ApplicationRegistry.MetadataModel namespace.

MashPoint API's

MOSS BDC API's

image image

 

   

Lets take a look at some sample code from MSDN and see what you have to change to use MashPoint.

namespace Microsoft.SDK.SharePointServer.Samples
{
    using System;
    using Microsoft.Office.Server.ApplicationRegistry.MetadataModel;
    using Microsoft.Office.Server.ApplicationRegistry.Infrastructure;
    using NUnit.Framework;

    [TestFixture]
    public class GetStartedAndDisplaySystems
    {
        const string yourSSPName = "SharedServices1";

        [Test]
        public void DisplayLOBSystemsinBDC()
        {
            SqlSessionProvider.Instance().SetSharedResourceProviderToUse(yourSSPName);
            NamedLobSystemInstanceDictionary sysInstances = 
                ApplicationRegistry.GetLobSystemInstances();
            Console.WriteLine("Listing system instances...");
            foreach (String name in sysInstances.Keys)
            {
                Console.WriteLine(name);
            }
        }
    }
}


namespace MashPoint.Samples
{
    using System;
    using Bamboo.Office.Server.ApplicationRegistry.Infrastructure;
    using Bamboo.Office.Server.ApplicationRegistry.MetadataModel;
    using NUnit.Framework;

    [TestFixture] 
    public class GetStartedAndDisplaySystems
    {
        const string yourSSPName = "SharedServices1";

        [Test]
        public void DisplayLOBSystemsinBDC()
        {
            SqlSessionProvider.Instance().SetSharedResourceProviderToUse(yourSSPName);
            IApplicationRegistry registry = ApplicationRegistry.Instance();

            INamedLobSystemInstanceDictionary sysInstances = 
                registry.GetLobSystemInstances();
            Console.WriteLine("Listing system instances...");
            foreach (String name in sysInstances.Keys)
            {
                Console.WriteLine(name);
            }
        }
    }
}

The changes we had to make was first to use the Bamboo.Office.Server.ApplicationRegistry.xxxx namespaces instead of the Microsoft ones. We have the same namespace hierarchy  to make it easy to port applications. The next change is to change all class references to interface refrences, just prefix the class name with an "I" for interface.

 

Let's look at another sample from MSDN:  How to: Execute a Finder Method on an Entity.

namespace Microsoft.SDK.SharePointServer.Samples
{
    using System;
    using Microsoft.Office.Server.ApplicationRegistry.MetadataModel;
    using Microsoft.Office.Server.ApplicationRegistry.Runtime;
    using Microsoft.Office.Server.ApplicationRegistry.Infrastructure;
    using NUnit.Framework;

    [TestFixture]
    public class ExecuteFinder
    {
        const string yourSSPName = "SharedServices1";

        [Test]
        public void FindAll()
        {
            SqlSessionProvider.Instance().SetSharedResourceProviderToUse(yourSSPName);

            NamedLobSystemInstanceDictionary sysInstances = 
                ApplicationRegistry.GetLobSystemInstances();

            LobSystemInstance AdvWorksIns = sysInstances["AdventureWorksSampleInstance"];
            Entity prodEntity = AdvWorksIns.GetEntities()["Product"];
            FilterCollection fc = prodEntity.GetFinderFilters();
            IEntityInstanceEnumerator prodEntityInstanceEnumerator = 
                prodEntity.FindFiltered(fc, AdvWorksIns);

            while (prodEntityInstanceEnumerator.MoveNext())
            {
                IEntityInstance IE = prodEntityInstanceEnumerator.Current;
                foreach (Field f in prodEntity.GetFinderView().Fields)
                {
                    Console.Write(IE[f]);
                }
                Console.WriteLine("");
            }
        }
    }
}

namespace MashPoint.Samples
{
    using System;
    using Bamboo.Office.Server.ApplicationRegistry.MetadataModel;
    using Bamboo.Office.Server.ApplicationRegistry.Runtime;
    using Bamboo.Office.Server.ApplicationRegistry.Infrastructure;
    using NUnit.Framework;

    [TestFixture]
    public class ExecuteFinder
    {
        const string yourSSPName = "SharedServices1";

        [Test]
        public void FindAll()
        {
            SqlSessionProvider.Instance().SetSharedResourceProviderToUse(yourSSPName);

            INamedLobSystemInstanceDictionary sysInstances = 
                ApplicationRegistry.Instance().GetLobSystemInstances();

            ILobSystemInstance AdvWorksIns = sysInstances["AdventureWorksSampleInstance"];
            IEntity prodEntity = AdvWorksIns.GetEntities()["Product"];
            IFilterCollection fc = prodEntity.GetFinderFilters();
            IEntityInstanceEnumerator prodEntityInstanceEnumerator = 
                prodEntity.FindFiltered(fc, AdvWorksIns);

            while (prodEntityInstanceEnumerator.MoveNext())
            {
                IEntityInstance IE = prodEntityInstanceEnumerator.Current;
                foreach (IField f in prodEntity.GetFinderView().Fields)
                {
                    Console.Write(IE[f]);
                }
                Console.WriteLine("");
            }
        }
    }
}
As you can see, it's pretty straightforward to port the code from using the MOSS APIs to use the MashPoint APIs.

To run these samples you need to download MashPoint and install it. This is so you get the required assemblies installed on your machine. As I said earlier you only need to set a reference to Bamboo.Portal.dll.

These code samples assume that you have installed the AdventureWorks sample ADF file into either MashPoint or the MOSS BDC.

In the next post we will write a custom Web Part that consumes data from MashPoint.

/Jonas

 


Posted Jun 17 2008, 11:02 PM by Jonas Nilsson
  
Bamboo Solutions Corporation, 2002-2008