예제 #1
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)
        {
            Debug.Assert(
                loaderCookie == null || loaderCookie is Func<Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>,
                "This is a bad loader cookie");
            typesInLoading = null;
            errors = null;

            using (var lockedAssemblyCache = AquireLockedAssemblyCache())
            {
                var loadingData = new ObjectItemLoadingSessionData(
                    knownAssemblies, lockedAssemblyCache, edmItemCollection, logLoadMessage, loaderCookie);

                LoadAssembly(assembly, loadReferencedAssemblies, loadingData);
                loaderCookie = loadingData.LoaderCookie;
                // resolve references to top level types (base types, navigation properties returns and associations, and complex type properties)
                loadingData.CompleteSession();

                if (loadingData.EdmItemErrors.Count == 0)
                {
                    // do the validation for the all the new types
                    // Now, perform validation on all the new types
                    var validator = new EdmValidator();
                    validator.SkipReadOnlyItems = true;
                    validator.Validate(loadingData.TypesInLoading.Values, loadingData.EdmItemErrors);
                    // Update the global cache if there are no errors
                    if (loadingData.EdmItemErrors.Count == 0)
                    {
                        if (ObjectItemAssemblyLoader.IsAttributeLoader(loadingData.ObjectItemAssemblyLoaderFactory))
                        {
                            // we only cache items from the attribute loader globally, the 
                            // items loaded by convention will change depending on the cspace 
                            // provided.  cspace will have a cache of it's own for assemblies
                            UpdateCache(lockedAssemblyCache, loadingData.AssembliesLoaded);
                        }
                        else if (loadingData.EdmItemCollection != null
                                 &&
                                 ObjectItemAssemblyLoader.IsConventionLoader(loadingData.ObjectItemAssemblyLoaderFactory))
                        {
                            UpdateCache(loadingData.EdmItemCollection, loadingData.AssembliesLoaded);
                        }
                    }
                }

                if (loadingData.TypesInLoading.Count > 0)
                {
                    foreach (var edmType in loadingData.TypesInLoading.Values)
                    {
                        edmType.SetReadOnly();
                    }
                }

                // Update the out parameters once you are done with loading
                typesInLoading = loadingData.TypesInLoading;
                errors = loadingData.EdmItemErrors;
            }
        }
예제 #2
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)
        {
            Debug.Assert(
                loaderCookie == null || loaderCookie is Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>,
                "This is a bad loader cookie");
            typesInLoading = null;
            errors         = null;

            using (var lockedAssemblyCache = AquireLockedAssemblyCache())
            {
                var loadingData = new ObjectItemLoadingSessionData(
                    knownAssemblies, lockedAssemblyCache, edmItemCollection, logLoadMessage, loaderCookie);

                LoadAssembly(assembly, loadReferencedAssemblies, loadingData);
                loaderCookie = loadingData.LoaderCookie;
                // resolve references to top level types (base types, navigation properties returns and associations, and complex type properties)
                loadingData.CompleteSession();

                if (loadingData.EdmItemErrors.Count == 0)
                {
                    // do the validation for the all the new types
                    // Now, perform validation on all the new types
                    var validator = new EdmValidator();
                    validator.SkipReadOnlyItems = true;
                    validator.Validate(loadingData.TypesInLoading.Values, loadingData.EdmItemErrors);
                    // Update the global cache if there are no errors
                    if (loadingData.EdmItemErrors.Count == 0)
                    {
                        if (ObjectItemAssemblyLoader.IsAttributeLoader(loadingData.ObjectItemAssemblyLoaderFactory))
                        {
                            // we only cache items from the attribute loader globally, the
                            // items loaded by convention will change depending on the cspace
                            // provided.  cspace will have a cache of it's own for assemblies
                            UpdateCache(lockedAssemblyCache, loadingData.AssembliesLoaded);
                        }
                        else if (loadingData.EdmItemCollection != null
                                 &&
                                 ObjectItemAssemblyLoader.IsConventionLoader(loadingData.ObjectItemAssemblyLoaderFactory))
                        {
                            UpdateCache(loadingData.EdmItemCollection, loadingData.AssembliesLoaded);
                        }
                    }
                }

                if (loadingData.TypesInLoading.Count > 0)
                {
                    foreach (var edmType in loadingData.TypesInLoading.Values)
                    {
                        edmType.SetReadOnly();
                    }
                }

                // Update the out parameters once you are done with loading
                typesInLoading = loadingData.TypesInLoading;
                errors         = loadingData.EdmItemErrors;
            }
        }
예제 #3
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;
     }
 }