Skip to content

Instantly share code, notes, and snippets.

@janvanderhaegen
Created January 3, 2014 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janvanderhaegen/8240387 to your computer and use it in GitHub Desktop.
Save janvanderhaegen/8240387 to your computer and use it in GitHub Desktop.
<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Xml.dll" #>
<#@ Assembly Name="System.Xml.Linq.dll" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
// Generated class, do not modify the class but the .tt file instead!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace LightSwitchApplication{
[DataObject]
public partial class ReportSource{
<#
XNamespace schema = "http://schemas.microsoft.com/LightSwitch/2010/xaml/model";
string serviceLsml = System.IO.File.ReadAllText(
System.IO.Path.GetDirectoryName(this.Host.TemplateFile) + "\\..\\TESS.DataWarehouse\\TESS.DataWarehouse.Server\\Properties\\Service.lsml");
System.Xml.Linq.XDocument XmlDoc = System.Xml.Linq.XDocument.Parse(serviceLsml);
foreach(var entityContainer in XmlDoc.Root.Descendants (schema + "EntityContainer"))
{
#>
// Data source: <#= entityContainer.Attribute("Name").Value #>
<#
foreach(var entitySet in entityContainer.Descendants( schema + "EntitySet" ))
{
if(entitySet.Attribute("Name").Value == "Reports" ||
entitySet.Attribute("Name").Value == "ReportDefinitions")
continue;
#> [DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable< <#=entitySet.Attribute("EntityType").Value #> > <#= entitySet.Attribute("Name").Value #> ()
{
return GenerateDummyData< <#=entitySet.Attribute("EntityType").Value #> >();
}
<#
}
#>
<#
}
#>
}
<#
foreach(var entityType in XmlDoc.Root.Descendants ( schema + "EntityType"))
{
if(entityType.Attribute("Name").Value == "Report" ||
entityType.Attribute("Name").Value == "ReportDefinition")
continue;
#>
public partial class <#= entityType.Attribute("Name").Value #> {
<#
foreach(var property in entityType.Descendants(schema + "KeyProperty")){ createProperty(property, schema);}
foreach(var property in entityType.Descendants(schema + "EntityProperty")){ createProperty(property, schema);}
#>
}
<#
}
#>
}
<#+
void createProperty(XElement input, XNamespace schema) {
if(input.Descendants(schema + "Hidden").Any())
return;
#>
public <#+ createPropertyType(input, schema); #> <#= input.Attribute("Name").Value #> {get;set;}
<#+
}
#>
<#+
void createPropertyType(XElement input, XNamespace schema) {
var propertyType = input.Attribute("PropertyType").Value.Substring(1);
if(propertyType.Equals("String?")) { #><#= "string" #><#+ }
else {#><#= propertyType #><#+}
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment