/// <summary> /// Open a dialog form to create new work item. /// </summary> /// <param name="workItemTypeName">work item type name</param> /// <param name="title">work item title</param> /// <param name="fields">A dictionary represents the workitem fields. The key should be the ReferenceName of a field.</param> public static void OpenWorkItemForm(string workItemTypeName, string title = null, Dictionary <string, object> fields = null) { var settings = MySettingsManager.GetSettings <TfsSettings>(); var uri = new Uri(settings.ProjectCollectionUri); var project = TfsHelper.GetProject(settings.ProjectCollectionUri, settings.ProjectName); var workItemType = project.WorkItemTypes[workItemTypeName]; var workItem = new WorkItem(workItemType); workItem.IterationPath = settings.Iteration; workItem.AreaPath = settings.Area; workItem.Title = title; if (fields != null) { foreach (var field in fields) { foreach (Field wField in workItem.Fields) { if (wField.ReferenceName == field.Key) { wField.Value = field.Value; break; } } } } var form = new WorkItemWindow(workItem); form.ShowDialog(); }
public static bool CheckSettings() { var settings = MySettingsManager.GetSettings <TfsSettings>(); if (string.IsNullOrEmpty(settings.ProjectName) || string.IsNullOrEmpty(settings.WorkItemType)) { return(false); } var uri = new Uri(settings.ProjectCollectionUri); try { var project = TfsHelper.GetProject(settings.ProjectCollectionUri, settings.ProjectName); var workItemType = project.WorkItemTypes[settings.WorkItemType]; if (workItemType == null) { return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Failed to connect to TFS", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } var registered = RegisteredTfsConnections.GetProjectCollection(uri); if (registered == null) { RegisteredTfsConnections.RegisterProjectCollection(new TfsTeamProjectCollection(uri)); } return(true); }