Share via


Implementing an Adapter

The warehouse service uses the IWarehouseAdapter interface to make calls periodically to each of the warehouse adapters. The adapters pull data from the operational store, transform the data as necessary, and write the result to the warehouse through the warehouse object model.

Warehouse Object Model

The warehouse object model consists of two parts: the Warehouse namespace and the Adapter namespace. The Microsoft.TeamFoundation.Warehouse namespace contains objects that comprise the warehouse schema. The Microsoft.TeamFoundation.Adapter namespace contains the IWarehouseAdapter interface an adapter must implement, and the IDataStore interface through which the adapter interacts with the warehouse.

IWarehouseAdapter Interface

A warehouse adapter implements the IWarehouseAdapter interface, defined in the Microsoft.TeamFoundation.Adapter namespace. This interface defines four methods that an adapter must implement.

void Initialize(IDataStore ds);

This method initializes the adapter. Generally, it will hold a reference to the IDataStore object. During initialization, the adapter sets variables holding the address of the Team Foundation Server and tools the adapter will work with.

SchemaChangesResult MakeSchemaChanges();

This method provides the means by which an adapter can indicate whether it will change schema on this run. If the schema is dynamic, the adapter checks for need for a schema change. It then returns an indication whether the schema will change.

DataChangesResult MakeDataChanges( );

This is the method that does the primary work of the adapter. It pulls data from the operational store and writes it to the warehouse using the object model.

void RequestStop( );

Use this method to stop the adapter in an orderly fashion in the event the service is taken down.

Adding Data to the Warehouse

Namespace: Microsoft.TeamFoundation.Adapter

The IDataStore interface in the Microsoft.TeamFoundation.Adapter namespace provides access to the Team Foundation reporting warehouse. The basic pattern for adding data to the warehouse is to create the object, set the properties, then save the object. This type of functionality is defined in the MakeDataChanges method of the adapter.

The following example adds a member to the Person dimension. The properties of the dimension entry are based on the schema for that dimension.

// get a person record from the data source

DimensionMember dm = m_IDataStore.CreateDimensionMember("Person");

dm["Alias"] = source.alias;

dm["FirstName"] = source.firstName;

dm["LastName"] = source.lastName;

m_IDataStore.BeginTransaction();

try

{

m_IDataStore.SaveDimensionMember(dm);

m_IDataStore.CommitTransaction(dm);

}

catch

{

m_IDataStore.RollbackTransaction(dm);

throw;

}

This example adds a member to the WorkItem fact. Like the dimension entry, the properties of the fact entry are based on the schema provided for that fact. The tracking ID is some marker from the operational store that can be used to determine the last item that was saved to the warehouse.

// get a work item record from the data source

// this object will be named "wi"

FactEntry fe = m_IDataStore.CreateFactEntry("WorkItem");

fe["Work Item ID"] = wi.ID;

fe["Title"] = wi.Title;

fe["Assigned To"] = wi.AssignedTo;

fe.TrackingID = trackingID;

m_IDataStore.BeginTransaction();

try

{

m_IDataStore.SaveFactEntry(fe, false);

m_IDataStore.CommitTransaction();

}

catch

{

m_IDataStore.RollbackTransaction(dm);

throw;

}

This example adds FactLink. It specifies the tracking ID of the fact from the two tables that are being related.

FactLinkEntry fl = m_IDataStore.CreateFactLinkEntry("Link1");

fl.SourceFactTrackingId = sourceTrackingID;

fl.LinkedFactTrackingId = targetTrackingID;

try

{

m_IDataStore.SaveFactLinkEntry(fl);

m_IDataStore.CommitTransaction();

}

catch

{

m_IDataStore.RollbackTransaction(dm);

throw;

}

Updating the Schema

Namespace: Microsoft.TeamFoundation.Adapter

Namespace: Microsoft.TeamFoundation.Warehouse

The IDataStore object provides methods to add, delete, and rename dimension uses, fields, and measures. It also provides a method to change the aggregation function of a measure. The following example shows how to add a new measure to a fact. This type of functionality should be defined in the MakeSchemaChanges method of the adapter.

Field fld = new Field();

fld.Name = "Work";

fld.Type = "INT";

fld.AggregationFunction = "Sum";

m_IDataStore.BeginTransaction();

try

{

m_IDataStore.Add("Work Item", fld);

m_IDataStore.CommitTransaction();

}

catch

{

m_IDataStore.RollbackTransaction(dm);

throw;

}

See Also

Tasks

How to: Create an Adapter

Concepts

Data Warehouse Organization

Data Warehouse Extensibility

Other Resources

Team Foundation Server SDK

Team Foundation Server Data Warehouse