Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                if (SessionManager.CountersEnabled)
                {
                    SessionManager.BlogService.IncrementNamedCounter(
                        SessionManager.Ticket, "SiteMap", 1);
                }

                TransitPostQueryOptions options = new TransitPostQueryOptions(0, string.Empty);
                options.PageNumber     = 0;
                options.PageSize       = 100;
                options.SortDirection  = WebServiceQuerySortDirection.Descending;
                options.SortExpression = "Created";
                options.PublishedOnly  = true;
                options.DisplayedOnly  = true;

                repeater.DataSource = SessionManager.GetCachedCollection <TransitPost>(
                    "GetPosts", SessionManager.PostTicket, options);
                repeater.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.StatusCode = 400;
            Response.Status     = ex.Message;
        }
    }
Ejemplo n.º 2
0
    public void GetData(object sender, EventArgs e)
    {
        // total number of items
        int total = SessionManager.GetCachedCollectionCount <TransitPost>("GetPostsCount",
                                                                          SessionManager.PostTicket, null);
        // number of items left
        int left = total - ((CurrentPageIndex + 1) * PageSize);

        // previous link
        linkPrev.Enabled = (CurrentPageIndex > 0);
        if (CurrentPageIndex > 0)
        {
            linkPrev.Text        = string.Format("&#171; Prev {0}", PageSize);
            linkPrev.NavigateUrl = string.Format("ListBlog.aspx?page={0}", CurrentPageIndex - 1);
        }
        // next link
        linkNext.Enabled = (left > 0);
        if (left > 0)
        {
            linkNext.NavigateUrl = string.Format("ListBlog.aspx?page={0}", CurrentPageIndex + 1);
            linkNext.Text        = string.Format("Next {0} &#187;", PageSize > left ? left : PageSize);
        }
        TransitPostQueryOptions options = new TransitPostQueryOptions(PageSize, CurrentPageIndex);

        options.SortDirection  = WebServiceQuerySortDirection.Descending;
        options.SortExpression = "Created";
        options.PublishedOnly  = !SessionManager.IsAdministrator;
        options.DisplayedOnly  = !SessionManager.IsAdministrator;
        grid.DataSource        = SessionManager.GetCachedCollection <TransitPost>(
            "GetPosts", SessionManager.PostTicket, options);
        grid.DataBind();
    }
Ejemplo n.º 3
0
    private void GetPosts(object sender, EventArgs e)
    {
        TransitPostQueryOptions options = new TransitPostQueryOptions();

        options.PageNumber     = 0;
        options.PageSize       = 25;
        options.SortDirection  = WebServiceQuerySortDirection.Descending;
        options.SortExpression = "Created";
        options.PublishedOnly  = true;
        options.DisplayedOnly  = true;

        Response.ContentType = "application/atom+xml;charset=\"utf-8\"";

        AtomFeed feed = new AtomFeed();

        feed.Title = new AtomTextConstruct(SessionManager.GetSetting("title", "Untitled"));

        List <TransitPost> posts = SessionManager.GetCachedCollection <TransitPost>(
            "GetPosts", SessionManager.PostTicket, options);

        foreach (TransitPost post in posts)
        {
            AtomEntry atomEntry = GetPost(post);
            feed.AddEntry(atomEntry);
        }

        feed.Save(Response.OutputStream);
        Response.End();
    }
Ejemplo n.º 4
0
    void grid_OnGetDataSource(object sender, EventArgs e)
    {
        TransitPostQueryOptions options = GetOptions();

        grid.DataSource = SessionManager.GetCachedCollection <TransitPost>(
            "GetPosts", SessionManager.PostTicket, options);

        GetCriteria();
    }
Ejemplo n.º 5
0
    private TransitPostQueryOptions GetOptions()
    {
        TransitPostQueryOptions options = new TransitPostQueryOptions(TopicId, Query, grid.PageSize, grid.CurrentPageIndex);

        options.DateStart = DateStart;
        options.DateEnd   = DateEnd;

        options.PublishedOnly = !SessionManager.IsAdministrator;
        options.DisplayedOnly = !SessionManager.IsAdministrator;

        options.SortDirection  = WebServiceQuerySortDirection.Descending;
        options.SortExpression = string.IsNullOrEmpty(options.Query) ? "Created" : "Rank";

        return(options);
    }
Ejemplo n.º 6
0
        public void CreateStickyPostTest()
        {
            TransitPost t_post1 = new TransitPost();

            t_post1.Body    = Guid.NewGuid().ToString();
            t_post1.Title   = Guid.NewGuid().ToString();
            t_post1.Publish = true;
            t_post1.Sticky  = true;
            t_post1.Created = t_post1.Modified = DateTime.UtcNow;
            t_post1.Id      = Blog.CreateOrUpdatePost(Ticket, t_post1);
            Assert.Greater(t_post1.Id, 0);

            Thread.Sleep(1000);

            TransitPost t_post2 = new TransitPost();

            t_post2.Body    = Guid.NewGuid().ToString();
            t_post2.Title   = Guid.NewGuid().ToString();
            t_post2.Publish = true;
            t_post2.Sticky  = false;
            t_post2.Created = t_post2.Modified = DateTime.UtcNow;
            t_post2.Id      = Blog.CreateOrUpdatePost(Ticket, t_post2);
            Assert.Greater(t_post1.Id, 0);

            TransitPostQueryOptions queryOptions = new TransitPostQueryOptions();

            queryOptions.PageNumber     = 0;
            queryOptions.PageSize       = 2;
            queryOptions.DateStart      = DateTime.MinValue;
            queryOptions.DateEnd        = DateTime.MaxValue;
            queryOptions.SortDirection  = WebServiceQuerySortDirection.Descending;
            queryOptions.SortExpression = "Created";
            TransitPost[] posts = Blog.GetPosts(Ticket, queryOptions);

            Blog.DeletePost(Ticket, t_post1.Id);
            Blog.DeletePost(Ticket, t_post2.Id);

            Assert.AreEqual(2, posts.Length);
            // make sure the sticky post is on top (the second post might not be in second position if there're other stick posts)
            Assert.AreEqual(t_post1.Id, posts[0].Id);
        }