当前位置: 首页>>代码示例>>C#>>正文


C# Document.Compare方法代码示例

本文整理汇总了C#中Document.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Compare方法的具体用法?C# Document.Compare怎么用?C# Document.Compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Compare方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compare

        /// <summary>
        /// Compare the two documents using Aspose.Words and save the result as a Word document
        /// </summary>
        /// <param name="document1">First document</param>
        /// <param name="document2">Second document</param>
        /// <param name="comparisonDocument">Comparison document</param>
        public void Compare(string document1, string document2, string comparisonDocument, ref int added, ref int deleted)
        {
            added = 0;
            deleted = 0;

            // Load both documents in Aspose.Words
            Document doc1 = new Document(document1);
            Document doc2 = new Document(document2);
            Document docComp = new Document(document1);
            DocumentBuilder builder = new DocumentBuilder(docComp);

            doc1.Compare(doc2, "a", DateTime.Now);

            foreach (Revision revision in doc1.Revisions)
            {
                switch (revision.RevisionType)
                {
                    case RevisionType.Insertion:
                        added++;
                        break;
                    case RevisionType.Deletion:
                        deleted++;
                        break;
                }
                Console.WriteLine(revision.RevisionType + ": " + revision.ParentNode);
            }

            Debug.WriteLine("Revisions: " + doc1.Revisions.Count);
            doc1.Save(comparisonDocument);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:36,代码来源:DocumentComparisonUtil.cs

示例2: NormalComparison

 private static void NormalComparison(string dataDir)
 {
     // ExStart:NormalComparison
     Document docA = new Document(dataDir + "TestFile.doc");
     Document docB = new Document(dataDir + "TestFile - Copy.doc");
     // DocA now contains changes as revisions. 
     docA.Compare(docB, "user", DateTime.Now); 
     // ExEnd:NormalComparison                     
 }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:9,代码来源:CompareDocument.cs

示例3: CompareForEqual

 private static void CompareForEqual(string dataDir)
 {
     // ExStart:CompareForEqual
     Document docA = new Document(dataDir + "TestFile.doc");
     Document docB = new Document(dataDir + "TestFile - Copy.doc");
     // DocA now contains changes as revisions. 
     docA.Compare(docB, "user", DateTime.Now);
     if (docA.Revisions.Count == 0)
         Console.WriteLine("Documents are equal");
     else
         Console.WriteLine("Documents are not equal");
     // ExEnd:CompareForEqual                     
 }  
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:13,代码来源:CompareDocument.cs

示例4: Execute

        protected override void Execute(CodeActivityContext executionContext)
        {
            // Get Values from the Input Parameters
            bool Logging = EnableLogging.Get(executionContext);
            string LicenseFilePath = LicenseFile.Get(executionContext);
            string LogFilePath = LogFile.Get(executionContext);
            int detectIn = DetectIn.Get(executionContext);
            OutputAttachmentId.Set(executionContext, new EntityReference("annotation", Guid.Empty));

            if (Logging)
                Log("Execution Started", LogFilePath);

            // Creating CRM service from Context
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                // Applying Licence for Aspose (If Exist)
                if (Logging)
                    Log("Enable Licensing", LogFilePath);
                if (LicenseFilePath != "" && File.Exists(LicenseFilePath))
                {
                    License Lic = new License();
                    Lic.SetLicense(LicenseFilePath);
                    if (Logging)
                        Log("License Set", LogFilePath);
                }
            }
            catch (Exception ex)
            {
                Log("Error while applying license: " + ex.Message, LogFilePath);
            }

            if (detectIn == 0) // under this record
            {
                Guid ThisRecordId = context.PrimaryEntityId;
                string RecordType = context.PrimaryEntityName;
                Document Result = new Document();
                DocumentBuilder ResultWriter = new DocumentBuilder(Result);
                if (Logging)
                    Log("Working under all attachments under this record", LogFilePath);
                // Retrieve All attachments under this Record
                QueryExpression RetrieveNoteQuery = new QueryExpression("annotation");
                RetrieveNoteQuery.ColumnSet = new ColumnSet(new string[] { "filename", "subject", "documentbody" });
                RetrieveNoteQuery.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, ThisRecordId));
                if (Logging)
                    Log("Executing Query to retrieve All Notes within this record", LogFilePath);
                EntityCollection Notes = service.RetrieveMultiple(RetrieveNoteQuery);
                // Loop through All Notes
                foreach (Entity Note in Notes.Entities)
                {
                    try
                    {
                        if (Note.Contains("documentbody"))
                        {
                            string FileName = "";
                            if (Note.Contains("filename"))
                                FileName = Note["filename"].ToString();

                            // Read Attachment in Aspose
                            byte[] DocumentBody = Convert.FromBase64String(Note["documentbody"].ToString());
                            MemoryStream fileStream = new MemoryStream(DocumentBody);
                            Document doc = new Document(fileStream);

                            ResultWriter.Writeln("Comparing Document: " + FileName);
                            ResultWriter.StartTable();

                            // Comparing document with other attachments
                            foreach (Entity OtherNote in Notes.Entities)
                            {
                                if (OtherNote.Id != Note.Id)
                                {
                                    if (OtherNote.Contains("documentbody"))
                                    {
                                        string OtherFileName = "";
                                        if (OtherNote.Contains("filename"))
                                            OtherFileName = OtherNote["filename"].ToString();
                                        // Reading attachment in Aspose
                                        byte[] OtherDocumentBody = Convert.FromBase64String(OtherNote["documentbody"].ToString());
                                        MemoryStream fileStream2 = new MemoryStream(OtherDocumentBody);
                                        Document doc2 = new Document(fileStream);

                                        ResultWriter.InsertCell();
                                        ResultWriter.Write(OtherFileName);

                                        // Compare documents
                                        doc.Compare(doc2, "a", DateTime.Now);
                                        if (doc.Revisions.Count == 0)
                                        {
                                            // If documents are same
                                            ResultWriter.InsertCell();
                                            ResultWriter.Write("Duplicate Documents");
                                        }
                                        ResultWriter.EndRow();
                                    }
                                }
                            }
                            ResultWriter.EndTable();
//.........这里部分代码省略.........
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:101,代码来源:DuplicateDocument.cs

示例5: CompareDocumentWithRevisions

 public void CompareDocumentWithRevisions()
 {
     Document doc1 = new Document(MyDir + "Document.Compare.1.doc");
     Document docWithRevision = new Document(MyDir + "Document.Compare.Revisions.doc");
     
     if (docWithRevision.Revisions.Count > 0)
         Assert.That(() => docWithRevision.Compare(doc1, "authorName", DateTime.Now),
         Throws.TypeOf<InvalidOperationException>());
 }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:9,代码来源:ExDocument.cs

示例6: CompareEx

        public void CompareEx()
        {
            //ExStart
            //ExFor:Document.Compare
            //ExSummary:Shows how to apply the compare method to two documents and then use the results. 
            Document doc1 = new Document(MyDir + "Document.Compare.1.doc");
            Document doc2 = new Document(MyDir + "Document.Compare.2.doc");

            // If either document has a revision, an exception will be thrown.
            if (doc1.Revisions.Count == 0 && doc2.Revisions.Count == 0)
                doc1.Compare(doc2, "authorName", DateTime.Now);

            // If doc1 and doc2 are different, doc1 now has some revisons after the comparison, which can now be viewed and processed.
            foreach (Revision r in doc1.Revisions)
                Console.WriteLine(r.RevisionType);

            // All the revisions in doc1 are differences between doc1 and doc2, so accepting them on doc1 transforms doc1 into doc2.
            doc1.Revisions.AcceptAll();

            // doc1, when saved, now resembles doc2.
            doc1.Save(MyDir + @"\Artifacts\Document.CompareEx.doc");
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:23,代码来源:ExDocument.cs


注:本文中的Document.Compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。