<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Velir Blog</title>
	<atom:link href="http://blog.velir.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.velir.com</link>
	<description>Sitecore, custom apps, and all things web development</description>
	<lastBuildDate>Thu, 03 May 2012 14:56:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Velir’s Adobe CQ5 IntelliJ Plugin</title>
		<link>http://blog.velir.com/index.php/2012/05/01/adobe-cq5-intellij-plugin/</link>
		<comments>http://blog.velir.com/index.php/2012/05/01/adobe-cq5-intellij-plugin/#comments</comments>
		<pubDate>Tue, 01 May 2012 14:19:15 +0000</pubDate>
		<dc:creator>SamG</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[CQ5]]></category>
		<category><![CDATA[Adobe CMS]]></category>
		<category><![CDATA[CRXDE]]></category>
		<category><![CDATA[IntelliJ Plugin]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=2272</guid>
		<description><![CDATA[With the recent release of Adobe&#8217;s CQ5 platform (CQ5.5), there has been no mention of updating the canonical CQ5 IDE, CRXDE. This seems like a perfect opportunity for Velir to announce the beta release of a plugin for IntelliJ IDEA &#8230; <a href="http://blog.velir.com/index.php/2012/05/01/adobe-cq5-intellij-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With the recent release of Adobe&#8217;s CQ5 platform (CQ5.5), there has been no mention of updating the canonical CQ5 IDE, CRXDE. This seems like a perfect opportunity for Velir to announce the beta release of a plugin for IntelliJ IDEA by Jetbrains, making it a suitable replacement for most things usually done in CRXDE by allowing editing of JCR content and synchronization with CQ5’s JCR as well as with an industry-standard version control system.</p>
<p>I won&#8217;t sing the praises of IntelliJ here, but there is no shortage of discerning Java developers who prefer it to the alternative Java IDEs. But more than IDEology, it&#8217;s important to have a light-weight tool (or plugin) that can fit into a developer&#8217;s existing IDE and development process. CRXDE seems to be intended as a complete and self-contained solution to CQ5 development. As such, it may not provide the flexibility to interface with the other tools in a developer’s chest. Velir’s plugin, by being more lightweight, attempts to fill a niche for developers who want a customized CQ5 development process.</p>
<p>A good VCS (Version Control System) is a necessity for long-term success in software development.  Although the JCR specification has some support for content versioning, it is not intended to be a robust VCS. Most teams working with CQ5 have relied on Adobe’s FileVault (vlt) tool to import/export JCR content from the JCR to the file system in XML form.  This content is then stored in the team’s VCS of choice.  This extra layer of check-in and check-out from vlt adds another step to software development that feels a bit awkward when you first begin developing on the CQ5 platform. Velir&#8217;s IntelliJ plugin is based on the same XML format that is found in JCR content exported by vlt, but the plugin can handle import/export directly. Dialogs are provided that allow for easy editing of JCR content, and creation of common CQ5 nodes like cq:Component. It also provides suggestions for node creation based on the type of the parent node you&#8217;re creating it under. It is actually more robust than CRXDE in a few cases (try editing an array of booleans in CRXDE), although a user will probably still want to use CRXDE (or CRXDE light) for some things like search.</p>
<p>Since JCR import/export functionality has been developed recently, it may have some bugs. Please be careful when importing files to CQ5’s /lib and /etc directories, or you may have to reinstall CQ5.</p>
<p>Velir plans to add many more features, including</p>
<ul>
<li>JCR-centric view showing nodes and their properties, the way CRXDE does</li>
<li>Ability to display files directly from the JCR</li>
<li>Automatic syncing of content between the JCR and filesystem</li>
<li>Search for content within the JCR</li>
<li>Clickthrough from Sling/CQ includes in JSPs to OSGI servlet bundle code</li>
</ul>
<p>You can find the plugin at <a href="https://github.com/Velir/intellij-jcr-plugin">https://github.com/Velir/intelliJ-jcr-plugin</a>. Contributors/suggestions/bug reports are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2012/05/01/adobe-cq5-intellij-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Item URL Helper</title>
		<link>http://blog.velir.com/index.php/2012/04/24/item-url-helper/</link>
		<comments>http://blog.velir.com/index.php/2012/04/24/item-url-helper/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 15:06:32 +0000</pubDate>
		<dc:creator>TimB</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Item Url Helper]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=2236</guid>
		<description><![CDATA[Where can this Module be found? http://trac.sitecore.net/ItemUrlTool/ We’re introducing our newest module for Sitecore which is called the Item URL Helper. The Item URL Helper adds two great features to the Content Manager that will enrich your life as a &#8230; <a href="http://blog.velir.com/index.php/2012/04/24/item-url-helper/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Where can this Module be found? </strong><a href="http://trac.sitecore.net/ItemUrlTool/" target="_blank">http://trac.sitecore.net/ItemUrlTool/</a></p>
<p>We’re introducing our newest module for Sitecore which is called the Item URL Helper.</p>
<p>The Item URL Helper adds two great features to the Content Manager that will enrich your life as a content editor or developer.  The first is the ability to right click an item and have the item&#8217;s URL copied directly to your clipboard.  Wow, now that alone is a huge time saver!  This alleviates us from building a URL by the item path and now we can select a URL for different devices as well!  The second feature is just as robust.  You can now take a URL and paste it into the Search Box above the Content Tree and go directly to the item.  No more staring at a URL and drilling down the Content Tree!</p>
<p><strong>Retrieving a URL</strong><br />
Now retrieving a URL is easy, by right clicking the item in the Content Tree we are presented with the Copy Item URL command.  By selecting the command it will analyze the item&#8217;s presentation details and give you the option to select a URL for any device that is assigned to the items presentation details.  For Internet Explorer it will copy the URL directly to your clipboard, for other browsers you have the ability to manually select and copy the text your clipboard.  This is due to security issues by these other browsers.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/04/RightClick.png"><img class="alignleft size-full wp-image-2237" title="Right Click" src="http://blog.velir.com/wp-content/uploads/2012/04/RightClick.png" alt="" width="315" height="271" /></a></p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/04/ClipboardMessage.png"><img class="alignleft size-full wp-image-2238" title="Clipboard Message" src="http://blog.velir.com/wp-content/uploads/2012/04/ClipboardMessage.png" alt="" width="365" height="173" /></a></p>
<p><strong>Searching by URL</strong><br />
We are now able to utilize the search box at the top of the Content Tree for searching for an item by its URL.  This gives us the ability to quickly and accurately take a url from the website and find it within the Content Manager.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/04/UrlSearch.png"><img class="alignleft size-full wp-image-2239" title="Url Search" src="http://blog.velir.com/wp-content/uploads/2012/04/UrlSearch.png" alt="" width="633" height="302" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2012/04/24/item-url-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Velir Developer Daniel DeLay is named 2011 Sitecore MVP</title>
		<link>http://blog.velir.com/index.php/2012/04/09/velir-developer-daniel-delay-is-named-a-sitecore-most-valuable-professional/</link>
		<comments>http://blog.velir.com/index.php/2012/04/09/velir-developer-daniel-delay-is-named-a-sitecore-most-valuable-professional/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 19:12:31 +0000</pubDate>
		<dc:creator>Mark Gregor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=2211</guid>
		<description><![CDATA[Velir is pleased to announce that our very own Daniel DeLay has been recognized by Sitecore as one of 2011’s Most Valuable Professionals. He is now the third Velir Developer to receive the honor. The award recognizes individuals who have made a bold impact within the Sitecore community and are leaders in their field. <a href="http://blog.velir.com/index.php/2012/04/09/velir-developer-daniel-delay-is-named-a-sitecore-most-valuable-professional/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Velir is pleased to announce that our very own <a href="http://blog.velir.com/index.php/author/danield/">Daniel DeLay</a> has been recognized by <a href="http://www.sitecore.net/">Sitecore</a> as one of 2011’s Most Valuable Professionals. He is now the third Velir Developer to receive the honor. The award recognizes individuals who have made a bold impact within the Sitecore community and are leaders in their field.</p>
<p>Here at <a href="http://www.velir.com/">Velir</a>, we are very proud of Daniel’s accomplishments. His outstanding work shows his passion for technology as well as his willingness to help educate others. Daniel’s work has provided an invaluable contribution to Velir and the Sitecore community, most notably in spearheading projects for <a href="http://www.brookings.edu/">The Brookings Institution’s</a> Mobile Application, as well as implementing a home grown Learning Management System for <a href="http://www.cardiosource.org/acc">The American College of Cardiology</a>. In addition to his involvement in the Sitecore community, Daniel spends his time with his family and as a guitarist in the rock band, <a href="http://electricmummy.com/">Electric Mummy</a>.</p>
<p>Daniel joins a distinguished group of professionals who are some of the most active Sitecore community members around the world, and whose work encourages the objective exchange of knowledge.</p>
<p>“MVPs are technology experts who inspire others to learn and grow through active participation in the Sitecore technical community,” said Lars Floe Nielsen, Senior Vice President, Technical Marketing, Sitecore. “MVPs are not just about evangelizing Sitecore. They are passionate about improving technology and driving innovation and sharing their knowledge and real-world experiences at user groups, on blogs and social channels.”</p>
<p>Sitecore MVPs are chosen by a special panel that considers a professional’s technical expertise and voluntary community involvement over the past year. The panel considers the quality, quantity, and level of impact of the nominees’ contributions, in the areas of general technical advocacy, input via blogs and forums, and content development.</p>
<p>To learn more about Electric Mummy visit <a href="http://electricmummy.com">electricmummy.com</a> and to download the free song, &#8220;I Wanna Live Forever&#8221; <a href="http://wiggio.com/yui/folder/stream_file.php?doc_key=rssQunowS8PiWKxTRtTkCfm69NB76vurzfjkKv+kjMo">click here</a>.</p>
<p>Kudos to you, Daniel! Keep rocking!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2012/04/09/velir-developer-daniel-delay-is-named-a-sitecore-most-valuable-professional/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sitecore Edit Form</title>
		<link>http://blog.velir.com/index.php/2012/02/21/sitecore-edit-form/</link>
		<comments>http://blog.velir.com/index.php/2012/02/21/sitecore-edit-form/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 14:59:33 +0000</pubDate>
		<dc:creator>TimB</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=2175</guid>
		<description><![CDATA[Where can the Module be found? http://trac.sitecore.net/EditForm/ In Sitecore&#8217;s Content Manager, performing actions such as a delete against many items can be very cumbersome. You need to right click each of the items and then click on the Delete menu &#8230; <a href="http://blog.velir.com/index.php/2012/02/21/sitecore-edit-form/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p></a><strong>Where can the Module be found? </strong><a href="http://trac.sitecore.net/EditForm/" target="_blank">http://trac.sitecore.net/EditForm/</a></p>
<p>In Sitecore&#8217;s Content Manager, performing actions such as a delete against many items can be very cumbersome.  You need to right click each of the items and then click on the Delete menu item individually.  This approach works fine when you are deleting one or two items but when you need to delete items in bulk you are losing productivity.  The Edit Form is a Sitecore Shared Source Module that provides the content editors with the ability to perform multiple tasks at once, such as copy, cut, and delete.  The form allows a user to simply click on multiple items, putting each clicked item in a &#8220;Selected&#8221; state, shown in the screenshot below.  Once one or more items have been selected we can then select a command.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/EditForm.png"><img src="http://blog.velir.com/wp-content/uploads/2012/02/EditForm.png" alt="Edit Form" title="Edit Form" width="594" height="330" class="alignleft size-full wp-image-2187" /></a></p>
<p>The Edit Form is packaged with three commands, Copy, Cut and Delete, which can all be customized within the Content Manager.  For example, you are able to change the sort order of the buttons, delete a button, change the click event for a command to a custom javascript method and even add your own custom command to the Edit Form.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/EditFormButtonCropped.png"><img src="http://blog.velir.com/wp-content/uploads/2012/02/EditFormButtonCropped.png" alt="Edit Form Button Customization" title="Edit Form Button Customization" width="637" height="366" class="alignleft size-full wp-image-2189" /></a></p>
<p>The packaged cut, copy and delete commands make use of the Sitecore pipeline, which means that as the Edit Form&#8217;s commands are being executed, they are following the normal process of the respective command in the right click Context Menu.  This ensures that custom functionality such as the shared source module the <a href="http://trac.sitecore.net/MoveValidator/" target="_blank">Move Validator</a> that we created earlier in the year will be utilized.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2012/02/21/sitecore-edit-form/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Enhanced Template Builder</title>
		<link>http://blog.velir.com/index.php/2012/02/07/enhanced-template-builder/</link>
		<comments>http://blog.velir.com/index.php/2012/02/07/enhanced-template-builder/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 20:28:21 +0000</pubDate>
		<dc:creator>TimB</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[sitecore]]></category>
		<category><![CDATA[Velir]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=2123</guid>
		<description><![CDATA[.Net developers at Velir have experience implementing the Enhanced Template Builder. Where can the Module be found? http://trac.sitecore.net/EnhancedTemplateBuilder/ What is the Enhanced Template Builder The Enhanced Template Builder is a Sitecore Shared Source module that allows the user to easily &#8230; <a href="http://blog.velir.com/index.php/2012/02/07/enhanced-template-builder/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>.Net developers at Velir have experience implementing the Enhanced Template Builder.</p>
<p><strong>Where can the Module be found? </strong><a href="http://trac.sitecore.net/EnhancedTemplateBuilder/" target="_blank">http://trac.sitecore.net/EnhancedTemplateBuilder/</a></p>
<p><strong>What is the Enhanced Template Builder</strong></p>
<p>The Enhanced Template Builder is a Sitecore Shared Source module that allows the user to easily create and edit templates.  It focuses on providing the user with tools and options such as the Field Type Selector, Source Field Builder and the Required Field checkbox that allow for a more efficient and streamlined experience.</p>
<p><strong>Field Type Selector</strong></p>
<p>Selecting a field type can be a confusing process due to the vast amount of field types with similar names and functionality.  What ends up happening is you go back and forth between the template and a content item to verify that this is the actual field type you would like to use for that field.   Going back and forth from the template to the item may happen several times until the correct field type is selected.  On the Enhanced Template Builder form I have added an image button to the right of the Field Type dropdown list.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_FieldTypeCropped.png"><img title="Template Builder Field Type Image Button" alt="Template Builder Field Type Image Button" class="alignleft size-full wp-image-2134" src="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_FieldTypeCropped.png" width="585" height="159" /></a></p>
<p>By clicking on the image button, it will launch the Field Type Selector modal (a screenshot of the modal is below) that consists of two sections.  The left side contains a content tree of the field types as specified in the core database.  This also includes custom fields that you may have developed.  By clicking a field type it will initiate the Preview section on the right which will render the selected field type.  By rendering the field, it allows the user to actively use the field as they normally would in the Sitecore Content Editor.  If this is the field you would like to use, you can click the Submit button and it will backfill the dropdown list on the Enhanced Template Builder, therefore selecting your field type.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_FieldTypeModal.png"><img title="Template Builder Field Type Selector Modal" alt="Template Builder Field Type Selector Modal" class="size-full wp-image-2135 alignleft" src="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_FieldTypeModal.png" width="573" height="354" /></a></p>
<p><strong>Source Field Builder</strong></p>
<p>The source field is very cumbersome if you wish to do anything more than selecting a root item for that field.   You need to know the Sitecore Query language which is confusing and most developers do not use it enough to remember the syntax.  Therefore you find yourself consistently going back to older projects or searching the internet for examples that we can modify and make work to the needs of our field.  On the Enhanced Template Builder form I have added an image button to the right of the source field and when clicked launches the Source Field Builder.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_SourceFieldCropped.png"><img title="Source Field Image Button" alt="Source Field Image Button" class="alignleft size-full wp-image-2140" src="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_SourceFieldCropped.png" width="585" height="159" /></a></p>
<p>The Source Field Builder allows the user to select a root node, filter the query based on templates as well as defining whether the query is a deep or not.   This greatly increases the efficiency of any developer, reduces research time and allows the developer to focus their attention on more critical areas without having to worry about the proper syntax of a simple or complex query</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_SourceFieldSelectorModal_NotCropped2.png"><img title="Source Field Selector" alt="Source Field Selector" class="alignleft size-full wp-image-2145" src="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_SourceFieldSelectorModal_NotCropped2.png" width="651" height="741" /></a></p>
<p><strong>Required Field</strong></p>
<p>The template builder in its current form does not allow a field to be set as required.  To do so, you must leave the template builder and drill down to the field item and set the four fields under the Validation Rules section.   This means you need to save your changes, leave the template builder to set the field as required only to most likely return to the template builder to continue building the template.  To alleviate this I have added a required checkbox that when saved will auto-populate each of the four fields under Validation Rules with the Required flag.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_RequiredFieldCropped.png"><img title="Template Builder Required Field" alt="Template Builder Required Field" class="alignleft size-full wp-image-2131" src="http://blog.velir.com/wp-content/uploads/2012/02/TemplateBuilder_RequiredFieldCropped.png" width="587" height="155" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2012/02/07/enhanced-template-builder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Strategies for Mobile Applications and Sitecore Part 2</title>
		<link>http://blog.velir.com/index.php/2011/12/21/strategies-for-mobile-applications-and-sitecore-part-2/</link>
		<comments>http://blog.velir.com/index.php/2011/12/21/strategies-for-mobile-applications-and-sitecore-part-2/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 19:51:37 +0000</pubDate>
		<dc:creator>Daniel DeLay</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=2057</guid>
		<description><![CDATA[This is Part 2 of our blog post about how we used Sitecore to make a Mobile API. To recap, this single API is used to drive 4 different devices, iPhone, iPad, Andriod, and Blackberry. In the first part we &#8230; <a href="http://blog.velir.com/index.php/2011/12/21/strategies-for-mobile-applications-and-sitecore-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is Part 2 of our blog post about how we used Sitecore to make a Mobile API.   To recap, this single API is used to drive 4 different devices, iPhone, iPad, Andriod, and Blackberry.    In the first part we covered the highlights of Design Patterns, the RESTful API approach, as well as how we configured Sitecore to support our Mobile API.   This last point included Sitecore Devices, Layouts, and Content Tree Structure.</p>
<p>In Part 2 we’ll be looking at more technical issues such as how we build the API codebase in Visual Studio, the XML and JSON serialization components, and the scenarios our caching strategy covers.</p>
<p><strong>API Architecture</strong></p>
<p>The API we built in Visual Studio can be grouped into two areas: the Model classes and the Sublayouts.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_model-tree.png"><img class="aligncenter size-full wp-image-1810" title="mblog_model-tree" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_model-tree.png" alt="" width="264" height="404" /></a></p>
<p><strong>Model Classes</strong></p>
<p>As you likely know, a Model class (sometimes called an Entity Class), contains all the properties that define a single Object. We’ll have a model class for each type of object we want to send back to our mobile apps. For example, there is an Article class, an Expert class, and a Topic class.</p>
<p>These models are then serialized into either JSON or XML. To accomplish the serialization we use features that area already part of the .NET Framework. Namely DataContractSerializer and DataContractJsonSerializer. These two classes rely on Reflection to identify serializable classes and methods using attributes called DataContract (for the class) and DataMember (for the properties).</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/12/mblog_data_contract_dr.png"><img class="aligncenter size-full wp-image-2102" title="mblog_data_contract_dr" src="http://blog.velir.com/wp-content/uploads/2011/12/mblog_data_contract_dr.png" alt="" width="426" height="467" /></a></p>
<p>One common question from folks who use the Custom Item Generator is: why not just use the generated classes as our Models?</p>
<p>A little background on the CIG: The goal of the Custom Item Generator is to facilitate agile development through code generation. Each custom item class is a reflection of the corresponding template found in Sitecore. As changes are made to a template in Sitecore, the custom item file can be regenerated to show the new fields, new base classes, and any field updates.</p>
<p>However the information we send to our mobile apps necessarily needs to be fixed or it would require a client update on the mobile devices. For example, the mobile clients are expecting specific fields with specific names to be passed through via the JSON. The code generation of the custom item generator makes it really easy to rename or remove fields which has the huge impact of breaking the data contract between Sitecore and the mobile devices. So we keep these model classes to expose just the data that is need for the mobile apps in an easily serializable way as well as for maintaining that data contract. There are other ways to accomplish the same goal, (maybe a Mobile API Interface), this way worked well for us.</p>
<p><strong>Layouts and Sublayouts</strong></p>
<p>The Mobile API layout and sublayouts, as we saw, are plugged into the Mobile API Device. For our case, we know we’re going to be returning something more data oriented like JSON or XML so we don’t need much in presentation. Therefore our Layout file is very simple and only contains a Placeholder for the Sublayout.</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_layouts_diagram.png"><img class="aligncenter size-full wp-image-1841" title="mblog_layouts_diagram" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_layouts_diagram.png" alt="" width="553" height="221" /></a></p>
<p>For the Sublayouts, there is one for each request type. In our example we’ll be looking at segments from the Article sublayout. Each sublayout has a couple common responsibilites: they should a) populate the equivalent Model Class, and b) issue the JSON/XML Response. For issuing the Response, let’s look at the following segment:</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_sublayout_response.png"><img class="aligncenter size-full wp-image-1815" title="mblog_sublayout_response" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_sublayout_response.png" alt="" width="594" height="180" /></a></p>
<p>This snippet deserves a little discussion because it has some elements we haven’t talked about yet. First, our mobile apps have the option of including a date with the request representing the last time that mobile app issued that request. The idea is that if the mobile app has issued that request before and the content on the server hasn’t changed, then the mobile app is allowed to use its local cache. Let’s explain:</p>
<p>In the first condition, if there is no date (LastFetchValue == null) or if the date is more recent than the last time the content was updated (represented as ‘mostRecentUpdateUtc’), then we will execute the serialization normally and return that in the response.</p>
<p>However, if there was a date, and it is more recent than the last time the content was updated, then we have the opportunity for some performance gains. We will skip the serialization (gain 1); return something very small, a “Not Modified” response code (gain 2); which then tells the mobile app to use its local cache (gain 3).</p>
<p><strong>Base Class: ApiResponder</strong></p>
<p>Because the goals of each Sublayout are similar, there is a benefit to having each sublayout inherit from a base class which can implement common actions. Our base class is called ApiResponder. This baseclass shares its implementation with the Sublayouts for the following two areas: a) execution of the JSON/XML Serialization and b) cache management (which we haven’t talked much about yet). The following is a segment from ApiResponder that handles the serialization:</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_serialize_switch.png"><img class="aligncenter size-full wp-image-1814" title="mblog_serialize_switch" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_serialize_switch.png" alt="" width="600" height="223" /></a></p>
<p>In this code snippet we’re calling the appropriate DataContract method depending on which serialization format has been requested.</p>
<p><strong>Caching Strategy</strong></p>
<p>We’ve identified so far that there is a caching strategy involved. Let’s look more closely at what this means. First, some of the benefits we’ll gain from using caching:</p>
<ul>
<li>When we use a caching strategy it can result in fewer round trips to the server</li>
<li>This implies less load on the server which increases scalability</li>
<li>We gain faster page loads when using the local cache</li>
<li>This implies a better user experience.</li>
</ul>
<p><strong>Local Cache DB</strong></p>
<p>A local cache on a mobile device can be something as straightforward as a database record. Take this example which is essentially what we need: The record contains:</p>
<ul>
<li>The URL which for our RESTful API is the equivalent of the web method call.</li>
<li>The Response: which for our app will contain the raw JSON/XML from the initial request</li>
<li>The Date: this is what we use to record the date/time our response data was collected from the server.</li>
</ul>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/12/mblog_cache_record_dr.png"><img class="aligncenter size-full wp-image-2103" title="mblog_cache_record_dr" src="http://blog.velir.com/wp-content/uploads/2011/12/mblog_cache_record_dr.png" alt="" width="700" height="284" /></a></p>
<p style="text-align: center;">
<p>Next, let’s look at the logic behind how we will use our cache. This somewhat complex looking Cache State Diagram can be summarized in 4 basic use cases. But first to understand it we need to introduce the concept of the cache trust period. That is to say, suppose our period is 20 minutes, then our mobile app will trust the local cache for 20 minutes. Any requests for something in the cache that is older than 20 minutes is considered stale, requiring a request to Sitecore.</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_cache_state_diagram.png"><img class="aligncenter size-full wp-image-1819" title="mblog_cache_state_diagram" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_cache_state_diagram.png" alt="" width="588" height="309" /></a></p>
<p><strong>Use Cases</strong></p>
<p><strong>#1: The user requests from the mobile app an Expert page for the first time.</strong></p>
<p>Because it’s the first request, there will not be a record in the local cache. Our flow will go to Sitecore. Because there is no date in our request, Sitecore will issue a serialized response of the Expert item. Our mobile app will store that response data in the cache table and render the view.</p>
<p><strong>#2: The user requests the same Expert page 10 minutes later.</strong></p>
<p>The response data will already be in our cache db, and because it is only 10 minutes old, it is under our 20 minute threshold. We can use the local cache and avoid reaching out to Sitecore entirely. Because we didn’t check with Sitecore we will not modify the date already in our cache record.</p>
<p><strong>#3: The user requests the same Expert page 20 minutes later.</strong></p>
<p>We are now 30 minutes after our initial request, or 10 minutes beyond our threshold. So the response data will be found in our cache table, but it is considered stale. Therefore we issue a request to Sitecore. In this use case, let’s assume that nothing has changed on this expert page within the last 30 minutes. Sitecore will now bypass the serialization and instead issue a 304 code as the result. Our mobile app, when receiving the 304 code, knows to use the local cache. And because we did confirm this content with Sitecore we will modify the date on our cache record.</p>
<p><strong>#4: The user requests the same Expert page 30 minutes later.</strong></p>
<p>Again, we are 10 minutes past our threshold for determining if our local cache is stale. Similar to use case #3 we will send our request to Sitecore. This time, let’s say that something did change on this Expert page within the last 30 minutes. Therefore Sitecore will execute the serialization and return that in the response. Our mobile app will update the local cache record with the latest data and a new date, and render the view to the user.</p>
<p>If you followed along, we covered each state represented in the diagram. Cool! We’ve also now described and implemented a very robust caching system that will improve the user experience, and decrease the server load.</p>
<p><strong>Sitecore Publishing Strategies</strong></p>
<p><strong>Hiding Pages from Mobile Devices</strong></p>
<p>There are some mechanics we can provide to make managing mobile content easier for content authors. One example is suppose our website has pages that are great for a desktop web browser but are less friendly for mobile devices. I’m looking at you, Mr. Flash Media Player. A simple checkbox in the Sitecore template can address this for the content author’s experience. And in the back end, we’ll want to implement code to ensure these pages are not discoverable on mobile apps.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_mobile_friendly_checkbox.png"><img class="aligncenter size-full wp-image-1820" title="mblog_mobile_friendly_checkbox" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_mobile_friendly_checkbox.png" alt="" width="297" height="307" /></a></p>
<p><strong>Hiding Content from Mobile Devices</strong></p>
<p>Or, if we want the page to be discoverable on mobile apps, but perhaps there is something on the page from a Rich Text Editor that isn’t going to render well, that can be addressed too. In this case we added a button to the Rich Text interface which inserts a not-mobile tag. In the codebase we add a Mobile Tag Resolver class which goes into the Rich Text pipeline. This class is responsible for removing the not-mobile wrapped content prior to serialization. Additionally there is a message attribute. Our content authors can add text here which the viewer would see instead of the original content. Something like, “This table has been removed from the mobile view. Please view this page on a desktop/laptop to see the table.”</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_rich_text.png"><img class="aligncenter size-full wp-image-1821" title="mblog_rich_text" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_rich_text.png" alt="" width="600" height="311" /></a></p>
<p>In addition to flash content, examples of things that may be removed include large images and complex table layouts.</p>
<p><strong>Additional Strategies to Consider</strong></p>
<p><strong>Identify a target OS and Feature set</strong></p>
<p>In contrast to simply building a Blackberry app, identify the minimum version and OS that this app will support. It will greatly simplify the requirements and codebase when there isn’t a need to support every possible scenario. The further back we go, the harder it is to maintain, obviously. Take for example a web application that is required to support IE6 vs one that only needs to provide support for IE7/8. Enough said.</p>
<p><strong>Render images asynchronously</strong></p>
<p>Note that in our JSON/XML we are not passing the images themselves, but rather we are passing the location of the image. This means that we’re still going to need to get those images. A good strategy here is to go ahead and load as much of the view as possible, while in the background retrieve and load in the images asynchronously. The benefits of getting the user to their content as fast as possible goes without saying, and this one way to improve the user experience.</p>
<p>Keep the user within the app for internal links</p>
<p>In rich text content, authors have the flexibility to add both external links to pages out in the webiverse and internal links to other Sitecore based content. If our mobile app supports internally linked content, such as Article and Expert pages, then the worst thing to happen would be to have the user click that link and see it opened in the mobile device’s browser. Ideally what we want is to keep the user inside the context of the mobile app. Our method here was to append api=1 to the end of internal URLs prior to returning the response. This will be the indicator our mobile app uses to keep the rendering with the mobile app.</p>
<p><strong>Recap</strong></p>
<p>There are a number of different strategies we looked at to conceptualize the Mobile App integration with Sitecore.</p>
<p>RESTful API: We looked at the specifics of what it means to be RESTful as well as relating this to design patterns and their benefits.</p>
<p>Sitecore Configuration: We looked at how Sitecore was configured using standard Sitecore features in order to facilitate the use of the RESTful API concepts and coordinate the codebase.</p>
<p>The Code: We looked first at Model classes which would become serialized and represent our response data. And we looked at the Sublayouts and their shared base class, the API Responder which was responsible for populating the Models, executing the serialization, and managing the cache.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_resting_dude2.jpg"><img class="aligncenter size-full wp-image-1847" title="mblog_resting_dude2" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_resting_dude2.jpg" alt="" width="489" height="362" /></a></p>
<p><strong>References</strong></p>
<p>RESTful API</p>
<p><a href="http://www.freshblurbs.com/pragmatic-restful-api-design"><strong>http://www.freshblurbs.com/pragmatic-restful-api-design</strong></a></p>
<p><a href="https://www.ibm.com/developerworks/webservices/library/ws-restful/"><strong>https://www.ibm.com/developerworks/webservices/library/ws-restful/</strong></a></p>
<p><a href="http://en.wikipedia.org/wiki/Representational_State_Transfer"><strong>http://en.wikipedia.org/wiki/Representational_State_Transfer</strong></a></p>
<p>DataContract Serialization</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms733127.aspx"><strong>http://msdn.microsoft.com/en-us/library/ms733127.aspx</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2011/12/21/strategies-for-mobile-applications-and-sitecore-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strategies for Mobile Applications and Sitecore Part 1</title>
		<link>http://blog.velir.com/index.php/2011/12/14/strategies-for-mobile-applications-and-sitecore-part-1/</link>
		<comments>http://blog.velir.com/index.php/2011/12/14/strategies-for-mobile-applications-and-sitecore-part-1/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 19:16:31 +0000</pubDate>
		<dc:creator>Daniel DeLay</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mobile Development]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=1994</guid>
		<description><![CDATA[Recently Velir had the opportunity to build Mobile Applications for one of our very prominent clients. One of the challenges was an interest in supporting iPhone, Android, and Blackberry devices. Our content is stored in Sitecore, so we wanted to &#8230; <a href="http://blog.velir.com/index.php/2011/12/14/strategies-for-mobile-applications-and-sitecore-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently Velir had the opportunity to build Mobile Applications for one of our very prominent clients. One of the challenges was an interest in supporting iPhone, Android, and Blackberry devices. Our content is stored in Sitecore, so we wanted to retain this as the single source of content. Our goal was to build a single API in Sitecore to support the Mobile Applications and which can be reused for additional devices in the future. Indeed, when it became time to build the iPad Application in a later phase, the API proved to be completely reusable.</p>
<p>At a high level, the requirements included:</p>
<ul>
<li>Sitecore      continues to be the single source of content.</li>
<li>The      Mobile API is to be built using the Sitecore API and the custom .NET code      that already powers the website</li>
<li>The      Mobile API needs to be device agnostic. We&#8217;re originally targeting clients      that will be built in Object C (IPhone) and Java (Android/Blackberry)</li>
</ul>
<p>One of the great things about Sitecore, and ideally why we would want to use any CMS, is the ability to maintain our content in a single environment, then to reuse that content in a variety of environments and mediums including Web, RSS, Newsletters, Print Media, Social Media, and this article&#8217;s topic: Mobile Applications.</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/08/mblog_modalities2.png"><img class="size-large wp-image-1864 aligncenter" style="margin-top: 10px; margin-bottom: 10px;" title="mblog_modalities2" src="http://blog.velir.com/wp-content/uploads/2011/08/mblog_modalities2-1024x476.png" alt="" width="512" height="238" /></a></p>
<p><strong>Restful API</strong></p>
<p>The foundation for building this API was to prescribe to the RESTful pattern. This can be thought of as a Design Pattern for building reusable APIs. Some important aspects of Design Patterns in general include:</p>
<ul>
<li> Shared      common language between developers. (If I use Design Pattern &#8220;A&#8221;      and the next developer knows Design Pattern &#8220;A&#8221;, then there will      be certain constructs and vocabularies that are assumed. Essentially we      both speak the same language)</li>
<li> A      Design Pattern is a structure that has been found acceptable for solving a      particular problem.</li>
<li>A      Design Pattern is robust; it has withstood the test of time and analysis.</li>
</ul>
<p>As a Design Pattern, building a Restful API fits in well with our goals as many of its tenents will be beneficial to us. Some of the key tenents that we are interested in include:</p>
<ul>
<li><strong>Stateless</strong>:      Our Mobile Apps will not be reliant on session data, a simple request and      response is all that his required.</li>
<li><strong>JSON/XML</strong>:      The response should be an abstraction of the data that is easily consumed.</li>
<li><strong>HTTP      Methods</strong>: Also called verbs, the RESTful web methods should use      GET/POST/PUT/DELETE as intended. For example, calling GET should only      retrieve information. It shouldn&#8217;t be used to create or delete records.</li>
<li><strong>Directory      Based URIs</strong>: With RESTful, the directory and filename is the API call.      This fits in very well with Sitecore since Sitecore&#8217;s URI structure      already mirrors the content tree.</li>
<p><strong>Configuring Sitecore</strong></p>
<p>We&#8217;ll be looking at a few places where we configure Sitecore to support the RESTful API. This part is straightforward and proves to be a natural fit within Sitecore which is a big win. It includes the Device Configuration, Presentation/Sublayouts, and the Content Tree structure.</p>
<p><strong>Device Configuration</strong></p>
<p style="text-align: left;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_device_configuration.png"><img class="size-full wp-image-1833 aligncenter" style="margin-top: 10px; margin-bottom: 10px;" title="mblog_device_configuration" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_device_configuration.png" alt="" width="618" height="427" /></a>Since browser requests look exactly the same as RESTful requests, we need a way to distinguish when our Mobile App is issuing the request. RESTful recommends using the ACCEPT header which can then ask for JSON or XML instead of the usual HTML. However in Sitecore what we really want to do is to call a different sublayout which will be responsible for returning JSON/XML instead of HTML. Sitecore makes it easy to do by using the Device Configurations. Here we can identify our device one of two ways, either by User-Agent or by Query Param. We decided to use the query param &#8220;api=1&#8243;. Thus when Sitecore sees the param it can switch to the sublayouts we&#8217;ve specified for handling Mobile API requests.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_device_configuration.png"></a></p>
<p><strong>Presentation Settings</strong></p>
<p>The Default Device in Sitecore generally contains layouts/sublayouts that are used for the HTML rendering of the website. Now that we have a MobileAPI Device we can use this to similarly store the layout/sublayouts we want to use to handle our API Request. In the following picture we focus in on the MobileAPI devices&#8217; layout and sublayout for an Article page<strong>.</strong></p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_layout_details.png"><img class="size-full wp-image-1806 aligncenter" style="margin-top: 10px; margin-bottom: 10px;" title="mblog_layout_details" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_layout_details.png" alt="" width="507" height="159" /></a></p>
<p>In the following two screens we should the difference between a page rendered with the Default Device, which returns HTML, and a page rendered with the MobileAPI Device, which returns JSON.</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/12/mblog_html_page_dr.png"><img class="aligncenter size-medium wp-image-2100" title="mblog_html_page_dr" src="http://blog.velir.com/wp-content/uploads/2011/12/mblog_html_page_dr-300x186.png" alt="" width="300" height="186" /></a></p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/12/mblog_json_page_dr.png"><img class="aligncenter size-full wp-image-2098" title="mblog_json_page_dr" src="http://blog.velir.com/wp-content/uploads/2011/12/mblog_json_page_dr.png" alt="" width="429" height="163" /></a></p>
<p><strong>Content Tree Design</strong></p>
<p>As mentioned earlier, the synergy between the way that Sitecore constructs URLs from the Content Tree path and the RESTful API approach to web method calls is important. If we want to retrieve a list of all Experts for example, we would issue a request to the node representing the Experts folder such as: http://www.rilev.edu/experts.aspx</p>
<p>However if we wanted an individual Expert, the method call would extend upon this path to include the specific Expert. For Example:</p>
<p>http://www.rilev.edu/experts/ddelay.aspx</p>
<p>(Note that the /a/ has been stripped from the request. The /a/ is important in the Sitecore content tree for organizational and performance purposes. It is okay to keep this in the request, but isn&#8217;t required. So for simplicity and readability, we remove this by adding a custom ItemResolver class to the pipeline in Sitecore.)</p>
<p style="text-align: center;"><a href="http://blog.velir.com/wp-content/uploads/2011/07/mblog_expert_content_tree.png"><img class="size-full wp-image-1835 aligncenter" title="mblog_expert_content_tree" src="http://blog.velir.com/wp-content/uploads/2011/07/mblog_expert_content_tree.png" alt="" width="224" height="371" /></a></p>
<p>This is it for Part 1. In Part 2 of this blog post we&#8217;ll delve deeply into several technical topics such as the API Architecture, Caching Strategy &amp; Use Cases.</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2011/12/14/strategies-for-mobile-applications-and-sitecore-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lazy Websites</title>
		<link>http://blog.velir.com/index.php/2011/09/22/lazy-websites/</link>
		<comments>http://blog.velir.com/index.php/2011/09/22/lazy-websites/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 16:40:33 +0000</pubDate>
		<dc:creator>Martin Fowler</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[lazy loading]]></category>
		<category><![CDATA[sitecore]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=1871</guid>
		<description><![CDATA[We often build websites that showcase a large amount of high quality media in the form of images, text, and video. While this media makes for a compelling user experience it often comes at the cost of bandwidth in terms &#8230; <a href="http://blog.velir.com/index.php/2011/09/22/lazy-websites/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We often build websites that showcase a large amount of high quality media in the form of images, text, and video.  While this media makes for a compelling user experience it often comes at the cost of bandwidth in terms of network throughput and server processing power.  It is our challenge as developers to show as much of this high quality media in as little time as possible, and make sure it does not negatively impact the user’s browsing experience.  I’d like to share a technique known as Lazy Loading which we have used to show a large number of high quality images with little effect on the visitor’s browsing experience.</p>
<p><a href="http://en.wikipedia.org/wiki/Lazy_loading" target="_blank">Lazy Loading</a> is a design pattern that is used to defer the loading of information or content until it is needed. This pattern has several implementations that can be used to improve the performance of websites and applications.  The method we will focus on is called Lazy Initialization, in this pattern content will not be loaded until you actually need it.  If you have any sort of click navigation, or rotating features, or AJAX style design features, then it could become very easy for you to render content only when content is needed.  Let’s look at the workflow of a lazy loading solution and what it actually does to provide us with this benefit.</p>
<p>We will implement our lazy loading using JQuery AJAX and .NET Webservices.  On the client side, we use <a href="http://jquery.com/" target="_blank">JQuery</a> to create content control objects that will make an AJAX style call to an <strong><a href="http://msdn.microsoft.com/en-us/library/t745kdsh.aspx" target="_blank">ASP.NET Webservice</a>. </strong> This will perform the calculations and content fetching and return the required data in a JSON format. The data is then processed through JTemplate to produce the output.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/09/LazyLoadingUml.png"><img title="LazyLoadingUml" alt="" class="alignnone size-full wp-image-1895" src="http://blog.velir.com/wp-content/uploads/2011/09/LazyLoadingUml.png" width="282" height="317" /></a></p>
<p>Client calls out to a .NET Webservice and request a list of items from Sitecore. Then it will process the results from this request and compile that information into a JSON return object.</p>
<p>The following code shows an example of a JavaScript/JQuery object that includes an AJAX method for data retrieval.</p>
<pre class="brush:csharp">this.sendRequest = function (url, postData) {
			var data = { "scriptPostData": postData };
			$.ajax({
				type: 'POST',
				url: url,
				contentType: "application/json; charset=utf-8",
				dataType: 'json',
				data: JSON.stringify(data),
				success: this.cfg.OnDataSuccess
			});
		};</pre>
<p>The config value for OnDataSuccess is a callback method inside the Javascript object that is used to display the return results. For example, you can use a method that takes the data in the return object and displays the information using a template plugin like <a href="http://jtemplates.tpython.com/" target="_blank"><strong>JTemplate</strong></a>. For example:</p>
<pre class="brush:csharp">this.DefaultProcessData = function (response) {
			var items = { items: response.d.ContentItems };
			var cfg = JSON.parse(this.data);
			var contentArea = jQuery(cfg.scriptPostData.PlaceholderSelector);
			var oldHtml = contentArea.html();
			contentArea.setTemplateURL(cfg.scriptPostData.TemplateUrl, null, { filter_data: false });
			contentArea.processTemplate(items);
			contentArea.prepend(oldHtml);
}</pre>
<p>This type of implementation is used in a “Load More” scenario where the list renders the first (say 5) content objects. When the client clicks a button, it fires off a request to the content control object that uses a webservice to pull the next set of information. Next we will take a look at the ASP.NET Webservice’s side of Lazy Loading.</p>
<p>If you are not familiar with the process of creating a Webservice in Visual Studio, then take a look at this <a href="http://msdn.microsoft.com/en-us/library/8wbhsy70.aspx" target="_blank"><strong>MSDN article</strong></a>. After creating the webservice it should look something like this:</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/09/WebMethodBasic.png"><img title="WebMethodBasic" alt="" class="alignnone size-full wp-image-1914" src="http://blog.velir.com/wp-content/uploads/2011/09/WebMethodBasic.png" width="663" height="377" /></a></p>
<p>There is one additional thing requirement that is needed in the Webservice to allow JQuery to make the call. You will need to uncomment the class decoration for [ScriptService].</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/08/servicescript.png"><img title="servicescript" alt="" class="alignnone size-full wp-image-1876" src="http://blog.velir.com/wp-content/uploads/2011/08/servicescript.png" width="640" height="32" /></a></p>
<p>Now its time to implement your own Webmethod to process the request from the AJAX call. To make things easier, you should first implement 2 data contracts. The first data contract will represent the values being sent to the Webservice from the AJAX JSON POST request, while the second data contract will represent the return value. This return value will be converted to a JSON string that can then be parsed and used in the return method. Here is how we create the classes inline with the Webservice code:</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/08/postDataContract.png"><img title="postDataContract" alt="" class="alignnone size-full wp-image-1877" src="http://blog.velir.com/wp-content/uploads/2011/08/postDataContract.png" width="401" height="354" /></a></p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/08/ReturnContent.png"><img title="ReturnContent" alt="" class="alignnone size-full wp-image-1879" src="http://blog.velir.com/wp-content/uploads/2011/08/ReturnContent.png" width="553" height="372" /></a></p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/08/ContentItem.png"><img title="ContentItem" alt="" class="alignnone size-full wp-image-1880" src="http://blog.velir.com/wp-content/uploads/2011/08/ContentItem.png" width="363" height="409" /></a></p>
<p>Now that we have the data contracts, we can access the information that the JQuery AJAX call is sending to us, and the JQuery return method will be able to understand our responses. Our new WebMethod looks like this:</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/08/WebMethodBasic.png"><img title="WebMethodBasic" alt="" class="alignnone size-full wp-image-1878" src="http://blog.velir.com/wp-content/uploads/2011/08/WebMethodBasic.png" width="346" height="62" /></a></p>
<p>The GetContent method retrieves the Content Item objects and then inserts them into the Return Content object. The return object is then serialized into a JSON string (which is handled by ASP.NET behind the scenes so there&#8217;s no need to worry about this part) and then sent back to the AJAX request call. Finally, when the AJAX call receives the data it fires off the OnDataSuccess callback method to handle and process the return results.</p>
<p>That&#8217;s all there is to creating and using the Lazy Initialization pattern using JQuery and ASP.NET Webservices. In our testing we have seen pages that would have taken up to 20 to 30 seconds to load, but by using Lazy Loading they have been reduced to roughly 500 milliseconds. I would consider this to be a  mission accomplished and would say that here is proof that it pays to be Lazy!</p>
<p>Here are a couple of notes to consider before implementing this yourself.</p>
<p>1.) The Request type for the JQuery AJAX call *must* be POST. Because of this, you can forget about using services to cache the response from the request. Instead, use localized caching methods to speed up requests. For instance, we make our cache key named based on values of input to the GetContent webmethod. Applying this method will greatly reduce the load on your servers when users send the request to load more content. This is what our cache key looks like.</p>
<p><a href="http://blog.velir.com/wp-content/uploads/2011/08/CacheKey.png"><img title="CacheKey" alt="" class="alignnone size-full wp-image-1882" src="http://blog.velir.com/wp-content/uploads/2011/08/CacheKey.png" width="528" height="74" /></a></p>
<p>We then use a cache object to insert / retrieve values of the cache based on this key.</p>
<p>2.) You can implement the “GetContent” method with any signature you like, but he data you pass to it from the JQuery must match the signature. So in this case you see that the JQuery sends in the post data a JSON stringafied object that within it contains a variable “scriptPostData” which matches up to the name of the variable in the signature of the WebMethod. While you don’t need to use a single object for the information you pass to the Webservice, it is much easier to use this PostData object, than it is to list out 10+ variables in the WebMethod signature.</p>
<p>To read more about the other types of Lazy Loading (Virtual Proxy, Virtual Holder, and Ghost), please see the <a href="http://en.wikipedia.org/wiki/Lazy_loading">Lazy Loading</a> article on Wikipedia.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2011/09/22/lazy-websites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Improve Code Reusability Using C# Delegates</title>
		<link>http://blog.velir.com/index.php/2011/07/14/how-to-improve-code-reusability-using-c-delegates/</link>
		<comments>http://blog.velir.com/index.php/2011/07/14/how-to-improve-code-reusability-using-c-delegates/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 17:09:20 +0000</pubDate>
		<dc:creator>PaulG</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[lambda]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=1703</guid>
		<description><![CDATA[Delegates are a powerful, functional language feature of C# that are heavily utilized but rarely implemented by most developers who are not familiar of the advantages they give you. Similar to function pointers in C/C++, delegates in C# allow you &#8230; <a href="http://blog.velir.com/index.php/2011/07/14/how-to-improve-code-reusability-using-c-delegates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>Delegates are a powerful, functional language feature of C# that are heavily utilized but rarely implemented by most developers who are not familiar of the advantages they give you. Similar to function pointers in C/C++, delegates in C# allow you to assign a type to a particular method signature. In addition to referencing existing methods as delegates, C# also lets you define delegates inline as anonymous methods. We can apply static typing to both the input parameters and return value of a delegate, a concept I will touch upon again later in this post. If you&#8217;ve been programming in C# for any significant period of time, you&#8217;ve almost certainly run into delegates while using LINQ. Without getting into LINQ and how awesome it is (note: it is awesome), I&#8217;m going to explain how you yourself can use delegates to make code that is vastly more robust, clean, and powerful. This post is intended for developers who have the following skills:</div>
<ul>
<li>Experience writing C# code.</li>
<li>The ability to use delegates already. Maybe you just don’t use them often or are not sure how utilize them effectively. Knowing how to use delegates will be important as I don’t cover this. I recommend reading the <a href="http://msdn.microsoft.com/en-us/library/ms379564.aspx">MSDN documentation</a> on them if you don’t already have experience with them.</li>
<li>Intermediate programming experience. I&#8217;ll be using some programming jargon that will seem foreign to novice programmers. If you&#8217;re a novice but consider yourself up to the challenge, feel free to continue with the tutorial as you too will certainly get something out of it.</li>
</ul>
<h2>Why Delegates?</h2>
<div>When you think with delegates, you will find yourself writing not just methods that do one thing, but little behavioral engines that a developer can enhance, reuse, and extend. The amount of refactoring will drop significantly, because instead of having a large number of rigid methods each doing a very specific task, you will have a smaller number of much more general methods that can be enhanced to handle a wide variety of potential scenarios. Your code will become highly reusable, and you will feel better about yourself because of it.  Consider the following case where we have a list processor that takes in a list of strings and processes each item in the list, and then returns a new list of the processed strings. The current implementation replaces all instances of “a” with “b” for each string in the list.</div>
<pre class="brush:csharp">public class ListProcessor
{
        public static List&lt;string&gt; ProcessList(List&lt;string&gt; strings)
        {
                List newList = new List();
                foreach (string str in strings)
                {
                        newList.Add(ProcessItem(str));
                }
                return newList;
        }

        private string ProcessItem(string str)
        {
                return str.Replace("a", "b");
        }
}</pre>
<div>Cool, it does its job, but what if we want to use this for other tasks? What if we want to modify what we do to each of the strings? Let’s use delegates to solve this.</div>
<pre class="brush:csharp">public class ListProcessor
{
        public delegate string StringProcessor(string str);

        public static List&lt;string&gt; ProcessList(
                        List&lt;string&gt; strings,
                        StringProcessor processor)
        {
                List newList = new List();
                foreach (string str in strings)
                {
                        newList.Add(processor(str));
                }
                return newList;
        }
}</pre>
<div>Awesome, now we have the ability to do custom string processing, and aren’t limited to just replacing “a” with “b”. We can do whatever we want with the string now. To make the same call as in the original, you’d type:</div>
<pre class="brush:csharp">ListProcessor.ProcessList(
        myListOfStrings,
        str =&gt; str.Replace("a", "b"));</pre>
<div>What if we’d like to filter out certain items from being processed? We could just iterate over the items beforehand and filter them out, but as good software developers, we know that it’s wise to keep our code <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a>. Is there any way to avoid writing another loop, when we know that the ProcessList method has a perfectly nice one already? Yes. Let’s add a delegate that, if it returns false, doesn’t include that item in the return list, and have that be our acceptance condition for an item being retained in the returned list.</div>
<pre class="brush:csharp">public class ListProcessor
{
        public delegate bool StringAcceptor(string str);

        public delegate string StringProcessor(string str);

        public static List&lt;string&gt; ProcessList(
                        List&lt;string&gt; strings,
                        StringAcceptor acceptor,
                        StringProcessor processor)
        {
                List&lt;string&gt; newList = new List&lt;string&gt;();
                foreach (string str in strings)
                {
                        if (!acceptor(str))
                        {
                                continue;
                        }
                        newList.Add(processor(str));
                }
                return newList;
        }
}</pre>
<div>If the item passed into the StringAcceptor delegate returns false, then the item is not added to the return list, nor processed for that matter. Now, if we just want to process items who don’t have a “c” in them, and replace the instances of “a” with “b” in the ones we accept, we can do the following:</div>
<pre class="brush:csharp">ListProcessor.ProcessList(
        myListOfStrings,
        str =&gt; !str.Contains("c"),
        str =&gt; str.Replace("a", "b"));</pre>
<div>Simple enough. We now have a single method call that takes a list of items, filters out items with a “c” in them, and replaces all instances of “a” with “b”. Best of all, we can swap out the acceptance condition and processing method to suit whatever needs we have.</div>
<h2>Let’s Go Further With Generics</h2>
<div>Delegates support the powerful generics system in C#. Let’s take our code above, and refactor it to work on any kind of item, while retaining the static typing niceness of C#. We’re going to make this list processor take in a list of Type A and return a list of Type B. Now, our Acceptor (formerly StringAcceptor) delegate will accept items of Type A, and our Processor (formerly StringProcessor) takes in objects of Type A and outputs objects of Type B (note: We can make it take in and pump out objects of the same type, if that is what we desire). Now, our ListProcessor class looks like this:</div>
<pre class="brush:csharp">public class ListProcessor
{
        // This is equivalent to the built-in Predicate delegate
        // http://msdn.microsoft.com/en-us/library/bfcke1bz.aspx
        public delegate bool Acceptor&lt;in TA&gt;(TA obj);

        public delegate TB Processor&lt;in TA, out TB&gt;(TA obj);

        public static List&lt;TB&gt; ProcessList(
                        List&lt;TA&gt; objects,
                        Acceptor&lt;TA&gt; acceptor,
                        Processor&lt;TA, TB&gt; processor)
        {
                List&lt;TB&gt; newList = new List&lt;TB&gt;();
                foreach (TA obj in objects)
                {
                        if (!acceptor(obj))
                        {
                                continue;
                        }
                        newList.Add(processor(obj));
                }
                return newList;
        }
}</pre>
<div>This still works:</div>
<pre class="brush:csharp">List&lt;string&gt; resultStrings = ListProcessor.ProcessList(
        myListOfStrings,
        str =&gt; !str.Contains("c"),
        str =&gt; str.Replace("a", "b"));</pre>
<div>But we can also do this:</div>
<pre class="brush:csharp">List&lt;Uri&gt; resultUris = ListProcessor.ProcessList(
        myListOfStrings,
        str =&gt; !str.Contains("amikawaiiuguu.com"),
        str =&gt; new Uri(str));</pre>
<div>If you’ve used LINQ before, you’re probably saying to yourself “this looks a lot like the stuff I do in LINQ”. That’s a good thing, because LINQ makes fantastic use of the delegate system in C#, and what we’ve done here is behaviorally the same to this LINQ statement:</div>
<pre class="brush:csharp">List&lt;Uri&gt; resultUris = myListOfStrings.
        Where(str =&gt; !str.Contains("amikawaiiuguu.com")).
        Select(str =&gt; new Uri(str)).ToList();</pre>
<div>We’re absolutely not limited to just lists though. Here’s an example of using delegates for validation on database records.</div>
<pre class="brush:csharp">public class DatabaseRecord
{
        public delegate bool RecordCallback&lt;in T&gt;(T record)
                where T : DatabaseRecord;

        // Returns true if the record is saved.
        public static bool SaveRecord(DatabaseRecord dbr)
        {
                // Saves the record
                // Assume this is implemented
        }

        // Returns false if the pre or post validation fail, or if the saving fails.
        // Returns true otherwise.
        public static bool SaveRecordWithValidation&lt;T&gt;(
                        T record,
                        RecordCallback&lt;T&gt; onPreSave,
                        RecordCallback&lt;T&gt; onPostSave)
                                where T : DatabaseRecord
        {
                return  onPreSave(record) &amp;&amp;
                        SaveRecord(record) &amp;&amp;
                        onPostSave(record);
        }
}</pre>
<div>Simply implement your database Record subclass and pass it to the DatabaseRecord.SaveRecordWithValidation method. Put in your pre- and post- save validations and you’ve got typesafe validations that can be dynamically set where needed. We’re just leveraging the ability to inject behavior to make our application level code more extensible and cleaner.</div>
<h2>Case in Point</h2>
<div>Delegates give developers the power to make methods that can have behavior injected into them, while retaining the type safety of C#. They lend themselves well to writing highly reusable and DRY code. They are very effective when used as callbacks to various system events, handling data structures that will have common code affecting it’s various parts, or if you want to write your code in a more functional style, such as utilizing advanced functional programming techniques like <a href="http://en.wikipedia.org/wiki/Currying">currying</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2011/07/14/how-to-improve-code-reusability-using-c-delegates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Published Item Comparer: Customization</title>
		<link>http://blog.velir.com/index.php/2011/06/27/published-item-comparer-customization/</link>
		<comments>http://blog.velir.com/index.php/2011/06/27/published-item-comparer-customization/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 14:11:08 +0000</pubDate>
		<dc:creator>TimB</dc:creator>
				<category><![CDATA[Published Item Comparer]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[item comparer]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://blog.velir.com/?p=1570</guid>
		<description><![CDATA[In my last post I introduced the Published Item Comparer and showed how convenient it was to visually compare an item between databases.  I also mentioned that the Published Item Comparer runs through a series of validations to determine differences &#8230; <a href="http://blog.velir.com/index.php/2011/06/27/published-item-comparer-customization/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my last post I introduced the <a title="Published Item Comparer" href="http://blog.velir.com/index.php/2011/04/29/published-item-comparer/">Published Item Comparer</a> and showed how convenient it was to visually compare an item between databases.  I also mentioned that the Published Item Comparer runs through a series of validations to determine differences between the item in context and the same item in the target database.   This post will explain how simple it is to create your own validators and remove existing validators.</p>
<p><strong>Creating Your Own Validator</strong></p>
<p>To create your own validator you will need to create a new class and inherit from the Validator base class (ItemComparer.Library.Validations.Validator). The base class contains the correct signature and parameters that the Item Comparer will call and pass during its validation process. I&#8217;ve included a quick example below which checks to make sure an item exists in the target database.</p>
<pre class="brush:csharp">    public class ExampleValidator : Validator
    {
        public override List Validate(ItemComparerContext context)
        {
            //default list
            List outputs = new List();

            //check to see if the item exists in the target database which
            //was specified in the settings item
            Item publishedItem = context.TargetDatabase.GetItem(context.Item.ID);
            if (publishedItem == null)
            {
                outputs.Add("The item does not exist in the target database.");
            }

            return outputs;
        }
    }</pre>
<p><strong>Adding your Validator to the Published Item Comparer</strong></p>
<p>The Item Comparer&#8217;s validators are managed within a configuration file. This gives us the flexibility to add, remove, and even position the order in which they run in. Positioning is important due to the fact that when the Item Comparer does its initial check against an item in the content tree, it stops when the first validation fails and outputs its result in the ribbon. Therefore its beneficial to have the less intensive, core validators run first. Once your Validator class is complete, you will need to add a line in the ItemComparer.config file (located: /App_Config/Include/ItemComparer.config). This will tell the Item Comparer to run the new validation during its process. If you needed to remove a Validator you only need to comment or remove that validation from the configuration file.</p>
<pre class="brush:xml">
<itemComparer>
	<validation type="ItemComparer.Library.Validations.ItemValidator, ItemComparer.Library"></validation>
	<validation type="ItemComparer.Library.Validations.AncestorValidator, ItemComparer.Library"></validation>
	<validation type="ItemComparer.Library.Validations.PresentationDetailValidator, ItemComparer.Library"></validation>
	<validation type="ItemComparer.Library.Validations.ItemsTemplateValidator, ItemComparer.Library"></validation>
	<validation type="ItemComparer.Library.Validations.TemplateValidator, ItemComparer.Library"></validation>
</itemComparer>
</pre>
<p><strong>Item Comparer Context Object</strong></p>
<p>Each validation class implements a member called Validate which takes in the ItemComparerContext object. This object gives you direct access to a few useful objects and was meant to decrease the amount of redundant lookups within each validator class.</p>
<pre class="brush:csharp">    public class ItemComparerContext
    {
        public Item Item { get; set; }
        public ItemComparerSettingsItem ItemComparerSettingsItem { get; set; }
        public Database TargetDatabase { get; set; }
    }</pre>
<p><strong>Ending Note</strong><br />
Over the last couple months, Velir has added this module to several of our projects including a few of my own. My co-workers, clients and I are finding ourselves increasingly using this tool. One of the main reasons for the success of this module is we are able to add custom validations on a per project basis depending on that project&#8217;s needs.</p>
<p>I look forward to any comments or feedback regarding the module and I hope it has made it a little easier to compare an item between databases.<br />
Thanks!<br />
Tim</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.velir.com/index.php/2011/06/27/published-item-comparer-customization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

