14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

createteamproject /collection:http://ssgs-vs-tfs2012:8080/<br />

tfs/DefaultCollection /teamproject:\”” + ProjectName + “\”<br />

/processtemplate:\”MSF for CMMI Process Improvement 6.2<br />

\””;<br />

ProcessStartInfo psi =new ProcessStartInfo(“cmd.exe”);<br />

psi.UseShellExecute = false;<br />

psi.RedirectStandardOutput = true;<br />

psi.RedirectStandardInput = true;<br />

psi.RedirectStandardError = true;<br />

psi.WorkingDirectory = @”C:\”;<br />

psi.Verb = “runas”;<br />

//start the process<br />

Process p = Process.Start(psi);<br />

p.StandardInput.WriteLine(args);<br />

p.WaitForExit();<br />

p.StandardInput.WriteLine(“EXIT”);<br />

p.Close();<br />

}<br />

This workflow project is built and deployed to the SharePoint<br />

server. After deployment, it is associated with the document library<br />

that is hosting the Vision Document. It is configured to run when<br />

a Vision document is created and then changed having the state<br />

‘Approved’. This workflow will trigger the creation of a team<br />

project. The name of that team project is provided by the approver<br />

as property of the vision document in the SharePoint Library.<br />

Now we will focus on another driving document – Requirement<br />

Document. We create a document library in the team portal that<br />

will provide a repository for requirement document for the project.<br />

We will call that document library as ‘Requirement Documents’.<br />

The requirement document is a standardized document in every<br />

organization and its structure does not change much. We are going<br />

to assume that it is the MS Excel worksheet that contains multiple<br />

requirements, each individually on a row and the title of each<br />

requirement is in column B.<br />

For the document library, we will have a similar set of properties<br />

that we had created earlier for the library that we had created for<br />

Vision Document. We will have ‘Team Project Name’ and status as<br />

two properties.<br />

We will also create a SharePoint workflow that will have the event<br />

handling code. In this code, we will read the requirement<br />

document and create work items of the type Requirement. First we<br />

should add a few references to the TFS API class libraries and their<br />

related using statements. We are going to use OpenXML that is a<br />

standard used for editing MS Office files<br />

programmatically without installing MS Office, usually on the<br />

server. We can download V 2.0 (one that I used) of that from http://<br />

www.microsoft.com/en-in/download/details.aspxid=5124.<br />

using Microsoft.TeamFoundation.Client;<br />

using Microsoft.TeamFoundation.WorkItemTracking.Client;<br />

The boilerplate code for such a SharePoint workflow project is as<br />

follows:<br />

private void CreateRequirements()<br />

{<br />

prj = (string)workflowProperties.Item[“Team<br />

Project Name”];<br />

collection = new<br />

TfsTeamProjectCollection(new<br />

Uri(“http://ssgsvs-tfs2012:8080/tfs/<br />

DefaultCollection”));<br />

store = collection.<br />

GetService();<br />

SP<strong>Web</strong> web = workflowProperties.<br />

<strong>Web</strong>;<br />

SPFile file = web.<br />

GetFile(@”http://<br />

ssgs-vs-tfs2012/sites/<br />

DefaultCollection/SSGS%20CMMI/<br />

Requirements%20Documents/<br />

RequirementDocument.xlsx”);<br />

SPFileStream dataStream = (SPFileStream)file.<br />

OpenBinaryStream();<br />

SpreadsheetDocument document = SpreadsheetDocument.<br />

Open(dataStream, false);<br />

WorkbookPart workbookPart = document.WorkbookPart;<br />

IEnumerable sheets = document.WorkbookPart.<br />

Workbook.GetFirstChild().Elements();<br />

DNcmagazine www.dotnetcurry.com | 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!