public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { 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 ComposableFilterByInfo { Expression = String.Format(@"(items, repository, 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 InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = filter.Parameter, ErrorMessage = String.Format("Maximum value of {0} is {1}.", Property.Name, Value), Source = Property.DataStructure }; return(new IConceptInfo[] { filterParameter, filter, invalidData }); }
public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { var filterParameter = new ParameterInfo { Module = Property.DataStructure.Module, Name = Property.Name + "_RegExMatchFilter", }; string filterExpression = string.Format(@"(source, repository, 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 itemFilterRegExMatchProperty = new ComposableFilterByInfo { Expression = filterExpression, Parameter = filterParameter.Module.Name + "." + filterParameter.Name, Source = Property.DataStructure }; var invalidDataRegExMatchProperty = new InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = itemFilterRegExMatchProperty.Parameter, ErrorMessage = ErrorMessage, Source = Property.DataStructure }; return(new IConceptInfo[] { filterParameter, itemFilterRegExMatchProperty, invalidDataRegExMatchProperty }); }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { string filterName = "SystemRequired" + Property.Name; var filter = new ItemFilterInfo { Source = Property.DataStructure, FilterName = filterName, Expression = "item => item." + Property.Name + " == null" }; var invalidData = new InvalidDataMarkPropertyInfo { Source = Property.DataStructure, FilterType = filterName, ErrorMessage = "System required property " + Property.GetUserDescription() + " is not set.", DependedProperty = Property }; var reloadBeforeValidations = new ReloadBeforeValidationsInfo { DataStructure = Property.DataStructure }; return new IConceptInfo[] { filter, invalidData, reloadBeforeValidations }; }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { // Expand the base entity: var itemFilterMinLengthProperty = new ItemFilterInfo { Expression = String.Format("item => !String.IsNullOrEmpty(item.{0}) && item.{0}.Length < {1}", Property.Name, Length), FilterName = Property.Name + "_MinLengthFilter", Source = Property.DataStructure }; var invalidDataMinLengthProperty = new InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = itemFilterMinLengthProperty.FilterName, ErrorMessage = String.Format("Minimum allowed length of {0} is {1} characters.", Property.Name, Length), Source = Property.DataStructure }; return new IConceptInfo[] { itemFilterMinLengthProperty, invalidDataMinLengthProperty }; }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { // Expand the base entity: var itemFilterRange = new ItemFilterInfo { Expression = String.Format("item => item.{0} != null && item.{1} != null && item.{0} > item.{1}", PropertyFrom.Name, PropertyTo.Name), FilterName = PropertyFrom.Name + "_" + PropertyTo.Name + "_RangeFilter", Source = PropertyFrom.DataStructure }; var invalidDataRange = new InvalidDataMarkPropertyInfo { DependedProperty = PropertyFrom, FilterType = itemFilterRange.FilterName, ErrorMessage = String.Format("Value of {0} has to be less than or equal to {1}.", PropertyFrom.Name, PropertyTo.Name), Source = PropertyFrom.DataStructure }; return new IConceptInfo[] { itemFilterRange, invalidDataRange }; }
public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { // Expand the base entity: var itemFilterRange = new ItemFilterInfo { Expression = String.Format("item => item.{0} != null && item.{1} != null && item.{0} > item.{1}", PropertyFrom.Name, PropertyTo.Name), FilterName = PropertyFrom.Name + "_" + PropertyTo.Name + "_RangeFilter", Source = PropertyFrom.DataStructure }; var invalidDataRange = new InvalidDataMarkPropertyInfo { DependedProperty = PropertyFrom, FilterType = itemFilterRange.FilterName, ErrorMessage = String.Format("Value of {0} has to be less than or equal to {1}.", PropertyFrom.Name, PropertyTo.Name), Source = PropertyFrom.DataStructure }; return(new IConceptInfo[] { itemFilterRange, invalidDataRange }); }
public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { // Expand the base entity: var itemFilterMinLengthProperty = new ItemFilterInfo { Expression = String.Format("item => !String.IsNullOrEmpty(item.{0}) && item.{0}.Length < {1}", Property.Name, Length), FilterName = Property.Name + "_MinLengthFilter", Source = Property.DataStructure }; var invalidDataMinLengthProperty = new InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = itemFilterMinLengthProperty.FilterName, ErrorMessage = String.Format("Minimum allowed length of {0} is {1} characters.", Property.Name, Length), Source = Property.DataStructure }; return(new IConceptInfo[] { itemFilterMinLengthProperty, invalidDataMinLengthProperty }); }
public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { string filterName = "SystemRequired" + Property.Name; var filter = new ItemFilterInfo { Source = Property.DataStructure, FilterName = filterName, Expression = "item => item." + Property.Name + " == null" }; var invalidData = new InvalidDataMarkPropertyInfo { Source = Property.DataStructure, FilterType = filterName, ErrorMessage = "System required property " + Property.GetUserDescription() + " is not set.", DependedProperty = Property }; return(new IConceptInfo[] { filter, invalidData }); }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { 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 ComposableFilterByInfo { Expression = String.Format(@"(items, repository, 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 InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = filter.Parameter, ErrorMessage = String.Format("Maximum value of {0} is {1}.", Property.Name, Value), Source = Property.DataStructure }; return new IConceptInfo[] { filterParameter, filter, invalidData }; }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { string propertyPrepared = (this.Property is IntegerPropertyInfo) ? Value : (this.Property is DecimalPropertyInfo) ? "(decimal)" + Value : (this.Property is MoneyPropertyInfo) ? "(decimal)" + Value : (this.Property is DatePropertyInfo) ? String.Format(@"DateTime.Parse({0})", CsUtility.QuotedString(Value)) : (this.Property is DateTimePropertyInfo) ? String.Format(@"DateTime.Parse({0})", CsUtility.QuotedString(Value)) : ""; // Expand the base entity: var itemFilterMinValueProperty = new ItemFilterInfo { Expression = String.Format(@"item => item.{0} != null && item.{0} < {1}", Property.Name, propertyPrepared), FilterName = Property.Name + "_MinValueFilter", Source = Property.DataStructure }; var invalidDataMinValueProperty = new InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = itemFilterMinValueProperty.FilterName, ErrorMessage = String.Format("Minimum value of {0} is {1}.", Property.Name, Value), Source = Property.DataStructure }; return new IConceptInfo[] { itemFilterMinValueProperty, invalidDataMinValueProperty }; }
public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { var newConcepts = new List <IConceptInfo>(); // Expand the base entity: var activeSinceProperty = new DateTimePropertyInfo { DataStructure = Entity, Name = "ActiveSince" }; // TODO: SystemRequired, Default 1.1.1900. 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 = 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)", Entity.Module.Name, Entity.Name) }; var invalidDataValidation = new InvalidDataMarkPropertyInfo { FilterType = "Common.OlderThanHistoryEntries", Source = Entity, ErrorMessage = "ActiveSince is not allowed to be older than last entry in history.", DependedProperty = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilter, invalidDataValidation, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "OlderThanHistoryEntries" } }); // Create a new entity for history data: var currentProperty = new ReferencePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = "Entity", Referenced = Entity }; var historyActiveSinceProperty = new DateTimePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = activeSinceProperty.Name }; newConcepts.AddRange(new IConceptInfo[] { currentProperty, new ReferenceDetailInfo { Reference = currentProperty }, new RequiredPropertyInfo { Property = currentProperty }, // TODO: SystemRequired new PropertyFromInfo { Destination = Dependency_ChangesEntity, Source = activeSinceProperty }, historyActiveSinceProperty, new UniquePropertiesInfo { DataStructure = Dependency_ChangesEntity, Property1 = currentProperty, Property2 = historyActiveSinceProperty } }); // InvalidData for history entity: it is not allowed to save with ActiveSince newer than current entity var denyFilterHistory = new ComposableFilterByInfo { Parameter = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, Expression = @"(items, repository, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)" }; var invalidDataValidationHistory = new InvalidDataMarkPropertyInfo { FilterType = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry.", DependedProperty = historyActiveSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilterHistory, invalidDataValidationHistory, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "NewerThanCurrentEntry" } }); // Create ActiveUntil SqlQueryable: var activeUntilSqlQueryable = new SqlQueryableInfo { Module = Entity.Module, Name = Entity.Name + "_ChangesActiveUntil", SqlSource = ActiveUntilSqlSnippet() }; newConcepts.AddRange(new IConceptInfo[] { activeUntilSqlQueryable, new DateTimePropertyInfo { DataStructure = activeUntilSqlQueryable, Name = "ActiveUntil" }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Entity }, new DataStructureExtendsInfo { Base = Dependency_ChangesEntity, Extension = activeUntilSqlQueryable } }); // Configure History SqlQueryable: newConcepts.AddRange(new IConceptInfo[] { new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Entity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = activeUntilSqlQueryable }, new DateTimePropertyInfo { DataStructure = Dependency_HistorySqlQueryable, Name = "ActiveUntil" }, new AllPropertiesFromInfo { Source = Dependency_ChangesEntity, Destination = Dependency_HistorySqlQueryable } }); // Configure AtTime SqlFunction: newConcepts.Add(new SqlDependsOnDataStructureInfo { Dependent = Dependency_AtTimeSqlFunction, DependsOn = Dependency_HistorySqlQueryable }); return(newConcepts); }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { var newConcepts = new List<IConceptInfo>(); // Expand the base entity: var activeSinceProperty = new DateTimePropertyInfo { DataStructure = Entity, Name = "ActiveSince" }; // TODO: SystemRequired, Default 1.1.1900. 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 = 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)", Entity.Module.Name, Entity.Name) }; var invalidDataValidation = new InvalidDataMarkPropertyInfo { FilterType = "Common.OlderThanHistoryEntries", Source = Entity, ErrorMessage = "ActiveSince is not allowed to be older than last entry in history.", DependedProperty = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilter, invalidDataValidation, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "OlderThanHistoryEntries" } }); // Create a new entity for history data: var currentProperty = new ReferencePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = "Entity", Referenced = Entity }; var historyActiveSinceProperty = new DateTimePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = activeSinceProperty.Name }; newConcepts.AddRange(new IConceptInfo[] { currentProperty, new ReferenceDetailInfo { Reference = currentProperty }, new RequiredPropertyInfo { Property = currentProperty }, // TODO: SystemRequired new PropertyFromInfo { Destination = Dependency_ChangesEntity, Source = activeSinceProperty }, historyActiveSinceProperty, new UniquePropertiesInfo { DataStructure = Dependency_ChangesEntity, Property1 = currentProperty, Property2 = historyActiveSinceProperty } }); // InvalidData for history entity: it is not allowed to save with ActiveSince newer than current entity var denyFilterHistory = new ComposableFilterByInfo { Parameter = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, Expression = @"(items, repository, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)" }; var invalidDataValidationHistory = new InvalidDataMarkPropertyInfo { FilterType = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry.", DependedProperty = historyActiveSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilterHistory, invalidDataValidationHistory, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "NewerThanCurrentEntry" } }); // Create ActiveUntil SqlQueryable: var activeUntilSqlQueryable = new SqlQueryableInfo { Module = Entity.Module, Name = Entity.Name + "_ChangesActiveUntil", SqlSource = ActiveUntilSqlSnippet() }; newConcepts.AddRange(new IConceptInfo[] { activeUntilSqlQueryable, new DateTimePropertyInfo { DataStructure = activeUntilSqlQueryable, Name = "ActiveUntil" }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Entity }, new DataStructureExtendsInfo { Base = Dependency_ChangesEntity, Extension = activeUntilSqlQueryable } }); // Configure History SqlQueryable: newConcepts.AddRange(new IConceptInfo[] { new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Entity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = activeUntilSqlQueryable }, new DateTimePropertyInfo { DataStructure = Dependency_HistorySqlQueryable, Name = "ActiveUntil" }, new AllPropertiesFromInfo { Source = Dependency_ChangesEntity, Destination = Dependency_HistorySqlQueryable } }); // Configure AtTime SqlFunction: newConcepts.Add(new SqlDependsOnDataStructureInfo { Dependent = Dependency_AtTimeSqlFunction, DependsOn = Dependency_HistorySqlQueryable }); return newConcepts; }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { var itemFilterRegExMatchProperty = new ItemFilterInfo { Expression = String.Format(@"item => !String.IsNullOrEmpty(item.{0}) && !(new System.Text.RegularExpressions.Regex({1})).IsMatch(item.{0})", Property.Name, CsUtility.QuotedString("^" + RegularExpression + "$")), FilterName = Property.Name + "_RegExMatchFilter", Source = Property.DataStructure }; var invalidDataRegExMatchProperty = new InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = itemFilterRegExMatchProperty.FilterName, ErrorMessage = ErrorMessage, Source = Property.DataStructure }; return new IConceptInfo[] { itemFilterRegExMatchProperty, invalidDataRegExMatchProperty }; }
public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { var filterParameter = new ParameterInfo { Module = Property.DataStructure.Module, Name = Property.Name + "_RegExMatchFilter", }; string filterExpression = string.Format(@"(source, repository, 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 itemFilterRegExMatchProperty = new ComposableFilterByInfo { Expression = filterExpression, Parameter = filterParameter.Module.Name + "." + filterParameter.Name, Source = Property.DataStructure }; var invalidDataRegExMatchProperty = new InvalidDataMarkPropertyInfo { DependedProperty = Property, FilterType = itemFilterRegExMatchProperty.Parameter, ErrorMessage = ErrorMessage, Source = Property.DataStructure }; return new IConceptInfo[] { filterParameter, itemFilterRegExMatchProperty, invalidDataRegExMatchProperty }; }
private static string AdditionalInvalidMessageSnippet(InvalidDataMarkPropertyInfo info) { return string.Format(@"+"",Property:{0}""", info.DependedProperty.Name); }