Пример #1
0
 public void AddComments([NotNull] CommentBlock commentBlock)
 {
     foreach (var comment in commentBlock.Comments)
     {
         var text = comment.GetText();
         if (!text.Contains("method guid:"))
         {
             var trimmedText = text.Trim(' ', '\r', '\n', '\t');
             Comments.Add(trimmedText);
         }
     }
 }
Пример #2
0
        string WriteParagraph(CommentBlock para, bool writeCode)
        {
            string str = "\n\n";

            if (writeCode)
            {
                str += '\t';
            }

            str += WriteCommentBlock(para, writeCode);
            str += "\n\n";

            return(str);
        }
        public ActionResult AddComment(SitePageData currentPage, string commentName, string commentText)
        {
            // get (or create if necessary) the folder for comments for the current page
            ContentReference commentsFolderReference;

            if (!ContentReference.IsNullOrEmpty(currentPage.CommentFolder))
            {
                commentsFolderReference = currentPage.CommentFolder;
            }
            else
            {
                // get the start page's comments folder
                StartPage        start = repo.Get <StartPage>(ContentReference.StartPage);
                ContentReference siteCommentsFolderReference;
                siteCommentsFolderReference = start.CommentFolder;

                // create a comments folder for this page
                ContentFolder commentsFolder = repo.GetDefault <ContentFolder>(start.CommentFolder);
                commentsFolder.Name     = $"{currentPage.Name} (Comments)";
                commentsFolderReference = repo.Save(commentsFolder,
                                                    EPiServer.DataAccess.SaveAction.Publish,
                                                    EPiServer.Security.AccessLevel.Publish);

                currentPage = currentPage.CreateWritableClone() as SitePageData;
                currentPage.CommentFolder = commentsFolderReference;
                repo.Save(currentPage,
                          EPiServer.DataAccess.SaveAction.Publish,
                          EPiServer.Security.AccessLevel.NoAccess);
            }

            // create the comment in the page's Comments folder
            CommentBlock comment = repo.GetDefault <CommentBlock>(commentsFolderReference);

            comment.When        = DateTime.Now;
            commentName         = string.IsNullOrWhiteSpace(commentName) ? "Anonymous" : commentName;
            comment.CommentName = commentName;
            comment.CommentText = commentText;

            IContent saveableComment = comment as IContent;

            saveableComment.Name = commentName;
            repo.Save(saveableComment,
                      EPiServer.DataAccess.SaveAction.Publish,
                      EPiServer.Security.AccessLevel.Publish);

            // reload the original page
            return(RedirectToAction("Index"));
        }
        public ActionResult ReportComment(SitePageData currentPage, ContentReference id)
        {
            CommentBlock comment = repo.Get <CommentBlock>(id);

            IVersionable version = comment.CreateWritableClone() as IVersionable;

            version.StopPublish = DateTime.Now;

            // to report a comment the current user should have at least Read permission
            repo.Save(version as IContent,
                      EPiServer.DataAccess.SaveAction.Publish,
                      EPiServer.Security.AccessLevel.Read);

            // reload the original page
            return(RedirectToAction("Index"));
        }
Пример #5
0
        protected void ParseCodeBlocks()
        {
            MatchCollection matches = _codeRegex.Matches(_doc.Contents);
            CodeBlock       cb      = null;

            foreach (Match m in matches)
            {
                string s     = m.Value;
                Block  block = null;
                if (s.StartsWith("<%=") || s.StartsWith("<%:"))
                {
                    block = new ExpressionBlock();
                }
                else if (s.StartsWith("<%--"))
                {
                    block = new CommentBlock();
                }
                else if (s.StartsWith("<asp:ContentPlaceHolder"))
                {
                    string id = m.Groups["id"].Value;
                    block = new ContentPlaceHolderBlock {
                        ID = id
                    };
                }
                else
                {
                    block = new CodeBlock();
                    if (cb == null)
                    {
                        cb         = (CodeBlock)block;
                        cb.IsFirst = true;
                    }
                    else
                    {
                        cb.NextCodeBlock = (CodeBlock)block;
                        cb = (CodeBlock)block;
                    }
                }
                block.Index  = m.Index;
                block.Length = m.Length;
                _doc.Blocks.Add(block);
            }
        }
        public void FindAllProductCommentsTest()
        {
            using (var scope = new TransactionScope())
            {
                var category = CreateCategory(categoryName);
                var product  = CreateProduct("anotherProductNameTest", productPrice,
                                             productDate, productQuantity, category.categoryId);
                var user = CreateUser();

                List <long> tagIds1 = new List <long>();
                List <long> tagIds2 = new List <long>();
                tagIds1.Add(CreateTag(tagName1).tagId);
                tagIds2.Add(CreateTag(tagName2).tagId);

                List <string> commentsBody = new List <string>
                {
                    commentBody,
                    "comment2"
                };

                List <long> commentsIds = new List <long>
                {
                    productService.AddComment(product.productId, user.usrId, commentsBody[0], tagIds1),
                    productService.AddComment(product.productId, user.usrId, commentsBody[1], tagIds2)
                };

                CommentBlock listComments = productService.FindAllProductComments(product.productId);

                // Check data
                Assert.AreEqual(commentsIds.Count, listComments.Comments.Count);

                for (int i = 0; i < listComments.Comments.Count; i++)
                {
                    Assert.AreEqual(commentsIds[i], listComments.Comments[i].commentId);
                    Assert.AreEqual(user.usrId, listComments.Comments[i].userId);
                    Assert.AreEqual(commentsBody[i], listComments.Comments[i].comment1);
                    Assert.AreEqual(System.DateTime.Now.Date, listComments.Comments[i].commentDate.Date);
                }

                Assert.AreEqual(tagName1, listComments.Comments[0].Tags.ToList()[0].tagName);
                Assert.AreEqual(tagName2, listComments.Comments[1].Tags.ToList()[0].tagName);
            }
        }
Пример #7
0
 public CommentWrapper([NotNull] CommentBlock comment)
 {
     Comment  = comment;
     WasFound = false;
 }
Пример #8
0
 public CommentListItem(CommentBlock term, CommentBlock description)
 {
     Term        = term;
     Description = description;
 }
Пример #9
0
 public ParamComments(string name, CommentBlock description)
 {
     Name        = name ?? "";
     Description = description;
 }
Пример #10
0
 internal static void commentblock_child(this TextWriter trapFile, CommentBlock commentBlock, CommentLine commentLine, int child)
 {
     trapFile.WriteTuple("commentblock_child", commentBlock, commentLine, child);
 }
Пример #11
0
 internal static void commentblock(this TextWriter trapFile, CommentBlock k)
 {
     trapFile.WriteTuple("commentblock", k);
 }
Пример #12
0
 internal static Tuple commentblock_child(CommentBlock commentBlock, CommentLine commentLine, int child) => new Tuple("commentblock_child", commentBlock, commentLine, child);
Пример #13
0
 public string WriteCodeInline(CommentBlock code)
 {
     return($"`{WriteCommentBlock(code)}`");
 }
Пример #14
0
 public string WriteCodeBlock(CommentBlock code)
 {
     return(WriteParagraph(code, true));
 }
Пример #15
0
 public string WriteParagraph(CommentBlock para)
 {
     return(WriteParagraph(para, false));
 }
Пример #16
0
 internal static Tuple commentblock(CommentBlock k) => new Tuple("commentblock", k);
Пример #17
0
 internal static Tuple commentblock_binding(CommentBlock commentBlock, Label entity, Binding binding) => new Tuple("commentblock_binding", commentBlock, entity, binding);
Пример #18
0
 public string WriteCommentBlock(CommentBlock block)
 {
     return(WriteCommentBlock(block, false));
 }
Пример #19
0
 internal static Tuple commentblock_location(CommentBlock k, Location l) => new Tuple("commentblock_location", k, l);
        protected void Page_Load(object sender, EventArgs e)
        {
            int  startIndex, count;
            long productId;

            lnkPrevious.Visible   = false;
            lnkNext.Visible       = false;
            lblNoComments.Visible = false;
            btnDelete.Visible     = false;
            btnModify.Visible     = false;

            /* Get productId */
            try
            {
                productId = long.Parse(Request.Params.Get("product"));
                btnDelete.Attributes["name"] = productId.ToString();
            }
            catch (ArgumentNullException)
            {
                lblNoComments.Visible = true;
                lnkBack.NavigateUrl   = "~/Pages/Product/ProductSearch.aspx";
                return;
            }

            lnkBack.NavigateUrl = "~/Pages/Product/ProductDetails.aspx?product=" + productId.ToString();

            /* Get Start Index */
            try
            {
                startIndex = int.Parse(Request.Params.Get("startIndex"));
            }
            catch (ArgumentNullException)
            {
                startIndex = 0;
            }

            /* Get Count */
            try
            {
                count = int.Parse(Request.Params.Get("count"));
            }
            catch (ArgumentNullException)
            {
                count = Settings.Default.PracticaMaD_defaultCount;
            }

            /* Get the Service */
            IIoCManager     iocManager     = (IIoCManager)HttpContext.Current.Application["managerIoC"];
            IProductService productService = iocManager.Resolve <IProductService>();

            /* Get Products Info */
            CommentBlock commentBlock =
                productService.FindAllProductComments(productId, startIndex, count);

            if (commentBlock.Comments.Count == 0)
            {
                lblNoComments.Visible = true;
                return;
            }

            gvProducts.DataSource = commentBlock.Comments;
            gvProducts.DataBind();

            /* "Previous" link */
            if ((startIndex - count) >= 0)
            {
                string url =
                    "~/Pages/Product/ProductComments.aspx" + "?product=" + productId +
                    "&startIndex=" + (startIndex - count) + "&count=" + count;

                lnkPrevious.NavigateUrl = Response.ApplyAppPathModifier(url);
                lnkPrevious.Visible     = true;
            }

            /* "Next" link */
            if (commentBlock.ExistMoreComments)
            {
                string url =
                    "~/Pages/Product/ProductComments.aspx" + "?product=" + productId +
                    "&startIndex=" + (startIndex + count) + "&count=" + count;

                lnkNext.NavigateUrl = Response.ApplyAppPathModifier(url);
                lnkNext.Visible     = true;
            }

            Comment comment = null;

            if (SessionManager.IsUserAuthenticated(Context))
            {
                try
                {
                    comment = productService.FindCommentByProductAndUser(productId,
                                                                         SessionManager.GetUserSession(Context).UserProfileId);

                    cellOwnCommentId.Text          = comment.commentId.ToString();
                    cellOwnCommentProfileName.Text = comment.UserProfile.loginName;
                    cellOwnCommentBody.Text        = comment.comment1;
                    cellOwnCommentDate.Text        = comment.commentDate.ToString("d/M/yyyy");
                    cellOwnCommentTags.Text        = "";
                    foreach (Tag tag in comment.Tags)
                    {
                        cellOwnCommentTags.Text += tag.tagName + " <br/>";
                    }

                    ownComment.Visible = true;
                    btnDelete.Visible  = true;
                    btnModify.Visible  = true;
                }
                catch (InstanceNotFoundException)
                {
                    ownComment.Visible = false;
                }
            }
            else
            {
                ownComment.Visible = false;
            }
        }
Пример #21
0
 internal static void commentblock_binding(this TextWriter trapFile, CommentBlock commentBlock, Label entity, CommentBinding binding)
 {
     trapFile.WriteTuple("commentblock_binding", commentBlock, entity, (int)binding);
 }
Пример #22
0
 static CommentBlock()
 {
     OpenBlock = new CommentBlock { GrammarSegment = GrammarSegment.CommentOpen };
     CloseBlock = new CommentBlock { GrammarSegment = GrammarSegment.CommentClose };
 }
Пример #23
0
 internal static void commentblock_location(this TextWriter trapFile, CommentBlock k, Location l)
 {
     trapFile.WriteTuple("commentblock_location", k, l);
 }
Пример #24
0
        public void Generate(AspxDocument doc, string outfile)
        {
            using (StreamWriter sw = new StreamWriter(outfile, false, new UTF8Encoding(true)))
            {
                if (!string.IsNullOrEmpty(doc.Inherits))
                {
                    //sw.WriteLine(string.Format("@inherits {0}", doc.Inherits));
                }


                foreach (Directive directive in doc.Directives)
                {
                    PageDirective pageDirective = directive as PageDirective;
                    if (pageDirective != null)
                    {
                        if (!string.IsNullOrEmpty(pageDirective.MasterPageFile))
                        {
                            sw.WriteLine(string.Format("@{{\r\n\tLayout = \"{0}\";\r\n}}", pageDirective.MasterPageFile.Replace(".Master", ".cshtml")));
                        }
                    }

                    ImportDirective importDirective = directive as ImportDirective;
                    if (importDirective != null)
                    {
                        sw.WriteLine(string.Format("@using {0}", importDirective.Namespace));
                    }
                }

                bool afterCodeBlock = false;
                foreach (Block block in doc.Blocks)
                {
                    HtmlBlock htmlBlock = block as HtmlBlock;
                    if (htmlBlock != null)
                    {
                        string contents = doc.Contents.Substring(block.Index, block.Length);
                        Regex  regex    = new Regex("^\\s*<"); //Check if started with <
                        if (!afterCodeBlock || regex.IsMatch(contents))
                        {
                            sw.Write(contents); //Write the contents directlhy
                        }
                        else
                        {
                            //Wrap it inside <text>...</text>
                            sw.Write("<text>");
                            sw.Write(contents);
                            sw.Write("</text>");
                        }
                    }

                    afterCodeBlock = false;
                    CodeBlock codeBlock = block as CodeBlock;
                    if (codeBlock != null)
                    {
                        if (codeBlock.IsFirst)
                        {
                            sw.WriteLine(" @{");
                        }

                        sw.WriteLine("\r\n" + doc.Contents.Substring(block.Index + 2, block.Length - 4));

                        if (codeBlock.IsLast)
                        {
                            sw.WriteLine("}");
                        }

                        afterCodeBlock = true;
                    }

                    ExpressionBlock expressionBlock = block as ExpressionBlock;
                    if (expressionBlock != null)
                    {
                        sw.Write(string.Format("@{0} ", doc.Contents.Substring(block.Index + 3, block.Length - 5).Trim()));
                    }

                    CommentBlock commentBlock = block as CommentBlock;
                    if (commentBlock != null)
                    {
                        sw.Write(string.Format("@*{0}*@", doc.Contents.Substring(block.Index + 3, block.Length - 6)));
                    }

                    ContentPlaceHolderBlock cphBlock = block as ContentPlaceHolderBlock;
                    if (cphBlock != null)
                    {
                        if ("MainContent".Equals(cphBlock.ID))
                        {
                            sw.WriteLine("\r\n\t@RenderBody()");
                        }
                    }
                }
            }
        }