示例#1
0
        protected static string MemberFunctionsSnippet(WriteInfo info)
        {
            return string.Format(
            @"        void Rhetos.Dom.DefaultConcepts.IWritableRepository.Save(IEnumerable<object> insertedNew, IEnumerable<object> updatedNew, IEnumerable<object> deletedIds, bool checkUserPermissions = false)
            {{
            Save(
                insertedNew != null ? insertedNew.Cast<{0}>() : null,
                updatedNew != null ? updatedNew.Cast<{0}>() : null,
                deletedIds != null ? deletedIds.Cast<{0}>() : null,
                checkUserPermissions);
            }}

            public void Insert(IEnumerable<object> items)
            {{
            Save(items.Cast<{0}>(), null, null);
            }}

            public void Update(IEnumerable<object> items)
            {{
            Save(null, items.Cast<{0}>(), null);
            }}

            public void Delete(IEnumerable<object> items)
            {{
            Save(null, null, items.Cast<{0}>());
            }}

            public void Save(IEnumerable<{0}> insertedNew, IEnumerable<{0}> updatedNew, IEnumerable<{0}> deletedIds, bool checkUserPermissions = false)
            {{
            if (insertedNew == null) insertedNew = new {0}[] {{ }};
            if (updatedNew == null) updatedNew = new {0}[] {{ }};
            if (deletedIds == null) deletedIds = new {0}[] {{ }};

            if (insertedNew.Count() == 0 && updatedNew.Count() == 0 && deletedIds.Count() == 0)
                return;

            foreach(var item in insertedNew)
                if(item.ID == Guid.Empty)
                    item.ID = Guid.NewGuid();

            {2}

            {1}

            {3}

            {4}
            }}

            ",
                info.DataStructure.GetKeyProperties(),
                info.SaveImplementation,
                WritableOrmDataStructureCodeGenerator.InitializationTag.Evaluate(info.DataStructure),
                WritableOrmDataStructureCodeGenerator.OnSaveTag1.Evaluate(info.DataStructure),
                WritableOrmDataStructureCodeGenerator.OnSaveTag2.Evaluate(info.DataStructure));
        }
示例#2
0
        public void InitializeNonparsableProperties(out IEnumerable<IConceptInfo> createdConcepts)
        {
            Dependency_ChangesEntity = new EntityInfo { Module = Entity.Module, Name = Entity.Name + "_Changes" };
            Dependency_HistorySqlQueryable = new SqlQueryableInfo { Module = Entity.Module, Name = Entity.Name + "_History", SqlSource = HistorySqlSnippet() };
            Dependency_AtTimeSqlFunction = new SqlFunctionInfo { Module = Entity.Module, Name = Entity.Name + "_AtTime", Arguments = "@ContextTime DATETIME", Source = AtTimeSqlSnippet() };
            Dependency_Write = new WriteInfo {
                    DataStructure = Dependency_HistorySqlQueryable,
                    SaveImplementation = HistorySaveFunction()
                };

            createdConcepts = new IConceptInfo[] { Dependency_ChangesEntity, Dependency_HistorySqlQueryable, Dependency_AtTimeSqlFunction, Dependency_Write };        
        }
示例#3
0
        public void InitializeNonparsableProperties(out IEnumerable <IConceptInfo> createdConcepts)
        {
            Dependency_ChangesEntity = new EntityInfo {
                Module = Entity.Module, Name = Entity.Name + "_Changes"
            };
            Dependency_HistorySqlQueryable = new SqlQueryableInfo {
                Module = Entity.Module, Name = Entity.Name + "_History", SqlSource = HistorySqlSnippet()
            };
            Dependency_AtTimeSqlFunction = new SqlFunctionInfo {
                Module = Entity.Module, Name = Entity.Name + "_AtTime", Arguments = "@ContextTime DATETIME", Source = AtTimeSqlSnippet()
            };
            Dependency_Write = new WriteInfo {
                DataStructure      = Dependency_HistorySqlQueryable,
                SaveImplementation = HistorySaveFunction()
            };

            createdConcepts = new IConceptInfo[] { Dependency_ChangesEntity, Dependency_HistorySqlQueryable, Dependency_AtTimeSqlFunction, Dependency_Write };
        }
示例#4
0
        public void InitializeNonparsableProperties(out IEnumerable <IConceptInfo> createdConcepts)
        {
            if (!(Property.DataStructure is EntityInfo))
            {
                throw new DslSyntaxException(this, "History concept may only be used on entity or its property.");
            }
            Dependency_EntityHistory = new EntityHistoryInfo {
                Entity = (EntityInfo)Property.DataStructure
            };
            Dependency_AtTimeSqlFunction = new SqlFunctionInfo {
                Module = Property.DataStructure.Module, Name = Property.DataStructure.Name + "_AtTime"
            };
            Dependency_HistorySqlQueryable = new SqlQueryableInfo {
                Module = Property.DataStructure.Module, Name = Property.DataStructure.Name + "_History"
            };
            Dependency_Write = new WriteInfo {
                DataStructure = Dependency_HistorySqlQueryable
            };

            createdConcepts = new IConceptInfo[] { Dependency_EntityHistory };
        }
示例#5
0
        protected static string MemberFunctionsSnippet(WriteInfo info)
        {
            return string.Format(
@"        public void Save(IEnumerable<{0}.{1}> insertedNew, IEnumerable<{0}.{1}> updatedNew, IEnumerable<{0}.{1}> deletedIds, bool checkUserPermissions = false)
        {{
            Rhetos.Utilities.CsUtility.Materialize(ref insertedNew);
            Rhetos.Utilities.CsUtility.Materialize(ref updatedNew);
            Rhetos.Utilities.CsUtility.Materialize(ref deletedIds);

            if (insertedNew == null) insertedNew = Enumerable.Empty<{0}.{1}>();
            if (updatedNew == null) updatedNew = Enumerable.Empty<{0}.{1}>();
            if (deletedIds == null) deletedIds = Enumerable.Empty<{0}.{1}>();

            if (insertedNew.Count() == 0 && updatedNew.Count() == 0 && deletedIds.Count() == 0)
                return;

            foreach (var item in insertedNew)
                if (item.ID == Guid.Empty)
                    item.ID = Guid.NewGuid();

            " + WritableOrmDataStructureCodeGenerator.ClearContextTag.Evaluate(info.DataStructure) + @"

            " + WritableOrmDataStructureCodeGenerator.ArgumentValidationTag.Evaluate(info.DataStructure) + @"

            " + WritableOrmDataStructureCodeGenerator.InitializationTag.Evaluate(info.DataStructure) + @"

            {2}

            " + WritableOrmDataStructureCodeGenerator.OnSaveTag1.Evaluate(info.DataStructure) + @"

            " + WritableOrmDataStructureCodeGenerator.OnSaveTag2.Evaluate(info.DataStructure) + @"
        }}

",
                info.DataStructure.Module.Name,
                info.DataStructure.Name,
                info.SaveImplementation);
        }
示例#6
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(EntityHistoryInfo conceptInfo, IDslModel existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            var atTimeSqlFunction = new SqlFunctionInfo {
                Module = conceptInfo.Entity.Module, Name = conceptInfo.Entity.Name + "_AtTime", Arguments = $"@ContextTime {_dateTimeSqlColumnType}", Source = AtTimeSqlSnippet(conceptInfo)
            };

            newConcepts.Add(atTimeSqlFunction);

            var historySqlQueryable = new SqlQueryableInfo {
                Module = conceptInfo.Entity.Module, Name = conceptInfo.Entity.Name + "_History", SqlSource = HistorySqlSnippet(conceptInfo)
            };

            newConcepts.Add(historySqlQueryable);

            var write = new WriteInfo {
                DataStructure = historySqlQueryable, SaveImplementation = HistorySaveFunction(conceptInfo)
            };

            newConcepts.Add(write);

            // Expand the base entity:
            var activeSinceProperty = new DateTimePropertyInfo {
                DataStructure = conceptInfo.Entity, Name = "ActiveSince"
            };                                                                                                               // TODO: SystemRequired, Default 1.1.1900., after implementing optimization for multiple simple property validations.
            var activeSinceHistory = new EntityHistoryPropertyInfo {
                Property = activeSinceProperty
            };

            newConcepts.AddRange(new IConceptInfo[] { activeSinceProperty, activeSinceHistory });

            // InvalidData for base entity: it is not allowed to save with ActiveSince older than last one used in History
            var denyFilter = new ComposableFilterByInfo {
                Parameter  = "Common.OlderThanHistoryEntries",
                Source     = conceptInfo.Entity,
                Expression = String.Format(
                    @"(items, repository, parameter) => items.Where(item => 
                                repository.{0}.{1}_Changes.Subquery.Where(his => his.ActiveSince >= item.ActiveSince && his.Entity == item).Count() > 0)",
                    conceptInfo.Entity.Module.Name,
                    conceptInfo.Entity.Name)
            };
            var invalidDataValidation = new InvalidDataInfo {
                FilterType   = "Common.OlderThanHistoryEntries",
                Source       = conceptInfo.Entity,
                ErrorMessage = "ActiveSince is not allowed to be older than last entry in history."
            };

            newConcepts.AddRange(new IConceptInfo[]
            {
                denyFilter,
                invalidDataValidation,
                new ParameterInfo {
                    Module = new ModuleInfo {
                        Name = "Common"
                    }, Name = "OlderThanHistoryEntries"
                },
                new InvalidDataMarkProperty2Info {
                    InvalidData = invalidDataValidation, MarkProperty = activeSinceProperty
                }
            });

            // Create a new entity for history data:
            var currentProperty = new ReferencePropertyInfo {
                DataStructure = conceptInfo.Dependency_ChangesEntity, Name = "Entity", Referenced = conceptInfo.Entity
            };
            var historyActiveSinceProperty = new DateTimePropertyInfo {
                DataStructure = conceptInfo.Dependency_ChangesEntity, Name = activeSinceProperty.Name
            };

            newConcepts.AddRange(new IConceptInfo[] {
                currentProperty,
                new ReferenceDetailInfo {
                    Reference = currentProperty
                },
                new RequiredPropertyInfo {
                    Property = currentProperty
                },                                                       // TODO: SystemRequired, after implementing optimization for multiple simple property validations.
                new PropertyFromInfo {
                    Destination = conceptInfo.Dependency_ChangesEntity, Source = activeSinceProperty
                },
                historyActiveSinceProperty,
                new UniqueMultiplePropertiesInfo {
                    DataStructure = conceptInfo.Dependency_ChangesEntity, PropertyNames = $"{currentProperty.Name} {historyActiveSinceProperty.Name}"
                }
            });

            // InvalidData for history entity: it is not allowed to save with ActiveSince newer than current entity
            var denyFilterHistory = new ComposableFilterByInfo
            {
                Parameter  = "Common.NewerThanCurrentEntry",
                Source     = conceptInfo.Dependency_ChangesEntity,
                Expression = @"(items, repository, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)"
            };
            var invalidDataValidationHistory = new InvalidDataInfo
            {
                FilterType   = "Common.NewerThanCurrentEntry",
                Source       = conceptInfo.Dependency_ChangesEntity,
                ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry."
            };

            newConcepts.AddRange(new IConceptInfo[]
            {
                denyFilterHistory,
                invalidDataValidationHistory,
                new ParameterInfo {
                    Module = new ModuleInfo {
                        Name = "Common"
                    }, Name = "NewerThanCurrentEntry"
                },
                new InvalidDataMarkProperty2Info {
                    InvalidData = invalidDataValidationHistory, MarkProperty = historyActiveSinceProperty
                }
            });

            // Create ActiveUntil SqlQueryable:
            var activeUntilSqlQueryable = new SqlQueryableInfo {
                Module = conceptInfo.Entity.Module, Name = conceptInfo.Entity.Name + "_ChangesActiveUntil", SqlSource = ActiveUntilSqlSnippet(conceptInfo)
            };

            newConcepts.AddRange(new IConceptInfo[] {
                activeUntilSqlQueryable,
                new DateTimePropertyInfo {
                    DataStructure = activeUntilSqlQueryable, Name = "ActiveUntil"
                },
                new SqlDependsOnDataStructureInfo {
                    Dependent = activeUntilSqlQueryable, DependsOn = conceptInfo.Dependency_ChangesEntity
                },
                new SqlDependsOnDataStructureInfo {
                    Dependent = activeUntilSqlQueryable, DependsOn = conceptInfo.Entity
                },
                new DataStructureExtendsInfo {
                    Base = conceptInfo.Dependency_ChangesEntity, Extension = activeUntilSqlQueryable
                }
            });

            // Configure History SqlQueryable:
            newConcepts.AddRange(new IConceptInfo[] {
                new SqlDependsOnDataStructureInfo {
                    Dependent = historySqlQueryable, DependsOn = conceptInfo.Entity
                },
                new SqlDependsOnDataStructureInfo {
                    Dependent = historySqlQueryable, DependsOn = conceptInfo.Dependency_ChangesEntity
                },
                new SqlDependsOnDataStructureInfo {
                    Dependent = historySqlQueryable, DependsOn = activeUntilSqlQueryable
                },
                new DateTimePropertyInfo {
                    DataStructure = historySqlQueryable, Name = "ActiveUntil"
                },
                new AllPropertiesFromInfo {
                    Source = conceptInfo.Dependency_ChangesEntity, Destination = historySqlQueryable
                }
            });

            // Configure AtTime SqlFunction:
            newConcepts.Add(new SqlDependsOnDataStructureInfo {
                Dependent = atTimeSqlFunction, DependsOn = historySqlQueryable
            });

            return(newConcepts);
        }