onsdag den 7. januar 2015

Jeg hader at planlægge min arbejdstid men hader også at vide, at det er nødvendigt....

Jeg har derfor de sidste par måneder tvunget mig selv til at starte med at notere på et papir, hvad dagen skal bruges på.  Det virker egentlig meget godt men.....

Det sætter en stor fed bremse i min iver og energi fra morgenstunden af og gør egentlig at jeg er lidt træt af det hele inden jeg er kommet rigtigt igang.
Lidt ligesom at starte med at læse sine mails om morgenen!

Jeg har derfor lavet følgende tiltag

Jeg planlægger nu morgendagens arbejde inden jeg går hjem. 
Samme øvelse som tidligere bare dagen inden

Fordele
  1. Bedre hukommelse af, hvilke udeståender, der skal følges op på.
  2. Man får tænkt de ting igennem man allerede er igang med og opdager måske noget man har overset.
  3. Hjernen får tid til at koble af inden fyraften da vi i mange tilfælde undgår at risikere at komme i tanke om noget efter fyraften da vi allerede har været det hele igennem i planlægningen.
Ulemper
  1. Ingen undskyldning for at lægge sig på sofaen fordi man er træt og udkørt.
  2. Svært at overbevise konen om at man er meget vigtig på arbejde fordi man ikke hele tiden kommer på ting man lige skal notere på et stykke papir.

torsdag den 4. december 2014

Dependency Injection in a Nutshell

Issue

How to explain in a nutshell how dependency injection makes our code more robust, simple and more easy to maintain.

Case

I have a class that returns a list of user objects loaded from an XML-file.

 public class OpusRepository : IOpusRespository  
 {  
   public virtual List<OpusUser> Users()  
   {  
     // Read file from static path  
     // Get users from file  
     // return list of users  
   }  
 }  

The code that uses the IOpusRepository gets an instance of the OpusRepository class by calling a custom class that creates an instance of the OpusRepository.
It looks like this

onsdag den 12. november 2014

How to move users from Sitecore 5.3 to Sitecore 7.2

Issue

Users from a Sitecore 5 solution is needed in a new Sitecore 7.2 solution.

Solution

Two webforms are made. One to serialize users from the Sitecore 5.3 site into xml and one to import users into the Sitecore 7.2 site from the xml.

Serialization of users from Sitecore 5.3

This code iterates all users in the solution and writes it to an xmlfile in the App_Data folder. Username, Email, Fullname and roles are serialized.


onsdag den 5. november 2014

Sitecore as a Nuget-package - Buildsetup Part 1


Issue

One of our main issues when developing Sitecore solutions is to keep our sites up to date with Sitecore files.

The solution to this issue has for years been to run a custom robocopy script that copies the files from the public development server.
This requires that the server is always reachable, up to date and not infected with misplaced files.

Solution

I have made a script that takes a Sitecore zip installation file as input and creates a nuget-package from it.

This article will show how this is done.

Following steps are taken when creating the nuget-package
  1. Initializing variables
  2. Unpacking zip-file
  3. Moving data-folder to App_Data/Sitecore
  4. Creating force.txt files to force empty directories to be included in nuget-package
  5. Copy developer license file to App_Data/Sitecore/License
  6. web.config changes - Correcting paths to dataFolder and license file 
  7. Creating nuspec file - Syncronising version of Sitecore with the nuget-package
  8. Creating nuget package

tirsdag den 21. oktober 2014

Parameter "AssemblyFiles" has invalid value

Issue

When  referencing an assembly the compiler fails with this error

 error MSB3248: Parameter "AssemblyFiles" has invalid value "C:\CruiseControl\...\myAssembly.dll". Culture is not supported. [C:\CruiseControl\Projects\TemplateSite\WebApp\WebApp.csproj]  
 error MSB3248: Parameter name: name [C:\CruiseControl\..\WebApp.csproj]  
 myAssembly is an invalid culture identifier. [C:\CruiseControl\..\WebApp.csproj]  

Cause

This is caused by an invalid value in the AssemblyCulture attribute in the Assembly.cs

 [assembly: AssemblyCulture("myInvalidValue")]  

Solution

Set the AssemblyCulture to a valid value e.g. en-US or da-DK or just set it to default


 [assembly: AssemblyCulture("")]  

torsdag den 16. oktober 2014

How to prevent NAnt task returning code 3 to fail full buildprocess

Issue

The issue is that my buildscript fails because a task returns a code different from 0 even though the executable succeeds.

The buildscript contains a task that copies my website to a development server.
I use RoboCopy.exe to do this.

The task looks like this

  <target name="upload" depends="release"> 
   <exec 
    program="${robocopy}" 
    commandline=".\Website ${devroot}\www ${robocopyUploadArgs}" 
           /> 
  </target> 

However RoboCopy has a set of codes it can return depending on how many files were copied. See http://ss64.com/nt/robocopy-exit.html for more info.
Here it tells that a return value below 9 is a success.

Solution

By specifying to parameters; failonerror="false" and resultproperty="return.code" it is possible to tell NAnt that we dont want to fail on error but want the exit-code to be put in a property named return.code. Following a simple <if> task enables us to test and fail if the return code is larger than 8.
The script now looks like this (remember to add property named return.code)

torsdag den 18. september 2014

Sublayout caching disabled when sublayout is hidden by serverside code

Issue

I have a leftmenu that can be configured on the page-template to be hidden using a Sitecore field. When the editor sets a checkmark in the HideLeftMenu field the placeholder containing the sc:Sublayout control is hidden. This seems to result in that caching of the Sublayout is ignored.
The code looks like this

Markup

 <asp:PlaceHolder runat="server" ID="phLeftColumn">  
   <div class="col-sm-4 col-md-3">  
     <asp:ContentPlaceHolder runat="server" ID="cphPageContentLeft">  
       <dom:Sublayout runat="server" ID="submenu" Path="/layouts/LeftMenu.ascx" Cacheable="True" VaryByData="True" />  
     </asp:ContentPlaceHolder>  
   </div>  
 </asp:PlaceHolder>  

Code behind

 phLeftColumn.Visible = Sitecore.Context.Item["HideLeftMenu"] != "1";