public static List <AttachmentHistory> Collect(DisplayItem item) { var items = new List <AttachmentHistory>(); if (item == null) { return(items); } var message = item.Message; var current = item.Entity; var entities = message.Entities.Where(x => x.ParentEntityId == current.EntityId).ToArray(); foreach (var entity in entities) { if (entity.EntityType == EntityType.Signature && entity.SignerBoxId == message.FromBoxId) { var data = entities.FirstOrDefault(x => x.AttachmentType == AttachmentType.AttachmentComment)?.Content?.Data; items.Add(new AttachmentHistory { Description = $"{message.FromTitle}, подписал и отправил документ", Comment = Encoding.UTF8.GetString(data ?? new byte[0]), Date = entity.CreationTime.ToLocalTime(), }); } else if (entity.EntityType == EntityType.Signature && entity.SignerBoxId == message.ToBoxId) { items.Add(new AttachmentHistory { Description = $"{message.ToTitle}, подписал документ и завершил документооборот", Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.ResolutionRequest) { var type = ""; if (entity.ResolutionRequestInfo.RequestType == ResolutionRequestType.ApprovementRequest) { type = "на согласование"; } else if (entity.ResolutionRequestInfo.RequestType == ResolutionRequestType.SignatureRequest) { type = "на подпись"; } var target = ""; if (!String.IsNullOrEmpty(entity.ResolutionRequestInfo.Target.User)) { target = $"сотруднику: {entity.ResolutionRequestInfo.Target.User}"; } else { var dep = entity.ResolutionRequestInfo.Target.Department; if (String.IsNullOrEmpty(dep)) { dep = "Головное подразделение"; } target = $"в подразделение: {dep}"; } items.Add(new AttachmentHistory { Description = $"{entity.ResolutionRequestInfo.Author} передал документ {type} {target}", Comment = Encoding.UTF8.GetString(entity.Content?.Data ?? new byte[0]), Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.SignatureRequestRejection) { items.Add(new AttachmentHistory { Description = "Отказано в подписании документа", Comment = Encoding.UTF8.GetString(entity.Content?.Data ?? new byte[0]), Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.Resolution) { if (entity.ResolutionInfo.ResolutionType == ResolutionType.Approve) { items.Add(new AttachmentHistory { Description = $"{entity.ResolutionInfo.Author} согласовал документ", Comment = Encoding.UTF8.GetString(entity.Content?.Data ?? new byte[0]), Date = entity.CreationTime.ToLocalTime() }); } else if (entity.ResolutionInfo.ResolutionType == ResolutionType.Disapprove) { items.Add(new AttachmentHistory { Description = $"{entity.ResolutionInfo.Author} отказал в согласовании документа", Comment = Encoding.UTF8.GetString(entity.Content?.Data ?? new byte[0]), Date = entity.CreationTime.ToLocalTime() }); } } else if (entity.AttachmentType == AttachmentType.ResolutionRequestDenial) { items.Add(new AttachmentHistory { Description = $"{entity.ResolutionRequestDenialInfo.Author} отказал в запросе подписи сотруднику", Comment = Encoding.UTF8.GetString(entity.Content?.Data ?? new byte[0]), Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.XmlSignatureRejection) { var xml = new DiadocXmlHelper(entity); var fio = xml.GetDiadokFIO("Файл/Документ/Подписант/ФИО/"); var comment = xml.GetValue("Файл/Документ/СвУведУточ/ТекстУведУточ"); items.Add(new AttachmentHistory { Description = $"{fio} отказал в подписи документа", Comment = comment, Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.InvoiceConfirmation) { items.Add(new AttachmentHistory { Description = $"{message.ToTitle}, документ получен", Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.InvoiceReceipt) { var xml = new DiadocXmlHelper(entity); var fio = xml.GetDiadokFIO("Файл/Документ/Подписант/ФИО/"); items.Add(new AttachmentHistory { Description = $"{fio} подписал и отправил извещение о получении", Date = entity.CreationTime.ToLocalTime() }); } else if (entity.AttachmentType == AttachmentType.RevocationRequest) { var xml = new DiadocXmlHelper(entity); var orgName = xml.GetValue("Файл/Документ/УчастЭДО/ЮЛ/@НаимОрг"); var fio = xml.GetDiadokFIO("Файл/Документ/Подписант/ФИО/"); var comment = xml.GetValue("Файл/Документ/СвПредАн/ТекстПредАн"); items.Add(new AttachmentHistory { Description = $"{orgName}, {fio} подписал и отправил соглашение об аннулировании", Comment = comment, Date = entity.CreationTime.ToLocalTime() }); if (current.DocumentInfo.RevocationStatus == RevocationStatus.RevocationAccepted) { var entityaccept = message.Entities.Where(x => x.ParentEntityId == entity.EntityId).OrderBy(x => x.CreationTime).Last(); orgName = xml.GetValue("Файл/Документ/НапрПредАн/ЮЛ/@НаимОрг"); items.Add(new AttachmentHistory { Description = $"{orgName}, аннулировал документ", Date = entityaccept.CreationTime.ToLocalTime() }); } else if (current.DocumentInfo.RevocationStatus == RevocationStatus.RevocationRejected) { var entityreject = message.Entities.Where(x => x.ParentEntityId == entity.EntityId).OrderBy(x => x.CreationTime).Last(); xml = new DiadocXmlHelper(entityreject); orgName = xml.GetValue("Файл/Документ/УчастЭДО/ЮЛ/@НаимОрг"); fio = xml.GetDiadokFIO("Файл/Документ/Подписант/ФИО/"); comment = xml.GetValue("Файл/Документ/СвУведУточ/ТекстУведУточ"); items.Add(new AttachmentHistory { Description = $"{orgName}, {fio} отказал в аннулировании документа", Comment = comment, Date = entityreject.CreationTime.ToLocalTime() }); } } else if (entity.AttachmentType == AttachmentType.XmlTorg12BuyerTitle) { var xml = new DiadocXmlHelper(entity); var fio = xml.GetDiadokFIO("Файл/Документ/Подписант/ЮЛ/ФИО/"); items.Add(new AttachmentHistory { Description = $"{fio} подписал документ и завершил документооборот", Date = entity.CreationTime.ToLocalTime() }); } } return(items.OrderBy(x => x.Date).ToList()); }
public DiadokAction(ActionPayload payload) { Success = false; InitFields(); Payload = payload; switch (payload.Entity.AttachmentType) { case AttachmentType.XmlTorg12: DocumentName = new DiadocXmlHelper(payload.Entity).GetDiadokTORG12Name(" , "); break; case AttachmentType.Invoice: DocumentName = new DiadocXmlHelper(payload.Entity).GetDiadokInvoiceName(" , "); break; default: DocumentName = payload.Entity.FileName; break; } IsEnabled.Value = true; if (Settings.Value.DebugUseTestSign) { SignerFirstName = "Иван"; SignerSureName = "Иванович"; SignerPatronimic = "Иванов"; SignerINN = Settings.Value.DebugDiadokSignerINN; } else { Cert = Settings.Value.GetCert(Settings.Value.DiadokCert); var certFields = X509Helper.ParseSubject(Cert.Subject); try { var namefp = certFields["G"].Split(' '); SignerFirstName = namefp[0]; SignerSureName = certFields["SN"]; SignerPatronimic = namefp[1]; if (!String.IsNullOrEmpty(Settings.Value.DebugDiadokSignerINN)) { SignerINN = Settings.Value.DebugDiadokSignerINN; } else { if (certFields.Keys.Contains("OID.1.2.643.3.131.1.1")) { SignerINN = certFields["OID.1.2.643.3.131.1.1"]; } if (certFields.Keys.Contains("ИНН")) { SignerINN = certFields["ИНН"]; } if (String.IsNullOrEmpty(SignerINN)) { throw new Exception("Не найдено поле ИНН(OID.1.2.643.3.131.1.1)"); } } SignerINN = SignerINN.Substring(2); } catch (Exception exept) { Log.Error("Ошибка разбора сертификата, G,SN,OID.1.2.643.3.131.1.1", exept); } } }