Exemple #1
0
        public Task <byte[]> Generate(ProfileViewModel profile, WorkItemsReportViewModel report, GenerateEmailViewModel model, VstsDataSourceViewModel vstsConfig)
        {
            _logger.LogInformation("Requesting email for {ProfileId} - {ProfileName}");
            var reportExt = new Report();

            reportExt.Active.AddRange(report.ActiveWorkItems.Select(w => new WorkItem()
            {
                Id        = w.WorkItemId,
                Url       = GetWorkItemUrl(vstsConfig, w.WorkItemProject, w.WorkItemId),
                Title     = w.WorkItemTitle,
                Type      = w.WorkItemType,
                Estimated = (int)w.EstimatedToComplete,
                Spent     = (int)w.TimeSpent
            }));
            reportExt.Completed.AddRange(report.ResolvedWorkItems.Select(w => new WorkItem()
            {
                Id        = w.WorkItemId,
                Url       = GetWorkItemUrl(vstsConfig, w.WorkItemProject, w.WorkItemId),
                Title     = w.WorkItemTitle,
                Type      = w.WorkItemType,
                Estimated = (int)w.EstimatedToComplete,
                Spent     = (int)w.TimeSpent
            }));
            reportExt.Inreview.AddRange(report.WorkItemsInReview.Select(w => new WorkItem()
            {
                Id        = w.WorkItemId,
                Url       = GetWorkItemUrl(vstsConfig, w.WorkItemProject, w.WorkItemId),
                Title     = w.WorkItemTitle,
                Type      = w.WorkItemType,
                Estimated = (int)w.EstimatedToComplete,
                Spent     = (int)w.TimeSpent
            }));

            var request = new EmailRequest
            {
                Id       = report.Id.ToString(),
                Name     = report.ProfileName,
                Report   = reportExt,
                Template = new EmailTemplate {
                    Subject = profile.EmailSubject, Body = profile.EmailBody
                },
                Points = model.Points,
            };

            request.Attendance.AddRange(model.Attendance.Select(a =>
            {
                var attendance = new TeamAttendance
                {
                    Name = a.MemberName
                };
                attendance.Attendance.AddRange(a.Attendance.Select(ma => ma));
                return(attendance);
            }));

            var reply = _client.Generate(request);

            return(Task.FromResult(reply.File.ToByteArray()));
        }
        private string ApplyBodyPlaceholders(string value, IEnumerable <TeamAttendanceViewModel> teamAttendance, WorkItemsReportViewModel report, string pointsString)
        {
            var resolvedTable   = CreateTable(report.ResolvedWorkItems, "#70AD47");
            var codeReviewTable = CreateTable(report.WorkItemsInReview, "#FFC000");
            var activeTable     = CreateTable(report.ActiveWorkItems, "#5B9BD5");
            var points          = CreatePoints(pointsString);
            var createTeam      = CreateTeamTable(teamAttendance);
            var teamCount       = GetTeamCount(teamAttendance);

            return(value
                   .Replace("{ResolvedItems}", resolvedTable)
                   .Replace("{InReviewItems}", codeReviewTable)
                   .Replace("{ActiveItems}", activeTable)
                   .Replace("{ResolvedCount}", report.ResolvedWorkItems.Count().ToString())
                   .Replace("{InReviewCount}", report.WorkItemsInReview.Count().ToString())
                   .Replace("{ActiveCount}", report.ActiveWorkItems.Count().ToString())
                   .Replace("{TeamCount}", teamCount.ToString())
                   .Replace("{Points}", points)
                   .Replace("{Team}", createTeam));
        }
        public void Generate(IEnumerable <TeamAttendanceViewModel> attendanceViewModel, WorkItemsReportViewModel report, ProfileViewModel profile, string points)
        {
            if (string.IsNullOrEmpty(profile.EmailSubject))
            {
                profile.EmailSubject = $"No subject template for profile '{profile.Name}'";
            }

            if (string.IsNullOrEmpty(profile.EmailBody))
            {
                profile.EmailBody = $"No email template found.\r\nPlease go to 'AzureDevOps -> Profiles -> Edit {profile.Name} -> Email Options' and add email template.";
            }

            var subject = ApplyCommonPlaceholders(profile.EmailSubject, profile);
            var body    = ApplyCommonPlaceholders(profile.EmailBody, profile);

            body = ApplyBodyPlaceholders(body, attendanceViewModel, report, points);
            body = body.Replace("style=\"\"", string.Empty);

            var app = new Application();
            var msg = app.CreateItem(OlItemType.olMailItem) as MailItem;

            msg.Subject  = subject;
            msg.HTMLBody = body;
            msg.Display();
        }
Exemple #4
0
        private void CreateReportSheet(XSSFWorkbook workbook, string sectionName, IEnumerable <WorkItemDetail> workItems, WorkItemsReportViewModel prReport, ExcelColumn[] columns)
        {
            var excelSheet     = workbook.CreateSheet(sectionName);
            var creationHelper = workbook.GetCreationHelper();

            var hlinkstyle = workbook.CreateCellStyle();
            var hlinkfont  = workbook.CreateFont();

            hlinkfont.Underline = FontUnderlineType.Single;
            hlinkfont.Color     = HSSFColor.Blue.Index;
            hlinkstyle.SetFont(hlinkfont);
            var includeTags   = ShouldInclude(columns, "Tags");
            var includeReason = ShouldInclude(columns, "Reason");

            SetHeader(excelSheet, columns);
            int rowIdx = 1, cellIdx;

            foreach (var reportEntry in workItems)
            {
                cellIdx = 0;
                var row    = excelSheet.CreateRow(rowIdx);
                var idCell = row.CreateCell(cellIdx++, CellType.String);
                idCell.SetCellValue(reportEntry.WorkItemId);
                var link = creationHelper.CreateHyperlink(HyperlinkType.Url);
                link.Address     = $"https://dynamicscrm.visualstudio.com/{reportEntry.WorkItemProject}/_workitems/edit/{reportEntry.WorkItemId}";
                idCell.Hyperlink = link;

                row.CreateCell(cellIdx++, CellType.String).SetCellValue(reportEntry.WorkItemTitle);
                row.CreateCell(cellIdx++, CellType.String).SetCellValue(reportEntry.WorkItemType);
                if (includeTags)
                {
                    row.CreateCell(cellIdx++, CellType.String).SetCellValue(reportEntry.Tags);
                }

                if (includeReason)
                {
                    row.CreateCell(cellIdx++, CellType.String).SetCellValue(reportEntry.Reason);
                }

                row.CreateCell(cellIdx++, CellType.Numeric).SetCellValue(reportEntry.EstimatedToComplete);
                row.CreateCell(cellIdx, CellType.Numeric).SetCellValue(reportEntry.TimeSpent);
                rowIdx++;
            }

            var summaryRow = excelSheet.CreateRow(rowIdx);

            cellIdx = 0;
            summaryRow.CreateCell(cellIdx++, CellType.String).SetCellValue("Total: ");
            summaryRow.CreateCell(cellIdx++, CellType.String).SetCellValue($"{prReport.GetTotalBugs(workItems)} bugs / {prReport.GetTotalTasks(workItems)} tasks");
            summaryRow.CreateCell(cellIdx++, CellType.String);
            if (includeTags)
            {
                _ = summaryRow.CreateCell(cellIdx++, CellType.String);
            }

            if (includeReason)
            {
                _ = summaryRow.CreateCell(cellIdx++, CellType.String);
            }

            summaryRow.CreateCell(cellIdx++, CellType.Numeric).SetCellValue(prReport.GetTotalEstimated(workItems));
            summaryRow.CreateCell(cellIdx, CellType.Numeric).SetCellValue(prReport.GetTotalTimeSpent(workItems));

            // AutosizeCells(excelSheet, summaryRow.Cells.Count);
        }
Exemple #5
0
        private void CreateActiveWorkItemsReport(XSSFWorkbook workbook, string sectionName, IEnumerable <WorkItemDetail> workItems, WorkItemsReportViewModel prReport)
        {
            var headerColumns = GetHeaderColumns();

            headerColumns.Single(x => x.Name == "Tags").IsDisplayed = true;
            CreateReportSheet(workbook, sectionName, workItems, prReport, headerColumns);
        }
Exemple #6
0
        private void CreateWorkItemsInPullRequestReport(XSSFWorkbook workbook, string sectionName, IEnumerable <WorkItemDetail> workItems, WorkItemsReportViewModel prReport)
        {
            var headerColumns = GetHeaderColumns();

            CreateReportSheet(workbook, sectionName, workItems, prReport, headerColumns);
        }
Exemple #7
0
        public void Generate(IEnumerable <TeamAttendanceViewModel> attendanceViewModel, WorkItemsReportViewModel report, ProfileViewModel profile, string points)
        {
            try
            {
                var subject = ApplyCommonPlaceholders(profile.EmailSubject, profile);
                var body    = ApplyCommonPlaceholders(profile.EmailBody, profile);
                body = ApplyBodyPlaceholders(body, attendanceViewModel, report, points);
                body = body.Replace("style=\"\"", string.Empty);

                var app = new Application();
                var msg = app.CreateItem(OlItemType.olMailItem) as MailItem;
                msg.Subject  = subject;
                msg.HTMLBody = body;
                msg.Display();
            }
            catch (System.Exception ex)
            {
                ExceptionDispatchInfo.Capture(ex).Throw();
                throw;
            }
        }