Пример #1
0
        public DocumentInfo ProcessStructuredDocument(DocumentRequest request)
        {
            using (var transaction = this.unitOfWork.BeginTransaction())
            {
                IncomingDoc incomingDoc = new IncomingDoc();
                incomingDoc.DocumentGuid = Guid.NewGuid();
                incomingDoc.IncomingDate = DateTime.Now;
                incomingDoc.IncomingDocStatusId = this.unitOfWork.DbContext.Set<IncomingDocStatus>().Single(e => e.Alias == "Pending").IncomingDocStatusId;

                IncomingDocFile incomingDocFile = new IncomingDocFile();
                incomingDocFile.DocFileTypeId = this.unitOfWork.DbContext.Set<DocFileType>().Single(e => e.Alias == "XML").DocFileTypeId;
                incomingDocFile.Name = String.Format("WebPortalApp_{0}_{1}", DateTime.Now.ToString(), Guid.NewGuid().ToString());
                incomingDocFile.DocFileName = String.Format("WebPortalApp_{0}_{1}.xml", DateTime.Now.ToString(), Guid.NewGuid().ToString());
                incomingDocFile.DocFileContent = request.DocumentData;
                incomingDocFile.IncomingDoc = incomingDoc;

                this.unitOfWork.DbContext.Set<IncomingDocFile>().Add(incomingDocFile);
                this.unitOfWork.Save();

                transaction.Commit();

                DocumentInfo documentInfo = new DocumentInfo();
                documentInfo.DocumentGuid = incomingDoc.DocumentGuid;
                documentInfo.RegistrationStatus = DocumentRegistrationStatus.Pending;
                documentInfo.DocumentData = new AISDocument();
                documentInfo.DocumentData.Name = incomingDocFile.Name;
                documentInfo.DocumentData.Content = Utf8Utils.GetBytes(request.DocumentData);

                return documentInfo;
            }
        }
Пример #2
0
        public IHttpActionResult SendCompetenceTransferDoc(int id, int electronicServiceProviderId)
        {
            var doc = this.docRepository.Find(id,
               e => e.DocFiles.Select(df => df.DocFileOriginType),
               e => e.DocFiles.Select(df => df.DocFileType));

            if (doc == null)
            {
                return BadRequest();
            }

            DocFile editable = doc.DocFiles.FirstOrDefault(e => e.DocFileOriginTypeId.HasValue && e.DocFileOriginType.Alias == "EditableFile");
            if (editable == null || editable.DocFileType.Alias != "ContainerTransferFileCompetence")
            {
                return BadRequest();
            }

            byte[] content;

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString))
            {
                connection.Open();

                using (MemoryStream m1 = new MemoryStream())
                using (var blobStream = new BlobReadStream(connection, "dbo", "Blobs", "Content", "Key", editable.DocFileContentId))
                {
                    blobStream.CopyTo(m1);
                    content = m1.ToArray();
                }
            }

            string xmlContent = Utf8Utils.GetString(content);

            ElectronicServiceProvider electronicServiceProvider =
                this.unitOfWork.DbContext.Set<ElectronicServiceProvider>().FirstOrDefault(e => e.ElectronicServiceProviderId == electronicServiceProviderId);

            using (var channelFactory = new ChannelFactory<IApplicationCommunicator>("AppCommunicatorEndpoint", new EndpointAddress(electronicServiceProvider.EndPointAddress)))
            {
                DocumentRequest documentRequest = new DocumentRequest()
                {
                    DocumentData = xmlContent,
                    DocumentFileName = String.Format("CompetenceTransferDoc_{0}.xml", editable.DocFileContentId.ToString()),
                    DocumentGuid = editable.DocFileContentId
                };

                var service = channelFactory.CreateChannel();
                DocumentInfo documentInfo = service.ProcessStructuredDocument(documentRequest);
            }

            return Ok();
        }