Pages

06 October, 2013

Sitecore: Image Resizer Pipeline (ResizeProcessor) Pipeline

Sitecore has a feature in processing high resolution images while rendering in the website.

Let’s say, content authors wants to use an image as Icon, Thumbnail and full scale in the website. Normally, they will upload three images in icon sized, thumbnail sized and full scale images. They will have different name to differentiate the sizes. They can use (<img src="/url/image.png" height="100" width="100") image tag with height and width but it will render with high resolution image size even for thumbnail. But Sitecore has an option of resizing the image at runtime. 

There is a pipeline in the <getMediaStream>.

<processor type="Sitecore.Resources.Media.ResizeProcessor, Sitecore.Kernel" />

This pipeline has the following advantages.
  • Depending upon the width and the height in the media url, this will resize the image and render it.  /~/media/image.JPG?h=300&w=400
  • While resizing the image, it will reduce the size of the image as well.
  • Authors can use same name for Icon, Thumbnail and Full Scale. 

Example:

High Resolution Image Size: 4.70 MB (4,938,293 bytes)

Without processor (Size – 4.7 MB): http://sitecore1/~/media/flower.JPG?h=300&w=400


With processor (Size – 55 KB): http://sitecore1/~/media/flower.JPG?h=300&w=400


Of course, there will be a performance impact for resizing at runtime. To avoid the impact, the site can be configured for ARRCache which will reduce the load on the subsequent request.


04 October, 2013

Sitecore: Ideal way to execute a long running job

One of our requirement was to execute a long running job in Sitecore Content Tree. In many cases, we end up in Timed out error. Obviously we can increase request timed out configuration. But Sitecore has a very good way of executing such long running task in a ProgressBox.

ProgressBox.Execute(JobName, JobTitle, ProgressBoxMethod, Params);

//Sitecore.Shell.Applications.Dialogs.ProgressBoxes
ProgressBox.Execute("Job Name", "Job Title ", new ProgressBoxMethod(ExecuteOperation), item);

This line of code will start progress box and the functionality will be executed in the
ProgressBoxMethod.

        protected void ExecuteOperation(params object[] parameters)
        {
            //Do the operations
           
            //Logging for the job
            Sitecore.Context.Job.Status.Messages.Add("Logs for the job: JobName");
           
            //Is the job done?
            if (Sitecore.Context.Job.IsDone)
            {
                //On completing the job
            }           
        }

By using the progress box, the long running tasks are executed successfully without getting any timed out errors. This has other methods to handle the queuing asynchronously.




18 August, 2013

Sitecore: Scheduler Job in Production server with SwitchMasterToWeb.config

One of our requirement is to schedule Sitecore job in Production environment. Most of the production environments will have SwitchMasterToWeb.config configuration to remove any master database traces in the configuration.

      <agent type="Sitecore.Tasks.DatabaseAgent" method="Run" interval="00:10:00">
        <param desc="database">master</param>
        <param desc="schedule root">/sitecore/system/tasks/schedules</param>
        <LogActivity>true</LogActivity>
      </agent>

We changed this database configuration to “web” but still the job was not executed on the scheduled time.

To investigate further we used the Sitecore admin configuration page /Sitecore/admin/showconfig.aspx. Surprisingly these agent were missing in the output. We analyzed SwitchMasterToWeb configuration and commented the patch configuration to delete these agents. Agent is there in the admin configuration page and job is running on scheduled time.

In SwitchMasterToWeb.config:

      <!--<agent type="Sitecore.Tasks.DatabaseAgent">
         <patch:delete />
      </agent>
      <agent type="Sitecore.Tasks.DatabaseAgent">
         <patch:delete />
      </agent>-->
blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }