Post start/end time

Topics: ASP.NET 2.0, Controls
Mar 26, 2009 at 10:38 PM
Hey Guys,


I am new to blogengine and think its awesome application.

I want my post to run between the desired time frame. Is that possible?
I have plans to put some ads as posts and i want those ads to run in desired time frame.

eg: If i create a post and enter start time for post as say Mar 30, Mon 9:00 am AND end time as Mar 31, Tue 9:00 am. So now i want the ad ( post) to run ( be displayed) only between that time frame and expire after that. I want the same behaviour for my RSS feeds as well.

How do i implement it??? Please recommend!!!!

Baccanalion
Mar 27, 2009 at 3:34 PM
Edited Mar 30, 2009 at 5:16 PM
Hey does any one have answere to this?? I actually want to set up time frames on content that is there in ma post
Mar 30, 2009 at 5:18 PM
Hey does any one have answere to this?? I actually want to set up time frames on content that is there in ma post
Coordinator
Mar 31, 2009 at 12:46 AM
There's already a Start time built in.  When creating a post, if you give it a future "date", then that post will not show up until that date/time arrives.  If you're logged into the blog, you'll still see the post, but people not logged in won't see it.

So the only part needed is to have an "end time".  This would require a few modifications.  You could add another date field to the Add Entry tab for "End Time" -- the field would be similar to the existing "Date" field.  You can add a new "EndTime" property in the Post class in the BE core code.  Also in the Post class, there's a "IsVisible" property.  If you change the IsVisible property so it looks at the new EndTime property, then posts that should not be shown after the EndTime won't be shown to people not logged into the blog.
Mar 31, 2009 at 3:51 PM
Hey Ben,

 Thats Awesome.... Thanks a loads...I didnot notice that.... LOL... Thanks again.... well one more thing the existing function has a time set for some different zone. Is there any setting in blogengine.net to change that time to CST??
Coordinator
Mar 31, 2009 at 7:14 PM
Do you mean the "Server time offset" setting?  If your server is located somewhere other than CST, then you can use Server Time Offset so your blog is using CST time.  So if the server is in PST (UTC -0700), and you want UTC -0500, then putting 2 in for the Server Time Offset will add 2 hours to PST time -- effectively making it CST (if CST is UTC -0500).

This is the best you can do -- which should be satisfactory in most cases.
Coordinator
Mar 31, 2009 at 7:34 PM
Also, looking at the code in BE, if you were to implement a Stop time, it might be better if you modified the "IsPublished" property in the Post class, rather than the IsVisible property.  The IsPublished property is the one that is already looking at the Start time.  So it would make sense that the same property also looks at the Stop time.
Mar 31, 2009 at 8:40 PM
Hey Ben,

I am always gona have ma server in CST zone so i already did set the server offset to zero. So thats not a problem any more. Now Only problem i am dealing with is End time for posts. I was wondering if i could find any blogengine compatible plug-in. I am new to C# and .Net so find it hard to understand when people explain in technical terms. I am trying to to what you said but understanding the code is a bit tough initially.

Thanks for for your Help. I really appreciate it.

Bacca.
Mar 31, 2009 at 8:54 PM
Hey Ben,

Can you explain a little more in detail the process of adding end time or expiration time for a post. That would really help me to do my work. Sorry for troubling you but i need your help on this.

Thanks in adavnce.

Bacca
Mar 31, 2009 at 11:15 PM
Hey Ben i have added new time box to the add_entry page. Now can you guide me thruogh the furthur process.
Coordinator
Apr 1, 2009 at 3:21 AM
So you will need Visual Studio to compile the BE core.  The BE core code is in the DotNetSlave.BusinessLogic folder.  This also assumes you're using the default XML storage (rather than DB storage).

1. In the BE core code, there's a file, BusinessBase.cs.  We need to add a StopDate property.  There's already a DateCreated property as shown below.

====== EXISTING CODE in BusinessBase.cs ======

private DateTime _DateCreated = DateTime.MinValue;
/// <summary>
/// The date on which the instance was created.
/// </summary>
public DateTime DateCreated
{
    get
    {
        if (_DateCreated == DateTime.MinValue)
            return _DateCreated;

        return _DateCreated.AddHours(BlogSettings.Instance.Timezone);
    }
    set
    {
        if (_DateCreated != value) MarkChanged("DateCreated");
        _DateCreated = value;
    }
}

*** The code above should remain untouched.  You will want to add the code shown below for the new StopDate property.

====== NEW CODE in BusinessBase.cs ======

private DateTime _StopDate = DateTime.MinValue;
/// <summary>
/// The date on which the instance should no longer be visible.
/// </summary>
public DateTime StopDate
{
    get
    {
        if (_StopDate == DateTime.MinValue)
            return _StopDate;

        return _StopDate.AddHours(BlogSettings.Instance.Timezone);
    }
    set
    {
        if (_StopDate != value) MarkChanged("StopDate");
        _StopDate = value;
    }
}


2. Also in the BE core code, is a file named Posts.cs in the Providers\XmlProvider file.  There's two new items to add.  The bolded items are new.

====== In InsertPost() method ======

writer.WriteElementString("pubDate", post.DateCreated.AddHours(-BlogSettings.Instance.Timezone).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));

writer.WriteElementString("stopDate", post.StopDate.AddHours(-BlogSettings.Instance.Timezone).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));


====== In SelectPost() method ======

if (doc.SelectSingleNode("post/pubDate") != null)
    post.DateCreated = DateTime.Parse(doc.SelectSingleNode("post/pubDate").InnerText, CultureInfo.InvariantCulture);

if (doc.SelectSingleNode("post/stopDate") != null)
    post.StopDate = DateTime.Parse(doc.SelectSingleNode("post/stopDate").InnerText, CultureInfo.InvariantCulture);


    
3. In the BE core code, there's a file named Post.cs (not to be confused with Posts.cs from # 2 above).  We want to update the IsPublished property.

======= EXISTING IsPublished property =======
    
private bool _IsPublished;
/// <summary>
/// Gets or sets whether or not the post is published.
/// The getter also takes into account the publish date
/// </summary>
public bool IsPublished
{
    get { return _IsPublished && DateCreated <= DateTime.Now.AddHours(BlogSettings.Instance.Timezone); }
    set
    {
        if (_IsPublished != value) MarkChanged("IsPublished");
        _IsPublished = value;
    }
}

======= REPLACE IsPublished property above with this new one below =======

private bool _IsPublished;
/// <summary>
/// Gets or sets whether or not the post is published.
/// The getter also takes into account the publish date
/// </summary>
public bool IsPublished
{
    get
    {
        return
            _IsPublished &&
            DateCreated <= DateTime.Now.AddHours(BlogSettings.Instance.Timezone) &&
            (StopDate.Equals(DateTime.MinValue) ||
             StopDate >= DateTime.Now.AddHours(BlogSettings.Instance.Timezone));
    }
    set
    {
        if (_IsPublished != value) MarkChanged("IsPublished");
        _IsPublished = value;
    }
}


**** Now you want to compile the BE Core project.  Under the Build menu in Visual Studio, there's a "Build BlogEngine.Core" option to do this.

4. In Add_entry.aspx (in the main web project), I added the following controls for the new StopDate.  There's 3 validation controls for this control.  The validation controls make sure that you enter a valid StopDate and the StopDate is after the main Date (the main Date is our Start Date).

<label for="<%=txtStopDate.ClientID %>">Stop <%=Resources.labels.date %></label>
<asp:TextBox runat="server" ID="txtStopDate" Width="110px" />

<asp:RegularExpressionValidator runat="server" ControlToValidate="txtStopDate" ValidationExpression="[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]" ErrorMessage="Please enter a valid stop date (yyyy-mm-dd hh:mm)" Display="dynamic" />

<asp:RequiredFieldValidator runat="server" ControlToValidate="txtStopDate" ErrorMessage="Please enter a valid Stop date (yyyy-mm-dd hh:mm)" Display="Dynamic" />

<asp:CustomValidator runat="server" ControlToValidate="txtStopDate" ErrorMessage="Stop Date must be on or after Date" EnableClientScript="false" OnServerValidate="ValidateStopDate" Display="Dynamic" />


5. In Add_entry.aspx.cs, I added this new function (ValidateStopDate) which does the validation making sure the StopDate is on or after the (start) date.

protected void ValidateStopDate(object sender, ServerValidateEventArgs args)
{
    DateTime dateCreated;
    DateTime stopDate;

    if (DateTime.TryParse(txtDate.Text, out dateCreated) &&
        DateTime.TryParse(txtStopDate.Text, out stopDate))
    {
        args.IsValid = stopDate >= dateCreated;
        return;
    }

    args.IsValid = false;
   

6. Also in Add_entry.aspx.cs, I added these bolded lines in the same places the existing Date is being saved/retrieved.  The bolded lines are new lines to be added.
    
post.DateCreated = DateTime.ParseExact(txtDate.Text, "yyyy-MM-dd HH\\:mm", null).AddHours(-BlogSettings.Instance.Timezone);
post.StopDate = DateTime.ParseExact(txtStopDate.Text, "yyyy-MM-dd HH\\:mm", null).AddHours(-BlogSettings.Instance.Timezone);

txtDate.Text = post.DateCreated.ToString("yyyy-MM-dd HH\\:mm");
txtStopDate.Text = post.StopDate.ToString("yyyy-MM-dd HH\\:mm");

txtDate.Text = DateTime.Now.AddHours(BlogSettings.Instance.Timezone).ToString("yyyy-MM-dd HH\\:mm");
txtStopDate.Text = DateTime.Now.AddHours(BlogSettings.Instance.Timezone).ToString("yyyy-MM-dd HH\\:mm");

******  That should be it.  I tested this and when not logged into the blog, the posts only show up between the Date and StopDate.
Apr 1, 2009 at 4:52 AM
Hey Ben ,

You are a life-Saver. Thanks  loadsssssssssssssss... God Bless you... I will try n put the code in... Thanks a lot again......

Bacca
Apr 7, 2009 at 8:01 PM
Edited Apr 7, 2009 at 9:23 PM
Hey Ben ,

I need your help again :(.

We have implemented start and end time for our posts. So now i want a bit adavnced applications where i want a parameter which records the number of times the post will display between the start and end date.
 example: we entered

Start Date: Tue, Apr 7 2009 10:14 and End Time: Thu, Apr 23 2009 11:45

So now i want say the post to be displayed like 100 times between those start and end dates. How do i implement this?
The user will enter number of times the post should be displayed between those start and end dates.


All i want is the posts will be used as advertisements and they will be rotated in those entered time frames. And the data is going to be only images.
 So i wnat those posts(images) to rotate ( entered no of times) between the start and end date.

example:
post1 . Start time: mon 10 am end time tue 9 am... 20 times
post2    Start time : mon 5 am and sun 10 am..... 10 times
.
.
..
.
post n

So the image will rotate among themselves the required amount of times between required time slots. So after mon 10 am post1 will stop rotating but rest will continue....


How do i implement this??????? Or of you have any suggestion???


Thanks..

Bacca

Apr 7, 2009 at 8:16 PM
I tried using the Ad rotater control of Asp.net but i am not able to use it with blogengine.net properly....So this might really solve my problem if i am able to implement this on ma Rss feeds (posts).
So i want each of the posts to come up the selected amount of times between the time frames.

<Advertisements>  
  <Ad>
      <ImageUrl>/Path/Banner.gif</ImageUrl>
      <Impressions>3</Impressions>
   </Ad>
</Advertisements>









  • ImageURL - this is the full path to the banner ad itself
  • Impressions - here's how we determine how often the ads run in regards to one another (relative 'weighting'). The higher the number, the more often the ad will run.
  • Apr 7, 2009 at 11:14 PM
    Edited Apr 8, 2009 at 3:12 PM
    ?
    Apr 8, 2009 at 3:11 PM
    Is the above thing that i mentioned possible??