Estimated reading time:
After using Unicorn 2.x for a while now, I was excited at the prospect of Unicorn 3 - with its new serialization format that solves a lot of the problems with the standard Sitecore serialization API (cough long file names cough)! I can also confirm that the speed increases are pretty dramatic, I believe the claims of 50% faster than Unicorn 2!
The new serialization format caused a small problem tho. With Fortis, all the model classes are auto generated using a T4 template. The current code uses the Transitus NuGet package to read those files into strongly typed objects and then the T4 template iterates through those objects to build the interfaces and classes for our Sitecore models.
This didn’t work as Transitus uses the Sitecore serialization API to read the files.
With some pointers from Kamsar and digging around the Rainbow source code - I found I could just use the YamlSerializationFormatter.cs to read the YAML files and deserialize them into the same strongly typed objects that were used in Transitus.
Just pass in the filename and the
RainbowItem object is returned:
To use, add
Transitus.Rainbow to your project using the Nuget package manager or entering the following command in the Package Manager Console:
This should install the
Rainbow.Storage.Yaml packages also.
Now you can use the
TransitusProvider.FolderDeserializer to get all the items deserialized into useable objects:
These template items can then be used to generate the code.
To see this in use you can clone this repo: https://github.com/Fortis-Collection/fortis.codegen.transitus.rainbow.
This project is a sample of how to generate the Fortis models:
AssembleyReferences.tt: This template contains the refernces needed by the
Fortis.t4template. Is is added to the includes.
Fortis/Fortis.t4: This is the main code generation template. It gets all the files from the folders supplied by
Model.tt, gets the templates available in the files and generates an interface and implementation for each Sitecore template.
Model.tt: This file sets up all the folders and the base settings for the
Fortis.t4template to use. This file should be customized for each project.
Please checkout the demo repo and give me or Jason Bert a shout with any questions!