public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; codeBuilder.InsertCode(CodeSnippet(info), ModuleCodeGenerator.NamespaceMembersTag, info.Module); codeBuilder.InsertCode("[DataContract]", AttributesTag, info); }
public static bool IsSupported(DataStructureInfo conceptInfo) { return(conceptInfo is IOrmDataStructure || conceptInfo is BrowseDataStructureInfo || conceptInfo is QueryableExtensionInfo || conceptInfo is ComputedInfo); }
private static string RepositoryReadFunctionsSnippet(DataStructureInfo info, string readFunctionBody) { return(string.Format( @"public IEnumerable<{0}> Load(object parameter, Type parameterType) {{ var items = _executionContext.GenericRepository(""{0}"").Load(parameter, parameterType); return (IEnumerable<{0}>)items; }} public IEnumerable<{0}> Read(object parameter, Type parameterType, bool preferQuery) {{ var items = _executionContext.GenericRepository(""{0}"").Read(parameter, parameterType, preferQuery); return (IEnumerable<{0}>)items; }} [Obsolete(""Use Load() or Query() method."")] public global::{0}[] All() {{ {1} }} [Obsolete(""Use Load() or Query() method."")] public global::{0}[] Filter(FilterAll filterAll) {{ return All(); }} ", info.GetKeyProperties(), readFunctionBody)); }
protected static string PersistenceStorageMappingSnippet(DataStructureInfo info) { return ($@"public class {info.Module.Name}_{info.Name}_Mapper : IPersistenceStorageObjectMapper {{ public PersistenceStorageObjectParameter[] GetParameters(IEntity genericEntity) {{ var entity = ({info.Module}.{info.Name})genericEntity; return new PersistenceStorageObjectParameter[] {{ new PersistenceStorageObjectParameter(""ID"", new SqlParameter("""", System.Data.SqlDbType.UniqueIdentifier) {{ Value = entity.ID }}), {PersistenceStorageMapperPropertyMappingTag.Evaluate(info)} }}; }} public IEnumerable<Guid> GetDependencies(IEntity genericEntity) {{ var entity = ({info.Module}.{info.Name})genericEntity; {PersistenceStorageMapperDependencyResolutionTag.Evaluate(info)} yield break; }} public string GetTableName() {{ return ""{((IOrmDataStructure)info).GetOrmSchema()}.{((IOrmDataStructure)info).GetOrmDatabaseObject()}""; }} }} "); }
/// <summary> /// Note: When using this function to create a database object, always add the dependencies from GetAdditionalForeignKeyDependencies(). /// </summary> public static string GetSchemaTableForForeignKey(DataStructureInfo dataStructure) { if (dataStructure is EntityInfo) { return(SqlUtility.Identifier(dataStructure.Module.Name) + "." + SqlUtility.Identifier(dataStructure.Name)); } if (dataStructure is LegacyEntityInfo) { var legacy = (LegacyEntityInfo)dataStructure; return(SqlUtility.GetFullName(legacy.Table)); } if (dataStructure is LegacyEntityWithAutoCreatedViewInfo) { var legacy = (LegacyEntityWithAutoCreatedViewInfo)dataStructure; return(SqlUtility.GetFullName(legacy.Table)); } if (dataStructure is PolymorphicInfo) { return(dataStructure.GetKeyProperties() + "_Materialized"); } return(null); }
public static bool IsEntityType(DataStructureInfo conceptInfo) { return((conceptInfo is IOrmDataStructure) || conceptInfo is BrowseDataStructureInfo || conceptInfo is QueryableExtensionInfo || conceptInfo is ComputedInfo); }
private static string SnippetLoadSimpleObjectsConversion(DataStructureInfo info) { return(string.Format(@"public static void LoadSimpleObjects(ref IEnumerable<{0}.{1}> items) {{ var query = items as IQueryable<Common.Queryable.{0}_{1}>; var navigationItems = items as IEnumerable<Common.Queryable.{0}_{1}>; if (query != null) items = query.ToSimple().ToList(); // The IQueryable function allows ORM optimizations. else if (navigationItems != null) items = navigationItems.Select(item => item.ToSimple()).ToList(); else {{ Rhetos.Utilities.CsUtility.Materialize(ref items); var itemsList = (IList<{0}.{1}>)items; for (int i = 0; i < itemsList.Count(); i++) {{ var navigationItem = itemsList[i] as Common.Queryable.{0}_{1}; if (navigationItem != null) itemsList[i] = navigationItem.ToSimple(); }} }} }} ", info.Module.Name, info.Name)); }
public static void GenerateReadableRepository(DataStructureInfo info, ICodeBuilder codeBuilder, string loadFunctionBody = null) { GenerateRepository(info, codeBuilder); string module = info.Module.Name; string entity = info.Name; if (loadFunctionBody != null) { string repositoryReadFunctionsSnippet = $@"public override global::{module}.{entity}[] Load() {{ {loadFunctionBody} }} "; codeBuilder.InsertCode(repositoryReadFunctionsSnippet, RepositoryMembers, info); } codeBuilder.InsertCode($"Common.ReadableRepositoryBase<{module}.{entity}>", OverrideBaseTypeTag, info); codeBuilder.InsertCode( $@"public static readonly KeyValuePair<string, Type>[] ReadParameterTypes = new KeyValuePair<string, Type>[] {{ {ReadParameterTypesTag.Evaluate(info)} }}; ", RepositoryMembers, info); codeBuilder.InsertCode( $@"{{ ""{module}.{entity}"", {module}._Helper.{entity}_Repository.ReadParameterTypes }}, ", ModuleCodeGenerator.DataStructuresReadParameterTypesTag); }
public static void GenerateRepository(DataStructureInfo info, ICodeBuilder codeBuilder) { codeBuilder.InsertCode(RepositorySnippet(info), ModuleCodeGenerator.HelperNamespaceMembersTag, info.Module); codeBuilder.InsertCode(CallFromModuleRepostiorySnippet(info), ModuleCodeGenerator.RepositoryMembersTag, info.Module); codeBuilder.InsertCode(RegisterRepository(info), ModuleCodeGenerator.CommonAutofacConfigurationMembersTag); codeBuilder.AddReferencesFromDependency(typeof(Rhetos.Extensibility.NamedPluginsExtensions)); }
private static string ServiceDefinitionCodeSnippet(DataStructureInfo info) { return(string.Format(@" [RoutePrefix(""Api/{0}/{1}"")] public class {0}{1}Controller : ApiController {{ private ServiceUtility _serviceUtility; public {0}{1}Controller(ServiceUtility serviceUtility) {{ _serviceUtility = serviceUtility; }} [HttpGet] [Route("""")] public DownloadReportResult DownloadReport(string parameter = null, string convertFormat = null) {{ return _serviceUtility.DownloadReport<{0}.{1}>(parameter, convertFormat); }} " + AdditionalOperationsTag.Evaluate(info) + @" }} ", info.Module.Name, info.Name)); }
private static string ImplementationCodeSnippet(DataStructureInfo info) { string dataStructureBezBrowsea = info.Name; if (dataStructureBezBrowsea.ToLower().EndsWith("browse")) { dataStructureBezBrowsea = dataStructureBezBrowsea.Substring(0, dataStructureBezBrowsea.Length - 6); } return(string.Format(@" namespace Omega.MvcModel.{0} {{ [Rhetos.Mvc.LocalizedDisplayName(""{3}"", {4})] public partial class {1} : Rhetos.Mvc.BaseMvcModel {{ public const string Entity{1} = ""{1}""; {2} }} }} ", info.Module.Name, info.Name, ClonePropertiesTag.Evaluate(info), CaptionHelper.GetCaptionConstant(info), "typeof(Captions)" )); }
private static string RegisterRepository(DataStructureInfo info) { return(string.Format( @"builder.RegisterType<{0}._Helper.{1}_Repository>().Keyed<IRepository>(""{0}.{1}"").InstancePerLifetimeScope(); ", info.Module.Name, info.Name)); }
public static bool IsEntityType(DataStructureInfo conceptInfo) { return(conceptInfo is IOrmDataStructure || conceptInfo is BrowseDataStructureInfo || conceptInfo is QueryableExtensionInfo || conceptInfo is ComputedInfo || conceptInfo is ActionInfo); // TODO: Remove ActionInfo. It is here only for backward compatibility. }
public static string getParentInstanceOfBrowse(DataStructureInfo conceptInfo) { if (conceptInfo is BrowseDataStructureInfo) { BrowseDataStructureInfo browseInfo = (BrowseDataStructureInfo)conceptInfo; return("\"" + browseInfo.Source.Module.Name + "." + browseInfo.Source.Name + "\""); } return("null"); }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; //System.Diagnostics.Debugger.Launch(); codeBuilder.InsertCode(ImplementationCodeSnippet(info), ModuleCodeGenerator.DataStructureTag, info.Module); codeBuilder.InsertCode(string.Format(@"{0}: _{1}{0}, ", info.Name, info.Module.Name), ModuleCodeGenerator.DataStructureReturnTag, info.Module); }
private static string CallFromModuleRepostiorySnippet(DataStructureInfo info) { return(string.Format( @"private {0}_Repository _{0}_Repository; public {0}_Repository {0} {{ get {{ return _{0}_Repository ?? (_{0}_Repository = ({0}_Repository)Rhetos.Extensibility.NamedPluginsExtensions.GetPlugin(_repositories, {1})); }} }} ", info.Name, CsUtility.QuotedString(info.Module.Name + "." + info.Name))); }
protected static string CodeSnippet(DataStructureInfo info) { return(AttributesTag.Evaluate(info) + @" public class " + info.Name + InterfaceTag.Evaluate(info) + @" { " + BodyTag.Evaluate(info) + @" } "); }
public static bool IsTypeSupported(DataStructureInfo conceptInfo) { return(conceptInfo is EntityInfo || conceptInfo is BrowseDataStructureInfo || conceptInfo is LegacyEntityInfo || conceptInfo is LegacyEntityWithAutoCreatedViewInfo || conceptInfo is SqlQueryableInfo || conceptInfo is QueryableExtensionInfo || conceptInfo is ComputedInfo); }
public static void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; if (info is IWritableOrmDataStructure) { codeBuilder.InsertCode( String.Format(ImplementationCodeSnippet, info.Module.Name, info.Name), DataStructureCodeGenerator.AdditionalOperationsTag.Evaluate(info)); } }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; if (DslUtility.IsQueryable(info)) { codeBuilder.InsertCode(SnippetQueryableClass(info), DomInitializationCodeGenerator.CommonQueryableMemebersTag); codeBuilder.InsertCode("IDetachOverride", DataStructureQueryableCodeGenerator.InterfaceTag, info); codeBuilder.InsertCode("bool IDetachOverride.Detaching { get; set; }\r\n\r\n ", DataStructureQueryableCodeGenerator.MembersTag, info); } }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; if (IsTypeSupported(info)) { GenerateInitialCode(codeBuilder); codeBuilder.InsertCode(ImplementationCodeSnippet(info), MvcModelGeneratorTags.ModuleMembers); } }
private static string HelperFunctionSnippet(ComputeForNewBaseItemsInfo info, string uniqueSuffix) { DataStructureInfo hookOnSave = info.Dependency_Extends.Base; return(string.Format( @" private static readonly Func<IEnumerable<{0}.{1}>, Guid[]> _filterComputeForNewBaseItems_{2} = changedItems => changedItems.Select(item => item.ID).ToArray(); ", hookOnSave.Module.Name, hookOnSave.Name, uniqueSuffix)); }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; codeBuilder.InsertCode(ImplementationCodeSnippet(info)); if (IsEntityType(info)) { Dom.DefaultConcepts.DataStructureCodeGenerator.AddInterfaceAndReference(codeBuilder, typeof(Mvc.BaseMvcModel), info); } LocalizedDisplayAttribute.InsertOrOverrideAttribute(codeBuilder, info, LocalizedDisplayAttributeProperties(info)); }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; if (IsTypeSupported(info)) { GenerateInitialCode(codeBuilder); codeBuilder.InsertCode(ImplementationCodeSnippet(info), InitialCodeGenerator.NamespaceMembersTag); codeBuilder.InsertCode(DataSourceExpositionCodeSnippet(info), InitialCodeGenerator.DataSourceExpositionMembersTag); } }
public static IEnumerable <IConceptInfo> GetAdditionalForeignKeyDependencies(DataStructureInfo dataStructure) { if (dataStructure is PolymorphicInfo) { return new IConceptInfo[] { new PersistedDataStructureInfo { Module = dataStructure.Module, Name = dataStructure.Name + "_Materialized" } } } ; return(new IConceptInfo[] { }); } }
/// <summary> /// The 'Common.KeepSynchronizedMetadata.Context' property serves as cache-invalidation mechanism. /// If the context is changed in the new version of the application, /// then the old persisted data should be recomputed on deployment. /// This does not cover all situations when the persisted data should be recomputed /// on deployment, but at least handles some obvious ones. /// </summary> private string GetRecomputeContext(DataStructureInfo source) { if (source is PolymorphicInfo) { return(string.Join(", ", _dslModel.FindByReference <IsSubtypeOfInfo>(s => s.Supertype, (PolymorphicInfo)source) .Select(GetSubtypeRecomputeContext) .OrderBy(description => description))); } else { return(source.GetFullDescription()); } }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { DataStructureInfo info = (DataStructureInfo)conceptInfo; if (IsTypeSupported(info)) { //codeBuilder.InsertCode(ServiceRegistrationCodeSnippet(info), InitialCodeGenerator.ServiceRegistrationTag); //codeBuilder.InsertCode(ServiceInitializationCodeSnippet(info), InitialCodeGenerator.ServiceInitializationTag); codeBuilder.InsertCode(ServiceDefinitionCodeSnippet(info), InitialCodeGenerator.RhetosRestClassesTag); codeBuilder.AddReferencesFromDependency(typeof(Rhetos.Processing.DefaultCommands.ReadCommandResult)); codeBuilder.AddReferencesFromDependency(typeof(Newtonsoft.Json.Linq.JToken)); } }
private static string DataSourceExpositionCodeSnippet(DataStructureInfo info) { return(string.Format(@" public IQueryable<Rhetos.OData.{0}.{1}> {0}{1} {{ get {{ return Rhetos.OData.{0}.{1}.Get{1}Queryable(_processingEngine); }} }}", info.Module.Name, info.Name, "_" + info.Module.Name.ToLower() + info.Name)); }
private static string SnippetToSimpleObjectsConversion(DataStructureInfo info) { return(string.Format(@"/// <summary>Converts the objects with navigation properties to simple objects with primitive properties.</summary> public static IQueryable<{0}.{1}> ToSimple(this IQueryable<Common.Queryable.{0}_{1}> query) {{ return query.Select(item => new {0}.{1} {{ ID = item.ID" + AssignSimplePropertyTag.Evaluate(info) + @" }}); }} ", info.Module.Name, info.Name)); }
private static string FilterOldItemsBeforeSaveSnippet(DataStructureInfo hookOnSaveEntity, string filterType, string filterFormula, string uniqueName) { return(string.Format( @"Func<IEnumerable<Common.Queryable.{0}_{1}>, {2}> filterLoadKeepSynchronizedOnChangedItems{3} = {4}; {2} filterKeepSynchronizedOnChangedItems{3}Old = filterLoadKeepSynchronizedOnChangedItems{3}(updated.Concat(deleted)); ", hookOnSaveEntity.Module.Name, hookOnSaveEntity.Name, filterType, uniqueName, filterFormula)); }