Staying close to your competitors? Make it closer with Sitefinity 4.0 publishing system

Staying close to your competitors? Make it closer with Sitefinity 4.0 publishing system

Posted on March 04, 2011 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

Monthly email newsletters are a common tool for informing customers about your products and services.  This information includes the latest product updates, new promotions, new tools and upcoming corporate events.  In order to stay informed, many organizations subscribe to competitor’s email newsletters to monitor their announcements and the quality of their marketing materials.  These materials are often circulated internally and used for strategic planning.

Sitefinity 4.0 can help by gathering, aggregating and publishing this content to your Intranet.  The blog post below describes how Sitefinity 4.0’s Publishing System helps organizations stay informed.

Subscribing to newsletters through Sitefinity’s Publishing System

With the release of Sitefinity 4.0 and its brand new publishing system, you have the ability to consume external RSS and Atom feeds as well as mail content using the POP3 protocol.   Once consumed, this data can be blended into a Publishing Point (data mashup) and published on your Intranet portal.

Once you aggregate the necessary information, you can choose either to publish this content in your Sitefinity project such as news, blogs, and events or push it directly to Twitter or RSS.  The flexibility of the system opens a wide range of possibilities, but there is one specific scenario that can easily allow you to stay on top of your competitors. Importing all your competitors’ newsletters into your corporate intranet and automatically publishing them, so that all your employees can stay up to date with important announcements and trends in your market is something I want to bring with this blog post.

Creating a Feed that will retrieve newsletters from a POP3 server.

In most cases, these newsletters will be sent to an email account hosted on a server that supports POP3 (Gmail, Yahoo and Microsoft Exchange all do support POP3).  Sitefinity 4.0’s Publishing System can be used to pull e-mails from this POP3 email account.

Below are the instructions for setting up a new POP3 import:

  1. Open the Sitefinity back-end interface and navigate to the Administration/Feeds and Notifications link.
  2. Click on Create a Feed and you will get to the following screen:

Empty Feed

Content to include is the content that goes in our Publishing point. As mentioned, it can be content from your Sitefinity website or an external ATOM, RSS or POP3 feed. In order to configure the feed to pull information from POP3 and publish it as news on our website we have to do the following:

Note that there is a warning message in the beginning of the dialog that warns you that “All successfully retrieved mail messages will be deleted from the POP3 server”. Please refer to the documentation of your mail server since this is subject to configuration. For example Gmail allows you to leave a copy of the retrieved messages in your inbox, so that you don’t lose any of your emails. For further information please refer to the Gmail POP3 configuration settings.

  1. Input a title of the feed e.g. “Competitors Newsletters”.
  2. Click on Add another content type and select Mail Content from the dialog menu.
  3. Enter the POP3 server e.g. pop.gmail.com
  4. Enter the Port number e.g. 995
  5. Choose whether you want to use SSL connection, in case you use Gmail you have to mark the checkbox.
  6. Enter your e-mail and password and click Done.

POP3 Configuration
 

Now that the POP3 import is created, we have to configure how this information will appear on our Sitefinity website. In order to configure the publishing of the content just retrieved you have to perform the following steps:

  1. On the Publish as panel click the Add more... button.

A new screen will appear that controls how the information aggregated in the publishing point will be published.

  1. Click on the Sitefinity content radio button
  2. Select Import data as News
  3. Choose “Automatically publish imported data” and click Done
  4. Finally click on Save Changes to create the feed.

Competitors Newsletters Feed 

Once the feed is created, Sitefinity displays a list of all feeds.  To run the new “Competitors Newsletters” feed simply click on Actions and press the Run button. Now the Competitors Newsletters feed will retrieve all information from the POP3 pipe and publish it as news.

Note: The retrieval of information is not yet automated, you will still have to click on “Run” every time you want to run your feed. However, this can be easily automated just with a few lines of code [See below].

For this sample we have only created a single pipe that contains information from the POP3 server, but other pipes can easily be created that aggregate to the Publishing point. For more information please look at our Creating a feed article.

Creating Scheduled Tasks that updates feed automatically.

Sitefinity has its own scheduling system that allows you to queue tasks that will execute on a specific date and time. To create a task inherit from the Telerik.Sitefinity.Scheduling.ScheduledTask class similar to this:

public class PipeScheduledTask : ScheduledTask
    {
        public override void ExecuteTask()
        {
            PublishingManager pubManager = PublishingManager.GetManager();
                var point = pubManager.GetPublishingPoints().Where((w) => w.Name == "Competitors Newsletters ").FirstOrDefault();
                if (point != null)
                {
                    PublishingManager.InvokeInboundPushPipes(point.Id, null);
                }
 
        }
 
        public override string TaskName
        {
            get
            {
                return "SitefinityWebApp.PipeScheduledTask";
            }
        }
    }

In the execute task we get our feed from the publishing system, in our case “Competitors Newsletters”, and execute it. We have to also set the TaskName to reflect your full class name, so that the system can properly instantiate the task from our factory and execute it at a specified point.

In order to schedule your task as early in the application lifecycle as possible, you should handle the Initialized event of our Bootstrapper inside the Application_Start handler of your application. To do that open your Sitefinity Web Application in Visual Studio and create a new Global.asax file that is used to handle application and session-state events in your ASP.NET website. In the Application_Start create a static call to the Telerik.Sitefinity.Abstractions.Bootstrapper and sign up for its Initialized event where you will add the logic for scheduling your custom task similar to this:

protected void Application_Start(object sender, EventArgs e)
        {
            Bootstrapper.Initialized += new EventHandler<ExecutedEventArgs>(this.OnSitefinityAppInitialized);
        }
 
        private void OnSitefinityAppInitialized(object sender, EventArgs args)
        {
            SchedulingManager manager = SchedulingManager.GetManager();
            string myKey = "239CE594-5613-42EC-AC57-8E2B33B28065";
 
            var count = manager.GetTaskData().Where(i => i.Key == "239CE594-5613-42EC-AC57-8E2B33B28065").ToList().Count;
 
            if (count == 0)
            {
                PipeScheduledTask newTask = new PipeScheduledTask()
                {
                    Key = myKey,
                    ExecuteTime = DateTime.UtcNow.AddSeconds(10),
                };
                manager.AddTask(newTask);
                manager.SaveChanges();
            }
        }

It is a good practice to create a key for your task so you can search for it later. The Key property of PipeScheduledTask is string, so you can create any kind of key you want. In this case I am using a string that represents a GUID. Second, you should set the ExecuteTime property of the tasks that determines when this task is going to be executed, note that you have to set all your date and time values in Sitefinity in a UTC format. In this case we will schedule a new automatic update of the feed every hour.

Once you queue the tasks in the manager and commit the transaction Sitefinity will determine when it should execute your tasks. If it finds a task that is not yet executed and its execution time has already passed, it will automatically execute it and delete it. This is useful if your application pool recycles and the task misses its execution time.

However, this will not be enough to make the task recurring.  Fixing this requires additional logic in the ExecuteTask method. Once your task is executed invoke the Scheduling manager and queue a new task of the same type like this:

public override void ExecuteTask()
{
    PublishingManager pubManager = PublishingManager.GetManager();
    var point = pubManager.GetPublishingPoints().Where((w) => w.Name == "Sitefinity news").FirstOrDefault();
    if (point != null)
    {
        PublishingManager.InvokeInboundPushPipes(point.Id, null);
    }
 
    SchedulingManager schedulingManager = SchedulingManager.GetManager();
 
    PipeScheduledTask newTask = new PipeScheduledTask()
    {
        Key = this.Key,
        ExecuteTime = DateTime.UtcNow.AddHours(1)
    };
 
    schedulingManager.AddTask(newTask);
    schedulingManager.SaveChanges();
}

We are aware that the manual scheduling of a new task is not a best practice here and we will do our best to implement an out of the box scheduling with customizable execution time and some way to monitor the proper execution and status of all tasks.

In order to make the following example you will need to download our latest service pack, Sitefinity 4.0 SP1 that introduces a couple of optimizations and bug fixes.

progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation