コード例 #1
0
        public async void IssueData_Test()
        {
            var r      = _cli_mock.GitHubClientMock.RepositoriesData.Data.FirstOrDefault();
            var i      = _cli_mock.GitHubClientMock.RepositoryIssuesData[r.Id].Data.FirstOrDefault();
            var result = await IssueData.Fetch(_cli_mock.GitHubClientMock.MockGitHubClient.Object, r.Id, i.Number);

            Assert.NotNull(result);
            Assert.Equal(i.State.StringValue, result.Issue.State.StringValue);
        }
コード例 #2
0
        public async void IssueData_Test()
        {
            ReportGithubModel m = new ReportGithubModel("");

            var r = _cli_mock.GitHubClientMock.RepositoriesData.Data.FirstOrDefault();
            var i = _cli_mock.GitHubClientMock.RepositoryIssuesData[r.Id].Data.FirstOrDefault();

            var result = m.issuesModel(new List <IssueData>()
            {
                await IssueData.Fetch(_cli_mock.GitHubClientMock.MockGitHubClient.Object, r.Id, i.Number)
            });

            Assert.NotNull(result);
            Assert.NotEmpty(result.issues);
            var issues = result.issues as IEnumerable <dynamic>;

            Assert.Equal(i.Number.ToString(), issues.ElementAt(0).issueName.ToString());
            Assert.Equal(i.State.StringValue, issues.ElementAt(0).state.ToString());
            Assert.Equal(i.Assignee.Login, issues.ElementAt(0).assignee.ToString());
        }
コード例 #3
0
        public async Task <IActionResult> PostExport([FromBody] List <Model.IssueListItem> issuesList, [FromQuery] bool generateQr = true)
        {
            User             user   = null;
            List <IssueData> issues = null;
            Dictionary <long, Repository> repo_dict = null;

            ReportModel.Document documentReportModel = null;

            string extension      = "pdf";
            string uid            = Guid.NewGuid().ToString();
            string reportFileName = $"{_configuration.GetValue<string>("Settings:StorageRoot", "clients_github")}/{uid}.{extension}";

            Report.PdfReport pdfReport = null;
            try
            {
                user = await _githubCli.User.Current();

                //Utils.Save2File("07_user.json", user);
                // fetch issues
                issues = (await Task.WhenAll(issuesList.Select(i => IssueData.Fetch(_githubCli, i.RepositoryId, i.IssueNo)))).ToList();
                // fetch repositories
                repo_dict = (await Task.WhenAll(issues.GroupBy(i => i.IssueRepoId).Select(i => _githubCli.Repository.Get(i.Key)))).ToDictionary(r => r.Id, r => r);
                // update issues repositories
                issues.ForEach(i => i.IssueRepo = repo_dict[i.IssueRepoId]);
                ReportGithubModel model = new ReportGithubModel(System.IO.File.ReadAllText(_configuration.GetValue("Templates:ReportIssuesModel", "template/Report-Issues.Mustache")));
                model.GenerateQRCode = generateQr;
                documentReportModel  = model.CreateReportModel(model.issuesModel(issues));
                if (null == documentReportModel.Options)
                {
                    documentReportModel.Options = new ReportModel.DocumentOptions();
                }

                pdfReport = new Report.PdfReport(filePath: reportFileName, storageName: _configuration.GetValue <string>("Settings:StorageName"), debug: _hostEnvironment.IsDevelopment());
                await pdfReport.Configure(_client.PdfApi, _client.BarcodeApi);

                await pdfReport.Report(documentReportModel);

                return(new OkObjectResult(new
                {
                    downloadlink = _basePathReplacement.ReplaceBaseUrl(Url.Link("GetDownload", new { id = uid })),
                    id = uid
                }));
            }catch (Exception ex)
            {
                ZipFileArchive archive = new ZipFileArchive().AddFile("010_request_params.json", new
                {
                    RequestId = _client.RequestId,
                    FileId    = uid,
                    FileName  = reportFileName
                });
                foreach (var f in new Dictionary <string, object> {
                    { "020_user.json", user },
                    { "030_issues.json", issues },
                    { "040_repo_dict.json", repo_dict },
                    { "050_report_model.json", documentReportModel },
                }.ToArray())
                {
                    archive.AddFile(f.Key, f.Value);
                }
                throw new ControllerException($"Error generating {reportFileName}", innerException: ex, customData: await archive.Archive());
            }
            finally
            {
                _client.Stat = pdfReport?.Stat;
            }
        }