当前位置: 首页>>代码示例>>C#>>正文


C# WorkItem.Close方法代码示例

本文整理汇总了C#中Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.Close方法的典型用法代码示例。如果您正苦于以下问题:C# WorkItem.Close方法的具体用法?C# WorkItem.Close怎么用?C# WorkItem.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem的用法示例。


在下文中一共展示了WorkItem.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
                    }
                }
//.........这里部分代码省略.........
开发者ID:mi-tettamanti,项目名称:tfs-outlook-addin,代码行数:101,代码来源:Ribbon.cs


注:本文中的Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。