From 9019e30f75fe66c926f1eff0b9503eaeaafd78d0 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Tue, 16 Aug 2016 11:15:44 +0800 Subject: [PATCH] remove tt template --- OpenAuth.App/SSO/AuthUtil.cs | 2 +- .../ReverseEngineerCodeFirst/Context.tt | 48 ---- .../ReverseEngineerCodeFirst/Entity.tt | 130 --------- .../ReverseEngineerCodeFirst/Mapping.tt | 269 ------------------ .../OpenAuth.Repository.csproj | 5 - 5 files changed, 1 insertion(+), 453 deletions(-) delete mode 100644 OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Context.tt delete mode 100644 OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Entity.tt delete mode 100644 OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt diff --git a/OpenAuth.App/SSO/AuthUtil.cs b/OpenAuth.App/SSO/AuthUtil.cs index 04d8796f..5b180b8b 100644 --- a/OpenAuth.App/SSO/AuthUtil.cs +++ b/OpenAuth.App/SSO/AuthUtil.cs @@ -154,7 +154,7 @@ namespace OpenAuth.App.SSO try { - var value = _helper.Post(requestUri); + var value = _helper.Post(null, requestUri); return true; } diff --git a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Context.tt b/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Context.tt deleted file mode 100644 index ce38b40c..00000000 --- a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Context.tt +++ /dev/null @@ -1,48 +0,0 @@ -<#@ template hostspecific="true" language="C#" #> -<#@ include file="EF.Utility.CS.ttinclude" #><#@ - output extension=".cs" #><# - - var efHost = (EfTextTemplateHost)Host; - var code = new CodeGenerationTools(this); -#> -using System.Data.Entity; -using System.Data.Entity.Infrastructure; -using OpenAuth.Domain; -using <#= code.EscapeNamespace(efHost.MappingNamespace) #>; - -namespace <#= code.EscapeNamespace(efHost.Namespace) #> -{ - public partial class <#= efHost.EntityContainer.Name #> : DbContext - { - static <#= efHost.EntityContainer.Name #>() - { - Database.SetInitializer<<#= efHost.EntityContainer.Name #>>(null); - } - - public <#= efHost.EntityContainer.Name #>() - : base("Name=<#= efHost.EntityContainer.Name #>") - { - } - -<# - foreach (var set in efHost.EntityContainer.BaseEntitySets.OfType()) - { -#> - public DbSet<<#= set.ElementType.Name #>> <#= set.Name #> { get; set; } -<# - } -#> - - protected override void OnModelCreating(DbModelBuilder modelBuilder) - { -<# - foreach (var set in efHost.EntityContainer.BaseEntitySets.OfType()) - { -#> - modelBuilder.Configurations.Add(new <#= set.ElementType.Name #>Map()); -<# - } -#> - } - } -} diff --git a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Entity.tt b/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Entity.tt deleted file mode 100644 index 4b7ed00a..00000000 --- a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Entity.tt +++ /dev/null @@ -1,130 +0,0 @@ -<#@ template hostspecific="true" language="C#" #> -<#@ include file="EF.Utility.CS.ttinclude" #><#@ - output extension=".cs" #><# - - var efHost = (EfTextTemplateHost)Host; - var code = new CodeGenerationTools(this); - code.GetSummryDictionary(".",efHost.EntityContainer.Name,efHost.EntityType.Name,"sa","000000"); - -#> -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; - -namespace OpenAuth.Domain -{ - /// - /// <#= code.GetSummry(code.Escape(efHost.EntityType.Properties[0])) #> - /// - public partial class <#= efHost.EntityType.Name #> - { -<# - var collectionNavigations = efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many); - - foreach (var property in efHost.EntityType.Properties) - { - var typeUsage = code.Escape(property.TypeUsage); - - // Fix-up spatial types for EF6 - if (efHost.EntityFrameworkVersion >= new Version(6, 0) - && typeUsage.StartsWith("System.Data.Spatial.")) - { - typeUsage = typeUsage.Replace( - "System.Data.Spatial.", - "System.Data.Entity.Spatial."); - } -#> - /// - /// <#= code.GetSummry(code.Escape(property)) #> - /// - /// - <#= Accessibility.ForProperty(property) #> <#= typeUsage #> <#= code.Escape(property) #> { get; set; } - -<# - } - - foreach (var navProperty in efHost.EntityType.NavigationProperties.Where(np => np.DeclaringType == efHost.EntityType)) - { - if (navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many) - { -#> - public virtual ICollection<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>> <#= code.Escape(navProperty) #> { get; set; } -<# - } - else - { -#> - public virtual <#= code.Escape(navProperty.ToEndMember.GetEntityType()) #> <#= code.Escape(navProperty) #> { get; set; } -<# - } - } -#> - - public <#= code.Escape(efHost.EntityType) #>() - { - <# foreach (var property in efHost.EntityType.Properties) - { - var typeUsage = code.Escape(property.TypeUsage); - - // Fix-up spatial types for EF6 - if (efHost.EntityFrameworkVersion >= new Version(6, 0) - && typeUsage.StartsWith("System.Data.Spatial.")) - { - typeUsage = typeUsage.Replace( - "System.Data.Spatial.", - "System.Data.Entity.Spatial."); - } - if(typeUsage=="System.Guid") - { - #> - this.<#= code.Escape(property) #>= Guid.NewGuid(); - <#} - else if(typeUsage=="System.DateTime") - { - #> - this.<#= code.Escape(property) #>= DateTime.Now; - <#} - else if(typeUsage=="bool") - { - #> - this.<#= code.Escape(property) #>= false; - <# } - else if(typeUsage=="int"||typeUsage=="double") - { - #> - this.<#= code.Escape(property) #>= 0; - <# } - else if(typeUsage=="byte[]") - { - #> - this.<#= code.Escape(property) #>= new byte[0]; - <# } - else if(typeUsage=="decimal") - { - #> - this.<#= code.Escape(property) #>= 0M; - <# } - else if(typeUsage=="string") - { - #> - this.<#= code.Escape(property) #>= string.Empty; - <#} - else{ } - } - if (collectionNavigations.Any()) - { - foreach (var navProperty in collectionNavigations) - { -#> - this.<#= code.Escape(navProperty) #> = new List<<#= code.Escape(navProperty.ToEndMember.GetEntityType()) #>>(); -<# - } - - }#> -} - - - - } -} \ No newline at end of file diff --git a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt b/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt deleted file mode 100644 index ddb3a39a..00000000 --- a/OpenAuth.Repository/CodeTemplates/ReverseEngineerCodeFirst/Mapping.tt +++ /dev/null @@ -1,269 +0,0 @@ -<# -// Simplifying assumptions based on reverse engineer rules -// - No complex types -// - One entity container -// - No inheritance -// - Always have two navigation properties -// - All associations expose FKs (except many:many) -#> -<#@ template hostspecific="true" language="C#" #> -<#@ include file="EF.Utility.CS.ttinclude" #><#@ - output extension=".cs" #><# - - var efHost = (EfTextTemplateHost)Host; - var code = new CodeGenerationTools(this); - - if (efHost.EntityFrameworkVersion >= new Version(4, 4)) - { -#> -using System.ComponentModel.DataAnnotations.Schema; -<# - } - else - { -#> -using System.ComponentModel.DataAnnotations; -<# - } -#> -using System.Data.Entity.ModelConfiguration; -using OpenAuth.Domain; - -namespace <#= code.EscapeNamespace(efHost.Namespace) #> -{ - public class <#= efHost.EntityType.Name #>Map : EntityTypeConfiguration<<#= efHost.EntityType.Name #>> - { - public <#= efHost.EntityType.Name #>Map() - { - // Primary Key -<# - if (efHost.EntityType.KeyMembers.Count() == 1) - { -#> - this.HasKey(t => t.<#= efHost.EntityType.KeyMembers.Single().Name #>); -<# - } - else - { -#> - this.HasKey(t => new { <#= string.Join(", ", efHost.EntityType.KeyMembers.Select(m => "t." + m.Name)) #> }); -<# - } -#> - - // Properties -<# - foreach (var prop in efHost.EntityType.Properties) - { - var type = (PrimitiveType)prop.TypeUsage.EdmType; - var isKey = efHost.EntityType.KeyMembers.Contains(prop); - var storeProp = efHost.PropertyToColumnMappings[prop]; - var sgpFacet = storeProp.TypeUsage.Facets.SingleOrDefault(f => f.Name == "StoreGeneratedPattern"); - var storeGeneratedPattern = sgpFacet == null - ? StoreGeneratedPattern.None - : (StoreGeneratedPattern)sgpFacet.Value; - - var configLines = new List(); - - if (type.ClrEquivalentType == typeof(int) - || type.ClrEquivalentType == typeof(decimal) - || type.ClrEquivalentType == typeof(short) - || type.ClrEquivalentType == typeof(long)) - { - if (isKey && storeGeneratedPattern != StoreGeneratedPattern.Identity) - { - // configLines.Add(".HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)"); - } - else if ((!isKey || efHost.EntityType.KeyMembers.Count > 1) && storeGeneratedPattern == StoreGeneratedPattern.Identity) - { - // configLines.Add(".HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)"); - } - } - - if (type.ClrEquivalentType == typeof(string) - || type.ClrEquivalentType == typeof(byte[])) - { - if (!prop.Nullable) - { - configLines.Add(".IsRequired()"); - } - - var unicodeFacet = (Facet)prop.TypeUsage.Facets.SingleOrDefault(f => f.Name == "IsUnicode"); - if(unicodeFacet != null && !(bool)unicodeFacet.Value) - { - configLines.Add(".IsUnicode(false)"); - } - - var fixedLengthFacet = (Facet)prop.TypeUsage.Facets.SingleOrDefault(f => f.Name == "FixedLength"); - if (fixedLengthFacet != null && (bool)fixedLengthFacet.Value) - { - configLines.Add(".IsFixedLength()"); - } - - var maxLengthFacet = (Facet)prop.TypeUsage.Facets.SingleOrDefault(f => f.Name == "MaxLength"); - if (maxLengthFacet != null && !maxLengthFacet.IsUnbounded) - { - configLines.Add(string.Format(".HasMaxLength({0})", maxLengthFacet.Value)); - - if (storeGeneratedPattern == StoreGeneratedPattern.Computed - && type.ClrEquivalentType == typeof(byte[]) - && (int)maxLengthFacet.Value == 8) - { - configLines.Add(".IsRowVersion()"); - } - } - } - - if(configLines.Any()) - { -#> - this.Property(t => t.<#= prop.Name #>) - <#= string.Join("\r\n ", configLines) #>; - -<# - } - } - - var tableSet = efHost.TableSet; - var tableName = (string)tableSet.MetadataProperties["Table"].Value - ?? tableSet.Name; - var schemaName = (string)tableSet.MetadataProperties["Schema"].Value; -#> - // Table & Column Mappings -<# - if (schemaName == "dbo" || string.IsNullOrWhiteSpace(schemaName)) - { -#> - this.ToTable("<#= tableName #>"); -<# - } - else - { -#> - this.ToTable("<#= tableName #>", "<#= schemaName #>"); -<# - } - - foreach (var property in efHost.EntityType.Properties) - { -#> - this.Property(t => t.<#= property.Name #>).HasColumnName("<#= efHost.PropertyToColumnMappings[property].Name #>"); -<# - } - - // Find m:m relationshipsto configure - var manyManyRelationships = efHost.EntityType.NavigationProperties - .Where(np => np.DeclaringType == efHost.EntityType - && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many - && np.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many - && np.RelationshipType.RelationshipEndMembers.First() == np.FromEndMember); // <- ensures we only configure from one end - - // Find FK relationships that this entity is the dependent of - var fkRelationships = efHost.EntityType.NavigationProperties - .Where(np => np.DeclaringType == efHost.EntityType - && ((AssociationType)np.RelationshipType).IsForeignKey - && ((AssociationType)np.RelationshipType).ReferentialConstraints.Single().ToRole == np.FromEndMember); - - if(manyManyRelationships.Any() || fkRelationships.Any()) - { -#> - - // Relationships -<# - foreach (var navProperty in manyManyRelationships) - { - var otherNavProperty = navProperty.ToEndMember.GetEntityType().NavigationProperties.Where(n => n.RelationshipType == navProperty.RelationshipType && n != navProperty).Single(); - var association = (AssociationType)navProperty.RelationshipType; - var mapping = efHost.ManyToManyMappings[association]; - var item1 = mapping.Item1; - var mappingTableName = (string)mapping.Item1.MetadataProperties["Table"].Value - ?? item1.Name; - var mappingSchemaName = (string)item1.MetadataProperties["Schema"].Value; - - // Need to ensure that FKs are decalred in the same order as the PK properties on each principal type - var leftType = (EntityType)navProperty.DeclaringType; - var leftKeyMappings = mapping.Item2[navProperty.FromEndMember]; - var leftColumns = string.Join(", ", leftType.KeyMembers.Select(m => "\"" + leftKeyMappings[m] + "\"")); - var rightType = (EntityType)otherNavProperty.DeclaringType; - var rightKeyMappings = mapping.Item2[otherNavProperty.FromEndMember]; - var rightColumns = string.Join(", ", rightType.KeyMembers.Select(m => "\"" + rightKeyMappings[m] + "\"")); -#> - this.HasMany(t => t.<#= code.Escape(navProperty) #>) - .WithMany(t => t.<#= code.Escape(otherNavProperty) #>) - .Map(m => - { -<# - if (mappingSchemaName == "dbo" || string.IsNullOrWhiteSpace(mappingSchemaName)) - { -#> - m.ToTable("<#= mappingTableName #>"); -<# - } - else - { -#> - m.ToTable("<#= mappingTableName #>", "<#= mappingSchemaName #>"); -<# - } -#> - m.MapLeftKey(<#= leftColumns #>); - m.MapRightKey(<#= rightColumns #>); - }); - -<# - } - - foreach (var navProperty in fkRelationships) - { - var otherNavProperty = navProperty.ToEndMember.GetEntityType().NavigationProperties.Where(n => n.RelationshipType == navProperty.RelationshipType && n != navProperty).Single(); - var association = (AssociationType)navProperty.RelationshipType; - - if (navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One) - { -#> - this.HasRequired(t => t.<#= code.Escape(navProperty) #>) -<# - } - else - { -#> - this.HasOptional(t => t.<#= code.Escape(navProperty) #>) -<# - } - - if(navProperty.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many) - { -#> - .WithMany(t => t.<#= code.Escape(otherNavProperty) #>) -<# - if(association.ReferentialConstraints.Single().ToProperties.Count == 1) - { -#> - .HasForeignKey(d => d.<#= association.ReferentialConstraints.Single().ToProperties.Single().Name #>); -<# - } - else - { -#> - .HasForeignKey(d => new { <#= string.Join(", ", association.ReferentialConstraints.Single().ToProperties.Select(p => "d." + p.Name)) #> }); -<# - } - } - else - { - // NOTE: We can assume that this is a required:optional relationship - // as EDMGen will never create an optional:optional relationship - // because everything is one:many except PK-PK relationships which must be required -#> - .WithOptional(t => t.<#= code.Escape(otherNavProperty) #>); -<# - } - } -#> - -<# - } -#> - } - } -} diff --git a/OpenAuth.Repository/OpenAuth.Repository.csproj b/OpenAuth.Repository/OpenAuth.Repository.csproj index 5671e77f..968216a6 100644 --- a/OpenAuth.Repository/OpenAuth.Repository.csproj +++ b/OpenAuth.Repository/OpenAuth.Repository.csproj @@ -99,11 +99,6 @@ - - - - -