Example #1
0
        private static void ValidateNewConceptSameAsExisting(IConceptInfo newConcept, IConceptInfo existingConcept)
        {
            if (newConcept == existingConcept)
            {
                return;
            }

            if (newConcept.GetFullDescription() == existingConcept.GetFullDescription())
            {
                return;
            }

            // The new concept is allowed to be a simple version (base class) of the existing concept, even if it is not the same.
            // This will allow some macro concepts to create simplified new concept that will be ignored if more specific version is already implemented.
            // Note: Unfortunately this logic should not simply be reversed to also ignore old concept if the new concept is a derivation of the old one,
            // because other macros might have already used the old concept to generate a different business logic.
            if (newConcept.GetType().IsAssignableFrom(existingConcept.GetType()) &&
                newConcept.GetFullDescription() == existingConcept.GetFullDescriptionAsBaseConcept(newConcept.GetType()))
            {
                return;
            }

            throw new DslSyntaxException(
                      "Concept with same key is described twice with different values."
                      + "\r\nValue 1: " + existingConcept.GetFullDescription()
                      + "\r\nValue 2: " + newConcept.GetFullDescription()
                      + "\r\nSame key: " + newConcept.GetKey());
        }
Example #2
0
        private bool ConteptsValueEqualOrBase(IConceptInfo newConcept, IConceptInfo existingConcept)
        {
            if (object.ReferenceEquals(newConcept, existingConcept))
            {
                return(true);
            }
            else if (newConcept.GetKey() != existingConcept.GetKey())
            {
                return(false);
            }
            else if (!newConcept.GetType().IsInstanceOfType(existingConcept))
            {
                return(false);
            }
            else
            {
                var newConceptMemebers = ConceptMembers.Get(newConcept);
                foreach (ConceptMember member in newConceptMemebers)
                {
                    if (member.IsKey)
                    {
                        continue;
                    }

                    if (!IsConceptMemberEqual(newConcept, existingConcept, member))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #3
0
 public UnresolvedReference(ConceptDescription dependant, ConceptMember referenceMember)
 {
     Dependant      = dependant;
     Member         = referenceMember;
     ReferencedStub = (IConceptInfo)Member.GetValue(Dependant.Concept);
     ReferencedKey  = ReferencedStub?.GetKey();
 }
Example #4
0
        public void Set <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey, T value)
        {
            Dictionary <Guid, object> conceptInfoMetadata;
            string conceptKey = conceptInfo.GetKey();

            if (!_metadata.TryGetValue(conceptKey, out conceptInfoMetadata))
            {
                conceptInfoMetadata = new Dictionary <Guid, object>();
                _metadata.Add(conceptKey, conceptInfoMetadata);
            }

            object oldValue;

            if (!conceptInfoMetadata.TryGetValue(metadataKey.Id, out oldValue))
            {
                conceptInfoMetadata.Add(metadataKey.Id, value);
            }
            else
            {
                if (!SameValue(value, oldValue))
                {
                    throw new FrameworkException(
                              $"Different metadata value is already set for concept {conceptInfo.GetUserDescription()}, key {metadataKey}." +
                              $" Previous value '{oldValue}', new value '{value}'.");
                }
            }
        }
        private static string Dump(IConceptInfo ci)
        {
            var result = ci.GetKey();

            Console.WriteLine(result);
            return(result);
        }
Example #6
0
        public T Get <T>(IConceptInfo conceptInfo, ConceptMetadataType <T> metadataType)
        {
            Func <string> missingMetadataMessage = () => "There is no metadata of requested type for concept " + conceptInfo.GetUserDescription() + ". Metadata type is " + metadataType + ".";
            var           conceptMetadataByType  = _metadata.GetValue(conceptInfo.GetKey(), missingMetadataMessage);
            var           metadataValue          = conceptMetadataByType.GetValue(metadataType.Id, missingMetadataMessage);

            return((T)metadataValue);
        }
Example #7
0
        public T Get <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey)
        {
            Func <string> missingMetadataMessage = () => "There is no requested metadata for concept " + conceptInfo.GetUserDescription() + ". Metadata key is " + metadataKey + ".";
            var           conceptInfoMetadata    = _metadata.GetValue(conceptInfo.GetKey(), missingMetadataMessage);
            var           metadataValue          = conceptInfoMetadata.GetValue(metadataKey.Id, missingMetadataMessage);

            return((T)metadataValue);
        }
Example #8
0
        public bool Contains <T>(IConceptInfo conceptInfo, ConceptMetadataType <T> metadataType)
        {
            Dictionary <Guid, object> conceptMetadataByType;

            if (!_metadata.TryGetValue(conceptInfo.GetKey(), out conceptMetadataByType))
            {
                return(false);
            }
            return(conceptMetadataByType.ContainsKey(metadataType.Id));
        }
 public NewConceptApplication(IConceptInfo conceptInfo, IConceptDatabaseDefinition conceptImplementation)
 {
     Id                            = Guid.Empty;
     ConceptInfo                   = conceptInfo;
     ConceptInfoTypeName           = conceptInfo.GetType().AssemblyQualifiedName;
     ConceptInfoKey                = conceptInfo.GetKey();
     ConceptImplementation         = conceptImplementation;
     ConceptImplementationType     = conceptImplementation.GetType();
     ConceptImplementationTypeName = ConceptImplementationType.AssemblyQualifiedName;
     ConceptImplementationVersion  = GetVersionFromAttribute(ConceptImplementationType);
 }
 public NewConceptApplication(IConceptInfo conceptInfo, IConceptDatabaseDefinition conceptImplementation)
 {
     Id = Guid.Empty;
     ConceptInfo = conceptInfo;
     ConceptInfoTypeName = conceptInfo.GetType().AssemblyQualifiedName;
     ConceptInfoKey = conceptInfo.GetKey();
     ConceptImplementation = conceptImplementation;
     ConceptImplementationType = conceptImplementation.GetType();
     ConceptImplementationTypeName = ConceptImplementationType.AssemblyQualifiedName;
     ConceptImplementationVersion = GetVersionFromAttribute(ConceptImplementationType);
 }
Example #11
0
        // The new concept is allowed to be a simple version (base class) of the existing concept, even if it is not the same.
        // This will allow some macro concepts to create simplified new concept that will be ignored if more specific version is already implemented.
        // Note: Unfortunately this logic should not simply be reversed to also ignore old concept if the new concept is a derivation of the old one,
        // because other macros might have already used the old concept to generate a different business logic.
        private void ValidateNewConceptSameAsExisting(IConceptInfo newConcept, IConceptInfo existingConcept)
        {
            _validateDuplicateStopwatch.Start();

            if (!ConteptsValueEqualOrBase(newConcept, existingConcept))
            {
                throw new DslSyntaxException(
                          "Concept with same key is described twice with different values."
                          + "\r\nValue 1: " + existingConcept.GetFullDescription()
                          + "\r\nValue 2: " + newConcept.GetFullDescription()
                          + "\r\nSame key: " + newConcept.GetKey());
            }

            _validateDuplicateStopwatch.Stop();
        }
Example #12
0
        // The new concept is allowed to be a simple version (base class) of the existing concept, even if it is not the same.
        // This will allow some macro concepts to create simplified new concept that will be ignored if more specific version is already implemented.
        // Note: Unfortunately this logic should not simply be reversed to also ignore old concept if the new concept is a derivation of the old one,
        // because other macros might have already used the old concept to generate a different business logic.
        private void ValidateNewConceptSameAsExisting(IConceptInfo newConcept, IConceptInfo existingConcept)
        {
            _validateDuplicateStopwatch.Start();

            if (newConcept != existingConcept &&
                newConcept.GetFullDescription() != existingConcept.GetFullDescription() &&
                !(newConcept.GetType().IsAssignableFrom(existingConcept.GetType()) &&
                  newConcept.GetFullDescription() == existingConcept.GetFullDescriptionAsBaseConcept(newConcept.GetType())))
            {
                throw new DslSyntaxException(
                          "Concept with same key is described twice with different values."
                          + "\r\nValue 1: " + existingConcept.GetFullDescription()
                          + "\r\nValue 2: " + newConcept.GetFullDescription()
                          + "\r\nSame key: " + newConcept.GetKey());
            }

            _validateDuplicateStopwatch.Stop();
        }
Example #13
0
        // Check if the data structure already contains a specific row permissions filter that is not rule-based. Such filter is not compatible with RowPermissionsPluginableFiltersInfo.
        private void CheckForIncompatibleSpecificRowPermissionsFilter(IDslModel existingConcepts, IConceptInfo newRowPermissionsFilter, RowPermissionsPluginableFiltersInfo conceptInfo)
        {
            IConceptInfo oldRowPermissions = existingConcepts.FindByKey(newRowPermissionsFilter.GetKey());

            if (oldRowPermissions == null)
            {
                return;
            }

            string filterName;
            string newFilterExpression;
            string oldFilterExpression = null;

            if (newRowPermissionsFilter is RowPermissionsReadInfo newReadFilter)
            {
                filterName          = RowPermissionsReadInfo.FilterName;
                newFilterExpression = newReadFilter.SimplifiedExpression;
                if (oldRowPermissions is RowPermissionsReadInfo oldReadFilter)
                {
                    oldFilterExpression = oldReadFilter.SimplifiedExpression;
                }
            }
            else if (newRowPermissionsFilter is RowPermissionsWriteInfo newWriteFilter)
            {
                filterName          = RowPermissionsWriteInfo.FilterName;
                newFilterExpression = newWriteFilter.SimplifiedExpression;
                if (oldRowPermissions is RowPermissionsWriteInfo oldWriteFilter)
                {
                    oldFilterExpression = oldWriteFilter.SimplifiedExpression;
                }
            }
            else
            {
                throw new InvalidOperationException($"Unexpected {nameof(newRowPermissionsFilter)} type '{newRowPermissionsFilter.GetType()}'.");
            }

            if (oldFilterExpression == null || oldFilterExpression != newFilterExpression)
            {
                throw new DslSyntaxException(conceptInfo, "Cannot use row permissions rules or row permissions inheritance on "
                                             + conceptInfo.DataStructure.GetUserDescription() + " because it already contains a specific row permissions filter ("
                                             + filterName + ")."
                                             + " Use RowPermissions concept instead of the specific filter, to create rules-based row permissions.");
            }
        }
Example #14
0
        public void Set <T>(IConceptInfo conceptInfo, ConceptMetadataType <T> metadataType, T value)
        {
            Dictionary <Guid, object> conceptMetadataByType;
            string conceptKey = conceptInfo.GetKey();

            if (!_metadata.TryGetValue(conceptKey, out conceptMetadataByType))
            {
                conceptMetadataByType = new Dictionary <Guid, object>();
                _metadata.Add(conceptKey, conceptMetadataByType);
            }

            if (conceptMetadataByType.ContainsKey(metadataType.Id))
            {
                throw new FrameworkException(string.Format(
                                                 "The metadata is already set for concept {0}. Metadata type {1}.",
                                                 conceptInfo.GetUserDescription(),
                                                 metadataType));
            }

            conceptMetadataByType.Add(metadataType.Id, value);
        }
Example #15
0
 private static ConceptApplication NewConceptApplication(
     IConceptInfo conceptInfo,
     IConceptDatabaseDefinition conceptImplementation,
     Guid Id,
     string CreateQuery,
     ConceptApplication[] DependsOn,
     int OldCreationOrder)
 {
     return(new ConceptApplication
     {
         //ConceptInfo = conceptInfo,
         ConceptInfoTypeName = conceptInfo.GetType().AssemblyQualifiedName,
         ConceptInfoKey = conceptInfo.GetKey(),
         //ConceptImplementation = conceptImplementation,
         //ConceptImplementationType = conceptImplementation.GetType(),
         ConceptImplementationTypeName = conceptImplementation.GetType().AssemblyQualifiedName,
         //ConceptImplementationVersion = GetVersionFromAttribute(conceptImplementation.GetType()),
         Id = Id,
         CreateQuery = CreateQuery,
         DependsOn = DependsOn,
         OldCreationOrder = OldCreationOrder
     });
 }
Example #16
0
 public bool Contains <T>(IConceptInfo conceptInfo, ConceptMetadataType <T> metadataType)
 {
     return(_metadata.ContainsKey(conceptInfo.GetKey()));
 }
Example #17
0
 public ConceptDescription(IConceptInfo concept)
 {
     Concept = concept;
     Key     = concept.GetKey();
     UnresolvedDependencies = 0;
 }
 private static string Dump(IConceptInfo ci)
 {
     var result = ci.GetKey();
     Console.WriteLine(result);
     return result;
 }
Example #19
0
        public static IEnumerable <T> FindByReference <T>(this IDslModel dslModel, Expression <Func <T, object> > referenceProperty, IConceptInfo referencedConcept) where T : IConceptInfo
        {
            var propertyName = GetPropertyName <T>(referenceProperty, checkValueType: referencedConcept);

            return(dslModel.GetIndex <DslModelIndexByReference>().FindByReference(typeof(T), true, propertyName, referencedConcept.GetKey()).Cast <T>());
        }