/// <summary> /// Generars the codigo domain. /// </summary> /// <returns></returns> public string GenerateCodeDomain() { TemplateFile template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_Domain); TemplateSection sectionProperties = template.ExtractSection("PROPERTIES"); TemplateSection sectionParameters = template.ExtractSection("PARAMETERS"); TemplateSectionCollection propertiesSectionList = new TemplateSectionCollection(); TemplateSectionCollection parametersSectionList = new TemplateSectionCollection(); foreach (var entityField in Entity.Fields) { TemplateSection propertySection = sectionProperties.ExtractSection(entityField.SimpleTypeName); propertySection.ReplaceTag("PROPERTYNAME", entityField.ColumnName); propertiesSectionList.AddSection(propertySection); TemplateSection parameterSection = sectionParameters.ExtractSection(entityField.SimpleTypeName); parameterSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName); parametersSectionList.AddSection(parameterSection); } template.ReplaceSection("PROPERTIES", propertiesSectionList); template.ReplaceSection("PARAMETERS", parametersSectionList); template.ReplaceTag("NAMESPACE_DOMAIN", Settings[CodeBaseConstants.NAMESPACE_DOMAIN].Value, false); template.ReplaceTag("CLASS_NAME_DOMAIN", DomainClassName, false); template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
static void Main(String[] args) { if (args == null || args.Length <= 0) { ShowHelp(); return; } if (args[0] == "/?" || args[0] == "?" || args[0] == "man") { ShowHelp(); return; } //args[0] = @"C:\My\test_cutoff.mbox"; TemplateSection section = ConfigurationManager.GetSection("TemplateGroup/TemplateSection") as TemplateSection; Parser parser = new Parser(section); List <Transaction> transactions; if (parser.TryParse(args[0], out transactions)) { Console.WriteLine("Count transactions:{0}", transactions.Count); } Console.ReadLine(); }
public static ModelTypeMetaCategory CreateFrom(TemplateSection section) { var m = new ModelTypeMetaCategory { Identifier = section.SectionId, Fields = null }; if (section.SectionLabels != null && section.SectionLabels.Any()) { m.Labels = section.SectionLabels; } var labels = m.Labels ?? new Dictionary <string, string>(); m.Label = labels.ContainsKey(WebHelper.DefaultLanguage) ? labels[WebHelper.DefaultLanguage] : m.Identifier; var templateFields = section.Fields ?? new List <TemplateField>(); foreach (var templateField in templateFields) { var categoryField = ModelTypeField.CreateFrom(templateField); if (categoryField != null) { m.Fields = m.Fields ?? new List <ModelTypeField>(); m.Fields.Add(categoryField); } } return(m); }
private static void AssertTemplates(TemplatesResolverRainbow resolver) { resolver.Templates.Select(t => t.SyncItem.Name).ShouldAllBeEquivalentTo(new[] { "Animal", "Dog", "Food", "Nameable" }); TemplateItem dogTemplate = resolver.Templates.FirstOrDefault(t => t.SyncItem.Name == "Dog"); dogTemplate.Should().NotBeNull(); dogTemplate.BaseTemplates.Select(b => b.SyncItem.Name).ShouldAllBeEquivalentTo(new[] { "Animal", "Nameable" }); TemplateSection dogSection = dogTemplate.Sections.FirstOrDefault(s => s.SyncItem.Name == "Dog"); dogSection.Should().NotBeNull(); dogSection.Fields.Select(f => f.SyncItem.Name).ShouldAllBeEquivalentTo(new[] { "Eats", "Friends" }); TemplateField eatsField = dogSection.Fields.FirstOrDefault(f => f.SyncItem.Name == "Eats"); eatsField.Should().NotBeNull(); eatsField.FieldTitle.Should().BeEquivalentTo("What food does the dog eat?"); eatsField.FieldTypeName.Should().BeEquivalentTo("Multilist with Search"); }
public string GenerateScriptListAll() { TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_ListAll); TemplateSection sectionSelectColumns = template.ExtractSection("SELECT_COLUMNS"); TemplateSectionCollection selectColumnsSectionList = new TemplateSectionCollection(); foreach (var entityField in Entity.Fields) { TemplateSection selectColumnsSection = sectionSelectColumns.ExtractSection("DEFAULT"); selectColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName); selectColumnsSectionList.AddSection(selectColumnsSection); } template.ReplaceSection("SELECT_COLUMNS", selectColumnsSectionList, ","); template.ReplaceTag("LISTALL_STORED_PROCEDURE", ListAllStoredProcedureName, false); template.ReplaceTag("ENTITY_NAME", Entity.Name, false); template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
/// <summary> /// Creates a new <see cref="TemplateSection"/> VieModel /// </summary> /// <param name="section"> The <see cref="TemplateSection"/> associated with this ViewModel</param> /// <param name="template">The <see cref="TemplateVM"/> associated with this <see cref="TemplateSection"/> </param> public SectionVM(TemplateSection section, TemplateVM template) { TemplateViewModel = template; m_section = section; AddAnalyticCommand = new RelayCommand(AddAnalytic, () => true); DeleteSectionCommand = new RelayCommand(RemoveSection, () => true); m_analytics = new ObservableCollection <AnalyticVM>(); }
public void AddSection_WhenCalled_AllowsGetSectionToBeFoundById(string name, ID id) { var fakeTemplate = new FakeTemplate(); TemplateSection section = fakeTemplate.AddSection(name, id); Template template = fakeTemplate.ToSitecoreTemplate(); var foundSection = template.GetSection(id); foundSection.Should().Be(section); }
private ICollection <TemplateSection> GetTemplateSections(ICollection <TemplateSection> templateSections) { List <TemplateSection> temSections = new List <TemplateSection>(); foreach (var t in templateSections) { var tempSection = new TemplateSection(); tempSection.ContentMarkup = t.ContentMarkup; tempSection.CreatedDate = DateTime.UtcNow; tempSection.SectionType = t.SectionType; temSections.Add(tempSection); } return(temSections); }
internal string GenerateViewIndex() { TemplateFile template = TemplateFile.LoadTemplate(TemplateType.HTML, Resources.view_Index); var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName); var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey); if (primaryEntityField == null) { throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key"); } TemplateSection sectionHeader = template.ExtractSection("HEADER"); TemplateSection sectionRow = template.ExtractSection("ROW"); TemplateSectionCollection propertiesHeaderList = new TemplateSectionCollection(); TemplateSectionCollection propertiesRowList = new TemplateSectionCollection(); foreach (var entityField in Entity.Fields) { TemplateSection columnSection = sectionHeader.ExtractSection("COLUMN"); columnSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName); propertiesHeaderList.AddSection(columnSection); columnSection = sectionRow.ExtractSection("COLUMN"); columnSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName); propertiesRowList.AddSection(columnSection); } template.ReplaceSection("HEADER", propertiesHeaderList); template.ReplaceSection("ROW", propertiesRowList); template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false); template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false); template.ReplaceTag("INDEX_VIEWNAME", Settings[AspNetMvcCoreConstants.INDEX_VIEWNAME].Value, false); template.ReplaceTag("CREATE_VIEWNAME", Settings[AspNetMvcCoreConstants.CREATE_VIEWNAME].Value, false); template.ReplaceTag("EDIT_VIEWNAME", Settings[AspNetMvcCoreConstants.EDIT_VIEWNAME].Value, false); template.ReplaceTag("DETAILS_VIEWNAME", Settings[AspNetMvcCoreConstants.DETAILS_VIEWNAME].Value, false); template.ReplaceTag("DELETE_VIEWNAME", Settings[AspNetMvcCoreConstants.DELETE_VIEWNAME].Value, false); template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
public static Dictionary <TemplateSection, string> SplitToSections(IEnumerable <string> content) { var result = new Dictionary <TemplateSection, string>(); var curSection = (TemplateSection)null; var curContent = string.Empty; foreach (var line in content) { var m = StartLine.Match(line); if (m.Success) { if (curSection != null) { throw new Exception($"Неожиданное начало секции {m.Groups[1].Value}"); } curContent = string.Empty; curSection = TemplateSection.GetDefaultTemplate().FirstOrDefault(x => x.Name.Equals(m.Groups[1].Value, StringComparison.InvariantCultureIgnoreCase)); continue; } m = EndLine.Match(line); if (m.Success) { if (curSection == null) { throw new Exception($"Неожиданный конец секции {m.Groups[1].Value}"); } result.Add(curSection, curContent); curContent = string.Empty; curSection = null; continue; } if (curSection == null) { continue; } curContent += $"{line}\r\n"; } return(result); }
protected virtual void ProcessTemplateSections([NotNull] FileCodeModel fileCodeModel, [NotNull] Template template, [NotNull] CodeInterface2 codeInterface) { Debug.ArgumentNotNull(fileCodeModel, nameof(fileCodeModel)); Debug.ArgumentNotNull(template, nameof(template)); Debug.ArgumentNotNull(codeInterface, nameof(codeInterface)); var templateSection = new TemplateSection(); template.Sections.Add(templateSection); templateSection.Name = "Data"; templateSection.TemplateSectionItemId = new ItemId(GuidExtensions.Hash(template.Name + @"/" + templateSection.Name)); foreach (var property in codeInterface.Members.OfType <CodeProperty2>()) { ProcessTemplateField(fileCodeModel, template, templateSection, property); } }
protected virtual void ProcessTemplateSections([NotNull] FileCodeModel fileCodeModel, [NotNull] Template template, [NotNull] IEnumerable <string> baseFields, [NotNull] CodeClass2 codeClass, bool isGlassMapper) { Debug.ArgumentNotNull(fileCodeModel, nameof(fileCodeModel)); Debug.ArgumentNotNull(template, nameof(template)); Debug.ArgumentNotNull(baseFields, nameof(baseFields)); Debug.ArgumentNotNull(codeClass, nameof(codeClass)); var templateSection = new TemplateSection(); template.Sections.Add(templateSection); templateSection.Name = "Data"; templateSection.TemplateSectionItemId = new ItemId(GuidExtensions.Hash(template.Name + @"/" + templateSection.Name)); foreach (var property in codeClass.Members.OfType <CodeProperty2>()) { if (!baseFields.Contains(property.Name)) { ProcessTemplateField(fileCodeModel, template, templateSection, property, isGlassMapper); } } }
public static Tuple <bool, string> IsValidTemplate(this FileInfo template) { try { var content = File.ReadLines(template.FullName).ToArray(); var sections = SplitToSections(content); var missed = TemplateSection.GetDefaultTemplate().Where(x => !x.IsHelp).Where(t => sections.Keys.Any(sk => sk.Name.Equals(t.Name, StringComparison.InvariantCultureIgnoreCase))) .ToArray(); if (!missed.Any()) { return(new Tuple <bool, string>(false, $"Потерялись следующие секции: {string.Join("\r\n", missed.Select(m => m.RusName))}")); } return(new Tuple <bool, string>(true, string.Empty)); } catch (Exception e) { return(new Tuple <bool, string>(false, $"Ошибка разбора шаблона {e}")); } }
internal string GenerateViewEdit() { TemplateFile template = TemplateFile.LoadTemplate(TemplateType.HTML, Resources.view_Edit); var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName); var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey); if (primaryEntityField == null) { throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key"); } TemplateSection sectionForm = template.ExtractSection("FORM"); TemplateSectionCollection propertiesFormList = new TemplateSectionCollection(); foreach (var entityField in Entity.Fields.Where(f => !f.IsPrimaryKey)) { TemplateSection fieldSection = sectionForm.ExtractSection("FIELD"); fieldSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName); propertiesFormList.AddSection(fieldSection); } template.ReplaceSection("FORM", propertiesFormList); template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false); template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false); template.ReplaceTag("EDIT_VIEWNAME", Settings[AspNetMvcCoreConstants.EDIT_VIEWNAME].Value, false); template.ReplaceTag("INDEX_VIEWNAME", Settings[AspNetMvcCoreConstants.INDEX_VIEWNAME].Value, false); template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
public void ShouldResolveTemplates() { var resolver = new TemplatesResolver( @"..\..\..\Sitecore.CodeGenerator.Sample.Glass\Data\Serialization", new [] { "/sitecore/templates" }); resolver.Templates.Select(t => t.SyncItem.Name).ShouldAllBeEquivalentTo(new [] { "Animal", "Dog", "Food", "Nameable" }); TemplateItem dogTemplate = resolver.Templates.FirstOrDefault(t => t.SyncItem.Name == "Dog"); dogTemplate.Should().NotBeNull(); dogTemplate.BaseTemplates.Select(b => b.SyncItem.Name).ShouldAllBeEquivalentTo(new [] { "Animal", "Nameable" }); TemplateSection dogSection = dogTemplate.Sections.FirstOrDefault(s => s.SyncItem.Name == "Dog"); dogSection.Should().NotBeNull(); dogSection.Fields.Select(f => f.SyncItem.Name).ShouldAllBeEquivalentTo(new [] { "Eats", "Friends" }); TemplateField eatsField = dogSection.Fields.FirstOrDefault(f => f.SyncItem.Name == "Eats"); eatsField.Should().NotBeNull(); eatsField.FieldTitle.Should().BeEquivalentTo("What food does the dog eat?"); eatsField.FieldTypeName.Should().BeEquivalentTo("Multilist with Search"); }
public string GenerateScriptGetById() { TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_GetByID); TemplateSection sectionSelectColumns = template.ExtractSection("SELECT_COLUMNS"); TemplateSectionCollection selectColumnsSectionList = new TemplateSectionCollection(); foreach (var entityField in Entity.Fields) { TemplateSection selectColumnsSection = sectionSelectColumns.ExtractSection("DEFAULT"); selectColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName); selectColumnsSectionList.AddSection(selectColumnsSection); } template.ReplaceSection("SELECT_COLUMNS", selectColumnsSectionList, ","); var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey); if (primaryEntityField == null) { throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key"); } template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false); template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("GETBYID_STORED_PROCEDURE", GetByIdStoredProcedureName, false); template.ReplaceTag("ENTITY_NAME", Entity.Name, false); template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
protected virtual void ProcessTemplateField([NotNull] FileCodeModel fileCodeModel, [NotNull] Template template, [NotNull] TemplateSection templateSection, [NotNull] CodeProperty2 property) { Debug.ArgumentNotNull(fileCodeModel, nameof(fileCodeModel)); Debug.ArgumentNotNull(template, nameof(template)); Debug.ArgumentNotNull(templateSection, nameof(templateSection)); Debug.ArgumentNotNull(property, nameof(property)); var type = property.Type.AsFullName; var handler = FieldTypeHandlerManager.FieldTypes.FirstOrDefault(h => h.CanHandle(type)); if (handler == null) { return; } var field = new TemplateField(property); templateSection.Fields.Add(field); field.Name = property.Name; field.TemplateFieldItemId = new ItemId(fileCodeModel.GetHash(property.Attributes, template.Name + @"/" + templateSection.Name + @"/" + field.Name)); field.Type = string.Empty; field.Source = string.Empty; field.Shared = false; field.Unversioned = false; field.Title = string.Empty; field.ValidatorBar = string.Empty; handler.Handle(type, field); var sitecoreField = property.Attributes.OfType <CodeAttribute2>().FirstOrDefault(a => a.Name == "SitecoreField" || a.Name == "SitecoreFieldAttribute"); if (sitecoreField == null) { return; } var index = 0; foreach (var argument in sitecoreField.Arguments.OfType <CodeAttributeArgument>()) { var value = argument.Value; if (value.StartsWith("\"") && value.EndsWith("\"")) { value = value.Mid(1, value.Length - 2); } if (string.IsNullOrEmpty(argument.Name) && index == 0) { field.Name = value; } if (argument.Name == "FieldName") { field.Name = value; } if (argument.Name == "Type") { field.Type = value; } if (argument.Name == "Shared") { field.Shared = value == "true"; } if (argument.Name == "Unversioned") { field.Shared = value == "true"; } if (argument.Name == "Source") { field.Source = value; } index++; } }
protected virtual void ParseField([NotNull] ItemParseContext context, [NotNull] Template template, [NotNull] TemplateSection templateSection, [NotNull] ITextNode templateFieldTextNode, ref int nextSortOrder) { SchemaService.ValidateTextNodeSchema(templateFieldTextNode, "TemplateField"); GetName(context.ParseContext, templateFieldTextNode, out var fieldName, out var fieldNameTextNode, "Field", "Name"); if (string.IsNullOrEmpty(fieldName)) { Trace.TraceError(Msg.P1005, Texts._Field__element_must_have_a__Name__attribute, templateFieldTextNode.Snapshot.SourceFile.AbsoluteFileName, templateFieldTextNode.TextSpan); return; } var templateField = templateSection.Fields.FirstOrDefault(f => string.Equals(f.FieldName, fieldName, StringComparison.OrdinalIgnoreCase)); if (templateField == null) { var itemIdOrPath = template.ItemIdOrPath + "/" + templateSection.SectionName + "/" + fieldName; var guid = StringHelper.GetGuid(template.Project, templateFieldTextNode.GetAttributeValue("Id", itemIdOrPath)); templateField = Factory.TemplateField(template, guid).With(templateFieldTextNode); templateSection.Fields.Add(templateField); templateField.FieldNameProperty.SetValue(fieldNameTextNode); templateField.FieldName = fieldName; } templateField.TypeProperty.Parse(templateFieldTextNode, "Single-Line Text"); templateField.Shared = string.Equals(templateFieldTextNode.GetAttributeValue("Sharing"), "Shared", StringComparison.OrdinalIgnoreCase); templateField.Unversioned = string.Equals(templateFieldTextNode.GetAttributeValue("Sharing"), "Unversioned", StringComparison.OrdinalIgnoreCase); templateField.SourceProperty.Parse(templateFieldTextNode); templateField.ShortHelpProperty.Parse(templateFieldTextNode); templateField.LongHelpProperty.Parse(templateFieldTextNode); templateField.SortorderProperty.Parse(templateFieldTextNode, nextSortOrder); nextSortOrder = templateField.Sortorder + 100; // set field standard value var standardValueTextNode = templateFieldTextNode.GetAttribute("StandardValue"); if (standardValueTextNode != null && !string.IsNullOrEmpty(standardValueTextNode.Value)) { if (template.StandardValuesItem == null) { Trace.TraceError(Msg.P1006, Texts.Template_does_not_a_standard_values_item, standardValueTextNode); } else { var field = template.StandardValuesItem.Fields.GetField(templateField.FieldName); if (field == null) { field = Factory.Field(template.StandardValuesItem).With(standardValueTextNode); field.FieldNameProperty.SetValue(fieldNameTextNode); template.StandardValuesItem.Fields.Add(field); } field.ValueProperty.SetValue(standardValueTextNode); } } template.References.AddRange(ReferenceParser.ParseReferences(template, templateField.SourceProperty)); }
protected override void WriteSection(XmlTextWriter output, [NotNull] Database database, TemplateSection section, Template template, bool includeInheritedFields, bool newId) { Debug.ArgumentNotNull(output, nameof(output)); Debug.ArgumentNotNull(database, nameof(database)); Debug.ArgumentNotNull(section, nameof(section)); Debug.ArgumentNotNull(template, nameof(template)); var fields = new List <TemplateField>(section.GetFields()); fields.Sort(this); foreach (var field in fields) { WriteField(output, database, field, template, includeInheritedFields, newId); } }
public TemplateSurvey ReadAll(int id) { TemplateSurvey survey = null; TemplateSection section = null; List <TemplateSection> sectionList = new List <TemplateSection>(); List <TemplateQuestions> questionsList = new List <TemplateQuestions>(); _dataProvider.ExecuteCmd( "SurveyTemplate_SSQ_Join", cmd => { cmd.AddWithValue("@Id", id); }, (reader, read) => { survey = new TemplateSurvey() { Id = (int)reader["SurveyId"], Name = (string)reader["Name"], Description = (string)reader["SurveyDescription"], TypeId = (int)reader["SurveyTypeId"], StatusId = (int)reader["SurveyStatusId"], OwnerId = (int)reader["SurveyOwnerId"], }; object version = reader["Version"]; if (version == DBNull.Value) { survey.Version = 0; } else { survey.Version = (int)version; } TemplateSection sectionTemplate = new TemplateSection() { Id = (int)reader["SectionId"], Title = (string)reader["Title"], Description = (string)reader["SectionDescription"], SortOrder = (int)reader["SectionSortOrder"] }; TemplateQuestions question = new TemplateQuestions() { Id = (int)reader["QuestionId"], Question = (string)reader["Question"], SortOrder = (int)reader["QuestionSortOrder"], HelpText = (string)reader["HelpText"], IsRequired = (bool)reader["IsRequired"], IsMultipleAllowed = (bool)reader["IsMultipleAllowed"], QuestionTypeId = (int)reader["QuestionTypeId"], StatusId = (int)reader["StatusId"], UserId = (int)reader["UserId"], AnswerOptions = new List <TemplateAnswerOption>() }; questionsList.Add(question); sectionTemplate.Questions = questionsList; section = sectionTemplate; }); sectionList.Add(section); survey.Sections = sectionList; return(survey); }
public string GenerateCodeDataAccessAsync() { TemplateFile template; string templateType = Settings[CodeBaseConstants.DATAACCESS_TEMPLATE].Value; if (templateType.Equals("en")) { template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_DataAccess_async_en); } else if (templateType.Equals("es")) { template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_DataAccess_async_es); } else { template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_DataAccess_async); } var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey); if (primaryEntityField == null) { throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key"); } TemplateSection sectionParameters = template.ExtractSection("PARAMETERS"); TemplateSection sectionParametersAsync = template.ExtractSection("PARAMETERS_ASYNC"); TemplateSection sectionProperties = template.ExtractSection("PROPERTIES"); TemplateSection sectionPropertiesAsync = template.ExtractSection("PROPERTIES_ASYNC"); TemplateSectionCollection sectionParameterList = new TemplateSectionCollection(); TemplateSectionCollection sectionParameterAsyncList = new TemplateSectionCollection(); TemplateSectionCollection sectionPropertyList = new TemplateSectionCollection(); TemplateSectionCollection sectionPropertyAsyncList = new TemplateSectionCollection(); var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName); foreach (var entityField in Entity.Fields) { TemplateSection sectionProperty = sectionProperties.ExtractSection(entityField.SimpleTypeName); sectionProperty.ReplaceTag("PROPERTYNAME", entityField.ColumnName); sectionProperty.ReplaceTag("COLUMNNAME", entityField.ColumnName); sectionPropertyList.AddSection(sectionProperty); TemplateSection sectionPropertyAsync = sectionPropertiesAsync.ExtractSection(entityField.SimpleTypeName); sectionPropertyAsync.ReplaceTag("PROPERTYNAME", entityField.ColumnName); sectionPropertyAsync.ReplaceTag("COLUMNNAME", entityField.ColumnName); sectionPropertyAsyncList.AddSection(sectionPropertyAsync); TemplateSection sectionParameter = sectionParameters.ExtractSection(entityField.SimpleTypeName); sectionParameter.ReplaceTag("PARAMETERNAME", entityField.ColumnName); sectionParameter.ReplaceTag("PROPERTYNAME", entityField.ColumnName); sectionParameter.ReplaceTag("INSTANCE_NAME_DOMAIN", instanceEntityName, false); sectionParameterList.AddSection(sectionParameter); TemplateSection sectionParameterAsync = sectionParametersAsync.ExtractSection(entityField.SimpleTypeName); sectionParameterAsync.ReplaceTag("PARAMETERNAME", entityField.ColumnName); sectionParameterAsync.ReplaceTag("PROPERTYNAME", entityField.ColumnName); sectionParameterAsync.ReplaceTag("INSTANCE_NAME_DOMAIN", instanceEntityName, false); sectionParameterAsyncList.AddSection(sectionParameterAsync); } template.ReplaceSection("PARAMETERS", sectionParameterList); template.ReplaceSection("PARAMETERS_ASYNC", sectionParameterAsyncList); template.ReplaceSection("PROPERTIES", sectionPropertyList); template.ReplaceSection("PROPERTIES_ASYNC", sectionPropertyAsyncList); template.ReplaceTag("PRIMARYKEY_DATATYPE", DataTypeHelper.GetCSharpType(primaryEntityField.SimpleTypeName), false); template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("PRIMARYKEY_LOCAL_VARIABLE", StringHelper.ConverToInstanceName(StringHelper.ConvertToSafeCodeName(primaryEntityField.ColumnName)), false); template.ReplaceTag("NAMESPACE_DOMAIN", Settings[CodeBaseConstants.NAMESPACE_DOMAIN].Value, false); template.ReplaceTag("NAMESPACE_DATAACCESS", Settings[CodeBaseConstants.NAMESPACE_DATAACCESS].Value, false); template.ReplaceTag("NAMESPACE_DBHELPER", Settings[CodeBaseConstants.NAMESPACE_DBHELPER].Value, false); template.ReplaceTag("NAMESPACE_ACCESS_MODEL", Settings[CodeBaseConstants.NAMESPACE_ACCESS_MODEL].Value, false); template.ReplaceTag("INSTANCE_NAME_DOMAIN", instanceEntityName, false); template.ReplaceTag("CLASS_NAME_DOMAIN", DomainClassName, false); template.ReplaceTag("CLASS_NAME_DATAACCESS", DataAccessClassName, false); template.ReplaceTag("SAVE_STORED_PROCEDURE", SaveStoredProcedureName, false); template.ReplaceTag("GETBYID_STORED_PROCEDURE", GetByIdStoredProcedureName, false); template.ReplaceTag("LISTALL_STORED_PROCEDURE", ListAllStoredProcedureName, false); template.ReplaceTag("DELETE_STORED_PROCEDURE", DeleteStoredProcedureName, false); template.ReplaceTag("SAVE_METHODNAME", Settings[CodeBaseConstants.SAVE_METHODNAME].Value, false); template.ReplaceTag("GETBYID_METHODNAME", Settings[CodeBaseConstants.GETBYID_METHODNAME].Value, false); template.ReplaceTag("LISTALL_METHODNAME", Settings[CodeBaseConstants.LISTALL_METHODNAME].Value, false); template.ReplaceTag("DELETE_METHODNAME", Settings[CodeBaseConstants.DELETE_METHODNAME].Value, false); template.ReplaceTag("BUILDFUNCTION_METHODNAME", Settings[CodeBaseConstants.BUILDFUNCTION_METHODNAME].Value, false); template.ReplaceTag("ASYNC_METHODS_SUFFIX", Settings[CodeBaseConstants.ASYNC_METHODS_SUFFIX].Value, false); template.ReplaceTag("CONNECTIONSTRING_KEY", Settings[CodeBaseConstants.CONNECTIONSTRING_KEY].Value, false); template.ReplaceTag("DBHELPER_INSTANCEOBJECT", Settings[CodeBaseConstants.DBHELPER_INSTANCEOBJECT].Value, false); template.ReplaceTag("GETSCALAR_METHODNAME", Settings[CodeBaseConstants.GETSCALAR_METHODNAME].Value, false); template.ReplaceTag("GETENTITY_METHODNAME", Settings[CodeBaseConstants.GETENTITY_METHODNAME].Value, false); template.ReplaceTag("GETDATATABLE_METHODNAME", Settings[CodeBaseConstants.GETDATATABLE_METHODNAME].Value, false); template.ReplaceTag("EXECUTESP_METHODNAME", Settings[CodeBaseConstants.EXECUTESP_METHODNAME].Value, false); template.ReplaceTag("GETSCALAR_ASYNC_METHODNAME", Settings[CodeBaseConstants.GETSCALAR_ASYNC_METHODNAME].Value, false); template.ReplaceTag("GETENTITY_ASYNC_METHODNAME", Settings[CodeBaseConstants.GETENTITY_ASYNC_METHODNAME].Value, false); template.ReplaceTag("GETDATATABLE_ASYNC_METHODNAME", Settings[CodeBaseConstants.GETDATATABLE_ASYNC_METHODNAME].Value, false); template.ReplaceTag("EXECUTESP_ASYNC_METHODNAME", Settings[CodeBaseConstants.EXECUTESP_ASYNC_METHODNAME].Value, false); template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
/// <summary> /// Initializes a new instance of the <see cref="Parser"/> class. /// </summary> /// <param name="configuration">The configuration.</param> public Parser(TemplateSection configuration) { this.Configuration = configuration; }
public string GenerateScriptSave() { TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_Save); TemplateSection sectionParameters = template.ExtractSection("PARAMETERS"); TemplateSection sectionUpdateParameters = template.ExtractSection("UPDATE_PARAMETERS"); TemplateSection sectionInsertColumns = template.ExtractSection("INSERT_COLUMNS"); TemplateSection sectionInsertParameters = template.ExtractSection("INSERT_PARAMETERS"); TemplateSectionCollection parameterSectionList = new TemplateSectionCollection(); TemplateSectionCollection updateParameterSectionList = new TemplateSectionCollection(); TemplateSectionCollection insertColumnsSectionList = new TemplateSectionCollection(); TemplateSectionCollection insertParameterSectionList = new TemplateSectionCollection(); foreach (var entityField in Entity.Fields) { TemplateSection parameterSection = sectionParameters.ExtractSection("DEFAULT"); parameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName); parameterSection.ReplaceTag("DATATYPE", entityField.TypeName); parameterSectionList.AddSection(parameterSection); if (!entityField.IsPrimaryKey) { TemplateSection updateParameterSection = sectionUpdateParameters.ExtractSection("DEFAULT"); updateParameterSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName); updateParameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName); updateParameterSectionList.AddSection(updateParameterSection); TemplateSection insertColumnsSection = sectionInsertColumns.ExtractSection("DEFAULT"); insertColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName); insertColumnsSectionList.AddSection(insertColumnsSection); TemplateSection insertParameterSection = sectionInsertParameters.ExtractSection("DEFAULT"); insertParameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName); insertParameterSectionList.AddSection(insertParameterSection); } } template.ReplaceSection("PARAMETERS", parameterSectionList, ","); template.ReplaceSection("UPDATE_PARAMETERS", updateParameterSectionList, ","); template.ReplaceSection("INSERT_COLUMNS", insertColumnsSectionList, ","); template.ReplaceSection("INSERT_PARAMETERS", insertParameterSectionList, ","); var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey); if (primaryEntityField == null) { throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key"); } template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false); template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false); template.ReplaceTag("SAVE_STORED_PROCEDURE", SaveStoredProcedureName, false); template.ReplaceTag("ENTITY_NAME", Entity.Name, false); template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false); template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false); return(template.Content); }
public TemplateSectionWriter([NotNull] TemplateSection templateSection) { TemplateSection = templateSection; }