private static void
updateStateToWorking(List<int> clonedWorkItemIds)
{
ArrayList validationResult = null;
try
{
using (var wiService = new WorkItemService(_tfsCollectionUri))
using (var wifieldService = new WorkItemFieldService(_tfsCollectionUri))
{
foreach (var id in clonedWorkItemIds)
{
var wis =
wiService.Query(id);
var keyVals = new List<KeyValuePair<String, object>>() {
new KeyValuePair<string, object>("狀況", "作用中"),
new KeyValuePair<string, object>("啟動者", wis[0].Fields["指派給"].Value)
};
wifieldService.Update(id, keyVals, out validationResult);
}
}
}
catch (Exception ex)
{
logger.Error(ex.Message);
throw;
}
}
private static List<int>
cloneWorkItems(Func<WorkItemResult,bool> filter)
{
List<int> clonedWorkItemIds = new List<int>();
IEnumerable<WorkItemResult> sourceWis = null;
try
{
using (var wiRsltService = new WorkItemResultService())
{
sourceWis =
wiRsltService.Query(filter);
}
using (var wiService = new WorkItemService(_tfsCollectionUri))
using (var wiCloneMappingService = new WorkItemCloneMappingService())
{
var wiDto = new WorkItemDto()
{
TeamProject = "資訊部",
AreaPath = @"資訊部\DevOps Team",
IterationPath = @"資訊部\2015",
};
var otherFieldsSettings = new List<KeyValuePair<string, object>>()
{
new KeyValuePair<String, object>("專業領域", "分析")
};
foreach (var wi in sourceWis)
{
ArrayList validationRslt = null;
int targetId =
wiService.Clone(
wi.Id, wiDto,
otherFieldsSettings, out validationRslt);
if
(validationRslt.Count > 0)
{
wiCloneMappingService.Add(new WorkItemCloneMapping() { FromId = wi.Id, IsSuccess = false });
String msg = String.Format("Work Itme
{0} clone attemp failed.", wi.Id);
logger.Info(msg);
}
else
{
clonedWorkItemIds.Add(targetId);
wiCloneMappingService.Add(new WorkItemCloneMapping() { FromId = wi.Id, ToId =
targetId, IsSuccess = true });
String msg = String.Format("Work Itme
{0} was cloned as Work Item {1}", wi.Id, targetId);
logger.Info(msg);
}
}
}
return clonedWorkItemIds;
}
catch (Exception ex)
{
logger.Error(ex.Message);
throw;
}
}
private static void
saveWorkItemsToDatabase(WorkItemCollection wiCollection)
{
using (var tfsDalService = new WorkItemResultService())
{
#region Clear the databse
tfsDalService.Clear();
#endregion
#region Add a work item information to
database
foreach (WorkItem wi in wiCollection)
{
tfsDalService.Add(new WorkItemResult()
{
Id = wi.Id,
Title = wi.Title,
AreaPath =
wi.AreaPath,
AssignedTo =
wi.Fields["指派給"].Value.ToString(),
IterationPath =
wi.IterationPath,
WiType =
wi.Type.Name,
Project =
wi.Project.Name,
State = wi.State,
CreatedDate =
wi.CreatedDate
});
}
#endregion
}
}
|