Proxy items in 5.3

You might have noticed it: Proxy items have changed again. While playing with it, I’ve found out that it isn’t possible anymore to create a deep proxy item, or proxying under proxy-nodes. I kind of like and dislike it. It’s a kind of protection from people who run thru items without checking the Runtime settings, so it prevents you from endless loops(creating a home-proxy-item under home, pointing to home ;)). It does  limit memusage and load as proxy items where always quite a preformence penalty. But it isn’t so flexible anymore. And the stangest stuff, when you create a nested proxy, you never get warned. There isn’t even something in the log-file… Thinking more of it, it’s quite Sitecore unlike: You can’t even configure the behaviour, it’s a quite big archtectural change and it can break solutions! Hopes someone can explain me why this choose is made or tells me that I’m wring…

Happy (sunny) saturday!

Sitecore Query Parsing Tree

Yesterday, I had a college about Design Patterns. This can be  very interested, but it requires a teacher which can describe the problems in a good way and show unlimited examples. To bad, the theacher wasn’t able.
So I decided to show some of the stuff in Sitecore(Factories, Facades, etc) to one my my classmates. And while clicking trough my Sandcastle -dump of Sitecore 5.3, I run trough the Query-class(Sitecore.Data.Query.Query). I knew that Sitecore uses lexical analysis, but what I didn’t knew was, that they provide the parsing-tree :).  For example, add the following code to the ‘Sample layout.aspx’:

<script runat=”server”>
protected override void Render(HtmlTextWriter output)
{
Sitecore.Data.Query.Query myQuery = new Sitecore.Data.Query.Query(“/sitecore/*[(@name=’content’ or @name=’master’)]/*[@@fieldname < 11]”);
base.Render(output);
myQuery.Print(output);
}
</script>

This is what appears on the screen:

– Root
– Children [“sitecore”]
– Children [“*”]
   – Predicate
      – OrOperator
         – EqualsOperator
            – FieldElement [“name”]
            – Literal [“content”]
         – EqualsOperator
            – FieldElement [“name”]
            – Literal [“master”]
– Children [“*”]
   – Predicate
      – SmallerOperator
         – FieldElement [“@fieldname”]
         – Number [“11”]

So now it’s possible to optimize your queries as you are now able to minimalize it’s states :).

Be friendly to the Sitecore editors

Yes, you have to be friendly! The message of today ;).
Well it’s not that simple. I want to point you guys on how you easily can improve the Sitecore experience. But first you have to know what the Sitecore experience should be! Well, the Sitecore exprience is a combination of:

  1. A quick client
  2. A nice website
  3. A clear content tree
  4. Good described items

As developer, you only have influence on point 3 and 4. For 3 there are several ways. I’ve discussed some of them before in combination with Search Optimalisation.
Something all the users are aware of are the inside items. This means the Fieldnames, Icons, Help, etc. I know filling them isn’t the most exciting work, rather you play with ‘*
Foundation’, but it is an essential part of the project. To many times users are confused by the way Sitecore works. They don’t undersdtand what the field ‘Abstract’ means and directly the discussion start how it should work…
What to do?

  • Rename predifined Item names like ‘Home’, ‘Internet’, ‘Meta’ or at least change their Displayname! Suggestions: ‘Startitem’, ‘LECTRIC Website’, ‘Settings’.
  • Change the friendly field names from ‘Title’ to ‘Standaard Title – Visible on all pages which refer to this page’, ‘Introtext’ becomes ‘Intro Text – Visible on all overview pages to let someone read the full page’.
  • Select a nice icon for an item on the template. There are so many nice icons in /sitecore/shell/Themes/Standard/. Browse them using your Windows Explorer, not the Fiel browser in Sitecore, as it takes to long.
  • Discuss with you project manager who’s responsible for this. I guess I’m when I create the structure in my Technical Design Document, but a later moment in the project is also good. Make sure it’s done before the customer touches it’s own Sitecore installation.

In large projects(20-50 templates, 50-100 masters) this can take up to 1 day when you have to do it afterwards, at the start of the project it takes half the time. Small projects(4-5 templates, 10 masters) can be finished this way afterwards in 2/3 hours, 1 hour at the start of the project… 🙂

Sitecore & XSLT, When, Where and Why using it?

This diagram is for all those guys out there who think I dislike XSLT or who think I can’t write XSLT at all. You guys are right. I dislike the XSLT syntax, I dislike the complex functionality of XSLT but also dislike putting simple straight-forward presentation-code in a DLL. So here is my vision on selecting the right way to present something to the world:

Alex' view when you should use XSLT and when transform to code.

Again, no copyrights, no restrictions, this is MY view! You think that you can do this better? Impress me! 😛 

More best practices

As addition on Hans’ entry, some more C# trics:
Use regions(to divide mehods)!
In don’t care you don’t use full triple slashing for all your methods! First start dividing classes in regions!
For example:

When opening this class I can easily navigate trough it, without running trough a huge amount of lines. It’s much easier to understand. Then it’s up to your code skills to write understandable code.

NEVER use regions(inside methods)!
You definitelly shouldn’t divide lines of code. Rather extract lines of code to new methods. Review or let someone else review your code. Why does this method contaqin this terrible amount of lines?

Use self explaining namespaces:
The first explaination of your code starts with dividing in the right chapters: namespaces. Microsoft shows how you should do it in the mscorlib(System.Text, System.IO, etc). For our internal library adapts the Sitecore-namespaces. For example: LECTRIC.SC.Pipelines or LECTRIC.SC.Configuration.
The SC is there instead of Sitecore as it would cause problems with the compiler :(. Namespaces are definitelly badly implemented in the CLR. MS promised to work on it before releasing .NET 2.0, but I guess we’ve to wait for .NEt 3.5 as notthing seems to be changed???

Library names and structures
One of the problems for maintaining is the usage of huge garbage DLLs. For now on, we try to divide functionality and presentation over more DLLs. In the past everythign was in just one, badly named DLL.
Conventions:
1. [Customer].(Subsite.)[Projectname].Layouts for the code behind the Layouts
2. [Customer].(Subsite.)[Projectname].Business for general logic
3. [Customer].(Subsite.)[Projectname].Controls for site independent WebControls
4. [Customer].(Subsite.)[Projectname].DataAccess for external data sources like databases, most of the time only contains Typed Datasets
Adapting the dll-names as namespaces is preferible, but not necesarry.

Examples:
LECTRIC.Yourzine.Internet.Layouts.dll: LECTRIC’s Internet subsite Yourzine, and then the layouts of them 😉
LECTRIC.Internet.Controls.dll: Controls to be used on all Internet sites and subsites.

Filestructure
We adapt Sitecore 5.3’s structure for solutions:
[Projectname]
+ Data (for licences and logs)
+ Databases (uhmm. database files ;))
+ Website (webroot)

Hans, Coffee?

Anniversary

Yes, today I became 20 years old. A fifth of a century… It’s quite hard to imagine! 🙂

For me this is going to be a big year. As I graduate within one and a half year at school and lots of stuff is changing in personal life it’s definitely time to make huge decisions. For example, what about software development? Is it actually my goal to stay engineer till my old days, if so what way? Specialization in CMS’s? Grow further to become an architect? What about testing? Test engineer could sound cool. Business processes are also interesting topics. What about project and product engineering? Working on releases or with marketing deadlines? One thing I do know for sure, the next 12 months I’ll be writing about Sitecore and continue working on Sitecore projects. Then it’s time to spend time on graduating which means I’m going to search for a nice subject. As a part of my study has something to do with embedded software, it would be cool to port Sitecore to a mobile device ;). But so far, I don’t know where and how to graduate, nothing is for sure, but maybe it would be interested to do it outside of LECTRIC, outside of Web development and/or outside of Holland. Ideas can be posted as a comment :)…

It will also become a big year for LECTRIC. We’ve just opened an office in Beijing. Hi to Bert, Hardy, Wu and all the others who are definitely going to make Yourzine a success in the Big Apple in the East (Big Easter Apple) ;).
Then, for LECTRIC as system integrator, it will become the year of adult software engineering. So far we haven’t worked so structured, we haven’t written such good code and haven’t had so much expertise with 2 different CMS’s(Smartsite and Sitecore). Procedures like project startups, deployment, development, module integration, nightly builds, code guidelines, best practices, etc are mostly available. It’s now time for the big solutions and huge enhancements on the existing projects :).
I’ve forgotten to talk here before about our HTML Development. Together with one (X)HTML-guru (Sander) and a direct colleague(Sjoerd), we are investigating the best way to transfer XHTML to the world of .NET. The first results are available and further steps are upcoming! Personal I’m going to look at the best way to provide CMS-users full experience in the HTML-editor, but limit the possibility to screw the layout at the front. Our webdesigners are definitely against the usage of the HTML-field, I’ve promised them that I can provide the best functionality to both worlds…
Lots of exciting stuff!

Well that’s it for now! I’m always looking for new opportunities, looking forward to your ideas about HTML development (As it is a kind of science! Thank you for showing me, Sander!) and definitely interested in subjects for graduating… 🙂

SC5.3 Release Candidate(1)

Wooohooo! It is finally released! SC5.3RC(1) :D. Which means I’m going to finish my blog serie starting the end of the week. And I’ve some stuff to play with :). For those guys who are interested, check SDN5…

A big kiss to Denmark, Ole, Jakob( & Runi)! 😉 And ofcourse team Ukraine and all those others for testing :D.

Retrieving Parameters from your layouts

Most of my collegues are used to the principle that they can provide parameters to their webcontrols. As those parameters differ from Item to Item, it won’t work configuring them in a config or resource file. Defining a field is mostly not recommed as you don’t want users to access paramaters as ‘showIntroText’,’maxItems’ and ‘sFAQ’.

Ofcourse, you can create much nicer solutions to provide the information to a sublayout. For example: you can create a Custom WebControl which will be loaded in more layouts containing other parameters. Nevertheless the parameter tab in the Layout selector of Sitecore can be very usefull for already exsisting soltutions. One of the problems is accessing those problems. I’ve written an wrapper method:

public static System.Collections.Specialized.NameValueCollection GetLayoutParameters(Sitecore.Data.Items.Item currentItem)
{
string xml = currentItem.Fields[Sitecore.FieldIDs.LayoutField].Value;
string parameters = string.Empty;

try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNodeList nodeList = xmlDoc.SelectNodes(“r/d/r”);

foreach (XmlNode node in nodeList)
{
XmlAttribute parAtrr = node.Attributes[“par”];
if (parAtrr != null && !string.IsNullOrEmpty(parAtrr.Value))
{
parameters = (parameters.Length == 0) ? parAtrr.Value : parameters + “&” + parAtrr.Value;
}
}
}
catch (XmlException)
{
return new System.Collections.Specialized.NameValueCollection();
}

return System.Web.HttpUtility.ParseQueryString(parameters);
}

Note 1: Stuff liek this should definitelly be documented
Note 2: Code above is only tested on Sitecore 5.2
Note 3: The functions takes all the paramaters from all renderings and sublayouts, so when you’ve got more parameters with the same name, the same stuff occurs as in the QueryString: last one overrules everything.

Suggestion for Sitecore: Define IParameterizable in the API which has just one field: string[] Parameters.  When a Sublayout will be rendered by the Sitecore render engine and the Sublayout implements IParameterizable, you guys will fill the field Parameters… 🙂

Enjoy! (Thanks to my collegue Max for challenging me ;))

Update: Updated the code a little so it will catch XmlExceptions…

Major Security Leak: Users with a blank password

As many of you guys know, Sitecore has some, by installation, defined users with a blank password. Never forget to change this before going live! Today again, I’ve found a website which contained an user with an empty password. When the users aren’t used, it’s even better to delete them.

In this case I’ve contacted the Sitecore HQ, and asked them to contact the implementation partner. That should be the best way.

At the office, in our Sitecore- project start-up document we’ve defined the clean up of the users and roles as one of the first steps. so these mistakes can’t be made again.

Demo Remoting Project

My serie of post on 5.3 is a bit delayed because a lack of inspiration this weekend. It’s coming… Maybe later tonight else tomorrow… 
But what I wanted to show to you guys is a project I’ve created last week. It’s a small Demo application which shows how easy it is to develop applications using v5.3 remoting… I’ve created a simple Windows Forms app which shows you the content tree. Children will be retrieved when you click on their parent.

Download the source(30Kb).
Note 1: You should refer the Beta2 dlls by yourself as Sitecore won’t appreciate it when I include them in the download.
Note 2: In the constructor of Form1, you can find stuff like ‘localhost’, ‘admin’ and ” ;).

Enjoy!