Exemplo n.º 1
0
 private static void UpdateCache(LockedAssemblyCache lockedAssemblyCache, Dictionary <Assembly, MutableAssemblyCacheEntry> assemblies)
 {
     foreach (var entry in assemblies)
     {
         // Add all the assemblies from the loading context to the global cache
         lockedAssemblyCache.Add(entry.Key, new ImmutableAssemblyCacheEntry(entry.Value));
     }
 }
Exemplo n.º 2
0
 private static void UpdateCache(
     LockedAssemblyCache lockedAssemblyCache,
     Dictionary <Assembly, MutableAssemblyCacheEntry> assemblies)
 {
     foreach (KeyValuePair <Assembly, MutableAssemblyCacheEntry> assembly in assemblies)
     {
         lockedAssemblyCache.Add(assembly.Key, new ImmutableAssemblyCacheEntry(assembly.Value));
     }
 }
Exemplo n.º 3
0
        internal ObjectItemLoadingSessionData(
            KnownAssembliesSet knownAssemblies, LockedAssemblyCache lockedAssemblyCache, EdmItemCollection edmItemCollection,
            Action <String> logLoadMessage, object loaderCookie)
        {
            Debug.Assert(
                loaderCookie == null || loaderCookie is Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>,
                "This is a bad loader cookie");

            _typesInLoading      = new Dictionary <string, EdmType>(StringComparer.Ordinal);
            _errors              = new List <EdmItemError>();
            _knownAssemblies     = knownAssemblies;
            _lockedAssemblyCache = lockedAssemblyCache;
            _loadersThatNeedLevel1PostSessionProcessing = new HashSet <ObjectItemAssemblyLoader>();
            _loadersThatNeedLevel2PostSessionProcessing = new HashSet <ObjectItemAssemblyLoader>();
            _edmItemCollection    = edmItemCollection;
            _loadMessageLogger    = new LoadMessageLogger(logLoadMessage);
            _cspaceToOspace       = new Dictionary <EdmType, EdmType>();
            _loaderFactory        = (Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>)loaderCookie;
            _originalLoaderCookie = loaderCookie;
            if (_loaderFactory == ObjectItemConventionAssemblyLoader.Create &&
                _edmItemCollection != null)
            {
                foreach (var entry in _knownAssemblies.GetEntries(_loaderFactory, edmItemCollection))
                {
                    foreach (var type in entry.CacheEntry.TypesInAssembly.OfType <EdmType>())
                    {
                        if (Helper.IsEntityType(type))
                        {
                            var entityType = (ClrEntityType)type;
                            _cspaceToOspace.Add(_edmItemCollection.GetItem <StructuralType>(entityType.CSpaceTypeName), entityType);
                        }
                        else if (Helper.IsComplexType(type))
                        {
                            var complexType = (ClrComplexType)type;
                            _cspaceToOspace.Add(_edmItemCollection.GetItem <StructuralType>(complexType.CSpaceTypeName), complexType);
                        }
                        else if (Helper.IsEnumType(type))
                        {
                            var enumType = (ClrEnumType)type;
                            _cspaceToOspace.Add(_edmItemCollection.GetItem <EnumType>(enumType.CSpaceTypeName), enumType);
                        }
                        else
                        {
                            Debug.Assert(Helper.IsAssociationType(type));
                            _cspaceToOspace.Add(_edmItemCollection.GetItem <StructuralType>(type.FullName), type);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 internal static void LoadAssembly(
     Assembly assembly,
     bool loadReferencedAssemblies,
     KnownAssembliesSet knownAssemblies,
     EdmItemCollection edmItemCollection,
     Action <string> logLoadMessage,
     ref object loaderCookie,
     out Dictionary <string, EdmType> typesInLoading,
     out List <EdmItemError> errors)
 {
     typesInLoading = (Dictionary <string, EdmType>)null;
     errors         = (List <EdmItemError>)null;
     using (LockedAssemblyCache lockedAssemblyCache = AssemblyCache.AquireLockedAssemblyCache())
     {
         ObjectItemLoadingSessionData loadingData = new ObjectItemLoadingSessionData(knownAssemblies, lockedAssemblyCache, edmItemCollection, logLoadMessage, loaderCookie);
         AssemblyCache.LoadAssembly(assembly, loadReferencedAssemblies, loadingData);
         loaderCookie = loadingData.LoaderCookie;
         loadingData.CompleteSession();
         if (loadingData.EdmItemErrors.Count == 0)
         {
             new EdmValidator()
             {
                 SkipReadOnlyItems = true
             }.Validate <EdmType>((IEnumerable <EdmType>)loadingData.TypesInLoading.Values, loadingData.EdmItemErrors);
             if (loadingData.EdmItemErrors.Count == 0)
             {
                 if (ObjectItemAssemblyLoader.IsAttributeLoader(loadingData.ObjectItemAssemblyLoaderFactory))
                 {
                     AssemblyCache.UpdateCache(lockedAssemblyCache, loadingData.AssembliesLoaded);
                 }
                 else if (loadingData.EdmItemCollection != null && ObjectItemAssemblyLoader.IsConventionLoader(loadingData.ObjectItemAssemblyLoaderFactory))
                 {
                     AssemblyCache.UpdateCache(loadingData.EdmItemCollection, loadingData.AssembliesLoaded);
                 }
             }
         }
         if (loadingData.TypesInLoading.Count > 0)
         {
             foreach (MetadataItem metadataItem in loadingData.TypesInLoading.Values)
             {
                 metadataItem.SetReadOnly();
             }
         }
         typesInLoading = loadingData.TypesInLoading;
         errors         = loadingData.EdmItemErrors;
     }
 }
Exemplo n.º 5
0
 internal ObjectItemLoadingSessionData(
     KnownAssembliesSet knownAssemblies,
     LockedAssemblyCache lockedAssemblyCache,
     EdmItemCollection edmItemCollection,
     Action <string> logLoadMessage,
     object loaderCookie)
 {
     this._typesInLoading       = new Dictionary <string, EdmType>((IEqualityComparer <string>)StringComparer.Ordinal);
     this._errors               = new List <EdmItemError>();
     this._knownAssemblies      = knownAssemblies;
     this._lockedAssemblyCache  = lockedAssemblyCache;
     this._edmItemCollection    = edmItemCollection;
     this._loadMessageLogger    = new LoadMessageLogger(logLoadMessage);
     this._cspaceToOspace       = new Dictionary <EdmType, EdmType>();
     this._loaderFactory        = (Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>)loaderCookie;
     this._originalLoaderCookie = loaderCookie;
     if (!(this._loaderFactory == new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemConventionAssemblyLoader.Create)) || this._edmItemCollection == null)
     {
         return;
     }
     foreach (KnownAssemblyEntry entry in this._knownAssemblies.GetEntries((object)this._loaderFactory, edmItemCollection))
     {
         foreach (EdmType edmType in entry.CacheEntry.TypesInAssembly.OfType <EdmType>())
         {
             if (Helper.IsEntityType(edmType))
             {
                 ClrEntityType clrEntityType = (ClrEntityType)edmType;
                 this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <StructuralType>(clrEntityType.CSpaceTypeName), (EdmType)clrEntityType);
             }
             else if (Helper.IsComplexType(edmType))
             {
                 ClrComplexType clrComplexType = (ClrComplexType)edmType;
                 this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <StructuralType>(clrComplexType.CSpaceTypeName), (EdmType)clrComplexType);
             }
             else if (Helper.IsEnumType(edmType))
             {
                 ClrEnumType clrEnumType = (ClrEnumType)edmType;
                 this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <EnumType>(clrEnumType.CSpaceTypeName), (EdmType)clrEnumType);
             }
             else
             {
                 this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <StructuralType>(edmType.FullName), edmType);
             }
         }
     }
 }
        internal ObjectItemLoadingSessionData(
            KnownAssembliesSet knownAssemblies, LockedAssemblyCache lockedAssemblyCache, EdmItemCollection edmItemCollection,
            Action<String> logLoadMessage, object loaderCookie)
        {
            Debug.Assert(
                loaderCookie == null || loaderCookie is Func<Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>,
                "This is a bad loader cookie");

            _typesInLoading = new Dictionary<string, EdmType>(StringComparer.Ordinal);
            _errors = new List<EdmItemError>();
            _knownAssemblies = knownAssemblies;
            _lockedAssemblyCache = lockedAssemblyCache;
            _loadersThatNeedLevel1PostSessionProcessing = new HashSet<ObjectItemAssemblyLoader>();
            _loadersThatNeedLevel2PostSessionProcessing = new HashSet<ObjectItemAssemblyLoader>();
            _edmItemCollection = edmItemCollection;
            _loadMessageLogger = new LoadMessageLogger(logLoadMessage);
            _cspaceToOspace = new Dictionary<EdmType, EdmType>();
            _loaderFactory = (Func<Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>)loaderCookie;
            _originalLoaderCookie = loaderCookie;
            if (_loaderFactory == ObjectItemConventionAssemblyLoader.Create
                && _edmItemCollection != null)
            {
                foreach (var entry in _knownAssemblies.GetEntries(_loaderFactory, edmItemCollection))
                {
                    foreach (var type in entry.CacheEntry.TypesInAssembly.OfType<EdmType>())
                    {
                        if (Helper.IsEntityType(type))
                        {
                            var entityType = (ClrEntityType)type;
                            _cspaceToOspace.Add(_edmItemCollection.GetItem<StructuralType>(entityType.CSpaceTypeName), entityType);
                        }
                        else if (Helper.IsComplexType(type))
                        {
                            var complexType = (ClrComplexType)type;
                            _cspaceToOspace.Add(_edmItemCollection.GetItem<StructuralType>(complexType.CSpaceTypeName), complexType);
                        }
                        else if (Helper.IsEnumType(type))
                        {
                            var enumType = (ClrEnumType)type;
                            _cspaceToOspace.Add(_edmItemCollection.GetItem<EnumType>(enumType.CSpaceTypeName), enumType);
                        }
                        else
                        {
                            Debug.Assert(Helper.IsAssociationType(type));
                            _cspaceToOspace.Add(_edmItemCollection.GetItem<StructuralType>(type.FullName), type);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 private static void UpdateCache(LockedAssemblyCache lockedAssemblyCache, Dictionary<Assembly, MutableAssemblyCacheEntry> assemblies)
 {
     foreach (var entry in assemblies)
     {
         // Add all the assemblies from the loading context to the global cache
         lockedAssemblyCache.Add(entry.Key, new ImmutableAssemblyCacheEntry(entry.Value));
     }
 }