Exemple #1
0
        public ActionResult DoPostBulkInsert(int numberOfPost)
        {
            string[] dummy = new string[6];
             dummy[0] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
             dummy[1] = "Sed ut perspiciatis unde omnis iste natus error sit <u>voluptatem</u> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?";
             dummy[2] = "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat";
             dummy[3] = "<i>Lorem ipsum dolor sit amet</i>, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.";
             dummy[4] = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.";
             dummy[5] = "<b>At vero eos et accusamus</b> et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. ";

             Random rndPost = new Random(DateTime.Now.Millisecond);
             Random rndDay = new Random(DateTime.Now.Millisecond);
             Random rndMonth = new Random(DateTime.Now.Millisecond);

             ICategoryService categoryService = IoC.Resolve<ICategoryService>();
             ITagService tagService = IoC.Resolve<ITagService>();
             IContentItemService<Post> contentItemService = IoC.Resolve<IContentItemService<Post>>();

             IEnumerable<Category> categories = categoryService.GetAllCategoriesBySite(Context.ManagedSite);
             IList<Tag> tags = tagService.GetAllTagsBySite(Context.ManagedSite);

             int categoryCount;
             int tagCount;

             Random rndCat = new Random(DateTime.Now.Millisecond);
             Random rndTag = new Random(DateTime.Now.Millisecond);

             try
             {
            using (NHTransactionScope tx = new NHTransactionScope())
            {
               // Bulk Insert
               for (int postIndex = 0; postIndex < numberOfPost; postIndex++)
               {
                  int indexPost = rndPost.Next(6);
                  if (indexPost > 5)
                     indexPost = 0;

                  int day = rndDay.Next(1, 29); // get a number of the day between 1 and 29
                  int month = rndMonth.Next(1, 12); // get a number of the day between 1 and 29

                  categoryCount = rndCat.Next(categories.Count());
                  //tagCount = rndCat.Next(tags.Count);
                  tagCount = rndCat.Next(1, 2);

                  DateTime publishedDate = new DateTime(DateTime.Now.Year, month, day);

                  if (publishedDate > DateTime.Now)
                     publishedDate = DateTime.Now.Subtract(new TimeSpan(numberOfPost, 0, 0, 0));

                  Post post = new Post()
                  {
                     Title = dummy[indexPost].StripHtml().GetFirstWords(5) + " @ " + publishedDate.ToShortDateString(),
                     Summary = null,
                     Content = dummy[indexPost],
                     WorkflowStatus = WorkflowStatus.Published,
                     AllowComments = Context.ManagedSite.AllowComments,
                     AllowPings = Context.ManagedSite.AllowPings,
                     Site = Context.ManagedSite,
                     Culture = Context.ManagedSite.DefaultCulture,
                     PublishedBy = Context.CurrentUser,
                     PublishedDate = publishedDate.ToUniversalTime()
                  };

                  if (categoryCount > 0)
                  {
                     foreach (Category item in categories)
                     {
                        if (categoryCount >= 0)
                           post.Categories.Add(item);

                        categoryCount--;
                     }
                  }

                  if (tagCount > 0)
                  {
                     foreach (Tag item in tags)
                     {
                        if (tagCount >= 0)
                           post.Tags.Add(item);

                        tagCount--;
                     }
                  }

                  // Save
                  contentItemService.Save(post);
               }

               // Commit all
               tx.VoteCommit();
            }
            MessageModel model = new MessageModel
            {
               Text = "Bulk Insert Done!!!",
               Icon = MessageModel.MessageIcon.Info,
               CssClass = "margin-topbottom",
               IsClosable = true
            };
            RegisterMessage(model, true);

             }
             catch (Exception ex)
             {
            log.Error(ex.ToString());

            MessageModel model = new MessageModel
            {
               Text = ex.Message,
               Icon = MessageModel.MessageIcon.Alert,
               CssClass = "margin-topbottom",
               IsClosable = true
            };
            RegisterMessage(model, true);
             }

             return View("Index");
        }
Exemple #2
0
        /// <summary>
        /// Common function to save a new post or update an existing one
        /// </summary>
        /// <param name="post"></param>
        /// <param name="categoryid"></param>
        /// <param name="tagid"></param>
        private void SaveOrUpdate(Post post, int[] categoryid, int[] tagid)
        {
            // TODO: content filtering!!!

             // due to the fact that the post title may be empty,
             // in that case the permalink is equal to the postid
             if (string.IsNullOrEmpty(post.Title))
            post.Title = string.Empty;

             post.Site = Context.ManagedSite;
             post.Culture = Context.ManagedSite.DefaultCulture;
             post.PublishedBy = Context.CurrentUser;
             //post.WorkflowStatus = WorkflowStatus.Published;

             // Store the published dates in UTC
             post.PublishedDate = post.PublishedDate.Value.ToUniversalTime();
             //post.PublishedUntil = post.PublishedUntil.Value.ToUniversalTime();

             if (categoryid != null)
             {
            post.Categories.Clear();
            foreach (int id in categoryid)
            {
               post.Categories.Add(categoryService.GetById(id));
            }
             }

             if (tagid != null)
             {
            post.Tags.Clear();
            foreach (int id in tagid)
            {
               post.Tags.Add(tagService.GetById(id));
            }
             }

             contentItemService.Save(post);

             // Send the pings
             SendPings(post);

             // Show the confirmation message
             MessageModel model = new MessageModel
             {
            Text = GlobalResource("Message_PostSaved"),
            Icon = MessageModel.MessageIcon.Info,
             };

             RegisterMessage(model, true);
        }
        /// <summary>
        /// Try to send trackback and pingback for each link in the content
        /// </summary>
        /// <param name="post"></param>
        private void SendPings(Post post)
        {
            if (post.AllowPings)
             {

            string partialUrl = post.GetContentUrl();
            Uri sourceUrl = new Uri(string.Concat(Request.Url.GetLeftPart(UriPartial.Authority),
                                                  "/",
                                                  partialUrl.StartsWith("~") || partialUrl.StartsWith("/")
                                                     ? partialUrl.Substring(1)
                                                     : partialUrl)
               );

            // cycle for each links in the post
            foreach (Uri url in GetUrlsFromContent(post.Content))
            {
               bool isTrackbackSent = false;

               // Get the remote web page
               string pageContent = WebUtils.DownloadWebPage(url);

               if (string.IsNullOrEmpty(pageContent) || pageContent == "\r\n")
                  continue;

               // try to get the remote trackback url
               Uri trackbackUrl = GetTrackBackUrlFromPage(pageContent);

               log.DebugFormat("AdminPostController.SendPings: TrackBackUrl = {0}", trackbackUrl.ToString());

               // try to send a trackback...
               if (trackbackUrl != null)
               {
                  TrackbackMessage message = new TrackbackMessage(post, trackbackUrl, sourceUrl);
                  isTrackbackSent = Trackback.Send(message);
               }

               // Send a pingback only if the trackback was not sended (or unsuccessfull)
               if (!isTrackbackSent)
                  Pingback.Send(sourceUrl, url);
            }

             }
        }
Exemple #4
0
        public ActionResult NewPost()
        {
            //   PostModel model = new PostModel();

             Post model = new Post();

             // Set defaults based on Site settings
             model.AllowPings = Context.ManagedSite.AllowPings;
             model.AllowComments = Context.ManagedSite.AllowComments;
             model.Site = Context.ManagedSite;

             IEnumerable<Category> list = categoryService.GetAllCategoriesBySite(Context.ManagedSite);
             ViewBag.SiteCategories = list;
             //model.SiteCategoriesSelectList = new SelectList(list, "Id", "Name");
             ViewBag.SiteTags = tagService.GetAllTagsBySite(Context.ManagedSite);
             ViewData["MonthsList"] = new SelectList(DateUtil.MonthNames(Thread.CurrentThread.CurrentUICulture, true), "Key", "Value", DateTime.Now.Month);

             // Get the full WorkflowStatus enum list, and remove the current page status value:
             IDictionary<String, String> statusList = GetLocalizedEnumList(typeof(WorkflowStatus));
             ViewBag.WorkflowStatusList = statusList;
             // Trick to force the selecteditem ( see http://blog.benhartonline.com/post/2008/11/24/ASPNET-MVC-SelectList-selectedValue-Gotcha.aspx )
             ViewData["WorkflowStatus"] = "Published";

             // Trick to force the selecteditem ( see http://blog.benhartonline.com/post/2008/11/24/ASPNET-MVC-SelectList-selectedValue-Gotcha.aspx )
             ViewData["Month"] = DateTime.Now.Month;

             return View("NewPost", model);
        }