本文整理汇总了C#中Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.Save方法的典型用法代码示例。如果您正苦于以下问题:C# WorkItem.Save方法的具体用法?C# WorkItem.Save怎么用?C# WorkItem.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem
的用法示例。
在下文中一共展示了WorkItem.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddWorkItem
public void AddWorkItem()
{
WorkItem newItem = new WorkItem( teamProject.WorkItemTypes["タスク"] );
newItem.Title = "作業項目の概要です";
newItem.Description = "作業項目の詳細です";
newItem.Save();
}
示例2: CreateWorkItem
/// <summary>
/// Creates a new work item of a defined type
/// </summary>
/// <param name="workItemType">The type name</param>
/// <param name="title">Default title</param>
/// <param name="description">Default description</param>
/// <param name="fieldsAndValues">List of extra propierties and values</param>
/// <returns></returns>
public WorkItem CreateWorkItem(string workItemType, string title, string description, Dictionary<string, object> fieldsAndValues)
{
WorkItemType wiType = workItemTypeCollection[workItemType];
WorkItem wi = new WorkItem(wiType) { Title = title, Description = description };
foreach (KeyValuePair<string, object> fieldAndValue in fieldsAndValues)
{
string fieldName = fieldAndValue.Key;
object value = fieldAndValue.Value;
if (wi.Fields.Contains(fieldName))
wi.Fields[fieldName].Value = value;
else
throw new ApplicationException(string.Format("Field not found {0} in workItemType {1}, failed to save the item", fieldName, workItemType));
}
if (wi.IsValid())
{
wi.Save();
}
else
{
ArrayList validationErrors = wi.Validate();
string errMessage = "Work item cannot be saved...";
foreach (Field field in validationErrors)
errMessage += "Field: " + field.Name + " has status: " + field.Status + "/n";
throw new ApplicationException(errMessage);
}
return wi;
}
示例3: AddNewWIFromMailBug
public int AddNewWIFromMailBug(MessageRequest data)
{
var manager = new TFSConnectionManager();
//var WIToAdd = GetNewWorkItem(Connection, ProjectName, "BUG", AreaPath, IterationPath, data.Subject, data.Body);
using (var conn = manager.GetConnection())
{
WorkItemStore workItemStore = conn.GetService<WorkItemStore>();
Project prj = workItemStore.Projects[ProjectName];
WorkItemType workItemType = prj.WorkItemTypes["BUG"];
var WIToAdd = new WorkItem(workItemType)
{
Title = data.Subject,
Description = data.Body,
IterationPath = IterationPath,
AreaPath = AreaPath,
};
WIToAdd.Fields[this.StepsToReproduceName].Value = data.Body;
if (!string.IsNullOrWhiteSpace(this.AssignedToValue))
{
WIToAdd.Fields[this.AssignedToName].Value = this.AssignedToValue;
}
var filePath = TempFileManager.SaveFileAndGetName(data.FileFormat);
try
{
WIToAdd.Attachments.Add(new Microsoft.TeamFoundation.WorkItemTracking.Client.Attachment(filePath));
WIToAdd.Save();
return WIToAdd.Id;
}
catch (Exception ex)
{
throw ex;
}
finally
{
TempFileManager.ClearFile(filePath);
}
}
}
示例4: button_save_Click
private void button_save_Click(object sender, EventArgs e)
{
try
{
////http://social.technet.microsoft.com/wiki/contents/articles/3280.tfs-2010-api-create-workitems-bugs.aspx
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(this.textbox_tfsUrl.Text));
WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
WorkItemTypeCollection workItemTypes = workItemStore.Projects[this.textbox_defaultProject.Text].WorkItemTypes;
WorkItemType workItemType = workItemTypes[combobox_workItemType.Text];
// Assign values to each mandatory field
var workItem = new WorkItem(workItemType);
workItem.Title = textbox_title.Text;
workItem.Description = textbox_description.Text;
var fieldAssignTo = "System.AssignedTo";
if (combobox_AssignTo.SelectedItem != null && workItem.Fields.Contains(fieldAssignTo))
{
workItem.Fields[fieldAssignTo].Value = combobox_AssignTo.Text;
}
var fieldSeverity="Microsoft.VSTS.Common.Severity";
if (combobox_severity.SelectedItem != null && workItem.Fields.Contains(fieldSeverity))
{
workItem.Fields[fieldSeverity].Value = combobox_severity.Text;
}
var fieldPriority = "Microsoft.VSTS.Common.Priority";
if (workItem.Fields.Contains(fieldPriority))
{
workItem.Fields[fieldPriority].Value = textbox_Priority.Text;
}
if (combobox_AreaPath.SelectedItem != null)
{
workItem.AreaPath = combobox_AreaPath.Text;
}
if (combobox_IterationPath.SelectedItem != null)
{
workItem.IterationPath = combobox_IterationPath.Text;
}
var fieldState = "System.State";
if (combobox_state.SelectedItem != null && workItem.Fields.Contains(fieldState))
{
workItem.Fields[fieldState].Value = combobox_state.Text;
}
var fieldReason = "System.Reason";
if (combobox_reason.SelectedItem != null && workItem.Fields.Contains(fieldReason))
{
workItem.Fields["System.Reason"].Value = combobox_reason.Text;
}
string fieldSystenInfo = "Microsoft.VSTS.TCM.SystemInfo";
if (workItem.Fields.Contains(fieldSystenInfo))
{
if (workItem.Fields[fieldSystenInfo].FieldDefinition.FieldType == FieldType.Html)
{
workItem.Fields[fieldSystenInfo].Value = textbox_SystemInfo.Text.Replace(Environment.NewLine,"<br/>");
}
else
{
workItem.Fields[fieldSystenInfo].Value = textbox_SystemInfo.Text;
}
}
string fieldsReproStreps = "Microsoft.VSTS.TCM.ReproSteps";
if (workItem.Fields.Contains(fieldsReproStreps))
{
workItem.Fields[fieldsReproStreps].Value = textbox_ReproStep.Text;
if (string.IsNullOrEmpty(textbox_ReproStep.Text))
{
workItem.Fields[fieldsReproStreps].Value = workItem.Description;
}
}
// add image
string tempFile = Path.Combine(Environment.CurrentDirectory, this.Filename);
File.WriteAllBytes(tempFile, this.ImageData);
workItem.Attachments.Add(new Attachment(tempFile));
// Link the failed test case to the Bug
// workItem.Links.Add(new RelatedLink(testcaseID));
// Check for validation errors before saving the Bug
ArrayList validationErrors = workItem.Validate();
if (validationErrors.Count == 0)
{
workItem.Save();
if (this.TFSInfo == null)
//.........这里部分代码省略.........
示例5: ValidateAndSaveWorkItem
private static void ValidateAndSaveWorkItem(WorkItem workItem)
{
if (!workItem.IsValid())
{
var invalidFields = workItem.Validate();
var sb = new StringBuilder();
sb.AppendLine("Can't save item because the following fields are invalid: ");
foreach (Field field in invalidFields)
{
sb.AppendFormat("{0}: '{1}'", field.Name, field.Value).AppendLine();
}
Logger.ErrorFormat(sb.ToString());
return;
}
workItem.Save();
}
示例6: CreateTask
private void CreateTask(Outlook.MailItem mail)
{
string tempPath = Path.GetTempPath();
string mailTempPath = Path.Combine(tempPath, MakeValidFileName(mail.Subject) + ".msg");
try
{
if (File.Exists(mailTempPath))
File.Delete(mailTempPath);
mail.SaveAs(mailTempPath, Outlook.OlSaveAsType.olMSG);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error saving Mail content", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
using (var tfs = new TfsTeamProjectCollection(new Uri(Settings.Default.TFSUrl)))
{
WorkItemStore wis = tfs.GetService(typeof(WorkItemStore)) as WorkItemStore;
var projectQuery = from prj in wis.Projects.Cast<Project>()
where prj.HasWorkItemWriteRights
select prj.Name;
var projectForm = new SelectProjectForm(projectQuery);
try
{
var pjResult = projectForm.ShowDialog();
if (pjResult != DialogResult.OK)
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error selecting Team Project", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
WorkItem wi = null;
try
{
var project = wis.Projects[projectForm.SelectedProject] as Project;
var tasktype = project.WorkItemTypes["Task"];
wi = new WorkItem(tasktype);
wi.Description = mail.Body;
wi.Reason = "New";
wi.Title = mail.Subject;
wi.Attachments.Add(new Attachment(mailTempPath, "Mail"));
foreach (Outlook.Attachment attachment in mail.Attachments)
{
string fileName = attachment.FileName;
int i = 1;
while (wi.Attachments.Cast<Attachment>().Where(a => a.Name == fileName).Count() > 0)
fileName = string.Format("{0}_{1}.{2}", Path.GetFileNameWithoutExtension(attachment.FileName), i++, Path.GetExtension(attachment.FileName));
string attachmentPath = Path.Combine(tempPath, fileName);
if (File.Exists(attachmentPath))
File.Delete(attachmentPath);
attachment.SaveAsFile(attachmentPath);
wi.Attachments.Add(new Attachment(attachmentPath, string.Format("Mail Attachment: {0}", attachment.DisplayName)));
}
wi.IterationPath = project.Name;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error creating Task", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var wiForm = new WorkItemForm(wi);
var wiResult = wiForm.ShowDialog();
if (wiResult == DialogResult.OK)
wi.Save();
wi.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error saving Task", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
//.........这里部分代码省略.........
示例7: CreateBugTask
/// <summary>
/// Responsável por criar tarefas de BUG
/// </summary>
/// <param name="idBug"></param>
/// <param name="assignedTo"></param>
/// <param name="title"></param>
/// <returns></returns>
public bool CreateBugTask(int idBug, string assignedTo, string title)
{
// TODO: Onde está se esperando a exceção? No save?
try
{
var basedOn = GetWorkItem(idBug);
var task = new WorkItem(project.WorkItemTypes["Task"]);
//var parent = GetParent(idBug);
task.Description = string.Format("Verificar o Bug {0}\n\n{1}", basedOn.Title, basedOn.Description);
task.Fields["Assigned To"].Value = assignedTo;
basedOn.Fields["Assigned To"].Value = assignedTo;
basedOn.State = "Active";
task.Title = title;
task.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Parent"], basedOn.Id));
task.Title = GetTitlePrefix(basedOn, title);
#region //
//task.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Tests"], basedOn.Id));
//TODO: Existe a possibilidade de um bug não ter tarefa pai?
/*if (parent != null)
{
task.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Parent"], parent.Id));
task.Title = GetTitlePrefix(parent, title);
}*/
//for (int i = 0; i < basedOn.WorkItemLinks.Count; i++)
//{
// if (basedOn.WorkItemLinks[i].LinkTypeEnd.Name.Equals("Parent"))
// {
// parentId = basedOn.WorkItemLinks[i].TargetId;
// task.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Parent"], basedOn.WorkItemLinks[i].TargetId));
// break;
// }
//}
#endregion
basedOn.Save();
task.Save();
return true;
}
catch
{
return false;
}
}
示例8: LinkWorkItems
/// <summary>
/// Link Work Items in TFS
/// </summary>
/// <param name="source">
/// The source.
/// </param>
/// <param name="targetWorkItemId">
/// The target Work Item Id.
/// </param>
/// <param name="linkTypeEndName">
/// The link Type End Name.
/// </param>
/// <param name="comments">
/// The comments.
/// </param>
public void LinkWorkItems(WorkItem source, int targetWorkItemId, string linkTypeEndName, string comments)
{
WorkItem wItem = tfsManager.GetWorkItem(targetWorkItemId);
if (wItem != null)
{
WorkItemLinkTypeEnd linkTypeEnd = tfsManager.GetAllWorkItemLinksTypes().LinkTypeEnds[linkTypeEndName];
var link = new RelatedLink(linkTypeEnd, targetWorkItemId) { Comment = comments };
source.Links.Add(link);
source.Save();
}
}
示例9: AddStep
/// <summary>
/// The add step for work item "Test Case".
/// </summary>
/// <param name="dataObject"></param>
/// <param name="workItem"></param>
public void AddStep(IDataObject dataObject, WorkItem workItem, out bool comment,bool isAddStep)
{
var popup = new StepActionsResult();
string temp = Regex.Replace(dataObject.GetData(DataFormats.Text).ToString(), @"\s+", " ");
popup.action.Text = temp;
popup.Create(null, Icons.AddDetails);
ITestManagementService testService = collection.GetService<ITestManagementService>();
var project = testService.GetTeamProject(workItem.Project.Name);
var testCase = project.TestCases.Find(workItem.Id);
var step = testCase.CreateTestStep();
if (!popup.IsCanceled)
{
switch (tfsVersion)
{
case TfsVersion.Tfs2011:
step.Title = "<div><p><span>" + popup.action.Text + "</span></p></div>";
step.ExpectedResult = "<div><p><span>" + popup.expectedResult.Text + "</span></p></div>";
//step.Title = popup.action.Text;
//step.ExpectedResult = popup.expectedResult.Text;
break;
case TfsVersion.Tfs2010:
step.Title = popup.action.Text;
step.ExpectedResult = popup.expectedResult.Text;
break;
}
if (isAddStep)
{
testCase.Actions.Add(step);
}
else
{
testCase.Actions.Clear();
testCase.Actions.Add(step);
}
testCase.Save();
workItem.Save();
comment = true;
}
else
{
comment = false;
}
}
示例10: CreateTask
private WorkItem CreateTask(Project project, string taskTitle, string iterationPath)
{
// Create the tasks
var taskType = project.WorkItemTypes["Task"];
var task = new WorkItem(taskType);
task.IterationPath = iterationPath;
//task.State = "New";
task.Title = taskTitle;
task.Save();
AddLog("created task - " + task.Id.ToString());
return task;
}
示例11: UpdateBackLogItemLink
private void UpdateBackLogItemLink(WorkItem backlogItem, WorkItemLink taskLink1)
{
backlogItem.Links.Add(taskLink1);
AddLog("updating backlogworkitem link - " + taskLink1.TargetId.ToString() + "- " + taskLink1.SourceId.ToString());
backlogItem.Save();
}
示例12: OkExecuteMethod
/// <summary>
/// Handles the execute command by resolving the provided command parameter
/// </summary>
public virtual void OkExecuteMethod(object executeCommandParam)
{
var tfs = ViewModel.TfsConnection;
var proj = ViewModel.TfsProject;
var store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
if (store != null && store.Projects != null)
{
WorkItemTypeCollection workItemTypes = store.Projects[proj.Name].WorkItemTypes;
WorkItemType wit = workItemTypes[ViewModel.ItemType];
var workItem = new WorkItem(wit)
{
Title = ViewModel.Title,
Description = ViewModel.Comment,
IterationPath = ViewModel.Iteration,
AreaPath = ViewModel.AreaPath,
};
workItem["Priority"] = ViewModel.Priority;
var assigned = workItem.Fields["Assigned To"];
if (assigned != null)
assigned.Value = ViewModel.AssignedTo;
// create file attachments
foreach (var attach in ViewModel.Attachments.Where(a => a.Chosen))
{
workItem.Attachments.Add(
new Microsoft.TeamFoundation.WorkItemTracking.Client.Attachment(attach.Path, attach.Comment));
}
var validationResult = workItem.Validate();
if (validationResult.Count == 0)
{
workItem.Save();
if (MessageBox.Show(string.Format("Created bug {0}", workItem.Id)) == MessageBoxResult.OK)
Dispose();
}
else
{
var tt = new StringBuilder();
foreach (var res in validationResult)
tt.AppendLine(res.ToString());
MessageBox.Show(tt.ToString());
}
}
}
示例13: ChangeWorkItemStatus
//save final state transition and set final reason.
private bool ChangeWorkItemStatus(WorkItem workItem, string orginalSourceState, string destState, string reason)
{
//Try to save the new state. If that fails then we also go back to the orginal state.
try
{
workItem.Open();
workItem.Fields["State"].Value = destState;
workItem.Fields["Reason"].Value = reason;
ArrayList list = workItem.Validate();
workItem.Save();
return true;
}
catch (Exception)
{
logger.WarnFormat("Failed to save state for workItem: {0} type:'{1}' state from '{2}' to '{3}' =>rolling workItem status to original state '{4}'",
workItem.Id, workItem.Type.Name, orginalSourceState, destState, orginalSourceState);
//Revert back to the original value.
workItem.Fields["State"].Value = orginalSourceState;
return false;
}
}
示例14: UpdateWorkItem
public void UpdateWorkItem(WorkItem workitem)
{
workitem.Save();
}
示例15: AddPivotalTasksAsLinkedWorkItems
private static void AddPivotalTasksAsLinkedWorkItems(WorkItemTypeCollection workItemTypes, WorkItem workItem,
Story pivotalStoryToAdd)
{
if (pivotalStoryToAdd.Tasks == null)
return;
foreach (var task in pivotalStoryToAdd.Tasks.tasks)
{
var workitemTask = new WorkItem(workItemTypes[SprintBacklogItem])
{
Title = task.Description,
IterationPath = workItem.IterationPath
};
workitemTask.Fields[HistoryField].Value = workItem.Fields[HistoryField].Value;
workitemTask.Save();
workItem.Links.Add(new RelatedLink(workitemTask.Id));
}
}