Beispiel #1
0
        public System.Collections.Generic.IEnumerable <IConceptInfo> CreateNewConcepts()
        {
            var activePropertyInfo = new BoolPropertyInfo
            {
                DataStructure = Entity,
                Name          = "Active"
            };

            var composableFilterActiveAndThis = new QueryFilterExpressionInfo
            {
                Expression = @"(items, parameter) =>
                    {
                        if (parameter != null && parameter.ItemID.HasValue)
                            return items.Where(item => item.Active == null || item.Active.Value || item.ID == parameter.ItemID.Value);
                        else
                            return items.Where(item => item.Active == null || item.Active.Value);
                    }",
                Parameter  = "Rhetos.Dom.DefaultConcepts.ActiveItems",
                Source     = Entity
            };

            var systemRequired = new SystemRequiredInfo {
                Property = activePropertyInfo
            };

            return(new IConceptInfo[] { activePropertyInfo, composableFilterActiveAndThis, systemRequired });
        }
Beispiel #2
0
        public IEnumerable <IConceptInfo> CreateNewConcepts()
        {
            var filterParameter = new ParameterInfo
            {
                Module = Property.DataStructure.Module,
                Name   = Property.Name + "_RegExMatchFilter",
            };

            string filterExpression = string.Format(@"(source, parameter) =>
                {{
                    var items = source.Where(item => !string.IsNullOrEmpty(item.{0})).Select(item => new {{ item.ID, item.{0} }}).ToList();
                    var regex = new System.Text.RegularExpressions.Regex({1});
                    var invalidItemIds = items.Where(item => !regex.IsMatch(item.{0})).Select(item => item.ID).ToList();
                    return Filter(source, invalidItemIds);
                }}",
                                                    Property.Name,
                                                    CsUtility.QuotedString("^" + RegularExpression + "$"));

            var itemFilter = new QueryFilterExpressionInfo
            {
                Expression = filterExpression,
                Parameter  = filterParameter.Module.Name + "." + filterParameter.Name,
                Source     = Property.DataStructure
            };
            var invalidData = new InvalidDataInfo
            {
                Source       = Property.DataStructure,
                FilterType   = itemFilter.Parameter,
                ErrorMessage = ErrorMessage
            };
            var invalidProperty = new InvalidDataMarkProperty2Info
            {
                InvalidData  = invalidData,
                MarkProperty = Property
            };

            return(new IConceptInfo[] { filterParameter, itemFilter, invalidData, invalidProperty });
        }
        public IEnumerable <IConceptInfo> CreateNewConcepts(ItemFilterInfo conceptInfo, IDslModel existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            ParameterInfo filterParameter = GetGeneratedFilter(conceptInfo);

            // Existing filter parameter does not have to be a ParameterInfo. Any DataStructureInfo is allowed.
            if (existingConcepts.FindByKey($"DataStructureInfo {filterParameter.Module.Name}.{filterParameter.Name}") == null)
            {
                newConcepts.Add(filterParameter);
            }

            var composableFilter = new QueryFilterExpressionInfo
            {
                Source     = conceptInfo.Source,
                Parameter  = filterParameter.GetKeyProperties(),
                Expression = "(source, parameter) => source.Where(" + conceptInfo.Expression + ")"
            };

            newConcepts.Add(composableFilter);

            return(newConcepts);
        }
        public IEnumerable <IConceptInfo> CreateNewConcepts()
        {
            string limitSnippet = MinValueInfo.LimitSnippetByType
                                  .Where(snippet => snippet.Key.IsAssignableFrom(Property.GetType()))
                                  .Select(snippet => snippet.Value.Invoke(Value))
                                  .Single();

            var filterParameter = new ParameterInfo
            {
                Module = Property.DataStructure.Module,
                Name   = Property.Name + "_MaxValueFilter"
            };
            var filter = new QueryFilterExpressionInfo
            {
                Expression = String.Format(@"(items, parameter) => {{ {1}; return items.Where(item => item.{0} != null && item.{0} > limit); }}", Property.Name, limitSnippet),
                Parameter  = filterParameter.Module.Name + "." + filterParameter.Name,
                Source     = Property.DataStructure
            };
            var invalidData = new InvalidDataInfo
            {
                Source       = Property.DataStructure,
                FilterType   = filter.Parameter,
                ErrorMessage = "Maximum value of {0} is {1}."
            };
            var messageParameters = new InvalidDataMessageParametersConstantInfo
            {
                InvalidData       = invalidData,
                MessageParameters = CsUtility.QuotedString(Property.Name) + ", " + CsUtility.QuotedString(Value)
            };
            var invalidProperty = new InvalidDataMarkProperty2Info
            {
                InvalidData  = invalidData,
                MarkProperty = Property
            };

            return(new IConceptInfo[] { filterParameter, filter, invalidData, messageParameters, invalidProperty });
        }
        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 QueryFilterExpressionInfo
            {
                Parameter  = "Common.OlderThanHistoryEntries",
                Source     = conceptInfo.Entity,
                Expression = String.Format(
                    @"(items, parameter) => items.Where(item => 
                                _domRepository.{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 QueryFilterExpressionInfo
            {
                Parameter  = "Common.NewerThanCurrentEntry",
                Source     = conceptInfo.Dependency_ChangesEntity,
                Expression = @"(items, 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);
        }