示例#1
0
        public void UpdateSdtBlockTest()
        {
            var destinationPoints = (new List <DestinationPoint>()); //4148 tag

            destinationPoints.Add(new DestinationPoint()
            {
                Id = Guid.Parse("bf21e129-09f7-4809-b8f6-794859cb33a2"), RangeId = "6df20cc4 - 1e0b - 2cdc - 699e-3f4e8d902670"
            });

            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "ConvertToHundreds"
            }
                );
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "IncludeBillionDescriptor"
            }
                );
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "IncludeDollarSymbol"
            }
                );
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "ConvertNegativeSymbolToParenthesis"
            }
                );

            var value = "-12,000,000";

            using (var stream = new FileStream("DK - Press Release FY17Q2_4.docx", FileMode.Open))
            {
                var result = new DocumentUpdateResult();
                DocumentService.UpdateStream(destinationPoints, value, stream, result);
                stream.Close();
            }

            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open("DK - Press Release FY17Q2_4.docx", true))
            {
                var items = wordDoc.MainDocumentPart.Document.Descendants <SdtBlock>().Where(
                    o =>
                {
                    var tagedItem = o.SdtProperties.Elements <Tag>().FirstOrDefault();
                    if (tagedItem != null)
                    {
                        return(tagedItem.Val == destinationPoints[0].RangeId);
                    }
                    return(false);
                });
                Assert.IsTrue(items.Count() == 1);

                Assert.AreEqual(value, items.First().InnerText);
            }
        }
示例#2
0
        public void UpdateSdtBlockTest()
        {
            var destinationPoints = (new List <DestinationPoint>()); //4148 tag

            destinationPoints.Add(new DestinationPoint()
            {
                Id = Guid.Parse("60d914b2-d757-e711-9ccc-382c4abb0b40"), DecimalPlace = 2, RangeId = "dfec554f-a607-c570-ae2e-44691d7751e7"
            });
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "ConvertToHundreds"
            }
                );
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "IncludeBillionDescriptor"
            }
                );
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "IncludeDollarSymbol"
            }
                );
            destinationPoints.FirstOrDefault().CustomFormats.Add(
                new CustomFormat()
            {
                Name = "ConvertNegativeSymbolToParenthesis"
            }
                );

            var value = "-12,000,000";

            using (var stream = new FileStream("MS-Press Release FY17Q2 01172017 - Copy.docx", FileMode.Open))
            {
                var result = new DocumentUpdateResult();
                DocumentService.UpdateStream(destinationPoints, value, stream, result);
                stream.Close();
            }

            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open("MS-Press Release FY17Q2 01172017 - Copy.docx", true))
            {
                var items = wordDoc.MainDocumentPart.Document.Descendants <SdtBlock>().Where(
                    o =>
                {
                    var tagedItem = o.SdtProperties.Elements <Tag>().FirstOrDefault();
                    if (tagedItem != null)
                    {
                        return(tagedItem.Val == destinationPoints[0].RangeId);
                    }
                    return(false);
                });
                Assert.IsTrue(items.Count() == 1);

                Assert.AreEqual(value, items.First().InnerText);
            }
        }
示例#3
0
        protected override Task <object> Post(IHttpRequest request)
        {
            return(ProcessRequestAsync(request,
                                       r => _queryFactory.CreatePostQuery(r),
                                       async query =>
            {
                IDictionary <string, BlobInfo> fileInfos = null;

                if (query.Files != null)
                {
                    fileInfos = new Dictionary <string, BlobInfo>();

                    // Сохранение списка файлов
                    foreach (var file in query.Files)
                    {
                        // Сохранение файла в хранилище
                        var blobInfo = await _blobStorage.CreateBlobAsync(file.Name, file.ContentType, file.Value);

                        // Включение информации о файле в ответ
                        fileInfos[file.Key] = blobInfo;

                        // Установка ссылки на файл в документе
                        query.Document.SetProperty(file.Key, blobInfo);
                    }
                }

                DocumentUpdateResult status = null;
                DocumentValidationResult validationResult = null;

                try
                {
                    // Сохранение документа в хранилище
                    status = await _storage.SaveOneAsync(query.Document);
                }
                catch (DocumentStorageWriteException exception)
                {
                    validationResult = exception.WriteResult?.ValidationResult;
                }

                return new DocumentPostQueryResult
                {
                    DocumentId = query.Document._id,
                    FileInfos = fileInfos,
                    Status = status,
                    ValidationResult = validationResult
                };
            },
                                       _serviceHandler.OnBeforePost,
                                       _serviceHandler.OnAfterPost));
        }
示例#4
0
        public async Task <DocumentUpdateResult> UpdateBookmrkValue(string documentId, IEnumerable <DestinationPoint> destinationPoints, string value)
        {
            DocumentUpdateResult retValue = new DocumentUpdateResult()
            {
                IsSuccess = true
            };

            try
            {
                string authHeader = GetAuthorizationHeader();
                DocumentCheckResult documentResult = await GetDocumentUrlByID(new DocumentCheckResult()
                {
                    DocumentId = documentId
                });

                if (documentResult.IsSuccess)
                {
                    FileContextInfo fileContextInfo = await GetFileContextInfo(authHeader, documentResult.DocumentUrl);

                    var stream = await GetFileStream(authHeader, documentResult.DocumentUrl, fileContextInfo);

                    stream.Seek(0, SeekOrigin.Begin);
                    UpdateStream(destinationPoints, value, stream, retValue);
                    await UploadStream(authHeader, documentResult.DocumentUrl, stream, fileContextInfo);

                    return(retValue);
                }
                else
                {
                    retValue.IsSuccess = false;
                    retValue.Message.Add(documentResult.Message);
                }
            }
            catch (Exception ex)
            {
                retValue.IsSuccess = false;
                retValue.Message.Add(ex.ToString());
            }
            return(retValue);
        }
示例#5
0
        static public void UpdateStream(IEnumerable <DestinationPoint> destinationPoints, string value, Stream stream, DocumentUpdateResult updateResult)
        {
            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true))
            {
                foreach (var destinationPoint in destinationPoints)
                {
                    int    foundTimes = 0;
                    var    position   = destinationPoint.RangeId;
                    string updatedTo  = string.Empty;

                    if (destinationPoint.ReferencedSourcePoint.SourceType == SourceTypes.Point)
                    {
                        var formats = destinationPoint.CustomFormats.OrderBy(c => c.GroupOrderBy).ToList();
                        updatedTo = GetFormattedValue(value, formats, destinationPoint.DecimalPlace);
                        //Update value in sdtBlock
                        foundTimes += UpdateValueInSdtBlock(updatedTo, wordDoc, position);
                        //Update value in sdtCell
                        foundTimes += UpdateValueInSdtCell(updatedTo, wordDoc, position);
                        //Update value in sdtRun
                        foundTimes += UpdateValueInSdtRun(updatedTo, wordDoc, position);
                    }
                    else if (destinationPoint.ReferencedSourcePoint.SourceType == SourceTypes.Table)
                    {
                        JObject json = JObject.Parse(value);
                        if (destinationPoint.DestinationType == DestinationTypes.TableImage)
                        {
                            //Update table in sdtPic
                            updatedTo   = json["image"].Value <string>();
                            foundTimes += UpdateValueInSdtPic(updatedTo, wordDoc, position);
                        }
                        else
                        {
                            //Update table in sdtTable
                            updatedTo   = ((JObject)json["table"]).ToString();
                            foundTimes += UpdateValueInSdtTable(updatedTo, wordDoc, position);
                        }
                    }
                    else
                    {
                        //Update image in sdtPic
                        updatedTo   = value;
                        foundTimes += UpdateValueInSdtPic(updatedTo, wordDoc, position);
                    }
                    updateResult.Message.Add($"Tag:{position} found {foundTimes}(updated to {updatedTo}).");
                }

                wordDoc.MainDocumentPart.Document.Save();
            }
        }
示例#6
0
        static public void UpdateStream(IEnumerable <DestinationPoint> destinationPoints, string value, Stream stream, DocumentUpdateResult updateResult)
        {
            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true))
            {
                foreach (var destinationPoint in destinationPoints)
                {
                    int foundTimes     = 0;
                    var position       = destinationPoint.RangeId;
                    var formats        = destinationPoint.CustomFormats.OrderBy(c => c.GroupOrderBy).ToList();
                    var formattedValue = GetFormattedValue(value, formats, destinationPoint.DecimalPlace);

                    //Update value in sdtBlock
                    foundTimes += UpdateValueInSdtBlock(formattedValue, wordDoc, position);
                    //Update value in sdtCell
                    foundTimes += UpdateValueInSdtCell(formattedValue, wordDoc, position);
                    //Update value in sdtRun
                    foundTimes += UpdateValueInSdtRun(formattedValue, wordDoc, position);
                    updateResult.Message.Add($"Tag:{position} found {foundTimes}(updated to {formattedValue}).");
                }

                wordDoc.MainDocumentPart.Document.Save();
            }
        }