Exemplo n.º 1
0
        public override void Apply(WordDocument doc)
        {
            _doc = doc;
            int index = 0;

            _writer.WriteStartElement("w", "comments", OpenXmlNamespaces.WordprocessingML);

            Int32 cp = doc.FIB.ccpText + doc.FIB.ccpFtn + doc.FIB.ccpHdr;

            for (int i = 0; i < doc.AnnotationsReferencePlex.Elements.Count; i++)
            {
                _writer.WriteStartElement("w", "comment", OpenXmlNamespaces.WordprocessingML);

                AnnotationReferenceDescriptor atrdPre10 = (AnnotationReferenceDescriptor)doc.AnnotationsReferencePlex.Elements[index];
                _writer.WriteAttributeString("w", "id", OpenXmlNamespaces.WordprocessingML, index.ToString());
                _writer.WriteAttributeString("w", "author", OpenXmlNamespaces.WordprocessingML, doc.AnnotationOwners[atrdPre10.AuthorIndex]);
                _writer.WriteAttributeString("w", "initials", OpenXmlNamespaces.WordprocessingML, atrdPre10.UserInitials);

                //ATRDpost10 is optional and not saved in all files
                if (doc.AnnotationReferenceExtraTable != null &&
                    doc.AnnotationReferenceExtraTable.Count > index)
                {
                    AnnotationReferenceDescriptorExtra atrdPost10 = doc.AnnotationReferenceExtraTable[index];
                    atrdPost10.Date.Convert(new DateMapping(_writer));
                }

                cp = writeParagraph(cp);
                _writer.WriteEndElement();
                index++;
            }

            _writer.WriteEndElement();

            _writer.Flush();
        }
Exemplo n.º 2
0
        public void TestComments()
        {
            foreach (FileInfo inputFile in this.files)
            {
                Document     omDoc  = loadDocument(inputFile.FullName);
                WordDocument dffDoc = new WordDocument(new StructuredStorageReader(inputFile.FullName));

                int    dffCommentCount        = dffDoc.AnnotationsReferencePlex.Elements.Count;
                int    omCommentCount         = omDoc.Comments.Count;
                string omFirstCommentInitial  = "";
                string omFirstCommentAuthor   = "";
                string dffFirstCommentInitial = "";
                string dffFirstCommentAuthor  = "";

                if (dffCommentCount > 0 && omCommentCount > 0)
                {
                    Comment omFirstComment = omDoc.Comments[1];
                    AnnotationReferenceDescriptor dffFirstComment = (AnnotationReferenceDescriptor)dffDoc.AnnotationsReferencePlex.Elements[0];

                    omFirstCommentInitial = omFirstComment.Initial;
                    omFirstCommentAuthor  = omFirstComment.Author;

                    dffFirstCommentInitial = dffFirstComment.UserInitials;
                    dffFirstCommentAuthor  = dffDoc.AnnotationOwners[dffFirstComment.AuthorIndex];
                }

                omDoc.Close(ref saveChanges, ref originalFormat, ref routeDocument);

                try
                {
                    //compare comment count
                    Assert.AreEqual(omCommentCount, dffCommentCount);

                    //compare initials
                    Assert.AreEqual(omFirstCommentInitial, dffFirstCommentInitial);

                    //compate the author names
                    Assert.AreEqual(omFirstCommentAuthor, dffFirstCommentAuthor);

                    Console.WriteLine("PASSED TestComments " + inputFile.FullName);
                }
                catch (AssertionException e)
                {
                    throw new AssertionException(e.Message + inputFile.FullName, e);
                }
            }
        }