Ejemplo n.º 1
0
        protected bool CheckToWeakRegisterExistingExtensions(ConversionKey conversionKey, ClassTupleEntry <V> classEntry)
        {
            bool changesHappened = false;

            foreach (Entry <Strong2Key <V>, List <Def2Entry <V> > > entry in classEntry.definitionReverseMap)
            {
                Strong2Key <V> strongKey           = entry.Key;
                ConversionKey  registeredStrongKey = strongKey.key;
                int            sourceDistance      = ClassExtendableContainer <V> .GetDistanceForType(conversionKey.SourceType, registeredStrongKey.SourceType);

                if (sourceDistance == ClassExtendableContainer <V> .NO_VALID_DISTANCE)
                {
                    continue;
                }
                int targetDistance = ClassExtendableContainer <V> .GetDistanceForType(registeredStrongKey.TargetType, conversionKey.TargetType);

                if (targetDistance == ClassExtendableContainer <V> .NO_VALID_DISTANCE)
                {
                    continue;
                }
                List <Def2Entry <V> > defEntries = entry.Value;
                for (int a = defEntries.Count; a-- > 0;)
                {
                    Def2Entry <V> defEntry = defEntries[a];
                    changesHappened |= AppendRegistration(registeredStrongKey, conversionKey, defEntry.extension, sourceDistance, targetDistance, classEntry);
                }
            }
            return(changesHappened);
        }
Ejemplo n.º 2
0
        public override bool ContainsKey(Type key)
        {
            bool contains = base.ContainsKey(key);

            if (contains)
            {
                return(true);
            }
            ClassExtendableContainer <IEntityMetaData> pendingToRefreshMetaDatas = pendingToRefreshMetaDatasTL.Value;

            if (pendingToRefreshMetaDatas == null)
            {
                return(contains);
            }
            return(pendingToRefreshMetaDatas.ContainsKey(key));
        }
Ejemplo n.º 3
0
        public override IEntityMetaData GetExtension(Type key)
        {
            IEntityMetaData metaData = base.GetExtension(key);

            if (metaData != null)
            {
                return(metaData);
            }
            ClassExtendableContainer <IEntityMetaData> pendingToRefreshMetaDatas = pendingToRefreshMetaDatasTL.Value;

            if (pendingToRefreshMetaDatas == null)
            {
                return(null);
            }
            return(pendingToRefreshMetaDatas.GetExtension(key));
        }
Ejemplo n.º 4
0
        protected bool CheckToWeakRegisterExistingTypes(ConversionKey key, V extension, ClassTupleEntry <V> classEntry)
        {
            bool changesHappened = false;

            foreach (Entry <ConversionKey, Object> entry in classEntry.typeToDefEntryMap)
            {
                ConversionKey existingRequestedKey = entry.Key;
                int           sourceDistance       = ClassExtendableContainer <V> .GetDistanceForType(existingRequestedKey.SourceType, key.SourceType);

                if (sourceDistance == ClassExtendableContainer <V> .NO_VALID_DISTANCE)
                {
                    continue;
                }
                int targetDistance = ClassExtendableContainer <V> .GetDistanceForType(key.TargetType, existingRequestedKey.TargetType);

                if (targetDistance == ClassExtendableContainer <V> .NO_VALID_DISTANCE)
                {
                    continue;
                }
                changesHappened |= AppendRegistration(key, existingRequestedKey, extension, sourceDistance, targetDistance, classEntry);
            }
            return(changesHappened);
        }
Ejemplo n.º 5
0
        protected IList <IEntityMetaData> GetMetaData(IList <Type> entityTypes, bool askRemoteOnMiss)
        {
            List <IEntityMetaData> result             = new List <IEntityMetaData>(entityTypes.Count);
            IList <Type>           missingEntityTypes = null;

            for (int a = entityTypes.Count; a-- > 0;)
            {
                Type            entityType   = entityTypes[a];
                IEntityMetaData metaDataItem = GetExtension(entityType);
                if (Object.ReferenceEquals(metaDataItem, alreadyHandled))
                {
                    metaDataItem = GetExtensionHardKey(entityType);
                    if (metaDataItem == null && askRemoteOnMiss)
                    {
                        if (missingEntityTypes == null)
                        {
                            missingEntityTypes = new List <Type>();
                        }
                        missingEntityTypes.Add(entityType);
                    }
                    continue;
                }
                if (metaDataItem == null)
                {
                    if (askRemoteOnMiss)
                    {
                        if (missingEntityTypes == null)
                        {
                            missingEntityTypes = new List <Type>();
                        }
                        missingEntityTypes.Add(entityType);
                    }
                    continue;
                }
                result.Add(metaDataItem);
            }
            if (missingEntityTypes == null || RemoteEntityMetaDataProvider == null)
            {
                return(result);
            }
            bool handlePendingMetaData = false;

            try
            {
                ClassExtendableContainer <IEntityMetaData> pendingToRefreshMetaDatas = pendingToRefreshMetaDatasTL.Value;
                if (pendingToRefreshMetaDatas == null)
                {
                    pendingToRefreshMetaDatas         = new ClassExtendableContainer <IEntityMetaData>("metaData", "entityType");
                    pendingToRefreshMetaDatasTL.Value = pendingToRefreshMetaDatas;
                    handlePendingMetaData             = true;
                }
                while (missingEntityTypes != null && missingEntityTypes.Count > 0)
                {
                    IList <IEntityMetaData> loadedMetaData = RemoteEntityMetaDataProvider.GetMetaData(missingEntityTypes);

                    IList <Type> cascadeMissingEntityTypes = AddLoadedMetaData(missingEntityTypes, loadedMetaData);

                    if (cascadeMissingEntityTypes != null && cascadeMissingEntityTypes.Count > 0)
                    {
                        missingEntityTypes = cascadeMissingEntityTypes;
                    }
                    else
                    {
                        missingEntityTypes.Clear();
                    }
                }
                if (handlePendingMetaData)
                {
                    ILinkedMap <Type, IEntityMetaData> extensions = pendingToRefreshMetaDatas.GetExtensions();
                    foreach (Entry <Type, IEntityMetaData> entry in extensions)
                    {
                        IEntityMetaData metaData = entry.Value;
                        if (Object.ReferenceEquals(metaData, alreadyHandled))
                        {
                            continue;
                        }
                        RefreshMembers(metaData);
                    }
                    Object writeLock = GetWriteLock();
                    lock (writeLock)
                    {
                        foreach (Entry <Type, IEntityMetaData> entry in pendingToRefreshMetaDatas.GetExtensions())
                        {
                            Type            entityType       = entry.Key;
                            IEntityMetaData existingMetaData = GetExtensionHardKeyGlobalOnly(entityType);
                            if (existingMetaData != null && !Object.ReferenceEquals(existingMetaData, alreadyHandled))
                            {
                                // existing entry is already a valid non-null entry
                                continue;
                            }
                            IEntityMetaData ownMetaData = entry.Value;
                            if (Object.ReferenceEquals(existingMetaData, ownMetaData))
                            {
                                // existing entry is already a null-entry and our entry is a null-entry, too - so nothing to do
                                continue;
                            }
                            if (Object.ReferenceEquals(existingMetaData, alreadyHandled))
                            {
                                Unregister(alreadyHandled, entityType);
                            }
                            Register(ownMetaData, entityType);
                        }
                    }
                }
            }
            finally
            {
                if (handlePendingMetaData)
                {
                    pendingToRefreshMetaDatasTL.Value = null;
                }
            }
            return(GetMetaData(entityTypes, false));
        }