Wednesday, May 25, 2016

Custom Processors in Sitecore


If the processor has a method, the method must accept a PipelineArgs object and return type will be void. Below code snippet will help us to write simple custom processor in Sitecore.


 public void Process(AverageRatingProcessorArguments args)
        {

            double average = 0;
            String ConStringName = Sitecore.Configuration.Settings.GetSetting("ratingconstring");

            using (SqlConnection connection = new SqlConnection(ConStringName))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("Getaverage", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@BlogItemID", args.itemID);
                    average = (double)command.ExecuteScalar();
                }
            }
       
            args.CustomData.Add("averagerating", Convert.ToString(average));
        }


 public class AverageRatingProcessorArguments:PipelineArgs
    {
        public string itemID { get; set; }

    }

//Invoking the custom processor
public string AverageRatingWithProcessor(string itemID)
        {
             
            RatingModule.Processors.AverageRatingProcessorArguments ARarg = new RatingModule.Processors.AverageRatingProcessorArguments();
            ARarg.itemID = itemID;          
           
            CorePipeline.Run(AVERAGE_RATING_PROCESSOR, ARarg);
            var AvgRating = ARarg.CustomData["averagerating"];

            return AvgRating.ToString();
        }

Wednesday, May 18, 2016

MongoDb Data is updated after your session end

After session end the data is sent to MongoDb but during development phase will you wait for the time when the session will be abandoned?I think you will say "No". So we can do one thing on that time that we can explicitly kill our session.

Steps:
create a simple abandon.aspx page and place it within [Sitecore Instance Name]/sitecore/admin folder and call the abandon.aspx page explicitely like [Sitecore Instance Name]/sitecore/admin/abandon.aspx
Code snippet for abandon.aspx
<% Session.Abandon();%><html><head></head><body><h1>Kill the session</h1>
>
We forcefully Abandon the session.</body></html>
Calling the "abandon.aspx" page


?


Monday, May 16, 2016

What is difference between droplink and droplist in Sitecore?


Today one of my friend asked me what is the basic difference between Droplink vs Droplist in very simple words. I replied that...

Droplink:
Droplink  stores the GUID(Unique in space and time) of the item that was chosen by content editor.

Droplist:
Droplist data type only stores the string value of the item that was chosen by the content editor.