コード例 #1
0
 public void Register(DocumentBase document)
 {
     if (document != null)
     {
         _identityMap.Add(document);
     }
 }
コード例 #2
0
ファイル: RavenDB_14234.cs プロジェクト: radtek/ravendb
        public void ShouldAssignTheTypeOfDerivedProperties()
        {
            var entity5 = new IDocumentWithPropertyTypeOverride5();
            var type5   = BlittableJsonConverter.GetPropertyType(nameof(entity5.Reference), entity5.GetType());

            Assert.Equal(typeof(IRefDerived_Class), type5);

            var entity4 = new DocumentWithPropertyTypeOverride4();
            var type4   = BlittableJsonConverter.GetPropertyType(nameof(entity4.Reference), entity4.GetType());

            Assert.Equal(typeof(RefDerived3), type4);

            var entity3 = new DocumentWithPropertyTypeOverride3();
            var type3   = BlittableJsonConverter.GetPropertyType(nameof(entity3.Reference), entity3.GetType());

            Assert.Equal(typeof(RefDerived3), type3);

            var entity2 = new DocumentWithPropertyTypeOverride2();
            var type2   = BlittableJsonConverter.GetPropertyType(nameof(entity2.Reference), entity2.GetType());

            Assert.Equal(typeof(RefDerived2), type2);

            var entity1 = new DocumentWithPropertyTypeOverride1();
            var type1   = BlittableJsonConverter.GetPropertyType(nameof(entity1.Reference), entity1.GetType());

            Assert.Equal(typeof(RefDerived2), type1);

            var entity0 = new DocumentBase();
            var type0   = BlittableJsonConverter.GetPropertyType(nameof(entity0.Reference), entity0.GetType());

            Assert.Equal(typeof(RefDerived1), type0);
        }
コード例 #3
0
ファイル: DocumentDbTest.cs プロジェクト: sagarSahay/BullOak
        public async Task UpsertDocument_NewDocument_IsStoredCorrectly()
        {
            // Arrange
            var db     = new DocumentDb(location, key, database);
            var id     = Guid.NewGuid();
            var person = new PersonTest()
            {
                PersonId = id,
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person, ETag = Guid.NewGuid().ToString()
            };

            // Act
            await db.UpsertDocument(CollectionId, id.ToString(), personEnvelope);

            // Assert
            var doc = await db.ReadDocument <PersonTest>(CollectionId, id.ToString());

            doc.VM.Age.Should().Be(87);
            doc.VM.Name.Should().Be("Barney Rubble");
            doc.VM.PersonId.Should().Be(person.PersonId);
        }
コード例 #4
0
        public IList <Form> GetForms(IDocument document)
        {
            DocumentBase documentBase = document as DocumentBase;

            if (documentBase == null)
            {
                return new List <Form> {
                           LoadForm(document)
                }
            }
            ;

            List <Form> forms = new List <Form> ();

            if (documentBase.PrintOriginal)
            {
                documentBase.IsOriginal = true;

                forms.Add(LoadForm(document));
            }

            if (documentBase.PrintInternational)
            {
                documentBase.IsOriginal = null;
                forms.Add(LoadForm(documentBase.GetInternational()));
            }

            for (int i = 0; i < documentBase.PrintCopies; i++)
            {
                documentBase.IsOriginal = false;
                forms.Add(LoadForm(documentBase));
            }
            return(forms);
        }
コード例 #5
0
        // ------------------------------ WRITING ------------------------------

        /// <summary>
        /// Writes given document to proper file
        /// </summary>
        /// <param name="document"></param>
        public void WriteMessage(DocumentBase document)
        {
            string content  = document.ToProxiaFormat();
            var    filename = GetFileName(document.DeutschName);

            File.WriteAllText($"{WritePath}/{filename}", content, (new UTF8Encoding(false)));
        }
コード例 #6
0
        public async Task Consume(ConsumeContext <PaymentError> context)
        {
            var message = context.Message;
            var id      = message.PaymentId.ToString();

            var paymentVm = new PaymentVM()
            {
                PaymentId     = message.PaymentId,
                OrderId       = message.OrderId,
                Amount        = message.Amount,
                CardNumber    = message.CardNumber,
                Currency      = message.Currency,
                MerchantId    = message.MerchantId,
                PaymentStatus = "System error",
                Cvv           = message.Cvv,
                ExpiryDate    = message.ExpiryDate
            };

            var paymentDoc = new DocumentBase <PaymentVM>()
            {
                VM = paymentVm
            };

            await repository.Upsert(id, paymentDoc);
        }
コード例 #7
0
 /// <summary>
 /// Add input document to buffer
 /// </summary>
 /// <param name="document">Document to add</param>
 public void AddMessage(DocumentBase document)
 {
     if (!_documents.ContainsKey(document.DeutschName))
     {
         _documents.Add(document.DeutschName, new ValuesList <DocumentBase>());
     }
 }
コード例 #8
0
        public void NextMessage()
        {
            do
            {
                while (_state.EOFCurrentFile())
                {
                    if (!string.IsNullOrEmpty(_state.CurrentFilePath))
                    {
                        if (File.Exists(Path.Combine(HistoryPath, _state.CurrentFileName)))
                        {
                            File.Delete(Path.Combine(HistoryPath, _state.CurrentFileName));
                        }

                        File.Move(Path.Combine(ReadPath, _state.CurrentFileName),
                                  Path.Combine(HistoryPath, _state.CurrentFileName));
                    }
                    _state.CurrentFilePath = GetOldestFilePath();
                    if (string.IsNullOrEmpty(_state.CurrentFilePath))
                    {
                        _lastMessage = null;
                        _logger.Log("No matched file found", LoggingMode.Enhanced);
                        return;
                    }
                }

                _lastMessage = Parse(_state.GetNextLine());
            } while (_lastMessage == null);
            _logger.Log(_state.CurrentFileName + "\t" + _state.CurrentLine.ToString("####") + "\t" + "NextMessage", LoggingMode.Enhanced);
        }
コード例 #9
0
        public async Task UpsertDocument_NewDocument_IsStoredCorrectly()
        {
            // Arrange
            var db         = new MongoDb(ConnectionString, DatabaseId);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };

            var personEnvelope = new DocumentBase <PersonTest>()
            {
                VM = person
            };
            // Act
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Assert
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            doc.VM.Age.Should().Be(87);
            doc.VM.Name.Should().Be("Barney Rubble");
            doc.VM.PersonId.Should().Be(person.PersonId);
        }
コード例 #10
0
 /// <summary>
 /// Сохранить документ.
 /// </summary>
 /// <param name="document">Сохраняемый документ.</param>
 /// <returns>Сохраненный документ с заполненным идентификатором</returns>
 public Guid Save(DocumentBase document)
 {
     using (var uow = CreateUnitOfWork())
     {
         return(uow.DocumentRepository.Save(document));
     }
 }
コード例 #11
0
        protected DocumentPresenterBase(DocumentBase document)
        {
            this.document          = document;
            this.AutoIndentCommand = new AutoIndentCommand(this);

            this.RefreshProperties();
        }
コード例 #12
0
        public async Task DeleteDocument_DocumentExists_DocumentIsDeleted()
        {
            // Arrange
            var db         = new MongoDb(ConnectionString, DatabaseId);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest>()
            {
                VM = person
            };
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Act
            await db.DeleteDocument(CollectionId, documentId);

            var exists = db.DocumentExists(CollectionId, documentId);

            // Assert
            exists.Should().BeFalse();
        }
コード例 #13
0
ファイル: DocumentDbTest.cs プロジェクト: sagarSahay/BullOak
        public async Task UpsertDocument_UpdateDocument_IsUpdatedCorrectly()
        {
            // Arrange
            var db         = new DocumentDb(location, key, database);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                Id       = Guid.Parse(documentId),
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person
            };
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            personEnvelope = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            personEnvelope.VM.Name = "Fred Flintstone";
            personEnvelope.VM.Age  = 88;

            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Assert
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            doc.VM.Age.Should().Be(88);
            doc.VM.Name.Should().Be("Fred Flintstone");
            doc.VM.PersonId.Should().Be(person.PersonId);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: stephanscheidl/SharpDocx
        private static void ExecuteTemplates(out WeakReference loadContextRef)
        {
            var loadCtx = new TestAssemblyLoadContext(Path.GetDirectoryName(typeof(Program).Assembly.Location));

            DocumentFactory.LoadContext = loadCtx;

            var viewPath       = $"{BasePath}/Views/Tutorial.cs.docx";
            var documentPath   = $"{BasePath}/Documents/Tutorial.docx";
            var imageDirectory = $"{BasePath}/Images";

#if DEBUG
            Ide.Start(viewPath, documentPath, null, null, f => f.ImageDirectory = imageDirectory);
#else
            DocumentBase document = DocumentFactory.Create(viewPath);
            document.ImageDirectory = imageDirectory;
            document.Generate(documentPath);
#endif
            loadContextRef = new WeakReference(loadCtx);

            Console.WriteLine("---------------------Assemblies Loaded In the Default Context-------------------------------");
            var assemblyNames = AssemblyLoadContext.Default.Assemblies.Select(s => s.FullName).ToArray();
            Console.WriteLine(string.Join(Environment.NewLine, assemblyNames));

            Console.WriteLine("---------------------Assemblies Loaded In Context-------------------------------");
            assemblyNames = loadCtx.Assemblies.Select(s => s.FullName).ToArray();
            Console.WriteLine(string.Join(Environment.NewLine, assemblyNames));

            loadCtx.Unload();
            DocumentFactory.LoadContext = null;
        }
コード例 #15
0
        private DocumentBase GetDocument(SupportedDocumentInfo docInfo, IDocumentDataContext context, bool activate)
        {
            //Tracer.Verbose("DocumentFactory:GetDocument", "docName{0}, docTitle{0}, docType{0}, activate{0}", docName, docTitle, docType, activate);

            DocumentBase doc = FindDocument(docInfo, context);

            try
            {
                if (doc == null)
                {
                    doc = CreateNewDocument(docInfo, context);
                }

                if (doc != null && activate)
                {
                    _DockManager.ActiveDocument = doc;
                }
            }
            catch (Exception err)
            {
                Tracer.Error("DocumentFactory.GetDocument", err);
            }
            finally
            {
                Tracer.Verbose("DocumentFactory:GetDocument", "END");
            }

            return(doc);
        }
コード例 #16
0
ファイル: DocumentDbTest.cs プロジェクト: sagarSahay/BullOak
        public async Task ReadDocument_DocumentExists_ReturnDocumentIsCorrect()
        {
            // Arrange
            var db         = new DocumentDb(location, key, database);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person
            };
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Act
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            // Assert
            doc.VM.Age.Should().Be(person.Age);
            doc.VM.Name.Should().Be(person.Name);
            doc.VM.PersonId.Should().Be(person.PersonId);
            doc.ETag.Should().NotBe(string.Empty);
        }
コード例 #17
0
        public async Task <Uri> GetCollectionUriAsync <T>() where T : DocumentBase
        {
            await GetDocumentClient();

            var collectionName = DocumentBase.GetCollectionName <T, string>();

            return(collectionLinks[collectionName]);
        }
コード例 #18
0
        //public void CloseDocument(SupportedDocumentInfo info, DocumentDataContext context)
        //{
        //    Tracer.Verbose("DocumentFactory:CloseDocument", "docName {0}", docName);

        //    try
        //    {
        //        IEnumerable<DocumentContent> docs = _DockManager.Documents.Where(d => d.Name == docName);

        //        if (docs.Count() == 0)
        //            return;
        //        else
        //        {
        //            foreach (DocumentContent doc in docs)
        //                doc.Close();
        //        }
        //    }
        //    catch (Exception err)
        //    {
        //        Tracer.Error("DocumentFactory.CloseDocument", err);
        //    }
        //    finally
        //    {
        //        Tracer.Verbose("DocumentFactory:CloseDocument", "END");
        //    }
        //}

        #endregion

        #region ---------------------EVENTS---------------------

        private void DocumentClosing(object sender, CancelEventArgs e)
        {
            DocumentBase db = sender as DocumentBase;

            Tracer.Verbose("DocumentFactory.DocumentClosing", db.Title + " closing");

            //manage dirty state ?
        }
コード例 #19
0
 public static DocumentWrapper <T> FromBase <T>(DocumentBase <T> @base, string id)
 {
     return(new DocumentWrapper <T>
     {
         Id = id,
         ETag = @base.ETag,
         VM = @base.VM
     });
 }
コード例 #20
0
        private void OnDocumentClosed(object sender, DocumentClosedEventArgs e)
        {
            DocumentBase document = e.Document.Content as DocumentBase;

            if (document != null)
            {
                document.Close();
            }
        }
コード例 #21
0
 private bool TryGetDocumentWithOutboxMessages(
     HashSet <DocumentBase> toSkip,
     out DocumentBase document)
 {
     document = _identityMap
                .Except(toSkip, DocumentBaseEqualityComparer.Instance)
                .FirstOrDefault(a => a.Outbox.Any());
     return(document != null);
 }
コード例 #22
0
        protected void btnOK_Clicked(object o, EventArgs args)
        {
            if (IsEditable)
            {
                if (!CheckEntries())
                {
                    return;
                }

                SetDocumentFields();

                SaveOperationPartner();

                if (!SaveDocument())
                {
                    return;
                }

                BusinessDomain.AppConfiguration.LastDocumentPaymentMethodId = (long)cboPaymentType.GetSelectedValue();
            }
            else
            {
                SetDocumentFields();
                if (!SaveDocument(FinalizeAction.None))
                {
                    return;
                }
            }

            try {
                if (isPrintable && (chkPrintOriginal.Active || chkPrintCopy.Active || chkPrintInternational.Active))
                {
                    document.PrintOriginal      = chkPrintOriginal.Active;
                    document.PrintCopies        = chkPrintCopy.Active ? spnPrintCopy.ValueAsInt : 0;
                    document.PrintInternational = chkPrintInternational.Active;

                    document.IsOriginal = document.PrintOriginal;

                    // Hide this dialog so the preview can show on a clean screen
                    dlgEditNewDocument.Hide();
                    DocumentBase doc = document;
                    if (!document.PrintOriginal && document.PrintInternational)
                    {
                        doc            = document.GetInternational();
                        doc.IsOriginal = null;
                    }
                    FormHelper.PrintPreviewObject(doc);
                }

                dlgEditNewDocument.Respond(ResponseType.Ok);
            } catch (Exception ex) {
                MessageError.ShowDialog(GetErrorWhileGeneratingMessage(), ErrorSeverity.Error, ex);

                dlgEditNewDocument.Respond(ResponseType.Cancel);
            }
        }
コード例 #23
0
ファイル: DocumentDbTest.cs プロジェクト: sagarSahay/BullOak
        private async Task <DocumentDb> SetupMultiplePersons()
        {
            var db = new DocumentDb(location, key, database);

            var personA = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87,
                Id       = new Guid("C9FCD0EB-E5F3-439D-BA4D-093E692046C0")
            };
            var personAEnvelope = new DocumentBase <PersonTest> {
                VM = personA, ETag = Guid.NewGuid().ToString()
            };
            var personB = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Wilma Flintstone",
                Age      = 88,
                Id       = Guid.NewGuid()
            };
            var personBEnvelope = new DocumentBase <PersonTest> {
                VM = personB, ETag = Guid.NewGuid().ToString()
            };
            var personC = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Wilma Flintstone",
                Age      = 66,
                Id       = Guid.Empty
            };
            var personCEnvelope = new DocumentBase <PersonTest> {
                VM = personC, ETag = Guid.NewGuid().ToString()
            };
            var personD = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Wilma Flintstone",
                Age      = 66,
                Id       = Guid.NewGuid()
            };
            var personDEnvelope = new DocumentBase <PersonTest> {
                VM = personD, ETag = Guid.NewGuid().ToString()
            };

            await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personAEnvelope);

            await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personBEnvelope);

            await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personCEnvelope);

            await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personDEnvelope);

            return(db);
        }
コード例 #24
0
        public void GetOrCreateCollection()
        {
            DocumentBase dbase = new DocumentBase("Test");

            var collection = dbase.GetOrCreateCollection("People");

            Assert.IsNotNull(collection);
            Assert.AreEqual("People", collection.Name);

            Assert.AreSame(collection, dbase.GetCollection("People"));
        }
コード例 #25
0
        private void DocumentClosed(object sender, EventArgs e)
        {
            DocumentBase db = sender as DocumentBase;

            Tracer.Verbose("DocumentFactory.DocumentClosed", db.Title + " closed");

            if (GetSupportedDocumentInfo(db).CanCreate)
            {
                WorkspaceService.Instance.AddRecentFile(db.Context.FullName);
            }
        }
コード例 #26
0
        public string GetTenantId <T>() where T : DocumentBase
        {
            var collectionName = DocumentBase.GetCollectionName <T, string>();

            if (options.CollectionInfos.TryGetValue(collectionName, out var collectionInfo) && !string.IsNullOrEmpty(collectionInfo.TenantId))
            {
                return(collectionInfo.TenantId);
            }

            return(DEFAULT_TENANT_NAME);
        }
コード例 #27
0
        // this is a workaround similar to that described in
        // http://stackoverflow.com/questions/17185780/prevent-document-from-closing-in-dockingmanager?rq=1
        // where the main view code directly calls this method handling the docking manager closing event.
        // The scenario is the following: AvalonDock has its document handling mechanism, which should be
        // synchronized with the Caliburn Micro's one. CM is based on a screen conductor; when a screen
        // needs to be closed, the method TryClose is used to close it if possible (i.e. unless a guard
        // method tells the framework that the screen cannot be closed, e.g. because the document is dirty).
        // I found no elegant alternative to this workaround: when AD is closing the document, call
        // the underlying VM guard method and cancel if required; if not cancelled, then AD goes on closing
        // thus firing the DocumentClosed event. Handling this event I can call TryClose on CM so that the
        // viewmodel representing the closed document screen is correctly removed. I can be sure that this
        // will be the case, as TryClose has just been called in handling OnDocumentClosing. I cannot directly
        // call TryClose in OnDocumentClosing, as this would cause null object reference errors in AD.

        private void OnDocumentClosing(object sender, DocumentClosingEventArgs e)
        {
            DocumentBase document = e.Document.Content as DocumentBase;

            if (document == null)
            {
                return;
            }

            e.Cancel = !document.CanClose();
        }
コード例 #28
0
        private void FixHyperlinks(DocumentBase originalDoc, string fixUrl)
        {
            if (fixUrl.EndsWith("/"))
            {
                fixUrl = fixUrl.Substring(0, fixUrl.Length - 1);
            }

            NodeCollection fieldStarts = mTopicDoc.GetChildNodes(NodeType.FieldStart, true);

            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType != FieldType.FieldHyperlink)
                {
                    continue;
                }

                Hyperlink hyperlink = new Hyperlink(fieldStart);
                if (hyperlink.IsLocal)
                {
                    // We use "Hyperlink to a place in this document" feature of Microsoft Word
                    // to create local hyperlinks between topics within the same doc file.
                    // It causes MS Word to auto generate the bookmark name.
                    string bmkName = hyperlink.Target;

                    // But we have to follow the bookmark to get the text of the topic heading paragraph
                    // in order to be able to build the proper filename of the topic file.
                    Bookmark bmk = originalDoc.Range.Bookmarks[bmkName];

                    if (bmk == null)
                    {
                        throw new Exception(string.Format("Found a link to a bookmark, but cannot locate the bookmark. Name:'{0}'.", bmkName));
                    }

                    Paragraph para      = (Paragraph)bmk.BookmarkStart.ParentNode;
                    string    topicName = para.GetText().Trim();

                    hyperlink.Target  = HeadingToFileName(topicName) + ".html";
                    hyperlink.IsLocal = false;
                }
                else
                {
                    // We "fix" URL like this:
                    // http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.Body.html
                    // by changing them into this:
                    // Aspose.Words.Body.html
                    if (hyperlink.Target.StartsWith(fixUrl) &&
                        (hyperlink.Target.Length > (fixUrl.Length + 1)))
                    {
                        hyperlink.Target = hyperlink.Target.Substring(fixUrl.Length + 1);
                    }
                }
            }
        }
コード例 #29
0
        public async Task Update(DocumentBase <TDocument> item)
        {
            // TODO: changes should all be done through stored procs and subject to security

            var result = await client.ReplaceDocumentAsync(DocumentCollectionUri, item);

            // TODO: Log all kinds of info from the result and respond to it
            // TODO: Handle failure much better than this
            if (result.StatusCode != System.Net.HttpStatusCode.Created)
            {
                throw new Exception(result.StatusCode.ToString());
            }
        }
コード例 #30
0
 /// <summary>
 /// 创建文本Paragraph
 /// </summary>
 /// <param name="docs"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public Paragraph newParagraph(DocumentBase docs, string text)
 {
     Aspose.Words.Paragraph p = new Paragraph(docs);
     if (string.IsNullOrEmpty(text))
     {
         //不进行操作
     }
     else
     {
         p.AppendChild(new Run(docs, text != null ? text : string.Empty));
     }
     return(p);
 }
コード例 #31
0
 /// <summary>
 /// Convert Excel Chart to Word Shape
 /// </summary>
 /// <param name="excelChart">Excel Chart</param>
 /// <param name="doc">Parent document</param>
 /// <returns>Word Shape</returns>
 private Aspose.Words.Drawing.Shape ConvertCartToShape(Aspose.Cells.Charts.Chart excelChart, DocumentBase doc)
 {
     //Create a new Shape
     Aspose.Words.Drawing.Shape wordsShape = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image);
     //Convert Chart to Bitmap. Now only supports to convert 2D chart to image. If the chart is 3D chart,return null.
     Bitmap chartPicture = excelChart.ToImage();
     if (chartPicture != null)
     {
         wordsShape.ImageData.SetImage(chartPicture);
         //Import Chart properties inhereted from Shape
         ImportShapeProperties(wordsShape, (Shape)excelChart.ChartObject);
         return wordsShape;
     }
     else
     {
         return null;
     }
 }
コード例 #32
0
 /// <summary>
 /// Convert Excel Picture to Word Shape
 /// </summary>
 /// <param name="excelPicture">Excel Picture</param>
 /// <param name="doc">Parent document</param>
 /// <returns>Word Shape</returns>
 private Aspose.Words.Drawing.Shape ConvertPictureToShape(Aspose.Cells.Drawing.Picture excelPicture, DocumentBase doc)
 {
     //Create new Shape
     Aspose.Words.Drawing.Shape wordsShape = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image);
     //Set image
     wordsShape.ImageData.ImageBytes = excelPicture.Data;
     //Import Picture properties inhereted from Shape
     ImportShapeProperties(wordsShape, (Aspose.Cells.Drawing.Shape)excelPicture);
     return wordsShape;
 }
コード例 #33
0
        private void FixHyperlinks(DocumentBase originalDoc, string fixUrl)
        {
            if (fixUrl.EndsWith("/"))
                fixUrl = fixUrl.Substring(0, fixUrl.Length - 1);

            NodeCollection fieldStarts = mTopicDoc.GetChildNodes(NodeType.FieldStart, true);
            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType != FieldType.FieldHyperlink)
                    continue;

                Hyperlink hyperlink = new Hyperlink(fieldStart);
                if (hyperlink.IsLocal)
                {
                    // We use "Hyperlink to a place in this document" feature of Microsoft Word
                    // to create local hyperlinks between topics within the same doc file.
                    // It causes MS Word to auto generate the bookmark name.
                    string bmkName = hyperlink.Target;

                    // But we have to follow the bookmark to get the text of the topic heading paragraph
                    // in order to be able to build the proper filename of the topic file.
                    Bookmark bmk = originalDoc.Range.Bookmarks[bmkName];

                    if (bmk == null)
                        throw new Exception(string.Format("Found a link to a bookmark, but cannot locate the bookmark. Name:'{0}'.", bmkName));

                    Paragraph para = (Paragraph)bmk.BookmarkStart.ParentNode;
                    string topicName = para.GetText().Trim();

                    hyperlink.Target = HeadingToFileName(topicName) + ".html";
                    hyperlink.IsLocal = false;
                }
                else
                {
                    // We "fix" URL like this:
                    // http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.Body.html
                    // by changing them into this:
                    // Aspose.Words.Body.html
                    if (hyperlink.Target.StartsWith(fixUrl) &&
                        (hyperlink.Target.Length > (fixUrl.Length + 1)))
                    {
                        hyperlink.Target = hyperlink.Target.Substring(fixUrl.Length + 1);
                    }
                }
            }
        }
コード例 #34
0
        /// <summary>
        /// Convert Excel Shape to Word Shape
        /// </summary>
        /// <param name="excelShape">Excel Shape</param>
        /// <param name="doc">Parent document</param>
        /// <returns>Word Shape</returns>
        private Aspose.Words.Drawing.Shape ConvertShapeToShape(Aspose.Cells.Drawing.Shape excelShape, DocumentBase doc)
        {
            //Create words Shape
            Aspose.Words.Drawing.Shape wordsShape = new Aspose.Words.Drawing.Shape(doc, ConvertDrawingShapetype(excelShape.MsoDrawingType));
            //Import properties
            ImportShapeProperties(wordsShape, excelShape);

            wordsShape.Stroked = true;
            wordsShape.Filled = true;

            return wordsShape;
        }
コード例 #35
0
 /// <summary>
 /// Convert Excel TextBox to Word TextBox
 /// </summary>
 /// <param name="excelTextBox">Excel TextBox</param>
 /// <param name="doc">Parent document</param>
 /// <returns>Word Shape</returns>
 private Aspose.Words.Drawing.Shape ConvertTextBoxToShape(Aspose.Cells.Drawing.TextBox excelTextBox, DocumentBase doc)
 {
     //Create a new TextBox
     Aspose.Words.Drawing.Shape wordsShape = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.TextBox);
     //Import TextBox properties inhereted from Shape
     ImportShapeProperties(wordsShape, (Shape)excelTextBox);
     //Import TextBox properties
     wordsShape.TextBox.LayoutFlow = ConvertDrawingTextOrientationType(excelTextBox.TextOrientationType);
     //Import text
     Run run = new Run(doc);
     if (!string.IsNullOrEmpty(excelTextBox.Text))
         run.Text = excelTextBox.Text;
     else
         run.Text = string.Empty;
     //Import text formating
     ImportFont(run.Font, excelTextBox.Font);
     //Create paragraph
     Paragraph paragraph = new Paragraph(doc);
     //Import horizontal alignment
     paragraph.ParagraphFormat.Alignment = ConvertHorizontalAlignment(excelTextBox.TextHorizontalAlignment);
     //Insert text into the paragraph
     paragraph.AppendChild(run);
     //insert Pragraph into textbox
     wordsShape.AppendChild(paragraph);
     return wordsShape;
 }