예제 #1
0
        /// <summary>
        /// CommentEx object, Get support mothod.
        /// </summary>
        /// <param name="commentsPart">Target comment include commentsPart</param>
        /// <param name="commentsExPart">Target comment include commentsExPart</param>
        /// <param name="commentID">Comment ID</param>
        /// <returns>CommentEx Object</returns>
        private W15.CommentEx GetCommentEx(WordprocessingCommentsPart commentsPart, WordprocessingCommentsExPart commentsExPart, string commentID)
        {
            Comment   comment = GetComment(commentsPart, commentID);
            Paragraph p       = comment.Descendants <Paragraph>().First();

            W15.CommentEx commentEx = commentsExPart.CommentsEx.Descendants <W15.CommentEx>().Where(e => e.ParaId.Value == p.ParagraphId.Value).Single();

            return(commentEx);
        }
예제 #2
0
        /// <summary>
        /// Verify Comment and CommentEx
        /// </summary>
        /// <param name="filePath">Verifying target file path</param>
        /// <param name="log">Logger</param>
        public void VerifyElements(string filePath, VerifiableLog log)
        {
            using (WordprocessingDocument package = WordprocessingDocument.Open(filePath, false))
            {
                WordprocessingCommentsPart   commentPart   = package.MainDocumentPart.WordprocessingCommentsPart;
                WordprocessingCommentsExPart commentExPart = package.MainDocumentPart.WordprocessingCommentsExPart;
                Comment       comment   = null;
                W15.CommentEx commentEx = null;

                //2.1 Verifying comment text
                comment = GetComment(commentPart, CommentIDs.CommentID1);
                Text text = comment.Descendants <Text>().First();
                log.Verify(text.Text == CommentStrings.CommentChangeString1, "Verify comment text.");

                //2.2 Verifying commnet initials attribute
                comment = GetComment(commentPart, CommentIDs.CommentID1);
                log.Verify(comment.Initials == CommentInitials.Initial2, "Verify comment attribute of initials.");

                //2.2 Verifying commnet date attribute
                log.Verify(comment.Date.Value.Year == 2015 &&
                           comment.Date.Value.Month == 12 &&
                           comment.Date.Value.Day == 24 &&
                           comment.Date.Value.Hour == 12 &&
                           comment.Date.Value.Minute == 34 &&
                           comment.Date.Value.Second == 56 &&
                           comment.Date.Value.Millisecond == 77, "Verify comment attribute of date.");

                //2.2 Verifying commnet author attribute
                log.Verify(comment.Author == CommentAuthors.Author2, "Verify comment attribute of author.");

                //2.3 Verifying comment parent-child relationship, Case of parent attribute deleteing.
                commentEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2);
                log.Verify(commentEx.ParaIdParent == null, "Verify parent-child relationship. Parent is null.");

                //2.3 Verifying comment parent-child relationship, Case of parent attribute appending.
                commentEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID3);
                W15.CommentEx comEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2);
                log.Verify(commentEx.ParaIdParent.Value == GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2).ParaId.Value, "Verify parent-child relationship. This ID is [{0}]. Parent ID is [{0}].", commentEx.ParaId, commentEx.ParaIdParent);

                //2.4 Verifying CommnetEx done attribute, Case of value "1" setting.
                log.Verify(GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID1).Done == true, "Verify CommentEx attribute of done.");

                //2.4 Verifying CommnetEx done attribute, Case of value "0" setting.
                log.Verify(GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID3).Done == false, "Verify CommentEx attribute of done.");

                //2.5 Verifying comment and CommentEx append.
                log.Verify(GetComment(commentPart, CommentIDs.CommentID4) != null &&
                           GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID4) != null, "Verify Comment and CommentEx append.");

                //2.5 Verifying comment and CommentEx append.
                log.Verify(GetComment(commentPart, CommentIDs.CommentID5) != null &&
                           GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID5) != null &&
                           GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID5).ParaIdParent.Value == GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID4).ParaId.Value,
                           "Verify Comment and CommentEx append, And CommentEx parent-child relationship");
            }
        }
예제 #3
0
        /// <summary>
        /// Edit Comment and CommentEx
        /// </summary>
        /// <param name="filePath">Editing target file path</param>
        /// <param name="log">Logger</param>
        public void EditElements(string filePath, VerifiableLog log)
        {
            using (WordprocessingDocument package = WordprocessingDocument.Open(filePath, true))
            {
                WordprocessingCommentsPart   commentPart   = package.MainDocumentPart.WordprocessingCommentsPart;
                WordprocessingCommentsExPart commentExPart = package.MainDocumentPart.WordprocessingCommentsExPart;
                Comment       comment   = null;
                W15.CommentEx commentEx = null;

                try
                {
                    //2.1 Change comment text
                    comment = GetComment(commentPart, CommentIDs.CommentID1);
                    Text text = comment.Descendants <Text>().First();
                    text.Text = CommentStrings.CommentChangeString1;

                    log.Pass("Edited comment text. comment ID=[{0}]. comment text=[{1}].", CommentIDs.CommentID1, CommentStrings.CommentChangeString1);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.2 Change commnet initials attribute
                    comment = GetComment(commentPart, CommentIDs.CommentID1);

                    comment.Initials = CommentInitials.Initial2;
                    log.Pass("Edited comment attribute of Initials. comment ID=[{0}]. Initials=[{1}].", CommentIDs.CommentID1, CommentInitials.Initial2);

                    //2.2 Change commnet date attribute
                    comment.Date = new DateTimeValue(new DateTime(2015, 12, 24, 12, 34, 56, 77));
                    log.Pass("Edited comment attribute of Date. comment ID=[{0}]. Date=[{1}/{2}/{3}-{4}:{5}:{6}-{7}].", CommentIDs.CommentID1, 12, 24, 2015, 12, 34, 56, 77);

                    //2.2 Change commnet author attribute
                    comment.Author = CommentAuthors.Author2;
                    log.Pass("Edited comment attribute of Author. comment ID=[{0}]. Author=[{1}].", CommentIDs.CommentID1, CommentAuthors.Author2);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.3 Change comment parent-child relationship, Case of parent attribute deleteing.
                    commentEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2);
                    commentEx.ParaIdParent = null;
                    log.Pass("Edited CommentEx parent-child relationship, Set CommentEx parent id is null. comment ID=[{0}]. CommentEx.ParaIdParent=[null].", CommentIDs.CommentID2);

                    //2.3 Change comment parent-child relationship, Case of parent attribute appending.
                    commentEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID3);
                    W15.CommentEx comEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2);
                    commentEx.ParaIdParent = comEx.ParaId;
                    log.Pass("Edited CommentEx parent-child relationship, Set CommentEx parent id is comment(id=1) have id. comment ID=[{0}]. CommentEx.ParaIdParent=[{1}].", CommentIDs.CommentID3, comEx.ParaId.Value);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.4 Change CommnetEx done attribute, Case of value "1" setting.
                    GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID1).Done = true;
                    log.Pass("Edited CommentEx attribute of Done. comment ID=[{0}]. Done=[true].", CommentIDs.CommentID1);

                    //2.4 Change CommnetEx done attribute, Case of value "0" setting.
                    GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID3).Done = false;
                    log.Pass("Edited CommentEx attribute of Done. comment ID=[{0}]. Done=[false].", CommentIDs.CommentID3);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.5 Add comment and CommentEx.
                    CommentRangeStart commentRangeStart1 = new CommentRangeStart();
                    commentRangeStart1.Id = CommentIDs.CommentID4;
                    CommentRangeEnd CommentRangeEnd1 = new CommentRangeEnd();
                    CommentRangeEnd1.Id = CommentIDs.CommentID4;

                    Paragraph paragraph1 = package.MainDocumentPart.Document.Descendants <Paragraph>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First();
                    paragraph1.Descendants <Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertBeforeSelf <CommentRangeStart>(commentRangeStart1);
                    paragraph1.Descendants <Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertAfterSelf <CommentRangeEnd>(CommentRangeEnd1);

                    CommentReference commentReference1 = new CommentReference();
                    commentReference1.Id = CommentIDs.CommentID4;
                    Run run1 = new Run();
                    run1.AppendChild <CommentReference>(commentReference1);

                    paragraph1.AppendChild <Run>(run1);
                    Comment comment1 = (Comment)GetComment(commentPart, CommentIDs.CommentID1).Clone();
                    comment1.Id = CommentIDs.CommentID4;
                    comment1.Descendants <Text>().First().Text             = CommentStrings.CommentAppendString1;
                    comment1.Descendants <Paragraph>().First().ParagraphId = AppendCommentExIDs.AppendCommentID1;

                    commentPart.Comments.AppendChild <Comment>(comment1);

                    W15.CommentEx commentEx1 = new W15.CommentEx();
                    commentEx1.ParaId = AppendCommentExIDs.AppendCommentID1;
                    commentExPart.CommentsEx.AppendChild <W15.CommentEx>(commentEx1);

                    log.Pass("Append new comment. comment ID=[{0}]. comment text=[{1}]. CommentEx.ParaIdParent=[null].", CommentIDs.CommentID4, CommentStrings.CommentAppendString1);

                    //2.5 Add comment and CommentEx.
                    CommentRangeStart commentRangeStart2 = new CommentRangeStart();
                    commentRangeStart2.Id = CommentIDs.CommentID5;
                    CommentRangeEnd CommentRangeEnd2 = new CommentRangeEnd();
                    CommentRangeEnd2.Id = CommentIDs.CommentID5;

                    Paragraph paragraph2 = package.MainDocumentPart.Document.Descendants <Paragraph>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First();
                    paragraph2.Descendants <Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertBeforeSelf <CommentRangeStart>(commentRangeStart2);
                    paragraph2.Descendants <Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertAfterSelf <CommentRangeEnd>(CommentRangeEnd2);

                    CommentReference commentReference2 = new CommentReference();
                    commentReference2.Id = CommentIDs.CommentID5;
                    Run run2 = new Run();
                    run2.AppendChild <CommentReference>(commentReference2);

                    paragraph2.AppendChild <Run>(run2);
                    Comment comment2 = (Comment)GetComment(commentPart, CommentIDs.CommentID2).Clone();
                    comment2.Id = CommentIDs.CommentID5;
                    comment2.Descendants <Text>().First().Text             = CommentStrings.CommentAppendString2;
                    comment2.Descendants <Paragraph>().First().ParagraphId = AppendCommentExIDs.AppendCommentID2;

                    commentPart.Comments.AppendChild <Comment>(comment2);

                    W15.CommentEx commentEx2 = new W15.CommentEx();
                    commentEx2.ParaId       = AppendCommentExIDs.AppendCommentID2;
                    commentEx2.ParaIdParent = AppendCommentExIDs.AppendCommentID1;
                    commentExPart.CommentsEx.AppendChild <W15.CommentEx>(commentEx2);

                    log.Pass("Append new comment. comment ID=[{0}]. comment text=[{1}]. CommentEx.ParaIdParent=[{2}].", CommentIDs.CommentID5, CommentStrings.CommentAppendString2, AppendCommentExIDs.AppendCommentID1);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Edit Comment and CommentEx
        /// </summary>
        /// <param name="filePath">Editing target file path</param>
        /// <param name="log">Logger</param>
        public void EditElements(string filePath, VerifiableLog log)
        {
            using (WordprocessingDocument package = WordprocessingDocument.Open(filePath, true))
            {
                WordprocessingCommentsPart commentPart = package.MainDocumentPart.WordprocessingCommentsPart;
                WordprocessingCommentsExPart commentExPart = package.MainDocumentPart.WordprocessingCommentsExPart;
                Comment comment = null;
                W15.CommentEx commentEx = null;

                try
                {
                    //2.1 Change comment text
                    comment = GetComment(commentPart, CommentIDs.CommentID1);
                    Text text = comment.Descendants<Text>().First();
                    text.Text = CommentStrings.CommentChangeString1;

                    log.Pass("Edited comment text. comment ID=[{0}]. comment text=[{1}].", CommentIDs.CommentID1, CommentStrings.CommentChangeString1);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.2 Change commnet initials attribute
                    comment = GetComment(commentPart, CommentIDs.CommentID1);

                    comment.Initials = CommentInitials.Initial2;
                    log.Pass("Edited comment attribute of Initials. comment ID=[{0}]. Initials=[{1}].", CommentIDs.CommentID1, CommentInitials.Initial2);

                    //2.2 Change commnet date attribute
                    comment.Date = new DateTimeValue(new DateTime(2015, 12, 24, 12, 34, 56, 77));
                    log.Pass("Edited comment attribute of Date. comment ID=[{0}]. Date=[{1}/{2}/{3}-{4}:{5}:{6}-{7}].", CommentIDs.CommentID1, 12, 24, 2015, 12, 34, 56, 77);

                    //2.2 Change commnet author attribute
                    comment.Author = CommentAuthors.Author2;
                    log.Pass("Edited comment attribute of Author. comment ID=[{0}]. Author=[{1}].", CommentIDs.CommentID1, CommentAuthors.Author2);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.3 Change comment parent-child relationship, Case of parent attribute deleteing.
                    commentEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2);
                    commentEx.ParaIdParent = null;
                    log.Pass("Edited CommentEx parent-child relationship, Set CommentEx parent id is null. comment ID=[{0}]. CommentEx.ParaIdParent=[null].", CommentIDs.CommentID2);

                    //2.3 Change comment parent-child relationship, Case of parent attribute appending.
                    commentEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID3);
                    W15.CommentEx comEx = GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID2);
                    commentEx.ParaIdParent = comEx.ParaId;
                    log.Pass("Edited CommentEx parent-child relationship, Set CommentEx parent id is comment(id=1) have id. comment ID=[{0}]. CommentEx.ParaIdParent=[{1}].", CommentIDs.CommentID3, comEx.ParaId.Value);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.4 Change CommnetEx done attribute, Case of value "1" setting. 
                    GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID1).Done = true;
                    log.Pass("Edited CommentEx attribute of Done. comment ID=[{0}]. Done=[true].", CommentIDs.CommentID1);

                    //2.4 Change CommnetEx done attribute, Case of value "0" setting. 
                    GetCommentEx(commentPart, commentExPart, CommentIDs.CommentID3).Done = false;
                    log.Pass("Edited CommentEx attribute of Done. comment ID=[{0}]. Done=[false].", CommentIDs.CommentID3);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }

                try
                {
                    //2.5 Add comment and CommentEx.
                    CommentRangeStart commentRangeStart1 = new CommentRangeStart();
                    commentRangeStart1.Id = CommentIDs.CommentID4;
                    CommentRangeEnd CommentRangeEnd1 = new CommentRangeEnd();
                    CommentRangeEnd1.Id = CommentIDs.CommentID4;

                    Paragraph paragraph1 = package.MainDocumentPart.Document.Descendants<Paragraph>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First();
                    paragraph1.Descendants<Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertBeforeSelf<CommentRangeStart>(commentRangeStart1);
                    paragraph1.Descendants<Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertAfterSelf<CommentRangeEnd>(CommentRangeEnd1);

                    CommentReference commentReference1 = new CommentReference();
                    commentReference1.Id = CommentIDs.CommentID4;
                    Run run1 = new Run();
                    run1.AppendChild<CommentReference>(commentReference1);

                    paragraph1.AppendChild<Run>(run1);
                    Comment comment1 = (Comment)GetComment(commentPart, CommentIDs.CommentID1).Clone();
                    comment1.Id = CommentIDs.CommentID4;
                    comment1.Descendants<Text>().First().Text = CommentStrings.CommentAppendString1;
                    comment1.Descendants<Paragraph>().First().ParagraphId = AppendCommentExIDs.AppendCommentID1;

                    commentPart.Comments.AppendChild<Comment>(comment1);

                    W15.CommentEx commentEx1 = new W15.CommentEx();
                    commentEx1.ParaId = AppendCommentExIDs.AppendCommentID1;
                    commentExPart.CommentsEx.AppendChild<W15.CommentEx>(commentEx1);

                    log.Pass("Append new comment. comment ID=[{0}]. comment text=[{1}]. CommentEx.ParaIdParent=[null].", CommentIDs.CommentID4, CommentStrings.CommentAppendString1);

                    //2.5 Add comment and CommentEx.
                    CommentRangeStart commentRangeStart2 = new CommentRangeStart();
                    commentRangeStart2.Id = CommentIDs.CommentID5;
                    CommentRangeEnd CommentRangeEnd2 = new CommentRangeEnd();
                    CommentRangeEnd2.Id = CommentIDs.CommentID5;

                    Paragraph paragraph2 = package.MainDocumentPart.Document.Descendants<Paragraph>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First();
                    paragraph2.Descendants<Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertBeforeSelf<CommentRangeStart>(commentRangeStart2);
                    paragraph2.Descendants<Run>().Where(e => e.InnerText == CommentBodyStrings.Comment2).First().InsertAfterSelf<CommentRangeEnd>(CommentRangeEnd2);

                    CommentReference commentReference2 = new CommentReference();
                    commentReference2.Id = CommentIDs.CommentID5;
                    Run run2 = new Run();
                    run2.AppendChild<CommentReference>(commentReference2);

                    paragraph2.AppendChild<Run>(run2);
                    Comment comment2 = (Comment)GetComment(commentPart, CommentIDs.CommentID2).Clone();
                    comment2.Id = CommentIDs.CommentID5;
                    comment2.Descendants<Text>().First().Text = CommentStrings.CommentAppendString2;
                    comment2.Descendants<Paragraph>().First().ParagraphId = AppendCommentExIDs.AppendCommentID2;

                    commentPart.Comments.AppendChild<Comment>(comment2);

                    W15.CommentEx commentEx2 = new W15.CommentEx();
                    commentEx2.ParaId = AppendCommentExIDs.AppendCommentID2;
                    commentEx2.ParaIdParent = AppendCommentExIDs.AppendCommentID1;
                    commentExPart.CommentsEx.AppendChild<W15.CommentEx>(commentEx2);

                    log.Pass("Append new comment. comment ID=[{0}]. comment text=[{1}]. CommentEx.ParaIdParent=[{2}].", CommentIDs.CommentID5, CommentStrings.CommentAppendString2, AppendCommentExIDs.AppendCommentID1);
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }