WorkItem Object Mapper

 

Samples

Page history last edited by Bernardo Heynemann 3 yrs ago

WOM Project Home Page / Samples /

 


This page list some samples as to help you get started.

 

Configuration

Just place the below configurations on your config file (app.config or web.config):

 

<configSections>

<section name="womConfiguration"

type="Wom.Configuration.Configurations,Wom" />

</configSections>

<womConfiguration

tfsServer="tfs01.codeplex.com"

tfsConnectionProtocol="HTTPS"

tfsPort="443"

tfsUsername="heynemann_cp"

tfsPassword="password"

tfsDomain="snd"

teamProject="wom" />

 

Codeplex Object Model

 

Objects

 

Managers

 

Workitem Code Samples

 

Defining a new Workitem Type

For setting up a Task class we use the following attributes:

[PrimaryKey("WorkItemType", typeof(WorkItemType), (int)WorkItemType.Task)]

[WorkItemType("Work Item")]

public class Task : DefaultWorkItem {

Notice that the Task class inherits from DefaultWorkItem. This only happens because Codeplex doesn´t have three different workitem types, it has one, and it differentiates based on a custom property called WorkItemType.

The WorkItemType attribute is the one that specifies the real workitem type for our workitem. In the case of Codeplex all of them have the value of "Work Item".

The PrimaryKey attribute is the one that tells the mapper which attribute it should use to differentiate this class from others (besides the WorkItem type). In the case of Codeplex we should use the WorkItemType property of the WorkItem Store, and if we are dealing with a Task, then we should use WorkItemType.Task enum value. But there´s something wrong, as we all know that WorkItemType has a string value of "Task" in the WorkItem Store and not an integer value of 0.

The mapping framework is smart here. Let´s take a look at the enumeration of WorkItemTypes:

public enum WorkItemType {

[EnumValueAttribute("Task")]

Task,

[EnumValueAttribute("Issue")]

Issue,

[EnumValueAttribute("Feature")]

Feature

}

What we use here are EnumValueAttributes that tell the mapper that if this enumeration is used as primary key, it should use the value specified in the EnumValueAttribute and not the integer value of the enumeration.

 

Declaring Properties in Workitem Types

Now let´s take a look at declaring properties:

[WorkItemProperty("Code Studio Rank")]

public Priorities Priority {

get { return priority; }

set { priority = value; }

}

This is a property of the DefaultWorkItem class.

The WorkItemProperty attribute is the attribute that tells the mapper what this property is named in the WorkItemStore. In our sample, the Priority property is named "Code Studio Rank" (talk about bad naming!).

 

Creating a new Workitem Object (Task)

Now let´s take a look at how to create a new Task:

Task task = new Task();

task.AssignedTo = "heynemann_cp";

task.Description = "test description";

task.Priority = Priorities.High;

task.Status = Status.Active;

task.Title = "Test Title";

TaskManager tm = new TaskManager();

tm.BeginTransaction();

try {

tm.Save(task);

tm.Commit();

}

catch {

tm.Rollback();

throw;

}

 

That´s pretty much everything you need to create a new Task in the WorkItemStore. Notice the transaction support and that the Task won´t be created until Commit takes place.

 

Loading a Task from the Workitem Store

How about loading Task #2323 from the WorkItem store? It´s as simple as:

Task t = new Task(2323);

 

Updating a Task in the Workitem Store

And Updating Task #2323 follows the same model as creating a Task, except that you initialize the task object with the task you want to save:

Task task = new Task(2323);

task.Status = Status.Closed;

TaskManager tm = new TaskManager();

tm.BeginTransaction();

try {

tm.Save(task);

tm.Commit();

}

catch {

tm.Rollback();

throw;

}

 

Workitem Query Samples

 

For querying the WorkItem store we use the QueryManager class.

It must receive a FilterCollection class. A filter collection class is built by adding up Filters with "&" for Logical And and "|" for Logical Or.

 

Querying for Active Features assigned to me

string targetUser = "Heynemann_cp";

FilterCollection fc =

Filter.Equal("Status", Status.Active) &

Filter.Equal("AssignedTo", targetUser);

IList feats = QueryManager.GetWorkItems(fc);

 

Querying for Active Features assigned to me or closed ones

string targetUser = "Heynemann_cp";

FilterCollection fc =

(Filter.Equal("Status", Status.Active) &

Filter.Equal("AssignedTo", targetUser))

| Filter.Equal("Status", Status.Closed);

IList feats = QueryManager.GetWorkItems(fc);

 

Hopefully, that will help you get on your feet.

Any doubts, or suggestions, please come to the forums and ask for it.

Comments (0)

You don't have permission to comment on this page.