コード例 #1
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Add work item
        /// </summary>
        /// <param name="projectName"></param>
        public void AddWorkItem(string projectName)
        {
            ListBoxItems listBoxCollection = new ListBoxItems(Application.Selection.Text, TfsManager.Instance.GetWorkItemsTypeForCurrentProject(projectName), WorkItemType);

            CreateNew popup = new CreateNew();
            popup.DataContext = listBoxCollection;
            popup.ListBox.ScrollIntoView(WorkItemType);
            popup.Create(null, Icons.AddNewWorkItem);

            if (popup.isCancelled && !popup.isCreated)
                return;

            string errorMessage = string.Empty;

            string type = listBoxCollection.GetValue();
            string title = listBoxCollection.GetTitle();
            int workItemId = CreateNewWi.AddWorkItemForCurrentProject(projectName, title, type);

            WorkItemType = type;

            if (workItemId != 0)
            {
                 WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                 progressDialog.Execute(cancelTokenSource =>
                 {
                     progressDialog.UpdateProgress(100, string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), 1, 1, string.Format("{0} {1}", type, workItemId)), true);

                     try
                     {
                         AddWIControl(workItemId, "System.Title");
                         WorkItemId = workItemId;
                     }
                     catch
                     {
                         errorMessage = ResourceHelper.GetResourceString("MSG_ERROR_ADD_WI");
                     }
                 });

                 progressDialog.Create(ResourceHelper.GetResourceString("MSG_CREATE_WI_TITLE"), Icons.AddNewWorkItem);
            }
            else
                errorMessage = ResourceHelper.GetResourceString("MSG_ERROR_ADD_WI");

            if (!string.IsNullOrEmpty(errorMessage))
                GenerateErrorMessage(errorMessage, Icons.AddNewWorkItem);
        }
コード例 #2
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Import items
        /// </summary>
        public void ImportItems()
        {

            ImportDialog popup = new ImportDialog();
            popup.InsertWorkItemPicker(TfsManager.Instance.ItemsStore, this.Project, true);
            popup.Create(null, Icons.ImportItems);

            if (popup.isCancelled && !popup.isOk)
                return;

            List<Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem> items = popup.GetSelectedWI();
            bool isImportEmptyContent = popup.isImportEmptyContent;

            if (items.Count > 0)
            {
                Application.Selection.Paragraphs.Last.Range.Paragraphs.Add();
                Range rangeToInsert = Application.Selection.Paragraphs.Last.Range;

                List<int> ids = GetAllWorkItemsIds();

                WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                progressDialog.Execute(cancelTokenSource =>
                {
                    string errorMessage = string.Empty;
                    int progress = 0;

                    progressDialog.UpdateProgress(0, ResourceHelper.GetResourceString("MSG_RETRIEVING_WORK_ITEMS"), true);

                    items.ForEach(item =>
                    {
                        if (!cancelTokenSource.IsCancellationRequested && !ids.Contains(item.Id))
                        {
                            try
                            {
                                progress++;
                                progressDialog.UpdateProgress(Convert.ToInt32(progress / items.Count * 100),
                                    string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), progress, items.Count, string.Format("{0} {1}", item.Type.Name, item.Id)), true);

                                Globals.ThisAddIn.Application.ScreenUpdating = false;

                                Paragraph p = rangeToInsert.Paragraphs.Add();

                                p.Range.HighlightColorIndex = WdColorIndex.wdNoHighlight;
                                p.Range.Text = item.Title;
                                p.Range.Select();
                                Application.Selection.ClearFormatting();

                                AddWIControl(item.Id, "System.Title");
                                p.Range.InsertParagraphAfter();
                                rangeToInsert = p.Range;
                                
                                if (!string.IsNullOrEmpty(item.Description))
                                {
                                    p = rangeToInsert.Paragraphs.Add();
                                    HtmlToDocx.Instance.ToDocxImport(p.Range, item.Description, item.Id, item.Fields["System.Description"].Name);
                                    p.Range.InsertParagraphAfter();
                                    rangeToInsert = p.Range;
                                }
                                else if (isImportEmptyContent)
                                {
                                    p = rangeToInsert.Paragraphs.Add();
                                    p.Range.HighlightColorIndex = WdColorIndex.wdNoHighlight;
                                    p.Range.Select();
                                    Application.Selection.ClearFormatting();
                                    AddWIControl(item.Id, item.Fields["System.Description"].Name);
                                    rangeToInsert = p.Range;
                                }

                                Globals.ThisAddIn.Application.ScreenUpdating = true;
                            }
                            catch
                            {
                                errorMessage += string.Format("{0}, ", item.Id);
                            }
                        }
                    });

                    Application.Selection.Collapse();

                    if (!string.IsNullOrEmpty(errorMessage))
                        GenerateErrorMessage(ResourceHelper.GetResourceString("MSG_ERROR_IMPORT_WIS") + errorMessage.Remove(errorMessage.Length - 2), Icons.ExportItem);
                });

                progressDialog.Create(ResourceHelper.GetResourceString("MSG_IMPORT_WIS_TITLE"), Icons.ImportItems);
            }
        }
コード例 #3
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Export items
        /// </summary>
        public void ExportItem()
        {
            ExportDialog popup = new ExportDialog();
            popup.Create(null, Icons.ExportItem);

            if (popup.isCancelled && !popup.isOk)
                return;

            ContentControl contentControl = (from control in this.Application.ActiveDocument.ContentControls.OfType<ContentControl>()
                                             where Application.Selection.InRange(control.Range)
                                             select control).FirstOrDefault();

            if (contentControl != null)
            {
                WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                progressDialog.Execute(cancelTokenSource =>
                {
                    progressDialog.UpdateProgress(100, string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), 1, 1, contentControl.Title), true);

                    string errorMessage = string.Empty;

                    if (!cancelTokenSource.IsCancellationRequested)
                    {
                        int id = 0;

                        try
                        {
                            string wiID = Application.ActiveDocument.Variables[contentControl.ID + "_wiid"].Value;
                            string wiField = Application.ActiveDocument.Variables[contentControl.ID + "_wifield"].Value;

                            if (Int32.TryParse(wiID, out id) && TfsManager.Instance.GetWorkItem(id) != null) // Check If comment has link to WI
                            {
                                contentControl.Range.Select();

                                if (wiField.Equals("System.Title", StringComparison.InvariantCultureIgnoreCase))
                                    TfsManager.Instance.ReplaceDetailsForWorkItem(id, wiField, Application.Selection.Text);
                                else
                                {
                                    DocxToHtml.Instance.ToHtmlExport(id, wiField);
                                }
                            }
                        }
                        catch
                        {
                            if (id > 0)
                                errorMessage += id;
                        }
                    }

                    Application.Selection.Collapse();

                    if (!string.IsNullOrEmpty(errorMessage))
                        GenerateErrorMessage(ResourceHelper.GetResourceString("MSG_ERROR_EXPORT_WI") + errorMessage, Icons.ExportItem);
                });

                progressDialog.Create(ResourceHelper.GetResourceString("MSG_EXPORT_WI_TITLE"), Icons.ExportItem);
            }
        }
コード例 #4
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Update status and content
        /// </summary>
        public void UpdateStatusAndContent()
        {
            List<ContentControl> controlsToUpdate = (from control in Application.ActiveDocument.ContentControls.OfType<ContentControl>()
                                                     select control).ToList<ContentControl>();
            if (controlsToUpdate.Count > 0)
            {
                WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                progressDialog.Execute(cancelTokenSource =>
                {
                    progressDialog.UpdateProgress(0, ResourceHelper.GetResourceString("MSG_RETRIEVING_WORK_ITEMS"), true);

                    string errorMessage = string.Empty;
                    int progress = 0;

                    controlsToUpdate.ForEach(control =>
                    {
                        if (!cancelTokenSource.IsCancellationRequested)
                        {
                            int id = 0;
                            string controlTitle = control.Title;

                            progress++;
                            progressDialog.UpdateProgress(Convert.ToInt32(progress / controlsToUpdate.Count * 100),
                                string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), progress, controlsToUpdate.Count, controlTitle), true);

                            try
                            {
                                string wiID = Application.ActiveDocument.Variables[control.ID + "_wiid"].Value;
                                string wiField = Application.ActiveDocument.Variables[control.ID + "_wifield"].Value;

                                if (Int32.TryParse(wiID, out id) && TfsManager.Instance.GetWorkItem(id) != null &&
                                    !wiField.Equals("Steps", StringComparison.InvariantCultureIgnoreCase) && !wiField.Equals("Шаги", StringComparison.InvariantCultureIgnoreCase)) // Check If comment has link to WI
                                {
                                    bool historyDescription = true;  // Check if Text Changed in WI Revision // TfsManager.Instance.GetWorkItemFieldHistory(id, wiField, DateTime.Now);

                                    if (historyDescription)
                                    {
                                        string description = string.Empty;

                                        if (wiField.ToLowerInvariant().Equals("System.Title"))
                                            description = TfsManager.Instance.GetWorkItemTitle(id);
                                        else
                                            description = TfsManager.Instance.GetWorkItemDescription(id, wiField);

                                        HtmlToDocx.Instance.ToDocx(control, description);
                                    }
                                }
                            }
                            catch
                            {
                                if (id > 0)
                                    errorMessage += string.Format("{0}, ", id);
                            }
                        }
                    });

                    if (!string.IsNullOrEmpty(errorMessage))
                        GenerateErrorMessage(ResourceHelper.GetResourceString("MSG_ERROR_PROCESS_WIS") + errorMessage.Remove(errorMessage.Length - 2), Icons.SyncConnectedTool);
                });

                progressDialog.Create(ResourceHelper.GetResourceString("MSG_UPDATE_WIS_TITLE"), Icons.SyncConnectedTool);
            }
        }
コード例 #5
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Update status
        /// </summary>
        public void UpdateStatus()
        {
            List<ContentControl> controlsToUpdate = (from control in Application.ActiveDocument.ContentControls.OfType<ContentControl>()
                                                     select control).ToList<ContentControl>();

            if (controlsToUpdate.Count > 0)
            {
                WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                progressDialog.Execute(cancelTokenSource =>
                {
                    progressDialog.UpdateProgress(0, ResourceHelper.GetResourceString("MSG_RETRIEVING_WORK_ITEMS"), true);

                    string errorMessage = string.Empty;
                    int progress = 0;

                    controlsToUpdate.ForEach(control =>
                    {
                        if (!cancelTokenSource.IsCancellationRequested)
                        {
                            progress++;

                            progressDialog.UpdateProgress(Convert.ToInt32(progress / controlsToUpdate.Count * 100),
                                string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), progress, controlsToUpdate.Count, control.Title), true);

                            int id = 0;

                            try
                            {
                                string wiID = this.Application.ActiveDocument.Variables[control.ID + "_wiid"].Value;
                                string wiField = this.Application.ActiveDocument.Variables[control.ID + "_wifield"].Value;

                                if (Int32.TryParse(wiID, out id) && TfsManager.Instance.GetWorkItem(id) != null) // Check If comment has link to WI
                                    control.Title = TfsManager.Instance.GetControlText(id, wiField);
                            }
                            catch
                            {
                                if (id > 0)
                                    errorMessage += string.Format("{0}, ", id);
                            }
                        }
                    });

                    if (!string.IsNullOrEmpty(errorMessage))
                        GenerateErrorMessage(ResourceHelper.GetResourceString("MSG_ERROR_PROCESS_WIS") + errorMessage.Remove(errorMessage.Length - 2), Icons.SyncConnectedTool);
                });

                progressDialog.Create(ResourceHelper.GetResourceString("MSG_UPDATE_WIS_TITLE"), Icons.SyncConnectedTool);
            }
        }
コード例 #6
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Add details
        /// </summary>
        public void AddDetails()
        {
            AddDetails popup = new AddDetails();

            popup.Loaded += popup_Loaded;
            popup.Create(null, Icons.AddDetails);

            if (popup.IsAdd || popup.IsReplace)
            {
                string errorMessage = string.Empty;

                int id = 0;
                string fieldName = popup.AddDetailsAsBox.SelectedValue.ToString();

                // if current document TabItem tab taking data from this tab
                if (popup.CurrentDocumentTabItem())
                {
                    Match match = Regex.Match(popup.ListBox.SelectedValue.ToString(), @"\d+");

                    if (match.Success)
                        Int32.TryParse(match.Value, out id);
                }

                // if By Work Item ID TabItem tab taking data from this tab
                if (popup.ByWorkItemIDTabItem())
                {
                    id = Convert.ToInt32(popup.GetWIID.Text);
                }

                if (id != 0)
                {
                    if (TfsManager.Instance.IsStep(id, fieldName))
                    {
                        TfsManager.Instance.AddStep(id, this.Application.Selection.Text);

                        WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                        progressDialog.Execute(cancelTokenSource =>
                        {
                            progressDialog.UpdateProgress(100, string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), 1, 1, string.Format("{0} - {1}", id, fieldName)), true);

                            try
                            {
                                AddWIControl(id, fieldName);
                            }
                            catch
                            {
                                errorMessage = ResourceHelper.GetResourceString("MSG_ERROR_REPLACE_WI");
                            }
                        });

                        progressDialog.Create(ResourceHelper.GetResourceString("MSG_EDIT_WI_TITLE"), Icons.AddDetails);
                    }
                    else
                    {
                        WordToTFS.View.ProgressDialog progressDialog = new WordToTFS.View.ProgressDialog();

                        progressDialog.Execute(cancelTokenSource =>
                        {
                            progressDialog.UpdateProgress(100, string.Format(ResourceHelper.GetResourceString("MSG_PROGRESS"), 1, 1, string.Format("{0} - {1}", id, fieldName)), true);

                            try
                            {
                                DocxToHtml.Instance.ToHtml(id, fieldName);
                            }
                            catch
                            {
                                errorMessage = ResourceHelper.GetResourceString("MSG_ERROR_REPLACE_WI");
                            }
                        });

                        progressDialog.Create(ResourceHelper.GetResourceString("MSG_EDIT_WI_TITLE"), Icons.AddDetails);
                    }
                }
                else
                    errorMessage = ResourceHelper.GetResourceString("MSG_ERROR_REPLACE_WI");
              

                if (!string.IsNullOrEmpty(errorMessage))
                    GenerateErrorMessage(errorMessage, Icons.AddDetails);
            }
        }