Пример #1
0
        internal TMetadata GetMetadataFromCache <TMetadata>(string name)
            where TMetadata : IMetadata
        {
            MetadataKey key = new MetadataKey(typeof(TMetadata), name, this.Notation.Comparer);

            if (this.entries.TryGetValue(key, out object value))
            {
                return((TMetadata)value);
            }

            return(default);
Пример #2
0
        public void AddMetadata <TMetadata>(TMetadata metadata)
            where TMetadata : IMetadata
        {
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            if (metadata.Relation == null)
            {
                throw new ArgumentNullException(nameof(metadata.Relation));
            }

            MetadataKey key = MetadataKey.FromIdentity <TMetadata>(metadata.Relation.Identity);

            if (!this.entries.TryAdd(key, metadata))
            {
                throw new InvalidOperationException("Metadata already added.");
            }
        }
Пример #3
0
        public TMetadata Lookup <TMetadata>(string name)
            where TMetadata : IMetadata
        {
            MetadataKey          key  = this.CreateKey <TMetadata>(name);
            ReaderWriterLockSlim slim = this.GetLock <TMetadata>();

            try
            {
                slim.EnterReadLock();

                if (this.entries.TryGetValue(key, out object value))
                {
                    return((TMetadata)value);
                }
            }
            catch (LockRecursionException ex)
            {
                throw MetadataBuilderException.NoRecursion <TMetadata>(name, ex);
            }
            finally
            {
                if (slim.IsReadLockHeld)
                {
                    slim.ExitReadLock();
                }
            }


            slim.EnterWriteLock();

            try
            {
                MetadataIdentity  identity = new MetadataIdentity(this, name);
                IRelationMetadata relation = this.GetCachedMetadata <IRelationMetadata>(name) ?? this.Store.RelationBuilder.GetMetadata(this, identity);

                if (relation == null)
                {
                    return(default);