February 28, 2017

Sitecore Server Switch

By: Craig Taylor
February 28, 2017

Sitecore Server Switch

One of the most time-consuming aspects of installing and configuring Sitecore is configuring the servers for their specific roles.  Per Sitecore documentation, specific configuration files should be enabled or disabled for a Content Management (CM) server and likewise, specific files should be enabled or disabled for Content Delivery (CD) server.  Failing to configure the servers for their roles can cause Sitecore to not perform as expected.

Note: There are additional roles for server configurations such as Processing, Reporting and Publishing.

Sitecore's ARM templates look to solve this problem in that they can quickly spin up and configure a Sitecore server, but this only works when using Azure PAAS.  For those not using Azure PAAS, manually adjusting the configuration files can be time consuming.

Sitecore Server Switch looks to solve this issue by using PowerShell.  After installing Sitecore on a server, you can run the "Sitecore_Switch_CM_CD_Lucene_Solr.ps1" script to configure a server as a CM server, as a CD server and additionally configure it to utilize either Lucene or Solr indexing.

Sitecore Server Switch currently supports Sitecore 8.0 (all versions) and Sitecore 8.2 Update 2.  More versions are coming soon.

Sources

Sitecore Server Switch GitHub Source
Sitecore Server Switch on the Sitecore Marketplace (coming soon!)

Acknowledgments

Big shout-out to Sarkis Einarsson for his PowerShell scripts that were the base of this project. (http://sitecoreunleashed.blogspot.com/2015/09/sitecore-8-toggle-cd-configuration.html)

Additional Reading

You can also take this to the next level and automate everything.  Check out Patrick Perrone's work into this space with his automation scripts.

Update (03/01/2017)

And of course, how it usually happens, after writing this module and post, I came across this site that has some automation scripts for 8.2 and even includes the ability to configure additional roles: https://bitbucket.org/sitecoreautomationteam/sitecore-automation/wiki/sitecore-environment
Note: I have not tested this.

And I've also been made aware of Michael West's PowerShell scripts as well: https://gist.github.com/michaellwest/d1124a459cb1fb47486f87d488ecfab8

February 17, 2017

Implement TDS Code Generation for a Helix Generic Repository Foundation Layer

By: Craig Taylor
February 17, 2017

Implement TDS Code Generation for a Helix Generic Repository Foundation Layer
I recently sat down to implement some of the suggestions from Phil and Jason's amazing book on Sitecore development, Professional Sitecore 8 Development.  I already had a few Helix architecture implementations under my belt, but felt like I could improve on what I had done.  I think it's probably the case after each implementation that you always find things to improve on for the next implementation. In particular, I was trying to get my Helix architecture to be more consistent, efficient and repeatable.

In chapter 5 of the Professional Sitecore 8 Development book, Phil and Jason speak of improving the architectural design by using design patterns.  Specifically, they recommend creating a generic repository foundation layer.  One of the tools that can help accomplish this goal is Glass Mapper.  Using Glass, we are able to let the repository remain generic and we can tell it the type of object to return at runtime.  In order to constrain the generic repository, their examples set the interface of the generic repository to require that the type being passed in implements "ICmsEntity" (a separate foundation layer that is used to represent a Sitecore item)

So, the "ICmsEntity" interface (code lifted directly from Professional Sitecore 8 Development) looks like this:
And the generic repository (code lifted directly from Professional Sitecore 8 Development)  looks like this:
As you can see, the ICmsEntity interface is empty.  It's really just a way to differentiate Sitecore items from other classes/items.  What we want to do is make sure that any interfaces that we create via Glass that represent Sitecore items implement this ICmsEntity interface.

The example in the book goes on to explain how you can utilize an ORM foundation layer to map to all your Sitecore objects.  In my case, I'm using Team Development For Sitecore (TDS) and have have TDS projects generating my code within my feature layers.

To utilize this generic repository and to have it incorporate the ICmsEntity interface constraint, we need to modify the code generation templates that TDS uses.  This is where it gets super-easy to implement. (wait, it's supposed to be difficult, right?)

First, edit the "glassv3header.tt" T4 template to import the namespace of the foundation layer that contains the ICmsEntity interface.  I'll continue to use the namespaces specified in the example from the book for consistency.  See line #11 below:

Now, edit the "glassv3item.tt" T4 template to have the interfaces that are created implement the ICmsEntity interface.  See line #8 below:

Re-generate your code and you're done!  You now automatically have all your Sitecore objects implementing the ICmsEntity interface and your generic repository will be able to retrieve the proper objects.

Additional Reading/Resources

Professional Sitecore 8 Development - You *do* have the book already, right??
Helix - Helix documentation