public DataServiceGen( DbContext dbContext, string projectPath, string projectName, JsonPropertyFormatEnum vmPropStyle, DIContainer dIContainer, bool activeCol = true, bool requestScope = false ) { ProjectPath = projectPath; if (ProjectPath[ProjectPath.Length - 1] == '\\' || ProjectPath[ProjectPath.Length - 1] == '/') { ProjectPath = ProjectPath.Remove(ProjectPath.Length - 1); } ProjectPath += "/"; OutputPath = ProjectPath; var curDir = Directory.GetCurrentDirectory() + '/'; this.Style = vmPropStyle; ProjectName = projectName; Data = new ContextParser(dbContext, projectName).Data; Data.DIContainer = dIContainer; Data.RequestScope = requestScope; Data.ActiveCol = activeCol; }
public static DataServiceGen GetDataServiceGenerator( this DbContext dbContext, string projectPath, string projectName, JsonPropertyFormatEnum vmPropStyle, DIContainer dIContainer, bool activeCol = true, bool requestScope = false ) { return(new DataServiceGen(dbContext, projectPath, projectName, vmPropStyle, dIContainer, requestScope)); }
public VMGen(EntityInfo eInfo, string[] jsonIgnoreProps, string[] exceptProps, JsonPropertyFormatEnum style) { Style = style; EInfo = eInfo; ResolveMapping.Add("entity", EInfo.EntityName); ResolveMapping.Add("entityVM", EInfo.VMClass); JsonIgnoreProps = jsonIgnoreProps; ExceptProps = exceptProps; Directive.Add(EInfo.Data.ProjectName + ".Global", EInfo.Data.ProjectName + ".Models", "Newtonsoft.Json"); //GENERATE GenerateNamespace(); GenerateVMClass(); GenerateVMClassBody(); }
public AutoViewModelGen(DataInfo dt, string[] jsonIgnoreProps, JsonPropertyFormatEnum style, string[] exceptProps, params string[] addedDirectives) : base(addedDirectives) { Style = style; Data = dt; AddDirectives( "import namespace=\"TNT.DataServiceTemplate.Data\"", "import namespace=\"TNT.DataServiceTemplate.ViewModels\"", "import namespace=\"static TNT.DataServiceTemplate.Helpers.GeneralHelper\""); ResolveMapping.Add("project", dt.ProjectName); ResolveMapping.Add("context", dt.ContextName); JsonIgnoreProps = jsonIgnoreProps; ExceptProps = exceptProps; GenerateInitManager(); GenerateBaseViewModel(); GenerateEntityViewModel(); }
//all relative to project: (projectPath/[continue]) public AutoDataServiceGen( string projectPath, string projectName, string templateApiLib, string dataServiceTemplateLib, string edmxFile, JsonPropertyFormatEnum vmPropStyle, bool activeCol = true, bool servicePool = false, bool requestScope = false ) { ProjectPath = projectPath; if (ProjectPath[ProjectPath.Length - 1] == '\\' || ProjectPath[ProjectPath.Length - 1] == '/') { ProjectPath = ProjectPath.Remove(ProjectPath.Length - 1); } ProjectPath += "/"; this.Style = vmPropStyle; ProjectName = projectName; TemplateAPILib = "$(ProjectDir)" + templateApiLib; DataServiceLib = "$(ProjectDir)" + dataServiceTemplateLib; var includeFile = "$(ProjectDir)" + "Templates/TTManager.ttinclude"; ExtraDirectives = new List <string>() { "assembly name=\"" + TemplateAPILib + "\"", "assembly name=\"" + DataServiceLib + "\"", "include file=\"" + includeFile + "\"" }; EdmxFile = ProjectPath + edmxFile; Data = new EdmxParser(EdmxFile, projectName).Data; Data.EdmxPath = edmxFile; Data.ServicePool = servicePool; Data.RequestScope = requestScope; Data.ActiveCol = activeCol; }
public static string ToJsonPropertyFormat(string noun, JsonPropertyFormatEnum style) { if (style == JsonPropertyFormatEnum.CamelCase) { return(char.ToLower(noun[0]) + noun.Substring(1)); } else if (style == JsonPropertyFormatEnum.JsonStyle) { noun = noun[0].ToString().ToLower() + noun.Substring(1); var i = 1; var isLastUpper = true; while (i < noun.Length) { while (i < noun.Length && (char.IsLower(noun[i]) || char.IsDigit(noun[i]))) { isLastUpper = false; i++; } if (i < noun.Length) { if (!isLastUpper) { noun = noun.Substring(0, i) + "_" + char.ToLower(noun[i]) + noun.Substring(i + 1); i++; isLastUpper = true; } else { noun = noun.Substring(0, i) + noun[i].ToString().ToLower() + noun.Substring(i + 1); } } i++; } return(noun); } return(null); }