예제 #1
0
        /// <summary>
        /// Looks up the metadata in the cache. If not present in the cache, then loads metadata from the provider.
        /// </summary>
        /// <param name="skipServiceOperations">Should service operations be loaded.</param>
        internal void LoadMetadata(bool skipServiceOperations)
        {
            Type dataServiceType = this.dataServiceInstance.GetType();
            Type dataSourceType  = this.dataSourceInstance.GetType();

            // If 2 threads enter at the same time, and none of them find the metadata (since its the first time),
            // both of them will load new metadata and try to add them to the cache. But the cache is thread safe, hence
            // before adding, it will check again and return if there is an existing metadata. If it is, we should discard the
            // metadata that just got initialized and use one from the cache.
            this.metadata = MetadataCache <ProviderMetadataCacheItem> .TryLookup(dataServiceType, this.dataSourceInstance);

            if (this.metadata == null)
            {
                this.metadata = new ProviderMetadataCacheItem(dataSourceType);

                // Populate metadata in provider.
                this.PopulateMetadata(this.metadata);

                // Populate service operations only on-demand.
                if (!skipServiceOperations)
                {
                    this.LoadServiceOperations();
                }

                this.metadataRequiresInitialization = true;

                // no need to add metadata yet in the cache, since there might be some encountered while applying
                // configuration or while making it read-only.
            }
        }
예제 #2
0
        /// <summary>Make all the metadata readonly</summary>
        private void MakeMetadataReadonly()
        {
            Debug.Assert(this.metadataRequiresInitialization, "Should only call when initializing metadata.");

            foreach (ResourceSet container in this.ResourceSets)
            {
                container.SetReadOnly();
            }

            foreach (ResourceType resourceType in this.Types)
            {
                resourceType.SetReadOnly();

                // This will cause Properties collection to be initialized and validated.
                resourceType.PropertiesDeclaredOnThisType.Count();
            }

            foreach (ServiceOperation operation in this.ServiceOperations)
            {
                operation.SetReadOnly();
            }

            // After metadata has been completely loaded, add it to the cache.
            this.metadata = MetadataCache <ProviderMetadataCacheItem> .AddCacheItem(this.dataServiceInstance.GetType(), this.dataSourceInstance, this.metadata);
        }
예제 #3
0
        internal void LoadMetadata()
        {
            System.Type serviceType = this.dataServiceInstance.GetType();
            System.Type type        = this.dataSourceInstance.GetType();
            this.metadata = MetadataCache <ProviderMetadataCacheItem> .TryLookup(serviceType, this.dataSourceInstance);

            if (this.metadata == null)
            {
                this.metadata = new ProviderMetadataCacheItem(type);
                this.PopulateMetadata();
                this.AddOperationsFromType(serviceType);
                this.metadataRequiresInitialization = true;
            }
        }
예제 #4
0
        /// <summary>
        /// Find the corresponding ResourceType for a given Type, primitive or not
        /// </summary>
        /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem.</param>
        /// <param name="type">Type to look for</param>
        /// <param name="resourceType">Corresponding ResourceType, if found</param>
        /// <returns>True if type found, false otherwise</returns>
        protected static bool TryGetType(ProviderMetadataCacheItem metadataCacheItem, Type type, out ResourceType resourceType)
        {
            Debug.Assert(metadataCacheItem != null, "metadataCacheItem != null");
            Debug.Assert(type != null, "type != null");

            resourceType = PrimitiveResourceTypeMap.TypeMap.GetPrimitive(type);

            if (resourceType == null)
            {
                resourceType = metadataCacheItem.TryGetResourceType(type);
            }

            return(resourceType != null);
        }
예제 #5
0
 internal void MakeMetadataReadonly()
 {
     if (this.metadataRequiresInitialization)
     {
         foreach (ResourceSet set in this.ResourceSets)
         {
             set.SetReadOnly();
         }
         foreach (ResourceType type in this.Types)
         {
             type.SetReadOnly();
             type.PropertiesDeclaredOnThisType.Count <ResourceProperty>();
         }
         foreach (ServiceOperation operation in this.ServiceOperations)
         {
             operation.SetReadOnly();
         }
         this.metadata = MetadataCache <ProviderMetadataCacheItem> .AddCacheItem(this.dataServiceInstance.GetType(), this.dataSourceInstance, this.metadata);
     }
 }
예제 #6
0
 /// <summary>
 /// Populate metadata for the given clr type.
 /// </summary>
 /// <param name="type">type whose metadata needs to be loaded.</param>
 /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem.</param>
 /// <returns>resource type containing metadata for the given clr type.</returns>
 protected abstract ResourceType PopulateMetadataForType(Type type, ProviderMetadataCacheItem metadataCacheItem);
예제 #7
0
 /// <summary>
 /// Populate types for metadata specified by the provider
 /// </summary>
 /// <param name="userSpecifiedTypes">list of types specified by the provider</param>
 /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem.</param>
 protected abstract void PopulateMetadataForUserSpecifiedTypes(IEnumerable <Type> userSpecifiedTypes, ProviderMetadataCacheItem metadataCacheItem);
예제 #8
0
 /// <summary>
 /// Populates the metadata for the given provider
 /// </summary>
 /// <param name="metadataCacheItem">Instance of ProviderMetadataCacheItem in which metadata needs to be populated.</param>
 protected abstract void PopulateMetadata(ProviderMetadataCacheItem metadataCacheItem);
예제 #9
0
        /// <summary>Assert that we are using the cached version of the provider metadata.</summary>
        internal void AssertUsingCachedProviderMetadata()
        {
            ProviderMetadataCacheItem providerMetadataCacheItem = MetadataCache <ProviderMetadataCacheItem> .TryLookup(this.dataServiceInstance.GetType(), this.dataSourceInstance);

            Debug.Assert(Object.ReferenceEquals(providerMetadataCacheItem, this.metadata), "we are not using the cached provider metadata");
        }