public void Four_delegates_constructor_uses_given_delegates_and_sets_up_default_oc_mapping() { var edmItemCollection = new EdmItemCollection(new[] { XDocument.Parse(Csdl).CreateReader() }); var storeItemCollection = new StoreItemCollection(new[] { XDocument.Parse(Ssdl).CreateReader() }); var objectItemCollection = new ObjectItemCollection(); var storageMappingItemCollection = LoadMsl(edmItemCollection, storeItemCollection); var workspace = new MetadataWorkspace( () => edmItemCollection, () => storeItemCollection, () => storageMappingItemCollection, () => objectItemCollection); Assert.Same(edmItemCollection, workspace.GetItemCollection(DataSpace.CSpace)); Assert.Same(storeItemCollection, workspace.GetItemCollection(DataSpace.SSpace)); Assert.Same(storageMappingItemCollection, workspace.GetItemCollection(DataSpace.CSSpace)); Assert.Same(objectItemCollection, workspace.GetItemCollection(DataSpace.OSpace)); var ocMappingCollection = (DefaultObjectMappingItemCollection)workspace.GetItemCollection(DataSpace.OCSpace); Assert.Same(objectItemCollection, ocMappingCollection.ObjectItemCollection); Assert.Same(edmItemCollection, ocMappingCollection.EdmItemCollection); }
private static bool LoadAssemblyFromCache( ObjectItemCollection objectItemCollection, Assembly assembly, bool loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action <String> logLoadMessage) { // Check if its loaded in the cache - if the call is for loading referenced assemblies, make sure that all referenced // assemblies are also loaded KnownAssemblyEntry entry; if (objectItemCollection._knownAssemblies.TryGetKnownAssembly( assembly, objectItemCollection._loaderCookie, edmItemCollection, out entry)) { // Proceed if only we need to load the referenced assemblies and they are not loaded if (loadReferencedAssemblies == false) { // don't say we loaded anything, unless we actually did before return(entry.CacheEntry.TypesInAssembly.Count != 0); } else if (entry.ReferencedAssembliesAreLoaded) { // this assembly was part of a all hands reference search return(true); } } lock (objectItemCollection.LoadAssemblyLock) { // Check after acquiring the lock, since the known assemblies might have got modified // Check if the assembly is already loaded. The reason we need to check if the assembly is already loaded, is that if (objectItemCollection._knownAssemblies.TryGetKnownAssembly( assembly, objectItemCollection._loaderCookie, edmItemCollection, out entry)) { // Proceed if only we need to load the referenced assemblies and they are not loaded if (loadReferencedAssemblies == false || entry.ReferencedAssembliesAreLoaded) { return(true); } } Dictionary <string, EdmType> typesInLoading; List <EdmItemError> errors; KnownAssembliesSet knownAssemblies; if (objectItemCollection != null) { knownAssemblies = new KnownAssembliesSet(objectItemCollection._knownAssemblies); } else { knownAssemblies = new KnownAssembliesSet(); } // Load the assembly from the cache AssemblyCache.LoadAssembly( assembly, loadReferencedAssemblies, knownAssemblies, edmItemCollection, logLoadMessage, ref objectItemCollection._loaderCookie, out typesInLoading, out errors); // Throw if we have encountered errors if (errors.Count != 0) { throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage(errors)); } // We can encounter new assemblies, but they may not have any time in them if (typesInLoading.Count != 0) { // No errors, so go ahead and add the types and make them readonly // The existence of the loading lock tells us whether we should be thread safe or not, if we need // to be thread safe, then we need to use AtomicAddRange. We don't need to actually use the lock // because the caller should have done it already // Recheck the assemblies added, another list is created just to match up the collection type // taken in by AtomicAddRange() var globalItems = new List <GlobalItem>(); foreach (var edmType in typesInLoading.Values) { globalItems.Add(edmType); var cspaceTypeName = ""; try { // Also populate the ocmapping information if (Helper.IsEntityType(edmType)) { cspaceTypeName = ((ClrEntityType)edmType).CSpaceTypeName; objectItemCollection._ocMapping.Add(cspaceTypeName, edmType); } else if (Helper.IsComplexType(edmType)) { cspaceTypeName = ((ClrComplexType)edmType).CSpaceTypeName; objectItemCollection._ocMapping.Add(cspaceTypeName, edmType); } else if (Helper.IsEnumType(edmType)) { cspaceTypeName = ((ClrEnumType)edmType).CSpaceTypeName; objectItemCollection._ocMapping.Add(cspaceTypeName, edmType); } // for the rest of the types like a relationship type, we do not have oc mapping, // so we don't keep that information } catch (ArgumentException e) { throw new MappingException(Strings.Mapping_CannotMapCLRTypeMultipleTimes(cspaceTypeName), e); } } // Create a new ObjectItemCollection and add all the global items to it. // Also copy all the existing items from the existing collection objectItemCollection.AtomicAddRange(globalItems); } // Update the value of known assemblies objectItemCollection._knownAssemblies = knownAssemblies; foreach (var loadedAssembly in knownAssemblies.Assemblies) { CollectIfViewGenAssembly(loadedAssembly); } return(typesInLoading.Count != 0); } }
public bool TryGetClrType(EnumType objectSpaceType, out Type clrType) { return(ObjectItemCollection.TryGetClrType((EdmType)objectSpaceType, out clrType)); }
public Type GetClrType(EnumType objectSpaceType) { return(ObjectItemCollection.GetClrType((EdmType)objectSpaceType)); }