public IEnumerable <IConceptInfo> CreateNewConcepts(ChangesOnReferencedInfo conceptInfo, IDslModel existingConcepts)
        {
            var reference = DslUtility.GetPropertyByPath(conceptInfo.Computation, conceptInfo.ReferencePath, existingConcepts).Value;

            if (!(reference is ReferencePropertyInfo))
            {
                throw new DslSyntaxException(conceptInfo, $"The given path '{conceptInfo.ReferencePath}' should end with a reference property, instead of the {reference.GetUserDescription()}.");
            }
            var referenced = ((ReferencePropertyInfo)reference).Referenced;

            var computationDependencies = new List <Tuple <DataStructureInfo, string> >();

            if (referenced is IWritableOrmDataStructure)
            {
                computationDependencies.Add(Tuple.Create(referenced, "item => item.ID"));
            }
            else if (referenced is PolymorphicInfo)
            {
                AddPolymorphicImplementations(computationDependencies, (PolymorphicInfo)referenced, existingConcepts, conceptInfo);
            }

            string referencePathWithGuid = ChangeReferenceToGuid(conceptInfo.ReferencePath);

            return(computationDependencies.Select(dep =>
                                                  new ChangesOnChangedItemsInfo
            {
                Computation = conceptInfo.Computation,
                DependsOn = dep.Item1,
                FilterType = "FilterCriteria",
                FilterFormula = $@"changedItems => new FilterCriteria({CsUtility.QuotedString(referencePathWithGuid)}, ""In"","
                                + $" _domRepository.Common.FilterId.CreateQueryableFilterIds(changedItems.Select({dep.Item2})))"
            }));
        }
        public IEnumerable <IConceptInfo> CreateNewConcepts(BrowseTakeNamedPropertyInfo conceptInfo, IDslModel existingConcepts)
        {
            ValueOrError <PropertyInfo> sourceProperty = DslUtility.GetPropertyByPath(conceptInfo.Browse.Source, conceptInfo.Path, existingConcepts);

            if (sourceProperty.IsError)
            {
                return(null); // Creating the browse property may be delayed for other macro concepts to generate the needed properties. If this condition is not resolved, the CheckSemantics function below will throw an exception.
            }
            var browseProperty = DslUtility.CreatePassiveClone(sourceProperty.Value, conceptInfo.Browse);

            browseProperty.Name = conceptInfo.Name;

            var browsePropertySelector = new BrowseFromPropertyInfo {
                PropertyInfo = browseProperty, Path = conceptInfo.Path
            };

            return(new IConceptInfo[] { browseProperty, browsePropertySelector });
        }
Esempio n. 3
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(InitializationConcept conceptInfo, IDslModel existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            var samePropertiesByInheritance = existingConcepts.FindByType <SamePropertyValueInfo>().Select(x => new {
                DerivedProperty = x.DerivedProperty,
                BaseSelector    = x.Path.Substring(0, x.Path.LastIndexOf('.')),
                BaseProperty    = DslUtility.GetPropertyByPath(x.DerivedProperty.DataStructure, x.Path, existingConcepts).Value,
            }).GroupBy(same => new {
                Module        = same.DerivedProperty.DataStructure.Module.Name,
                DataStructure = same.DerivedProperty.DataStructure.Name,
                same.BaseSelector
            })
                                              .ToDictionary(g => g.Key, g => g.ToList());

            foreach (var inherit in existingConcepts.FindByType <RowPermissionsInheritReadInfo>())
            {
                var key = new
                {
                    Module        = inherit.InheritFromInfo.RowPermissionsFilters.DataStructure.Module.Name,
                    DataStructure = inherit.InheritFromInfo.RowPermissionsFilters.DataStructure.Name,
                    BaseSelector  = inherit.InheritFromInfo.SourceSelector
                };
                var optimizeProperties = samePropertiesByInheritance.GetValueOrEmpty(key);
                newConcepts.AddRange(optimizeProperties
                                     .Select(op =>
                                             new RowPermissionsInheritReadSameMemberInfo
                {
                    InheritRead       = inherit,
                    BaseMemberName    = op.BaseProperty.Name,
                    DerivedMemberName = op.DerivedProperty.Name
                }));
                newConcepts.AddRange(optimizeProperties
                                     .Where(op => op.DerivedProperty is ReferencePropertyInfo && op.BaseProperty is ReferencePropertyInfo)
                                     .Select(op =>
                                             new RowPermissionsInheritReadSameMemberInfo
                {
                    InheritRead       = inherit,
                    BaseMemberName    = op.BaseProperty.Name + "ID",
                    DerivedMemberName = op.DerivedProperty.Name + "ID"
                }));
            }

            foreach (var inherit in existingConcepts.FindByType <RowPermissionsInheritWriteInfo>())
            {
                var key = new
                {
                    Module        = inherit.InheritFromInfo.RowPermissionsFilters.DataStructure.Module.Name,
                    DataStructure = inherit.InheritFromInfo.RowPermissionsFilters.DataStructure.Name,
                    BaseSelector  = inherit.InheritFromInfo.SourceSelector
                };
                var optimizeProperties = samePropertiesByInheritance.GetValueOrEmpty(key);
                newConcepts.AddRange(optimizeProperties
                                     .Select(op =>
                                             new RowPermissionsInheritWriteSameMemberInfo
                {
                    InheritWrite      = inherit,
                    BaseMemberName    = op.BaseProperty.Name,
                    DerivedMemberName = op.DerivedProperty.Name
                }));
                newConcepts.AddRange(optimizeProperties
                                     .Where(op => op.DerivedProperty is ReferencePropertyInfo && op.BaseProperty is ReferencePropertyInfo)
                                     .Select(op =>
                                             new RowPermissionsInheritWriteSameMemberInfo
                {
                    InheritWrite      = inherit,
                    BaseMemberName    = op.BaseProperty.Name + "ID",
                    DerivedMemberName = op.DerivedProperty.Name + "ID"
                }));
            }

            return(newConcepts);
        }