コード例 #1
0
ファイル: RangeInfo.cs プロジェクト: koav/Rhetos
 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 denySaveRange = new DenySaveForPropertyInfo
     {
         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, denySaveRange };
 }
コード例 #2
0
ファイル: MinLengthInfo.cs プロジェクト: koav/Rhetos
 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 denySaveMinLengthProperty = new DenySaveForPropertyInfo
     {
             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, denySaveMinLengthProperty };
 }
コード例 #3
0
ファイル: SystemRequiredInfo.cs プロジェクト: koav/Rhetos
        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 denySave = new DenySaveForPropertyInfo
            {
                Source = Property.DataStructure,
                FilterType = filterName,
                ErrorMessage = "System required property " +  Property.GetUserDescription() + " is not set.",
                DependedProperty = Property
            };

            return new IConceptInfo[] { filter, denySave };
        }
コード例 #4
0
 private static string AdditionalInvalidMessageSnippet(DenySaveForPropertyInfo info)
 {
     return string.Format(@"+"",Property:{0}""", info.DependedProperty.Name);
 }
コード例 #5
0
ファイル: EntityHistoryInfo.cs プロジェクト: koav/Rhetos
        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 });

            // DenySave 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.Query().Where(his => his.ActiveSince >= item.ActiveSince && his.Entity == item).Count() > 0)",
                                Entity.Module.Name,
                                Entity.Name)
            };
            var denySaveValidation = new DenySaveForPropertyInfo {
                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, denySaveValidation, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "OlderThanHistoryEntries" } });

            // Create a new entity for history data:
            var currentProperty = new ReferencePropertyInfo { DataStructure = ChangesEntity, Name = "Entity", Referenced = Entity };
            var historyActiveSinceProperty = new DateTimePropertyInfo { DataStructure = ChangesEntity, Name = activeSinceProperty.Name };
            newConcepts.AddRange(new IConceptInfo[] {
                currentProperty,
                new ReferenceDetailInfo { Reference = currentProperty },
                new RequiredPropertyInfo { Property = currentProperty }, // TODO: SystemRequired
                new PropertyFromInfo { Destination = ChangesEntity, Source = activeSinceProperty },
                historyActiveSinceProperty,
                new UniquePropertiesInfo { DataStructure = ChangesEntity, Property1 = currentProperty, Property2 = historyActiveSinceProperty }
            });

            // DenySave for history entity: it is not allowed to save with ActiveSince newer than current entity
            var denyFilterHistory = new ComposableFilterByInfo
            {
                Parameter = "Common.NewerThanCurrentEntry",
                Source = ChangesEntity,
                Expression = @"(items, repository, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)"
            };
            var denySaveValidationHistory = new DenySaveForPropertyInfo
            {
                FilterType = "Common.NewerThanCurrentEntry",
                Source = ChangesEntity,
                ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry.",
                DependedProperty = historyActiveSinceProperty
            };
            newConcepts.AddRange(new IConceptInfo[] { denyFilterHistory, denySaveValidationHistory, 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 = ChangesEntity },
                new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Entity },
                new DataStructureExtendsInfo { Base = ChangesEntity, Extension = activeUntilSqlQueryable }
            });

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

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

            return newConcepts;
        }
コード例 #6
0
ファイル: MaxValueInfo.cs プロジェクト: koav/Rhetos
 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 + "_MaxValueFilter",
             Source = Property.DataStructure
     };
     var denySaveMinValueProperty = new DenySaveForPropertyInfo {
             DependedProperty = Property,
             FilterType = itemFilterMinValueProperty.FilterName,
             ErrorMessage = String.Format("Maximum value of {0} is {1}.", Property.Name, Value),
             Source = Property.DataStructure
     };
     return new IConceptInfo[] { itemFilterMinValueProperty, denySaveMinValueProperty };
 }
コード例 #7
0
ファイル: RegExMatchInfo.cs プロジェクト: koav/Rhetos
 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 denySaveRegExMatchProperty = new DenySaveForPropertyInfo
     {
         DependedProperty = Property,
         FilterType = itemFilterRegExMatchProperty.FilterName,
         ErrorMessage = ErrorMessage,
         Source = Property.DataStructure
     };
     return new IConceptInfo[] { itemFilterRegExMatchProperty, denySaveRegExMatchProperty };
 }