Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<#@ 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