Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Metadata / ObjectLayer / ObjectItemLoadingSessionData.cs / 1305376 / ObjectItemLoadingSessionData.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Reflection; using System.Linq; using System.Collections.Generic; using System.Diagnostics; namespace System.Data.Metadata.Edm { internal sealed class ObjectItemLoadingSessionData { private Func_loaderFactory; // all the types that we encountered while loading - this may contain types from various assemblies private readonly Dictionary _typesInLoading; // private bool _conventionBasedRelationshipsAreLoaded = false; private LoadMessageLogger _loadMessageLogger; // list of errors encountered during loading private readonly List _errors; // keep the list of new assemblies that got loaded in this load assembly call. The reason why we need to keep a seperate // list of assemblies is that we keep track of errors, and if there are no errors, only then do we add the list of assemblies // to the global cache. Hence global cache is never polluted with invalid assemblies private readonly Dictionary _listOfAssembliesLoaded = new Dictionary (); // List of known assemblies - this list is initially passed by the caller and we keep adding to it, as and when we load // an assembly private readonly KnownAssembliesSet _knownAssemblies; private readonly LockedAssemblyCache _lockedAssemblyCache; private readonly HashSet _loadersThatNeedLevel1PostSessionProcessing; private readonly HashSet _loadersThatNeedLevel2PostSessionProcessing; private readonly EdmItemCollection _edmItemCollection; private Dictionary > _conventionCSpaceTypeNames; private Dictionary _cspaceToOspace; private object _originalLoaderCookie; internal Dictionary TypesInLoading { get { return _typesInLoading; } } internal Dictionary AssembliesLoaded { get { return _listOfAssembliesLoaded; } } internal List EdmItemErrors { get { return _errors; } } internal KnownAssembliesSet KnownAssemblies { get { return _knownAssemblies; } } internal LockedAssemblyCache LockedAssemblyCache { get { return _lockedAssemblyCache; } } internal EdmItemCollection EdmItemCollection { get { return _edmItemCollection; } } internal Dictionary CspaceToOspace{ get { return _cspaceToOspace; } } internal bool ConventionBasedRelationshipsAreLoaded { get { return _conventionBasedRelationshipsAreLoaded; } set { _conventionBasedRelationshipsAreLoaded = value; } } internal LoadMessageLogger LoadMessageLogger { get { return this._loadMessageLogger; } } // dictionary of types by name (not including namespace), we also track duplicate names // so if one of those types is used we can log an error internal Dictionary > ConventionCSpaceTypeNames { get { if (_edmItemCollection != null && _conventionCSpaceTypeNames == null) { _conventionCSpaceTypeNames = new Dictionary >(); // create the map and cache it foreach (var structuralType in _edmItemCollection.GetItems ().Where(item => item.BuiltInTypeKind != BuiltInTypeKind.AssociationType)) { KeyValuePair pair; if (_conventionCSpaceTypeNames.TryGetValue(structuralType.Name, out pair)) { _conventionCSpaceTypeNames[structuralType.Name] = new KeyValuePair (pair.Key, pair.Value + 1); } else { pair = new KeyValuePair (structuralType, 1); _conventionCSpaceTypeNames.Add(structuralType.Name, pair); } } } return _conventionCSpaceTypeNames; } } internal Func ObjectItemAssemblyLoaderFactory { get { return _loaderFactory; } set { if (_loaderFactory != value) { Debug.Assert(_loaderFactory == null || _typesInLoading.Count == 0, "Only reset the factory after types have not been loaded or load from the cache"); _loaderFactory = value; } } } internal object LoaderCookie { get { // be sure we get the same factory/cookie as we had before... if we had one if (_originalLoaderCookie != null) { Debug.Assert(_loaderFactory == null || (object)_loaderFactory == _originalLoaderCookie, "The loader factory should determine the next loader, so we should always have the same loader factory"); return _originalLoaderCookie; } return _loaderFactory; } } internal ObjectItemLoadingSessionData(KnownAssembliesSet knownAssemblies, LockedAssemblyCache lockedAssemblyCache, EdmItemCollection edmItemCollection, Action logLoadMessage, object loaderCookie) { Debug.Assert(loaderCookie == null || loaderCookie is Func , "This is a bad loader cookie"); _typesInLoading = new Dictionary (StringComparer.Ordinal); _errors = new List (); _knownAssemblies = knownAssemblies; _lockedAssemblyCache = lockedAssemblyCache; _loadersThatNeedLevel1PostSessionProcessing = new HashSet (); _loadersThatNeedLevel2PostSessionProcessing = new HashSet (); _edmItemCollection = edmItemCollection; _loadMessageLogger = new LoadMessageLogger(logLoadMessage); _cspaceToOspace = new Dictionary (); _loaderFactory = (Func )loaderCookie; _originalLoaderCookie = loaderCookie; if (_loaderFactory == ObjectItemConventionAssemblyLoader.Create && _edmItemCollection != null) { foreach (KnownAssemblyEntry entry in _knownAssemblies.GetEntries(_loaderFactory, edmItemCollection)) { foreach (StructuralType type in entry.CacheEntry.TypesInAssembly.OfType ()) { if (Helper.IsEntityType(type)) { ClrEntityType entityType = (ClrEntityType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem (entityType.CSpaceTypeName), entityType); } else if (Helper.IsComplexType(type)) { ClrComplexType complexType = (ClrComplexType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem (complexType.CSpaceTypeName), complexType); } else { Debug.Assert(Helper.IsAssociationType(type)); _cspaceToOspace.Add(_edmItemCollection.GetItem (type.FullName), type); } } } } } internal void RegisterForLevel1PostSessionProcessing(ObjectItemAssemblyLoader loader) { _loadersThatNeedLevel1PostSessionProcessing.Add(loader); } internal void RegisterForLevel2PostSessionProcessing(ObjectItemAssemblyLoader loader) { _loadersThatNeedLevel2PostSessionProcessing.Add(loader); } internal void CompleteSession() { foreach (ObjectItemAssemblyLoader loader in _loadersThatNeedLevel1PostSessionProcessing) { loader.OnLevel1SessionProcessing(); } foreach (ObjectItemAssemblyLoader loader in _loadersThatNeedLevel2PostSessionProcessing) { loader.OnLevel2SessionProcessing(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Reflection; using System.Linq; using System.Collections.Generic; using System.Diagnostics; namespace System.Data.Metadata.Edm { internal sealed class ObjectItemLoadingSessionData { private Func_loaderFactory; // all the types that we encountered while loading - this may contain types from various assemblies private readonly Dictionary _typesInLoading; // private bool _conventionBasedRelationshipsAreLoaded = false; private LoadMessageLogger _loadMessageLogger; // list of errors encountered during loading private readonly List _errors; // keep the list of new assemblies that got loaded in this load assembly call. The reason why we need to keep a seperate // list of assemblies is that we keep track of errors, and if there are no errors, only then do we add the list of assemblies // to the global cache. Hence global cache is never polluted with invalid assemblies private readonly Dictionary _listOfAssembliesLoaded = new Dictionary (); // List of known assemblies - this list is initially passed by the caller and we keep adding to it, as and when we load // an assembly private readonly KnownAssembliesSet _knownAssemblies; private readonly LockedAssemblyCache _lockedAssemblyCache; private readonly HashSet _loadersThatNeedLevel1PostSessionProcessing; private readonly HashSet _loadersThatNeedLevel2PostSessionProcessing; private readonly EdmItemCollection _edmItemCollection; private Dictionary > _conventionCSpaceTypeNames; private Dictionary _cspaceToOspace; private object _originalLoaderCookie; internal Dictionary TypesInLoading { get { return _typesInLoading; } } internal Dictionary AssembliesLoaded { get { return _listOfAssembliesLoaded; } } internal List EdmItemErrors { get { return _errors; } } internal KnownAssembliesSet KnownAssemblies { get { return _knownAssemblies; } } internal LockedAssemblyCache LockedAssemblyCache { get { return _lockedAssemblyCache; } } internal EdmItemCollection EdmItemCollection { get { return _edmItemCollection; } } internal Dictionary CspaceToOspace{ get { return _cspaceToOspace; } } internal bool ConventionBasedRelationshipsAreLoaded { get { return _conventionBasedRelationshipsAreLoaded; } set { _conventionBasedRelationshipsAreLoaded = value; } } internal LoadMessageLogger LoadMessageLogger { get { return this._loadMessageLogger; } } // dictionary of types by name (not including namespace), we also track duplicate names // so if one of those types is used we can log an error internal Dictionary > ConventionCSpaceTypeNames { get { if (_edmItemCollection != null && _conventionCSpaceTypeNames == null) { _conventionCSpaceTypeNames = new Dictionary >(); // create the map and cache it foreach (var structuralType in _edmItemCollection.GetItems ().Where(item => item.BuiltInTypeKind != BuiltInTypeKind.AssociationType)) { KeyValuePair pair; if (_conventionCSpaceTypeNames.TryGetValue(structuralType.Name, out pair)) { _conventionCSpaceTypeNames[structuralType.Name] = new KeyValuePair (pair.Key, pair.Value + 1); } else { pair = new KeyValuePair (structuralType, 1); _conventionCSpaceTypeNames.Add(structuralType.Name, pair); } } } return _conventionCSpaceTypeNames; } } internal Func ObjectItemAssemblyLoaderFactory { get { return _loaderFactory; } set { if (_loaderFactory != value) { Debug.Assert(_loaderFactory == null || _typesInLoading.Count == 0, "Only reset the factory after types have not been loaded or load from the cache"); _loaderFactory = value; } } } internal object LoaderCookie { get { // be sure we get the same factory/cookie as we had before... if we had one if (_originalLoaderCookie != null) { Debug.Assert(_loaderFactory == null || (object)_loaderFactory == _originalLoaderCookie, "The loader factory should determine the next loader, so we should always have the same loader factory"); return _originalLoaderCookie; } return _loaderFactory; } } internal ObjectItemLoadingSessionData(KnownAssembliesSet knownAssemblies, LockedAssemblyCache lockedAssemblyCache, EdmItemCollection edmItemCollection, Action logLoadMessage, object loaderCookie) { Debug.Assert(loaderCookie == null || loaderCookie is Func , "This is a bad loader cookie"); _typesInLoading = new Dictionary (StringComparer.Ordinal); _errors = new List (); _knownAssemblies = knownAssemblies; _lockedAssemblyCache = lockedAssemblyCache; _loadersThatNeedLevel1PostSessionProcessing = new HashSet (); _loadersThatNeedLevel2PostSessionProcessing = new HashSet (); _edmItemCollection = edmItemCollection; _loadMessageLogger = new LoadMessageLogger(logLoadMessage); _cspaceToOspace = new Dictionary (); _loaderFactory = (Func )loaderCookie; _originalLoaderCookie = loaderCookie; if (_loaderFactory == ObjectItemConventionAssemblyLoader.Create && _edmItemCollection != null) { foreach (KnownAssemblyEntry entry in _knownAssemblies.GetEntries(_loaderFactory, edmItemCollection)) { foreach (StructuralType type in entry.CacheEntry.TypesInAssembly.OfType ()) { if (Helper.IsEntityType(type)) { ClrEntityType entityType = (ClrEntityType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem (entityType.CSpaceTypeName), entityType); } else if (Helper.IsComplexType(type)) { ClrComplexType complexType = (ClrComplexType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem (complexType.CSpaceTypeName), complexType); } else { Debug.Assert(Helper.IsAssociationType(type)); _cspaceToOspace.Add(_edmItemCollection.GetItem (type.FullName), type); } } } } } internal void RegisterForLevel1PostSessionProcessing(ObjectItemAssemblyLoader loader) { _loadersThatNeedLevel1PostSessionProcessing.Add(loader); } internal void RegisterForLevel2PostSessionProcessing(ObjectItemAssemblyLoader loader) { _loadersThatNeedLevel2PostSessionProcessing.Add(loader); } internal void CompleteSession() { foreach (ObjectItemAssemblyLoader loader in _loadersThatNeedLevel1PostSessionProcessing) { loader.OnLevel1SessionProcessing(); } foreach (ObjectItemAssemblyLoader loader in _loadersThatNeedLevel2PostSessionProcessing) { loader.OnLevel2SessionProcessing(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HistoryEventArgs.cs
- newitemfactory.cs
- DataGridGeneralPage.cs
- FunctionParameter.cs
- AssemblyInfo.cs
- ProfilePropertyMetadata.cs
- StandardMenuStripVerb.cs
- TraceContextEventArgs.cs
- KeyGestureValueSerializer.cs
- SafeFileHandle.cs
- DataFieldConverter.cs
- PropertyGridCommands.cs
- WebPartActionVerb.cs
- MainMenu.cs
- ProjectionPlan.cs
- FixedElement.cs
- WSFederationHttpSecurityMode.cs
- ClientCredentialsSecurityTokenManager.cs
- LinqDataSourceContextEventArgs.cs
- XmlSchemaComplexContentExtension.cs
- MatrixCamera.cs
- Accessible.cs
- SQLString.cs
- ConditionedDesigner.cs
- SimpleWorkerRequest.cs
- ControlIdConverter.cs
- ColorKeyFrameCollection.cs
- CompiledIdentityConstraint.cs
- BindUriHelper.cs
- SerializationAttributes.cs
- Enlistment.cs
- PackageRelationship.cs
- StringUtil.cs
- WindowsRebar.cs
- AspNetHostingPermission.cs
- Hashtable.cs
- DPTypeDescriptorContext.cs
- MasterPageCodeDomTreeGenerator.cs
- AnyAllSearchOperator.cs
- GiveFeedbackEvent.cs
- TransactionTable.cs
- AnonymousIdentificationSection.cs
- AnnotationComponentManager.cs
- VisualTreeHelper.cs
- ConnectionConsumerAttribute.cs
- CriticalExceptions.cs
- CapabilitiesAssignment.cs
- EngineSite.cs
- ColumnMapTranslator.cs
- InvalidWMPVersionException.cs
- DbDataReader.cs
- GridViewSelectEventArgs.cs
- XAMLParseException.cs
- StaticResourceExtension.cs
- DataGridPagerStyle.cs
- ModuleBuilderData.cs
- EncoderBestFitFallback.cs
- DeferredSelectedIndexReference.cs
- GridLength.cs
- EDesignUtil.cs
- CustomError.cs
- ManipulationDelta.cs
- SafeFindHandle.cs
- TextRunCacheImp.cs
- DecimalAnimationUsingKeyFrames.cs
- XmlSecureResolver.cs
- XmlSubtreeReader.cs
- CompositeFontParser.cs
- FontDifferentiator.cs
- AttachedPropertyBrowsableAttribute.cs
- JsonByteArrayDataContract.cs
- AnimationException.cs
- PathGradientBrush.cs
- ContractTypeNameElement.cs
- IIS7WorkerRequest.cs
- HtmlElementCollection.cs
- GlyphCache.cs
- SafeReversePInvokeHandle.cs
- BinaryMessageFormatter.cs
- ToolTip.cs
- ValidationEventArgs.cs
- DescriptionAttribute.cs
- WebPartTransformerAttribute.cs
- ResXBuildProvider.cs
- HandleCollector.cs
- ExtentJoinTreeNode.cs
- AssociationEndMember.cs
- PeerCustomResolverSettings.cs
- RemotingServices.cs
- UpdatePanel.cs
- SubMenuStyleCollection.cs
- ParameterCollection.cs
- ObservableDictionary.cs
- ListViewItem.cs
- FileChangesMonitor.cs
- ConfigurationElementProperty.cs
- MinMaxParagraphWidth.cs
- GeometryCombineModeValidation.cs
- SelfIssuedAuthRSAPKCS1SignatureFormatter.cs
- TemplatedMailWebEventProvider.cs