コード例 #1
0
        public override async Task DoWork(CancellationToken cancellationToken)
        {
            Log.Information($"{nameof(AuditLogThumbprintJob)} {DateTime.Now:HH:mm:ss} is running the Job.");

            var transactionHistoryDate = DateTime.Now.AddDays(-1);

            try
            {
                var pdfModel = await _transformTransactionHistory.ToPdfModel(transactionHistoryDate);

                var dailyFingerPrintPdf = await _pdfService.GenerateTransactionHistory(pdfModel);

                if (_signerConfiguration.Base != null || _signerConfiguration.Url != null)
                {
                    dailyFingerPrintPdf = (await _signerClient.Seal(dailyFingerPrintPdf)).Output;
                }

                await _alfrescoHttpClient.CreateNode(AlfrescoNames.Aliases.Root,
                                                     new FormDataParam(dailyFingerPrintPdf, string.Format(JobsNames.DailyFingerPrintPdfName, transactionHistoryDate.ToString("yyyy-MM-dd"), _transactionHistoryConfiguration.Originator)),
                                                     ImmutableList <Parameter> .Empty
                                                     .Add(new Parameter(AlfrescoNames.Headers.RelativePath, JobsNames.DailyFingerPrintPath, ParameterType.GetOrPost)));
            }
            catch (Exception ex) when(ex is HttpClientException httpClientException && httpClientException.HttpStatusCode == HttpStatusCode.Conflict)
            {
                Log.Warning($"Fingerprint for {transactionHistoryDate:dd.MM.yyyy} already exists.");
            }
            catch (Exception ex)
            {
                Log.Error($"Couldn't create daily fingerprint. Message:{ex.Message}, StackTrace:{ex.StackTrace}");
            }
        }
コード例 #2
0
        public async Task <NodeEntry> ConvertToOutputFormat(string documentId, string componentId, string reason, string organization)
        {
            var nodeEntry = await _alfrescoHttpClient.GetNodeInfo(componentId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties}, {AlfrescoNames.Includes.Path}", ParameterType.QueryString)));

            var extension = Path.GetExtension(nodeEntry?.Entry?.Name);

            if (!_fileExtensions.Any(x => extension.Contains(x)))
            {
                return(await _alfrescoHttpClient.UpdateNode(componentId, new NodeBodyUpdate()
                                                            .AddProperty(SpisumNames.Properties.FileIsInOutputFormat, "impossible")));
            }

            var    properties = nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
            string pid        = properties.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();

            var componentPid = pid.Split('/');

            FormDataParam pdf = null;

            if (nodeEntry?.Entry?.Content.MimeType != MediaTypeNames.Application.Pdf)
            {
                pdf = await _alfrescoHttpClient.GetThumbnailPdf(componentId, ImmutableList <Parameter> .Empty
                                                                .Add(new Parameter("c", "force", ParameterType.QueryString)));
            }
            else
            {
                pdf = await _alfrescoHttpClient.NodeContent(componentId);
            }

            var data = await _pdfService.ConvertToPdfA2B(new MemoryStream(pdf.File));

            if (_signerConfiguration.Base != null || _signerConfiguration.Url != null)
            {
                SealResponse signer = await _signerClient.Seal(data);

                await _signerService.CheckAndUpdateComponent(componentId, signer.Output);

                data = signer.Output;
            }

            await _componentService.UploadNewVersionComponent(documentId, componentId, data,
                                                              Path.ChangeExtension(properties.GetNestedValueOrDefault(SpisumNames.Properties.FileName)?.ToString(), ".pdf"), MediaTypeNames.Application.Pdf);

            return(await _alfrescoHttpClient.UpdateNode(componentId, new NodeBodyUpdate()
                                                        .AddProperty(SpisumNames.Properties.FileIsInOutputFormat, "yes")
                                                        .AddProperty(SpisumNames.Properties.FinalVersion, true)
                                                        .AddProperty(SpisumNames.Properties.SettleReason, reason)
                                                        .AddProperty(SpisumNames.Properties.KeepForm, SpisumNames.KeepForm.Original_InOutputFormat)
                                                        .AddProperty(SpisumNames.Properties.LinkRendering, int.Parse(componentPid[1]) + 1)
                                                        .AddProperty(SpisumNames.Properties.ListOriginalComponent, int.Parse(componentPid[1]))
                                                        .AddProperty(SpisumNames.Properties.CompanyImplementingDataFormat, organization)
                                                        .AddProperty(SpisumNames.Properties.AuthorChangeOfDataFormat, $"{_identityUser.FirstName} {_identityUser.LastName}")
                                                        .AddProperty(SpisumNames.Properties.OriginalDataFormat, nodeEntry?.Entry?.Content?.MimeType)
                                                        .AddProperty(SpisumNames.Properties.ImprintFile, Hashes.Sha256CheckSum(new MemoryStream(data)))
                                                        .AddProperty(SpisumNames.Properties.DataCompleteVerificationItem, DateTime.Now)
                                                        .AddProperty(SpisumNames.Properties.UsedAlgorithm, "SHA-256")));
        }