My Notes on Sitecore CMS Advanced .NET Developer (AND)

Got Sitecore CMS Advanced .NET Developer training, and it was really helpful to get delve in to Sitecore concepts (Gutter,Processor,Events,Pipelines etc. hoohh!). But it was really fun! and the main Credit goes to Sitecore Rocks! (It really rocks!) and Ben LambSitecore Trainer [Really helpful person!].

Course Abstract:

Master advanced concepts and techniques for building winning website solutions with Sitecore CMS, Visual Studio 2010, and Sitecore Rocks! This Advanced .NET Developer course features live demonstrations, formal reviews, questions and answers, guided student exercises, and a graded exam. Designed to help you achieve mastery of Sitecore CMS advanced development practices, only Sitecore Certified Trainers deliver Sitecore CMS Advanced .NET Developer training.

It covered following topics:

  • Develop with Sitecore Rocks and Visual Studio 2010
  • Understand the benefits of Settings Items and Classes
  • Create customized events and pipelines
  • Work with custom item classes and ASP.NET Domain Model
  • Customize the Sitecore Client Editors
  • Implement Scheduled Tasks

It’s always good to make notes of your own (In Digital world It’s good to share notes with world — which we used to while studying :-))

  • Get Ready to Rock! (with Sitecore Rocks) – It really Rocks! [Hats off to this guys!] for such a nice tool in Visual Studio [.NET Developer’s main weapon!], No need to go to browser for CE and contains loads of functionalities which makes developers lives easier and faster.

To Install it Visual Studio 2010 | Tools >> Extension Manager (From Right side selected online Gallery, If you need to search online)

Make a connection

You can make the connection provide the required details and remember to use “HardRock Web Service” [Do you know you can check use Sitecore’s Web Service as well and you can consume it in your code. Just check

http:// yourdomain//sitecore/shell/WebService/service.asmx OR http:// yourdomain//sitecore/shell/WebService/service2.asmx

Update Server Components – Using this option you can update your server components. It stores this updated DLLs in your webroot/bin directory.

LogViewer – It’s really great has nice filter and it auto refreshes itself!

JobViewer –nice filter and shows progress and status of your Jobs as well! Really cool!

The best way to learn Sitecore Rocks is to play with it! Right click wherever you like to in Sitecore Rocks and you will find a hidden gem! (Have you seen merged configuration files? Have you installed Plugins? Have you seen how to Create Gutter? How to Create Pipeline [Check Sitecore Visual Studio Templates in Add New Item Dialog] Left it on you for brevity!)

What you are getting ‘Sitecore.Rocks.TemplateWizard, Version=0.7.0.0, Culture=neutral, PublicKeyToken=c9e2eeb5a3dd9908 error which Is stopping your Sitecore from Rocking? Check my article to solve this error click here

Frankly, Sitecore Rocks really rocks! [Agree that it is not fully stable yet! But the product looks promising! In next one year I’m confident enough to see loads of new Sitecore Rocks Plugins and Visual Studio Templates available!]

  • Settings Items and Classes – You have some settings which are static and should come from Web.Config/Sitecore Settings? then this guy is for you. Add all those settings which should be modified by Admin in Web.Config and create Static Settings Class to manage them very well and same for Item Settings, which Non-Admin users can also modify.

Sitecore.Configuration.Settings.GetSetting()

It’s always not good practice to modify Web.Config file, Include your configuration file in App_Config\Include Folder.

You can also store Settings in Sitecore! [Non-Admin users!]

As per best practice, create Static class which should act as an interface between your Code and Your configurations [web.config/sitecore].

  • Events – Do you like to do anything when any event occurs e.g. item”moved/item:saved etc.? then this guy is for you. Example – we created one EventHandler on item:saved which checks whether current item is of type News item if yes then based on Date, created Month and Year folder.

-ing event fires before the operation/ -ed event fires after the operation

Check Web.Config’s <events> section for defining events.

<event name=item:saved>

     <handler type=My. ItemSavedEventHandler, My.Kernelmethod=OnItemSaved/>

</event>

Here My.Kerenel is DLL’s name (Without .DLL suffix) and My. ItemSavedEventHandler is fully qualified class name.

Now, in My. ItemSavedEventHandler class your method should be:

Public void OnItemSaved(object sender,EventArgs e)

{

// Your code goes here..

}

CANCEL EVENT – You can cast your eventargs to SitecoreEventArgs class which contains the way to cancel an event. You can also cancel the events which ends with ing.

Check out Dynamically Subscribe/UnSubscribe/Raise events code.

  • Pipelines – Write your code in pipeline to get executed like — HttpRequestProcessor pipeline for 301 Redirection.

<processor> tag in Web.config.

Don’t get confused between Events and Pipelines. Events gets called on particular events like saving/saved/moving/moved etc.And processor gets called during execution of any request for example HttpRequestProcessor will get called before each HTTP Request.


  • Custom Items and Presentation

Sitecore Rocks provides nice feature for Creating Strongly typed items for your templates!

Use it to create strongly typed items and you can bind it with any ASP.NET DataSource.

  • Extending the Editors – You can extend Page Editor and Content Editor commands here.

WebEdit Buttons lies here:

/sitecore/system/Field types/…/WebEdit Buttons/ e.g /sitecore/system/Field types/Simple Types/Date/WebEdit Buttons/Show calendar

return Sitecore.WebEdit.editControl($JavascriptParameters,”webedit:clearimage“)

Here webedit:clearimage is your command name.

WebEditCommand Class


Ribbon Button for CE

Go to Core database and check following path:

 /sitecore/content/Applications/Content Editor/Ribbons/Chunks/

Command Name defines click and that should be there in your App_Config/Commands.config file.

<command name=”contenteditor:abc” type = “Sitecore.Shell.Framework.Commands.ContentEditor.ToggleHiddenItems,Sitecore.Kernel“/>

Sitecore.Kernel- DLL Name without .DLL extension.

Sitecore.Shell.Framework.Commands.ContentEditor.ToggleHiddenItems – Fully qualified class name.

NOTE : Command Name MUST not have “.”, and Sitecore Rocks has a bug that it adds “.” So, you have to remove it to make your things working!

Command Class

Execute() method gets called first and here you can get item using var item = context.Items[0];

And when you want to enable/Disable your Command you can override QueryState() method and do CommandState.Enabled stuff in your code!

  • Scheduled Tasks – Would like to execute your code at particular  time and one particular day? then this guy is for you.

Your scheduled Tasks time should be <= Frequency!

It should have three arguments. Ensure that all your classes are from right namespaces, especially Item class because Item class will exist at two places one which we generated using Strongly Typed exercise and the default one is with name Sitecore.Data.Items.Item class and you need to use Sitecore.Data.Items.Item class only!

And if you are writing in DEBUG log in file then ensure in Log4Net, DEBUG Log Level is enabled!

Items: if you want to pass an array of items to your method you can place any XPath here. Items can be divided by pipe separator. For example: /Sitecore/content/Home/Globals/Item1 |  /Sitecore/content/Home/Globals/Item2 [DO NOT USE ITEM’S ID]

Worth to read : http://sdn.sitecore.net/FAQ/Administration/Scheduled%20tasks.aspx

Course Source