2009年10月1日

Workflow of WorkItem

Workflow consists of States and Transitions.

Untitled

A workflow has multiple states, such as Active and Closed. Following code shows a state sample:

<State value="Active">
  <FIELDS>
    <FIELD refname="Microsoft.VSTS.Common.ClosedDate">
      <EMPTY />
    </FIELD>
    <FIELD refname="Microsoft.VSTS.Common.ClosedBy">
      <EMPTY />
    </FIELD>
  </FIELDS>
</State>

The field used in <Fields> means that when state of workitem was changed to “Active ”, the value of "Microsoft.VSTS.Common.ClosedDate" and ="Microsoft.VSTS.Common.ClosedBy" are set to empty.

 

There are transitions between states. Following code shows a transition sample:

<Transition from="Closed" to="Active">
  <REASONS>
    <DEFAULTREASON value="Reactivated" />
  </REASONS>
  <FIELDS>
    <FIELD refname="Microsoft.VSTS.Common.ActivatedBy">
      <COPY from="currentuser" />
      <VALIDUSER />
      <REQUIRED />
    </FIELD>
    <FIELD refname="Microsoft.VSTS.Common.ActivatedDate">
      <SERVERDEFAULT from="clock" />
    </FIELD>
    <FIELD refname="System.AssignedTo">
      <COPY from="field" field="Microsoft.VSTS.Common.ClosedBy" />
    </FIELD>
  </FIELDS>
</Transition>

Each transition  has a direction, such as “From Close to Active” or “From Active to Close”. The direction means that the state can be changed to another, if there is no transition whose direction is from StateA to another StateB, “StateB” will not appear in State DropdownList in WorkItemEditUI.

When a workitem is created, the initial state is “”, so there should be at least one transition whose “from” is “”.

You can add some reasons why the transition starts so that user can select one in WorkItemEditUI, the default value is set in <DEFAULTREASON>

Like <Fields> defined in State, The field used in <Fields> means that when the transition start, the value of "ActivatedBy"  is set to current user , the value of "ActivatedDate" is  current moment and the value of “ClosedBy” is copied from “ClosedBy”.

Some transitions also include a node named <Actions> like

<TRANSITION from="Working" to="Ready To Build">
<ACTIONS>
<ACTION value="microsoft.vsts.actions.checkin"/>
</ACTIONS>
</TRANSITION>

An chek-in action can be associated to a workitem. So it means that when a check-in action occured, the transition will start.

 

 
 

posted @ 2009-10-01 18:06 Ruiz 阅读(206) 评论(0) 编辑

How to:Create a Custom WI Control

http://social.msdn.microsoft.com/Forums/en-US/tfspowertools/thread/25867a00-3d49-4ca5-998e-6e5809ea7b1a/

Op has a requirement:
"I currently have two fields. Each one of them has an integer value from 1-5. I would like to add this two numbers and get the sum of them into another field. So if field1 has the value 3 and field2 has the value 5, I would like to have in the third field the value 8 (3+5)

I am using Power Tools and I have tried many IF,WHEN,COPY statements but without any result. I would be very nice if with can be done with power tools and not writing any code to create a new custom field."

We can create a custom workitem control to fix his requirement.  To create a custom workitem control, following these steps:

1.       Create a UserControl  class library.

1)      Create a class library project (ie  MyControls)

2)      Add a UserControl to this project(ie MyControls.SumControl)

3)      Add a label "label1" in the design mode.

4)      Implement interface  IWorkItemControl, you can just use following code. In my work item type, I want Demo.sum0= Demo.sum1+ Demo.sum2

#region IWorkItemControl Members

 

        private EventHandlerList m_events;

 

        private EventHandlerList Events

        {

            get

            {

                if (m_events == null)

                {

                    m_events = new EventHandlerList();

                }

                return m_events;

            }

        }

 

        private static object EventBeforeUpdateDatasource = new object();

        public event EventHandler BeforeUpdateDatasource

        {

            add { Events.AddHandler(EventBeforeUpdateDatasource, value); }

            remove { Events.RemoveHandler(EventBeforeUpdateDatasource, value); }

        }

 

        protected virtual void OnBeforeUpdateDatasource(EventArgs eventArgs)

        {

            EventHandler handler = (EventHandler)Events[EventBeforeUpdateDatasource];

            if (handler != null)

            {

                handler.Invoke(this, eventArgs);

            }

        }

 

        private static object EventAfterUpdateDatasource = new object();

        public event EventHandler AfterUpdateDatasource

        {

            add { Events.AddHandler(EventAfterUpdateDatasource, value); }

            remove { Events.RemoveHandler(EventAfterUpdateDatasource, value); }

        }

 

        void IWorkItemControl.Clear()

        {

            label1.Text = string.Empty;

        }

 

        void IWorkItemControl.FlushToDatasource()

        {

            // nothing to do

        }

 

        void IWorkItemControl.InvalidateDatasource()

        {

 

        }

 

        private StringDictionary m_properties;

        StringDictionary IWorkItemControl.Properties

        {

            get

            {

                return m_properties;

            }

            set

            {

                m_properties = value;

            }

        }

 

        private bool m_readOnly;

        bool IWorkItemControl.ReadOnly

        {

            get

            {

                return m_readOnly;

            }

            set

            {

                m_readOnly = value;

            }

        }

 

        private IServiceProvider m_serviceProvider;

        void IWorkItemControl.SetSite(IServiceProvider serviceProvider)

        {

            m_serviceProvider = serviceProvider;

        }

 

        private WorkItem m_workItem;

        object IWorkItemControl.WorkItemDatasource

        {

            get

            {

                return m_workItem;

            }

            set

            { 

                m_workItem = (WorkItem)value;

                if (m_workItem != null)

                {

                    m_workItem.FieldChanged += new WorkItemFieldChangeEventHandler(WIChanged);

                }

            }

        }

 

        void WIChanged(object sender, WorkItemEventArgs e)

        {

            try

            {

                if (e.Field.ReferenceName == "Demo.sum1" || e.Field.ReferenceName == "Demo.sum2")

                {

                    System.Diagnostics.Debugger.Launch();

                    try

                    {

                        m_workItem.Fields["Demo.sum0"].Value = int.Parse(m_workItem.Fields["Demo.sum1"].Value.ToString())

                            + int.Parse(m_workItem.Fields["Demo.sum2"].Value.ToString());

 

                    }

                    catch { m_workItem.Fields["Demo.sum0"].Value = 0; }

 

                    label1.Text = m_workItem.Fields["Demo.sum0"].Value.ToString();

                }

            }

            catch { }

           

        }

 

        private string m_fieldName;

        string IWorkItemControl.WorkItemFieldName

        {

            get

            {

                return m_fieldName;

            }

            set

            {

                m_fieldName = value;

            }

        }

 

        #endregion

 

5)      Compile the project.

 

 

2.       Make VS2008 use this control

1)      Copy MyControls.dll to " C:\ProgramData\Microsoft\Team Foundation\Work Item Tracking\Custom Controls\9.0", If this location does not exist, create it.

2)      Create a file named "SumControl.wicc" in the same location, add following code to this file.

<?xml version="1.0"?>

<CustomControl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <Assembly> MyControls.dll </Assembly>

  <FullClassName> MyControls.SumControl </FullClassName>

</CustomControl>

 

3.       Modify the work item type.( It is better to use Power Tools to do this operation. )

1)      Add field Demo.sum0, Demo.sum1 and  Demo.sum2 in Fields Tab.

2)      Add controls in Layout Tab.  The Field Type of Demo.sum1 and  Demo.sum2 is FieldControl, and the Field Type of Demo.sum0  is SumControl

After step 2, re-open VS2008, you will see "SumControl" in the dropdown list.

3)      Save it.

4.       Create a new work item, and now you can use the Sum function.

 

In additional, it is needed to copy > MyControls.dll and SumControl.wicc to each client PC.

 

If there is anything unclear, please let me known




posted @ 2009-10-01 13:41 Ruiz 阅读(1578) 评论(0) 编辑

<2009年10月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

公告

昵称:Ruiz
园龄:2年5个月
粉丝:1
关注:0

搜索

 
 

常用链接

我的标签

随笔分类

随笔档案

最新评论

阅读排行榜

评论排行榜

推荐排行榜