示例#1
0
 public GeneratedFile GenerateTorg12XmlForBuyer(string authToken, Torg12BuyerTitleInfo buyerInfo, string boxId, string sellerTitleMessageId, string sellerTitleAttachmentId)
 {
     if (buyerInfo == null)
     {
         throw new ArgumentNullException("buyerInfo");
     }
     return(diadocHttpApi.GenerateTorg12XmlForBuyer(authToken, buyerInfo, boxId, sellerTitleMessageId, sellerTitleAttachmentId));
 }
        public Task <GeneratedFile> GenerateTorg12XmlForBuyerAsync(string authToken, Torg12BuyerTitleInfo buyerInfo, string boxId, string sellerTitleMessageId, string sellerTitleAttachmentId)
        {
            var queryBuilder = new PathAndQueryBuilder("/GenerateTorg12XmlForBuyer");

            queryBuilder.AddParameter("boxId", boxId);
            queryBuilder.AddParameter("sellerTitleMessageId", sellerTitleMessageId);
            queryBuilder.AddParameter("sellerTitleAttachmentId", sellerTitleAttachmentId);
            return(PerformGenerateXmlHttpRequestAsync(authToken, queryBuilder.BuildPathAndQuery(), buyerInfo));
        }
示例#3
0
        public GeneratedFile GenerateTorg12XmlForBuyer(string authToken, Torg12BuyerTitleInfo buyerInfo, string boxId, string sellerTitleMessageId, string sellerTitleAttachmentId)
        {
            var queryString = string.Format("/GenerateTorg12XmlForBuyer?boxId={0}&sellerTitleMessageId={1}&sellerTitleAttachmentId={2}", boxId, sellerTitleMessageId, sellerTitleAttachmentId);

            return(PerformGenerateXmlHttpRequest(authToken, queryString, buyerInfo));
        }
示例#4
0
        public async Task Save()
        {
            try {
                BeginAction();
                MessagePatchToPost patch  = null;
                Signer             signer = GetSigner();
                if (ReqRevocationSign)
                {
                    Entity revocReq = Payload.Message.Entities.FirstOrDefault(x => x.AttachmentTypeValue == Diadoc.Api.Com.AttachmentType.RevocationRequest);
                    patch = Payload.Patch();
                    DocumentSignature acceptSignature = new DocumentSignature();
                    acceptSignature.IsApprovementSignature = true;
                    acceptSignature.ParentEntityId         = revocReq.EntityId;
                    byte[] sign = null;
                    if (!TrySign(revocReq.Content.Data, out sign))
                    {
                        throw new Exception("Ошибка подписи документа TrySign");
                    }
                    if (Settings.Value.DebugUseTestSign)
                    {
                        acceptSignature.SignWithTestSignature = true;
                    }
                    acceptSignature.Signature = sign;
                    patch.AddSignature(acceptSignature);
                    await Async(x => Payload.Api.PostMessagePatch(x, patch));
                }
                else
                {
                    if (Payload.Entity.AttachmentType == AttachmentType.Nonformalized)
                    {
                        patch = Payload.Patch();
                        byte[] sign = null;
                        if (!TrySign(Payload.Entity.Content.Data, out sign))
                        {
                            throw new Exception("Ошибка подписи документа TrySign");
                        }
                        var signature = new DocumentSignature {
                            ParentEntityId = Payload.Entity.EntityId,
                            Signature      = sign
                        };
                        if (Settings.Value.DebugUseTestSign)
                        {
                            signature.SignWithTestSignature = true;
                        }
                        patch.AddSignature(signature);
                        await Async(x => Payload.Api.PostMessagePatch(x, patch));
                    }
                    else if (Payload.Entity.AttachmentType == AttachmentType.XmlTorg12)
                    {
                        if (SaveData.Value)
                        {
                            SignTorg12Autosave autosave = new SignTorg12Autosave();
                            autosave.SignerJobTitle = RcvJobTitle.Value;
                            if (LikeReciever.Value)
                            {
                                autosave.LikeReciever = true;
                            }
                            else
                            {
                                autosave.AcptFirstName  = AcptFirstName.Value;
                                autosave.AcptSurename   = AcptSurename.Value;
                                autosave.AcptPatronimic = AcptPatronimic.Value;
                                autosave.AcptJobTitle   = AcptJobTitle.Value;
                            }
                            if (ByAttorney.Value)
                            {
                                autosave.ByAttorney      = true;
                                autosave.AtrNum          = AtrNum.Value;
                                autosave.AtrDate         = AtrDate.Value.Value;
                                autosave.AtrOrganization = AtrOrganization.Value;
                                autosave.AtrJobTitle     = AtrJobTitle.Value;
                                autosave.AtrSurename     = AtrSurename.Value;
                                autosave.AtrFirstName    = AtrFirstName.Value;
                                autosave.AtrPatronymic   = AtrPatronymic.Value;
                                autosave.AtrAddInfo      = AtrAddInfo.Value;
                            }
                            autosave.Comment = Comment.Value;
                            Session.Save(autosave);
                            for (int i = autosave_max - 1; i < SavedData.Value.Count; i++)
                            {
                                Session.Delete(SavedData.Value[i]);
                            }
                        }
                        Official recived  = GetRevicedOfficial();
                        Official accepted = GetAcceptetOfficial();
                        Attorney attorney = GetAttorney();

                        var inf = new Torg12BuyerTitleInfo()
                        {
                            ReceivedBy          = recived,                    //лицо, получившее груз signer
                            AcceptedBy          = accepted,                   //лицо, принявшее груз
                            Attorney            = attorney,
                            AdditionalInfo      = Comment,
                            ShipmentReceiptDate = RcvDate.Value.ToString("dd.MM.yyyy"),
                            Signer = signer
                        };

                        GeneratedFile torg12XmlForBuyer = await Async((x) => Payload.Api.GenerateTorg12XmlForBuyer(
                                                                          x,
                                                                          inf,
                                                                          Payload.BoxId,
                                                                          Payload.Entity.DocumentInfo.MessageId,
                                                                          Payload.Entity.DocumentInfo.EntityId));

                        SignedContent signContent = new SignedContent();
                        signContent.Content = torg12XmlForBuyer.Content;
                        if (!TrySign(signContent))
                        {
                            throw new Exception("Ошибка подписи документа TrySign");
                        }

                        ReceiptAttachment receipt = new ReceiptAttachment {
                            ParentEntityId = Payload.Entity.DocumentInfo.EntityId,
                            SignedContent  = signContent
                        };
                        patch = Payload.PatchTorg12(receipt);
                        await Async(x => Payload.Api.PostMessagePatch(x, patch));

                        Log.Info($"Документ {patch.MessageId} успешно подписан");
                    }
                    else if (Payload.Entity.AttachmentType == AttachmentType.Invoice)
                    {
                        Entity invoice = Payload.Message.Entities.First(i => i.AttachmentTypeValue == Diadoc.Api.Com.AttachmentType.Invoice);

                        GeneratedFile invoiceReceipt = await Async((x) => Payload.Api.GenerateInvoiceDocumentReceiptXml(
                                                                       x,
                                                                       Payload.BoxId,
                                                                       Payload.Entity.DocumentInfo.MessageId,
                                                                       invoice.EntityId,
                                                                       signer));

                        SignedContent signContentInvoiceReciept = new SignedContent();
                        signContentInvoiceReciept.Content = invoiceReceipt.Content;
                        if (!TrySign(signContentInvoiceReciept))
                        {
                            throw new Exception("Ошибка подписи документа TrySign");
                        }

                        ReceiptAttachment receiptInvoice = new ReceiptAttachment {
                            ParentEntityId = invoice.EntityId,
                            SignedContent  = signContentInvoiceReciept
                        };

                        Entity        invoiceConfirmation        = Payload.Message.Entities.OrderBy(x => x.CreationTime).First(i => i.AttachmentTypeValue == Diadoc.Api.Com.AttachmentType.InvoiceConfirmation);
                        GeneratedFile invoiceConfirmationReceipt = await Async((x) => Payload.Api.GenerateInvoiceDocumentReceiptXml(
                                                                                   x,
                                                                                   Payload.BoxId,
                                                                                   Payload.Entity.DocumentInfo.MessageId,
                                                                                   invoiceConfirmation.EntityId,
                                                                                   signer));

                        SignedContent signContentInvoiceConfirmationReciept = new SignedContent();
                        signContentInvoiceConfirmationReciept.Content = invoiceReceipt.Content;

                        if (!TrySign(signContentInvoiceConfirmationReciept))
                        {
                            throw new Exception("Ошибка подписи документа TrySign");
                        }

                        ReceiptAttachment invoiceConfirmationreceipt = new ReceiptAttachment {
                            ParentEntityId = invoiceConfirmation.EntityId,
                            SignedContent  = signContentInvoiceConfirmationReciept
                        };

                        patch = Payload.Patch(receiptInvoice, invoiceConfirmationreceipt);

                        await Async(x => Payload.Api.PostMessagePatch(x, patch));

                        Log.Info($"Документ {patch.MessageId} receiptInvoice, invoiceConfirmationreceipt отправлены");

                        Entity invoiceDateConfirmation = await Async((x) => {
                            Message msg        = null;
                            Entity dateConfirm = null;
                            int breaker        = 0;
                            do
                            {
                                msg = Payload.Api.GetMessage(Payload.Token,
                                                             Payload.BoxId,
                                                             Payload.Entity.DocumentInfo.MessageId,
                                                             Payload.Entity.EntityId);
                                dateConfirm = GetDateConfirmationStep7(msg);
                                breaker++;
                                TaskEx.Delay(500).Wait();
                            }while (dateConfirm == null && breaker < 10);
                            if (dateConfirm == null)
                            {
                                throw new TimeoutException("Превышено время ожидания ответа, попробуйте повторить позднее.");
                            }
                            LastPatchStamp = msg.LastPatchTimestamp;
                            return(dateConfirm);
                        });

                        GeneratedFile invoiceOperConfirmationReceipt = await Async((x) => Payload.Api.GenerateInvoiceDocumentReceiptXml(
                                                                                       x,
                                                                                       Payload.BoxId,
                                                                                       Payload.Entity.DocumentInfo.MessageId,
                                                                                       invoiceDateConfirmation.EntityId,
                                                                                       signer));

                        SignedContent signContentOperInvoiceConfrmReciept = new SignedContent();
                        signContentOperInvoiceConfrmReciept.Content = invoiceOperConfirmationReceipt.Content;

                        if (!TrySign(signContentOperInvoiceConfrmReciept))
                        {
                            throw new Exception("Ошибка подписи документа TrySign");
                        }

                        ReceiptAttachment receipt = new ReceiptAttachment {
                            ParentEntityId = invoiceDateConfirmation.EntityId,
                            SignedContent  = signContentOperInvoiceConfrmReciept
                        };
                        patch = Payload.Patch(receipt);
                        await Async(x => Payload.Api.PostMessagePatch(x, patch));

                        Log.Info($"Документ {patch.MessageId} invoiceDateConfirmation отправлен");
                    }
                }
                await EndAction();
            }
            catch (Exception e) {
                var error = ErrorHelper.TranslateException(e)
                            ?? "Не удалось выполнить операцию, попробуйте повторить позднее.";
                Manager.Warning(error);
                Log.Error(error, e);
                await EndAction(false);
            }
        }