void InsertIterationAsHeadline(AdopIteration iteration) { ThisAddIn.ThisApplication.Selection.TypeText( $"Leistungspaket: {iteration.Name} vom {iteration.StartDate:dd.MM.yyyy} bis {iteration.FinishDate:dd.MM.yyyy}"); object codeStyle = "Heading 1"; var range = ThisAddIn.ThisApplication.Selection.Range; range.set_Style(ref codeStyle); ThisAddIn.ThisApplication.Selection.TypeParagraph(); ThisAddIn.ThisApplication.Selection.TypeParagraph(); //ThisAddIn.ThisApplication.Selection.TypeText("Hier geht es weiter."); //ThisAddIn.ThisApplication.Selection.TypeParagraph(); //ThisAddIn.ThisApplication.Selection.TypeText("Hier geht es noch weiter."); //ThisAddIn.ThisApplication.Selection.TypeParagraph(); //range = ThisAddIn.ThisApplication.Selection.Range; //range.Text = "Test"; }
private async void DocumentProjectbutton_Click(object sender, RibbonControlEventArgs e) { string projectUrl = Properties.Settings.Default.ProjectUrl; string projectName = Properties.Settings.Default.ProjectName; if (string.IsNullOrWhiteSpace(projectUrl) || string.IsNullOrWhiteSpace(projectName)) { if (new AddProjectUrlForm().ShowDialog(out projectUrl, out projectName) == DialogResult.OK) { Properties.Settings.Default.ProjectUrl = projectUrl; Properties.Settings.Default.ProjectName = projectName; Properties.Settings.Default.Save(); } } if (!string.IsNullOrWhiteSpace(projectUrl)) { VssConnection vsConn = new VssConnection(new Uri(projectUrl), new VssClientCredentials()); WorkItemTrackingHttpClient witClient; try { //create http client and query for resutls witClient = vsConn.GetClient <WorkItemTrackingHttpClient>(); } catch (Exception ex) { throw (ex); } var workItemTracking = vsConn.GetClient <WorkItemTrackingHttpClient>(); ProjectHttpClient projClient = await vsConn.GetClientAsync <ProjectHttpClient>(); var projects = projClient.GetProjects().Result; var adopIteration = AdopIteration.GetIterations(projects.Where(pro => pro.Name == projectName). Select((item) => workItemTracking.GetClassificationNodeAsync( project: item.Name, structureGroup: TreeStructureGroup.Iterations, depth: 3).Result)); foreach (var iterationItem in adopIteration. Where((item) => item.Level == 2). OrderBy((item) => item.StartDate)) { InsertIterationAsHeadline(iterationItem); var iterationTable = BeginNewIterationTable(); Wiql query = new Wiql() { Query = "SELECT [Id], [Title], [State] FROM workitems" + " WHERE ([Work Item Type] = 'Bug'" + " OR [Work Item Type] = 'Product Backlog Item'" + " OR [Work Item Type] = 'Task')" + $" AND [Iteration Path] = '{iterationItem.FullPath}'" }; WorkItemQueryResult queryResults; try { queryResults = await witClient.QueryByWiqlAsync(query, projectName); } catch (Exception ex) { throw (ex); } //Display results in console if (queryResults == null || queryResults.WorkItems.Count() == 0) { Console.WriteLine("Query did not find any results"); } else { foreach (var item in queryResults.WorkItems) { Console.WriteLine(item.Id); string[] fieldNameArray; try { fieldNameArray = new string[] { $"System.{nameof(CoreField.Id)}", $"System.{nameof(CoreField.IterationPath)}", $"System.{nameof(CoreField.WorkItemType)}", $"System.{nameof(CoreField.Title)}", $"System.{nameof(CoreField.Description)}", $"System.{nameof(CoreField.AssignedTo)}", $"System.{nameof(CoreField.State)}", $"System.{nameof(CoreField.IsDeleted)}" }; var workItem = await witClient.GetWorkItemAsync(item.Id, fieldNameArray); AddWorkItemRow(iterationTable, workItem); } catch (Exception) { } } } ThisAddIn.ThisApplication.Selection.EndOf(WdUnits.wdStory); ThisAddIn.ThisApplication.Selection.InsertNewPage(); } //var ad = ThisAddIn.ThisApplication.ActiveDocument; //var newTable = ad.Tables.Add(ThisAddIn.ThisApplication.Selection.Range, // 1, 3); //var cell = newTable.Cell(1, 1); //cell.Range.Text = "Iteration/Leistungspaket"; //cell = newTable.Cell(1, 2); //cell.Range.Text = "Start-Datum"; //cell = newTable.Cell(1, 3); //cell.Range.Text = "End-Datum"; //foreach (var iterationItem in adopIteration. // Where((item)=> item.Level==2). // OrderBy((item)=>item.StartDate)) //{ // var currentRow = newTable.Rows.Add(); // currentRow.Cells[1].Range.Text = iterationItem.Name; // currentRow.Cells[2].Range.Text = iterationItem.StartDate.ToShortDateString(); // currentRow.Cells[3].Range.Text = iterationItem.FinishDate.ToShortDateString(); //} } }