Ejemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="filePath"></param>
 public Parser(string filePath, Document document)
 {
     Doc = document;
     Stack = new ModeStack();
     RtfReader reader = new RtfReader(this);
     reader.LoadRtfFile(filePath);
     reader.Parse();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the work in the background task
        /// </summary>
        public override void ExecuteWork()
        {
            OriginalDocument = new Document(OriginalFilePath);
            NewDocument = new Document(NewFilePath);

            NewDocument.UpdateState(OriginalDocument);

            PerformDelta(Specifications);
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="aDictionary"></param>
 /// <param name="importResult"></param>
 public DeltaImportReportHandler(Dictionary aDictionary, Document importResult, string baseFileName)
     : base(aDictionary)
 {
     createFileName(baseFileName);
     ImportResult = importResult;
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     Updates the state of the paragraphs located in source according to the original content, located in original
        /// </summary>
        /// <param name="source">The source paragraphs, to be updated</param>
        /// <param name="original">The original file content</param>
        public void UpdateState(Document original)
        {
            // Find paragraphs that have been inserted and those that have been modified
            foreach (Paragraph p in Paragraphs.Values)
            {
                Paragraph originalParagraph = original.FindParagraph(p.Id);
                if (originalParagraph != null)
                {
                    if (originalParagraph.Text.Equals(p.Text))
                    {
                        p.State = Paragraph.ParagraphState.NoChange;
                    }
                    else
                    {
                        p.OriginalText = originalParagraph.Text;
                        p.State = Paragraph.ParagraphState.Changed;

                        // Maybe the row has been moved (new row inserted before), or this is a new row
                        TableRow row = p as TableRow;
                        TableRow originalRow = originalParagraph as TableRow;
                        if (originalRow != null)
                        {
                            // Try to determine if the paragraph as been moved (instead of changed)
                            // The paragraph has been moved when we can find it, at another location in the original table
                            foreach (Paragraph otherParagraph in original.Paragraphs.Values)
                            {
                                TableRow otherRow = otherParagraph as TableRow;
                                if (otherRow != null && otherRow.EnclosingParagraph == originalRow.EnclosingParagraph)
                                {
                                    if (otherRow.Text.Equals(p.Text))
                                    {
                                        p.State = Paragraph.ParagraphState.Moved;
                                        p.OriginalText = otherRow.Id;
                                        break;
                                    }
                                }
                            }
                            if (p.State == Paragraph.ParagraphState.Changed)
                            {
                                // If the paragraph has not been moved, try to determine if the paragraph has been inserted
                                // The paragraph has been inserted if the corresponding paragraph in the original table
                                // can be found at another location of this table
                                foreach (Paragraph otherParagraph in Paragraphs.Values)
                                {
                                    TableRow otherRow = otherParagraph as TableRow;
                                    if (otherRow != null && otherRow.EnclosingParagraph == row.EnclosingParagraph)
                                    {
                                        if (otherRow.Text.Equals(originalRow.Text))
                                        {
                                            p.State = Paragraph.ParagraphState.Inserted;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Original paragraph could not be found => This is a new paragraph
                    p.State = Paragraph.ParagraphState.Inserted;

                    TableRow originalRow = originalParagraph as TableRow;
                    if (originalRow != null)
                    {
                        // Try to determine if the paragraph as been moved (instead of changed)
                        // The paragraph has been moved when we can find it, at another location in the original table
                        foreach (Paragraph otherParagraph in original.Paragraphs.Values)
                        {
                            TableRow otherRow = otherParagraph as TableRow;
                            if (otherRow != null && otherRow.EnclosingParagraph == originalRow.EnclosingParagraph)
                            {
                                if (otherRow.Text.Equals(p.Text))
                                {
                                    p.State = Paragraph.ParagraphState.Moved;
                                    p.OriginalText = otherRow.Id;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            // Find paragraphs that have been deleted
            foreach (Paragraph p in original.Paragraphs.Values)
            {
                Paragraph newParagraph = FindParagraph(p.Id);
                if (newParagraph == null)
                {
                    p.State = Paragraph.ParagraphState.Deleted;
                    Paragraphs.Add(p.Id, p);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the state of the paragraphs located in source according to the original content, located in original
        /// </summary>
        /// <param name="source">The source paragraphs, to be updated</param>
        /// <param name="original">The original file content</param>
        public void UpdateState(Document original)
        {
            // Find paragraphs that have been inserted and those that have been modified
            foreach (Paragraph p in Paragraphs.Values)
            {
                Paragraph originalParagraph = original.FindParagraph(p.Id);
                if (originalParagraph != null)
                {
                    if (originalParagraph.Text.Equals(p.Text))
                    {
                        p.State = Paragraph.ParagraphState.NoChange;
                    }
                    else
                    {
                        p.OriginalText = originalParagraph.Text;
                        p.State = Paragraph.ParagraphState.Changed;
                    }
                }
                else
                {
                    // Original paragraph could not be found => This is a new paragraph
                    p.State = Paragraph.ParagraphState.Inserted;
                }
            }

            // Find paragraphs that have been deleted
            foreach (Paragraph p in original.Paragraphs.Values)
            {
                Paragraph newParagraph = FindParagraph(p.Id);
                if (newParagraph == null)
                {
                    p.State = Paragraph.ParagraphState.Deleted;
                    Paragraphs.Add(p.Id, p);
                }
            }
        }