Created
November 27, 2018 08:25
-
-
Save IvanLieckens/27b11c3d772af4bc3950cd22a7483a47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ template debug="true" hostspecific="false" language="C#" #> | |
<#@ assembly name="System" #> | |
<#@ assembly name="System.Configuration" #> | |
<#@ assembly name="System.Core" #> | |
<#@ assembly name="System.Data" #> | |
<#@ assembly name="System.Design" #> | |
<#@ assembly name="System.DirectoryServices" #> | |
<#@ assembly name="System.Drawing" #> | |
<#@ assembly name="System.IO.Compression.FileSystem" #> | |
<#@ assembly name="System.Runtime.Caching" #> | |
<#@ assembly name="System.Runtime.Serialization" #> | |
<#@ assembly name="System.Security" #> | |
<#@ assembly name="System.ServiceModel" #> | |
<#@ assembly name="System.Web" #> | |
<#@ assembly name="System.Web.ApplicationServices" #> | |
<#@ assembly name="System.Web.Extensions" #> | |
<#@ assembly name="System.Web.Services" #> | |
<#@ assembly name="System.Windows.Forms" #> | |
<#@ assembly name="System.Xml.Linq" #> | |
<#@ assembly name="System.Xml" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\ComponentArt.Web.UI.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\HtmlAgilityPack.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\ITHit.WebDAV.Server.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Lucene.Net.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Microsoft.Extensions.DependencyInjection.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Microsoft.Extensions.DependencyInjection.Abstractions.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Microsoft.Practices.EnterpriseLibrary.Common.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Configuration.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Mvp.Xml.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Newtonsoft.Json.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Sitecore.Logging.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Sitecore.Logging.Client.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Sitecore.NVelocity.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Sitecore.Zip.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Telerik.Web.UI.dll" #> | |
<#@ assembly name="C:\inetpub\wwwroot\habitat.dev.local\bin\Sitecore.Kernel.dll" #> | |
<#@ assembly name="C:\projects\Sitecore.Demo.Group\packages\Rainbow.Core.2.0.2\lib\net452\Rainbow.dll" #> | |
<#@ assembly name="C:\projects\Sitecore.Demo.Group\packages\Rainbow.Storage.Yaml.2.0.2\lib\net452\Rainbow.Storage.Yaml.dll" #> | |
<#@ import namespace="System.Linq" #> | |
<#@ import namespace="System.Text" #> | |
<#@ import namespace="System.Xml" #> | |
<#@ import namespace="System.Collections.Generic" #> | |
<#@ import namespace="Rainbow.Model" #> | |
<#@ import namespace="Rainbow.Storage" #> | |
<#@ import namespace="Rainbow.Storage.Yaml" #> | |
<#@ output extension=".cs" #> | |
<# | |
StringBuilder result = new StringBuilder(); | |
YamlSerializationFormatter formatter = new YamlSerializationFormatter(null, null); | |
Tree = new SerializationFileSystemTree("Templates", "/sitecore/templates/Feature/Events", "master", "C:\\Projects\\Sitecore.Demo.Group\\src\\feature\\events\\serialization\\Sitecore.Feature.Events.Templates", formatter, false); | |
IItemData rootItem = Tree.GetRootItem(); | |
IEnumerable<IItemData> templates = Tree.GetChildren(rootItem); | |
if (templates.Any()) | |
{ | |
GenerateHeader(result); | |
GenerateClass(result, templates); | |
} | |
#> | |
<#= result #> | |
<#+ | |
public static SerializationFileSystemTree Tree = null; | |
public static string GetCleanName(string name) | |
{ | |
return name.Replace(" ", string.Empty).Replace("_", string.Empty); | |
} | |
private static void GenerateHeader(StringBuilder builder) | |
{ | |
builder.AppendLine(@"#pragma warning disable 1591 | |
#pragma warning disable 0108 | |
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by T4. | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
using System; | |
using Sitecore.Data; | |
"); | |
} | |
private static void GenerateClass(StringBuilder builder, IEnumerable<IItemData> templates) | |
{ | |
builder.AppendLine("namespace " + System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint")); | |
builder.AppendLine("{"); | |
builder.AppendLine(" public static class Templates"); | |
builder.AppendLine(" {"); | |
foreach (IItemData template in templates) | |
{ | |
GenerateTemplateStruct(builder, " ", template); | |
} | |
builder.AppendLine(" }"); | |
builder.AppendLine("}"); | |
} | |
private static void GenerateTemplateStruct(StringBuilder builder, string indent, IItemData template) | |
{ | |
builder.AppendLine(indent + "public static class " + GetCleanName(template.Name)); | |
builder.AppendLine(indent + "{"); | |
builder.AppendLine(indent + " public static readonly ID Id = new ID(\"" + template.Id.ToString() + "\");"); | |
IEnumerable<IItemData> sections = Tree.GetChildren(template); | |
if(sections.Any()) | |
{ | |
builder.AppendLine(indent + ""); | |
GenerateFieldsStruct(builder, indent + " ", sections); | |
} | |
builder.AppendLine(indent + "}"); | |
} | |
private static void GenerateFieldsStruct(StringBuilder builder, string indent, IEnumerable<IItemData> sections) | |
{ | |
builder.AppendLine(indent + "public struct Fields"); | |
builder.AppendLine(indent + "{"); | |
foreach(IItemData section in sections) | |
{ | |
foreach(IItemData field in Tree.GetChildren(section)) | |
{ | |
builder.AppendLine(indent + " public static readonly ID " + GetCleanName(field.Name) + " = new ID(\"" + field.Id.ToString() +"\");"); | |
} | |
} | |
builder.AppendLine(indent + "}"); | |
} | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment