Esempio n. 1
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")));
        }
 /// <summary>
 /// When Rogerthat users receive a message they can be presented a number of predefined answers. Rogerthat users can change their answer until the message is sealed. Only the sender can seal the message.
 /// </summary>
 /// <returns> SealResponse object</returns>
 /// <param name="request"> SealRequest object</param>
 /// <param name='jsonRpcCallId'>
 /// The json rpc call identifier. This is a string generated by the client, which can be used to correlate the response to the request. Max length is 256 characters. A JSON-RPC id must be generated on a per call invocation basis. The Rogerthat platform uses the id of the call to store the call result for a certain amount of time so that if something fails during the communication, the same call (having the same JSON-RPC id) can be resent to the Rogerthat service, allowing to fetch the result, without actually executing the call again. This avoids annoying problems such as duplicate delivery of messages.
 /// 
 /// You should use a different JSON-RPC id for every call you make.
 /// 
 /// In case of an intermittent failure such as a network connectivity problem, you can retry the same call using the same JSON-RPC id, without running the risk of duplicate execution of your call (e.g. duplicate message delivery).
 /// </param>
 public SealResponse Seal(SealRequest request, string jsonRpcCallId)
 {
     SealResponse result = new SealResponse();
     WireRequest(0, jsonRpcCallId, "messaging.seal", (writer) =>
     {
         request.Write(writer, false);
     }, (reader) =>
     {
         result.Read(reader);
     }
     );
     return result;
 }