예제 #1
0
        public async Task <byte[]> Generate(Guid movementId)
        {
            using (var memoryStream = DocumentHelper.ReadDocumentStreamShared("MovementMergeTemplate.docx"))
            {
                using (var document = WordprocessingDocument.Open(memoryStream, true))
                {
                    var movementDetails = await movementDetailsRepository.GetByMovementId(movementId);

                    var carrierCollection = await carrierRepository.GetByMovementId(movementId);

                    bool hasCarrierAnnex = carrierCollection.Carriers.Count() > 1;

                    var fields = MergeFieldLocator.GetMergeRuns(document);
                    var blocks = await blocksFactory.GetBlocks(movementId, fields);

                    var movementDocument = new MovementDocument(blocks);

                    ShipmentQuantityUnitFormatter.ApplyStrikethroughFormattingToUnits(document, movementDetails.ActualQuantity.Units);

                    movementDocument.Merge(hasCarrierAnnex);

                    MergeFieldLocator.RemoveDataSourceSettingFromMergedDocument(document);
                }

                return(memoryStream.ToArray());
            }
        }
예제 #2
0
        private byte[] GenerateMainDocument(NotificationApplication notification, string applicationDirectory)
        {
            var pathToTemplate = Path.Combine(applicationDirectory, "NotificationMergeTemplate.docx");

            // Minimise time the process is using the template file to prevent contention between processes.
            var templateFile = DocumentHelper.ReadDocumentShared(pathToTemplate);

            using (var memoryStream = new MemoryStream())
            {
                memoryStream.Write(templateFile, 0, templateFile.Length);

                using (var document = WordprocessingDocument.Open(memoryStream, true))
                {
                    var mergeFields = MergeFieldLocator.GetMergeRuns(document);

                    notificationDocumentMerger.MergeDataIntoDocument(mergeFields, notification);

                    MergeFieldLocator.RemoveDataSourceSettingFromMergedDocument(document);
                }

                return(memoryStream.ToArray());
            }
        }
        public async Task <byte[]> GenerateNotificationDocument(Guid notificationId)
        {
            using (var memoryStream = DocumentHelper.ReadDocumentStreamShared("NotificationMergeTemplate.docx"))
            {
                using (var document = WordprocessingDocument.Open(memoryStream, true))
                {
                    var mergeFields = MergeFieldLocator.GetMergeRuns(document);

                    var blocks = await blocksFactory.GetBlocks(notificationId, mergeFields);

                    var notificationDocument = new NotificationDocumentMerger(mergeFields, blocks);

                    var shipmentInfo = await shipmentInfoRepository.GetByNotificationId(notificationId);

                    ShipmentQuantityUnitFormatter.ApplyStrikethroughFormattingToUnits(document, shipmentInfo);

                    notificationDocument.Merge();

                    MergeFieldLocator.RemoveDataSourceSettingFromMergedDocument(document);
                }

                return(memoryStream.ToArray());
            }
        }