private void ExecuteTemplateApiTests(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos) { var pathOutput = PathOutput.PathOutputApiTest(tableInfo, configContext); if (!tableInfo.MakeTest) { return; } if (!tableInfo.MakeApi) { return; } var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.ApiTest(tableInfo)); if (!File.Exists(pathTemplateClass)) { return; } var pathTemplateMoqValues = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.ApiTestMoqValues(tableInfo)); var textTemplateClass = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder); var TextTemplateMoqValues = Read.AllText(tableInfo, pathTemplateMoqValues, this._defineTemplateFolder); var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass); var classBuilderMoqValues = string.Empty; foreach (var item in infos) { if (item.IsKey == 1) { continue; } if (Audit.IsAuditField(item.PropertyName)) { continue; } var itemvalue = TextTemplateMoqValues. Replace("<#propertyName#>", item.PropertyName). Replace("<#length#>", item.Type == "string" ? item.Length : string.Empty). Replace("<#moqMethod#>", DefineMoqMethd(item.Type)); classBuilderMoqValues += string.Format("{0}{1}{2}", Tabs.TabSets(), itemvalue, System.Environment.NewLine); } classBuilder = classBuilder.Replace("<#moqValuesinsert#>", classBuilderMoqValues); using (var stream = new HelperStream(pathOutput).GetInstance()) { stream.Write(classBuilder); } }
private void ExecuteTemplateAutoMapperProfileBase(TableInfo tableInfo, Context configContext) { var pathOutput = PathOutput.PathOutputAutoMapperProfileBase(configContext, tableInfo); var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile"); if (!File.Exists(pathTemplateClass)) { return; } var pathTemplateMappers = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers"); var pathTemplateMappersSave = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers.save"); var pathTemplateMappersGet = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers.get"); var pathTemplateMappersDetail = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers.detail"); var textTemplateClass = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder); var textTemplateMappers = Read.AllText(tableInfo, pathTemplateMappers, this._defineTemplateFolder); var textTemplateMappersSave = Read.AllText(tableInfo, pathTemplateMappersSave, this._defineTemplateFolder); var textTemplateMappersGet = Read.AllText(tableInfo, pathTemplateMappersGet, this._defineTemplateFolder); var textTemplateMappersDetail = Read.AllText(tableInfo, pathTemplateMappersDetail, this._defineTemplateFolder); var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass); var classBuilderMappers = string.Empty; foreach (var item in configContext.TableInfo) { var className = item.ClassName; if (!string.IsNullOrEmpty(className)) { var itemMapper = textTemplateMappers.Replace("<#className#>", className); var itemMapperSave = textTemplateMappersSave.Replace("<#className#>", className); var itemMapperGet = textTemplateMappersGet.Replace("<#className#>", className); var itemMapperDetail = textTemplateMappersDetail.Replace("<#className#>", className); classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapper, System.Environment.NewLine); classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapperSave, System.Environment.NewLine); classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapperGet, System.Environment.NewLine); classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapperDetail, System.Environment.NewLine); } } classBuilder = classBuilder.Replace("<#registers#>", classBuilderMappers); using (var stream = new StreamWriter(pathOutput)) { stream.Write(classBuilder); } }
private string InitParametersRequired(IEnumerable <Info> infos) { var _parametersRequired = string.Empty; foreach (var item in infos) { if (Audit.IsAuditField(item.PropertyName)) { continue; } if (IsRequired(item)) { _parametersRequired += string.Format("{0}this.{1} = {2};{3}", Tabs.TabSets(), item.PropertyName, item.PropertyName.ToLower(), System.Environment.NewLine); } } return(_parametersRequired); }
private void ExecuteTemplateRepositoryBase(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos) { if (tableInfo.CodeCustomImplemented) { return; } var pathOutput = PathOutput.PathOutputRepository(tableInfo, configContext); var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "repository"); if (!File.Exists(pathTemplateClass)) { return; } var pathTemplateFilters = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "repository.filters.expression"); if (!File.Exists(pathTemplateClass)) { return; } var textTemplateClass = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder); var textTemplateFilters = Read.AllText(tableInfo, pathTemplateFilters, this._defineTemplateFolder); var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass); var classBuilderFilters = string.Empty; if (infos.IsAny()) { foreach (var item in infos) { if (item.IsKey == 1) { classBuilder = classBuilder .Replace("<#KeyName#>", item.PropertyName) .Replace("<#KeyNameType#>", item.Type); var cast = item.Type == "string" ? ".ToString()" : string.Empty; classBuilder = classBuilder.Replace("<#toString()#>", cast); } var itemFilters = string.Empty; if (item.Type == "string") { itemFilters = textTemplateFilters.Replace("<#propertyName#>", item.PropertyName); itemFilters = itemFilters.Replace("<#condition#>", string.Format("_ => _.{0}.Contains(filters.{0})", item.PropertyName)); itemFilters = itemFilters.Replace("<#filtersRange#>", string.Empty); } else if (item.Type == "DateTime") { var itemFiltersStart = textTemplateFilters.Replace("<#propertyName#>", String.Format("{0}Start", item.PropertyName)); itemFiltersStart = itemFiltersStart.Replace("<#condition#>", string.Format("_ => _.{0} >= filters.{0}Start ", item.PropertyName)); itemFiltersStart = itemFiltersStart.Replace("<#filtersRange#>", string.Empty); var itemFiltersEnd = textTemplateFilters.Replace("<#propertyName#>", String.Format("{0}End", item.PropertyName)); itemFiltersEnd = itemFiltersEnd.Replace("<#condition#>", string.Format("_ => _.{0} <= filters.{0}End", item.PropertyName)); itemFiltersEnd = itemFiltersEnd.Replace("<#filtersRange#>", string.Format("filters.{0}End = filters.{0}End.AddDays(1).AddMilliseconds(-1);", item.PropertyName)); itemFilters = String.Format("{0}{1}{2}{3}{4}", itemFiltersStart, System.Environment.NewLine, Tabs.TabSets(), itemFiltersEnd, System.Environment.NewLine); } else if (item.Type == "DateTime?") { var itemFiltersStart = textTemplateFilters.Replace("<#propertyName#>", String.Format("{0}Start", item.PropertyName)); itemFiltersStart = itemFiltersStart.Replace("<#condition#>", string.Format("_ => _.{0} != null && _.{0}.Value >= filters.{0}Start.Value", item.PropertyName)); itemFiltersStart = itemFiltersStart.Replace("<#filtersRange#>", string.Empty); var itemFiltersEnd = textTemplateFilters.Replace("<#propertyName#>", String.Format("{0}End", item.PropertyName)); itemFiltersEnd = itemFiltersEnd.Replace("<#condition#>", string.Format("_ => _.{0} != null && _.{0}.Value <= filters.{0}End", item.PropertyName)); itemFiltersEnd = itemFiltersEnd.Replace("<#filtersRange#>", string.Format("filters.{0}End = filters.{0}End.Value.AddDays(1).AddMilliseconds(-1);", item.PropertyName)); itemFilters = String.Format("{0}{1}{2}{3}{4}", itemFiltersStart, System.Environment.NewLine, Tabs.TabSets(), itemFiltersEnd, System.Environment.NewLine); } else if (item.Type == "bool?") { itemFilters = textTemplateFilters.Replace("<#propertyName#>", item.PropertyName); itemFilters = itemFilters.Replace("<#condition#>", string.Format("_ => _.{0} != null && _.{0}.Value == filters.{0}", item.PropertyName)); itemFilters = itemFilters.Replace("<#filtersRange#>", string.Empty); } else if (item.Type == "int?" || item.Type == "Int64?" || item.Type == "Int16?" || item.Type == "decimal?" || item.Type == "float?") { itemFilters = textTemplateFilters.Replace("<#propertyName#>", item.PropertyName); itemFilters = itemFilters.Replace("<#condition#>", string.Format("_ => _.{0} != null && _.{0}.Value == filters.{0}", item.PropertyName)); itemFilters = itemFilters.Replace("<#filtersRange#>", string.Empty); } else { itemFilters = textTemplateFilters.Replace("<#propertyName#>", item.PropertyName); itemFilters = itemFilters.Replace("<#condition#>", string.Format("_ => _.{0} == filters.{0}", item.PropertyName)); itemFilters = itemFilters.Replace("<#filtersRange#>", string.Empty); } classBuilderFilters += string.Format("{0}{1}{2}", Tabs.TabSets(), itemFilters, System.Environment.NewLine); } } classBuilder = classBuilder.Replace("<#filtersExpressions#>", classBuilderFilters); using (var stream = new StreamWriter(pathOutput)) { stream.Write(classBuilder); } }