Esempio n. 1
0
        public static Post GetPost(Guid controllerID, string slug)
        {
            string key = string.Concat("Post", GetControllerItemKey(controllerID, slug));

            Post p = null;
            try
            {
                using (dbLock.Lock(key))
                {
                    p = CacheBroker.Get(key) as Post;
                    if (p == null)
                    {
                        p = Post.FindFirst(controllerID, slug);
                        if (p == null)
                        {
                            p = new Post();
                            p.Slug = "unknown";
                            p.ControllerID = Guid.Empty;
                        }
                        Cache(p, key);
                    }
                }
            }
            catch (NamedLock<string>.TimeoutException)
            {
                log.InfoFormat("Post lock timed out: {0}", key);
            }
            return p != null && p.ID != Guid.Empty ? p : null;
        }
Esempio n. 2
0
        public PostIndexingOptions(DataManager manager)
        {
            Post p = new Post();
            p.DataManager = manager;

            this.UseCustomFields = true;
            this.AddField("Title", FieldType.Text);
            this.AddField("Excerpt", FieldType.Text);
            this.AddValueField("Body", p.BodyShort, FieldType.Text);
            //this.AddField("Body", FieldType.TextUnStored);
            this.AddValueField("Path", p.Url.Path, FieldType.Keyword);
            this.AddValueField("PathExtra", p.Url.Extra, FieldType.Keyword);
            this.AddField("PublishDate", FieldType.Keyword);
            this.AddField("Status", FieldType.Keyword);

            this.AddField("Author", "UserName", FieldType.Keyword);

            if (manager["PublishDate"] is DateTime)
            {
                DateTime pubDate = p.PublishDate;
                if (pubDate > DateTime.Now)
                {
                    this.Expires = pubDate;
                }
            }

            this.Created = p.PublishDate;

            string text = string.Format("{0} {1}", p.Title, Regex.Replace(p.Body, @"\<[^\>]*\>", " "));
            this.AddValueField("Text", text, FieldType.TextUnStored);

            this.AddValueField("IsContent", true, FieldType.Keyword);
            this.AddValueField("IsContentContainer", false, FieldType.Keyword);

            this.AddValueField("ContainerFileName", p.Controller.FileName, FieldType.Keyword);
            this.AddValueField("ContainerID", p.ControllerID, FieldType.Keyword);

            this.GroupsWithViewPermissions = p.Permissions.GroupsWithViewPermissions;
        }
Esempio n. 3
0
        public void PostCreation()
        {
            Post p = new Post();
            p.ControllerID = new Guid("51799860-8138-43b4-9584-183af29503e4");
            p.Slug = p.Title = "Test Post";
            p.Body = "This is long and eloquent";
            p.ID = Guid.Empty;
            p.PublishDate = DateTime.Now;
            p.UserName = "******";
            p.Status = PublishStatus.Published;

            p.Save();

            Assert.AreNotEqual(p.ID, Guid.Empty, "The new ID was not returned");
        }
Esempio n. 4
0
        public static Post GetNextWithoutTags(Guid id)
        {
            Post p = new Post();
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("ID", id);
            ActiveCollection<Post> results = p.DataManager.List("GetNextWithoutTags", parameters, new ActiveCollection<Post>(), -1, -1)
                as ActiveCollection<Post>;

            if (results != null && results.Count > 0)
            {
                return results[0];
            }
            else
            {
                return null;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Ensures that the list of posts has been set.
        /// </summary>
        public void EnsurePosts()
        {
            if (this.DataSource == null)
            {
                Dictionary<string, object> parameters = this.BuildQueryParameters();

                int page = 1;
                if (!this.IgnoreUrlParameters && Params["Page"] != null)
                {
                    int.TryParse(Params["Page"], out page);
                }
                if (this.pageNumber == 0) this.PageNumber = page;

                int start = (this.PageNumber - 1) * pageSize;
                if (start < 0) start = 0;
                int end = start + pageSize;

                parameters.Add("RowIndex_start", start);
                parameters.Add("RowIndex_end", end);

                ActiveCollection<Post> posts = Post.Find(parameters);

                if (this.Mode == PostsDisplayMode.Single && posts.Count == 1)
                {
                    this.singlePost = posts[0];
                    Page.SetCacheDependency(this.Content);
                }

                Page.SetCacheDependency(this.Content);

                this.DataSource = posts;
                this.pageCount = posts.PageCount(this.PageSize);
            }
        }