14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Since these event handlers execute on TFS itself (in fact,<br />

within the process of TFS), these can be written using any of the<br />

Microsoft .NET languages. It does not matter which client<br />

performed the activity that triggered the event, which means<br />

that even if your project is a Java project, the event handler will<br />

still have to be written in .NET.<br />

The same Team Foundation Object Model can also be used to<br />

access Team Foundation <strong>Services</strong> from standalone applications.<br />

For example, we can create new Requirement type work items<br />

when a requirement document is approved in SharePoint. For<br />

this purpose, we can write a SharePoint workflow application<br />

in which we can refer to the TFS APIs, use those to create new<br />

Requirement type work items as desired and then associate that<br />

workflow with the appropriate library on the SharePoint portal.<br />

Following code shows how to do that (Some of the methods to<br />

handle worksheet data are not shown as they are secondary to<br />

the purpose)<br />

private void CreateRequirements()<br />

{<br />

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

Name”];<br />

collection = new TfsTeamProjectCollection(new<br />

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

DefaultCollection”));<br />

store = collection.GetService();<br />

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

SPFile file = web.GetFile(@”http://ssgs-vs-tfs2012/<br />

sites/DefaultCollection/SSGS%20CMMI/Requirements%20<br />

Documents/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().<br />

Elements();<br />

string relationshipId = sheets.First().Id.Value;<br />

WorksheetPart worksheetPart =<br />

(WorksheetPart)document.WorkbookPart.<br />

GetPartById(relationshipId);<br />

Worksheet workSheet = worksheetPart.Worksheet;<br />

SheetData sheetData = workSheet.<br />

GetFirstChild();<br />

IEnumerable rows = sheetData.<br />

Descendants();<br />

int i = rows.Count();<br />

foreach (Cell cell in rows.ElementAt(0))<br />

{<br />

string Title = GetCellValue(document, cell);<br />

WorkItem Requirement = new WorkItem(store.<br />

Projects[prj].WorkItemTypes[“Requirement”]);<br />

Requirement.Title = Title;<br />

Requirement.Save();<br />

}<br />

}<br />

public static string GetCellValue(SpreadsheetDocument<br />

document, Cell cell)<br />

{<br />

SharedStringTablePart stringTablePart = document.<br />

WorkbookPart.SharedStringTablePart;<br />

string value = cell.CellValue.InnerXml;<br />

if (cell.DataType != null && cell.DataType.Value ==<br />

CellValues.SharedString)<br />

{<br />

return stringTablePart.SharedStringTable.<br />

ChildElements[Int32.Parse(value)].InnerText;<br />

}<br />

else<br />

{<br />

return value;<br />

}<br />

}<br />

Another use of this object model is to create custom check-in<br />

policies. Such a custom check-in policy will exclusively use client<br />

side objects of Team Foundation Server. Checks on the code or<br />

associated work items can be done by using those. For example,<br />

we can check if the code being checked in has an associated<br />

work item of a specific type like a ‘Code Review’ and make<br />

further check on it to ensure that it is having the state as<br />

‘Approved’, for allowing the check-in to succeed. Since check-in<br />

policy is enabled on TFS but executes on the client side, it has to<br />

be developed using a language that is appropriate for the<br />

client environment. To develop check-in policies for Visual<br />

Studio, we can use Microsoft .NET languages, but for Team<br />

Explorer Everywhere 2012, that is a plug-in to Eclipse, we can<br />

use TFS SDK 2012 (For Java). It can be downloaded from http://<br />

www.microsoft.com/en-us/download/details.aspxid=22616.<br />

Many of the applications that use the Team Foundation Object<br />

Model are rich client applications so that they can reference the<br />

assemblies that encapsulate these objects. Size of such<br />

applications along with the TFS API assemblies is not optimized<br />

for lean environments like Windows Phone, Android Apps and<br />

Windows Store Apps (for Surface). For such environments, we<br />

need a broker that will consume TFS data using heavy TFS API<br />

assemblies and then in turn publish that same data as a lean<br />

HTTP service.<br />

60 | DNCmagazine www.dotnetcurry.com

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

Saved successfully!

Ooh no, something went wrong!