Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Hosting / Store / PipelineComponent.cs / 1305376 / PipelineComponent.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: PipelineComponent ** ** Purpose: Base class representing parts of the add-in ** pipeline, from the host to the contract to the addin. ** ===========================================================*/ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Reflection; using System.Security; using System.Security.Permissions; using System.Text; using System.Diagnostics; using System.AddIn.MiniReflection; using System.AddIn.Pipeline; using System.Diagnostics.Contracts; namespace System.AddIn { [Serializable] internal enum PipelineComponentType { HostAdapter, Contract, AddInAdapter, AddInBase, AddIn } [Serializable] internal abstract class PipelineComponent { private TypeInfo _typeInfo; private String _location; // fully qualified path, known after deserialization private String _relativeLocation; // relative to the add-in root or pipeline root. private bool _connectedToNeighbors; private bool _haveSetRootDirectory; // Whether the add-in root or pipeline root has been set. // Since these dictionaries are read-only after initialization and they are often empty, // a perf optimization is to have the empty ones be shared. private IDictionary_qualificationData; internal static readonly IDictionary s_emptyDictionary = new ReadOnlyDictionary (new Dictionary ()); private static Type s_IContractInReflectionLoaderContext; private static Type s_ContractAttrInReflectionLoaderContext; private static Type s_AddInAdapterAttrInReflectionLoaderContext; private static Type s_AddInBaseAttrInReflectionLoaderContext; private static Type s_AddInAttrInReflectionLoaderContext; private static Type s_QualificationDataAttrInReflectionLoaderContext; internal PipelineComponent(TypeInfo typeInfo, String assemblyLocation) { if (typeInfo == null) throw new ArgumentNullException("typeInfo"); if (assemblyLocation == null) throw new ArgumentNullException("assemblyLocation"); System.Diagnostics.Contracts.Contract.EndContractBlock(); _typeInfo = typeInfo; if (Path.IsPathRooted(assemblyLocation)) { // For FindAddIn case, we know the full location; _location = assemblyLocation; _haveSetRootDirectory = true; } else { _relativeLocation = assemblyLocation; } // load the qualification data, either from reflection or minireflection, as appropriate if (_typeInfo.HasReflectionType) { IList cas =CustomAttributeData.GetCustomAttributes(_typeInfo.ReflectionType); Dictionary dictionary = new Dictionary (); foreach (CustomAttributeData ca in cas) { if (Object.ReferenceEquals(ca.Constructor.DeclaringType, s_QualificationDataAttrInReflectionLoaderContext)) { IList args = ca.ConstructorArguments; String key = (String)args[0].Value; String val = (String)args[1].Value; dictionary[key] = val; } } _qualificationData = dictionary.Count == 0 ? s_emptyDictionary : new ReadOnlyDictionary (dictionary); } else { Type qualificationDataAttribute = typeof (QualificationDataAttribute); MiniCustomAttributeInfo[] cas = typeInfo.GetCustomAttributeInfos(qualificationDataAttribute); Dictionary dictionary = new Dictionary (); if (cas != null && cas.Length > 0) { foreach (MiniCustomAttributeInfo ca in cas) { MiniCustomAttributeFixedArgInfo[] fai = ca.FixedArgs; String key = (String)fai[0].Value; String val = (String)fai[1].Value; dictionary[key] = val; } } _qualificationData = dictionary.Count == 0 ? s_emptyDictionary : new ReadOnlyDictionary (dictionary); } } internal IDictionary QualificationData { get { return _qualificationData; } } protected static Type IContractInReflectionLoaderContext { get { System.Diagnostics.Contracts.Contract.Assert(s_IContractInReflectionLoaderContext != null); return s_IContractInReflectionLoaderContext; } } internal static Type ContractAttributeInReflectionLoaderContext { get { System.Diagnostics.Contracts.Contract.Assert(s_ContractAttrInReflectionLoaderContext != null); return s_ContractAttrInReflectionLoaderContext; } } internal static Type AddInAdapterAttributeInReflectionLoaderContext { get { System.Diagnostics.Contracts.Contract.Assert(s_AddInAdapterAttrInReflectionLoaderContext != null); return s_AddInAdapterAttrInReflectionLoaderContext; } } internal static Type AddInBaseAttributeInReflectionLoaderContext { get { System.Diagnostics.Contracts.Contract.Assert(s_AddInBaseAttrInReflectionLoaderContext != null); return s_AddInBaseAttrInReflectionLoaderContext; } } internal static Type AddInAttributeInReflectionLoaderContext { get { System.Diagnostics.Contracts.Contract.Assert(s_AddInAttrInReflectionLoaderContext != null); return s_AddInAttrInReflectionLoaderContext; } } internal static void SetTypesFromReflectionLoaderContext(System.Reflection.Assembly systemAddInInReflLoaderContext, System.Reflection.Assembly systemAddInContractsInReflLoaderContext) { System.Diagnostics.Contracts.Contract.Requires(systemAddInInReflLoaderContext != null); System.Diagnostics.Contracts.Contract.Requires(systemAddInInReflLoaderContext.ReflectionOnly); System.Diagnostics.Contracts.Contract.Requires(systemAddInContractsInReflLoaderContext != null); System.Diagnostics.Contracts.Contract.Requires(systemAddInContractsInReflLoaderContext.ReflectionOnly); s_IContractInReflectionLoaderContext = systemAddInContractsInReflLoaderContext.GetType(typeof(System.AddIn.Contract.IContract).FullName, true); s_ContractAttrInReflectionLoaderContext =systemAddInContractsInReflLoaderContext.GetType("System.AddIn.Pipeline.AddInContractAttribute", true); s_QualificationDataAttrInReflectionLoaderContext = systemAddInContractsInReflLoaderContext.GetType("System.AddIn.Pipeline.QualificationDataAttribute", true); s_AddInAdapterAttrInReflectionLoaderContext = systemAddInInReflLoaderContext.GetType("System.AddIn.Pipeline.AddInAdapterAttribute", true); s_AddInBaseAttrInReflectionLoaderContext = systemAddInInReflLoaderContext.GetType("System.AddIn.Pipeline.AddInBaseAttribute", true); s_AddInAttrInReflectionLoaderContext = systemAddInInReflLoaderContext.GetType("System.AddIn.AddInAttribute", true); } internal void SetRootDirectory(String root) { System.Diagnostics.Contracts.Contract.Requires(Path.IsPathRooted(root)); // Note that the same pipeline component may show up in multiple pipelines, // and we can't do this operation twice. if (!_haveSetRootDirectory) { System.Diagnostics.Contracts.Contract.Assert(!Path.IsPathRooted(_relativeLocation)); _location = Path.Combine(root, _relativeLocation); _haveSetRootDirectory = true; } } public String Location { get { System.Diagnostics.Contracts.Contract.Assert(_haveSetRootDirectory, "You must set this component's root directory before getting an absolute path. Either call SetRootDirectory or use RelativeLocation instead."); return _location; } } internal String RelativeLocation { get { return _relativeLocation; } } protected String BestAvailableLocation { get { System.Diagnostics.Contracts.Contract.Ensures(System.Diagnostics.Contracts.Contract.Result () != null); if (_haveSetRootDirectory) return _location; return _relativeLocation; } } public String Name { get { System.Diagnostics.Contracts.Contract.Ensures(System.Diagnostics.Contracts.Contract.Result () != null); return _typeInfo.Name; } } public TypeInfo TypeInfo { get { return _typeInfo; } } public String FullName { get { return _typeInfo.FullName; } } public bool ConnectedToNeighbors { get { return _connectedToNeighbors; } set { _connectedToNeighbors = value; } } // @ internal virtual bool Validate(Type type, Collection warnings) { return Validate(new TypeInfo(type), warnings); } // Finish the initialization, and ensure this type is a valid component // for use in the add-in model. On failure, log a message & return false. // Derived classes should do their own validation and then call this one. internal virtual bool Validate(TypeInfo type, Collection warnings) { if (type.IsGeneric) { warnings.Add(String.Format(System.Globalization.CultureInfo.CurrentCulture, Res.ComponentUnusableBecauseItIsGeneric, type.Name)); return false; } return true; } // used in AddIn class and HostAdapter class // Since MiniReflection doesn't support generics, we do a "best effort" while generating this list. [System.Security.SecuritySafeCritical] internal static TypeInfo[] FindBaseTypesAndInterfaces(TypeInfo type) { TypeInfo currentTypeInfo = type; TypeInfo objectType = new TypeInfo(typeof(Object)); List infos = new List (); try { //we walk up the hierarchy as far as we can until we can't //get the types anymore... while (!currentTypeInfo.Equals(objectType)) { // To get the base type and interfaces, we will need to resolve a TypeRef to a TypeDef first currentTypeInfo = currentTypeInfo.TryGetTypeDef(); if (currentTypeInfo != null) { TypeInfo[] interfaces = currentTypeInfo.GetInterfaces(); if (interfaces != null) infos.AddRange(interfaces); TypeInfo baseType = currentTypeInfo.BaseType; infos.Add(baseType); currentTypeInfo = baseType; } else { // we have reached the limit of what we can resolve in the addin/hostadapter's folder break; } } } catch (GenericsNotImplementedException) { // Since GetInterfaces() ignores all generic interfaces, we'll only come here if we encounter a generic base class. // We'll ignore the generic base class and return whatever bases we found earlier. } return infos.ToArray(); } } } // 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
- UniformGrid.cs
- Font.cs
- MetadataSerializer.cs
- DataBindingExpressionBuilder.cs
- XmlNamespaceMapping.cs
- SimpleBitVector32.cs
- ParallelTimeline.cs
- XPathSelfQuery.cs
- CacheDependency.cs
- GlyphCollection.cs
- RemotingService.cs
- SQLChars.cs
- IIS7WorkerRequest.cs
- LinqDataSourceInsertEventArgs.cs
- ConnectionInterfaceCollection.cs
- DataGrid.cs
- CorrelationManager.cs
- SineEase.cs
- FtpRequestCacheValidator.cs
- CodeEventReferenceExpression.cs
- GridItem.cs
- ActivityBindForm.cs
- _LocalDataStoreMgr.cs
- TableLayoutSettingsTypeConverter.cs
- RightsManagementInformation.cs
- _ListenerResponseStream.cs
- DataControlButton.cs
- SelectionGlyph.cs
- ConfigurationLocationCollection.cs
- DataGridColumnHeadersPresenterAutomationPeer.cs
- DispatcherExceptionEventArgs.cs
- ButtonBase.cs
- MessageHeaderException.cs
- WindowInteractionStateTracker.cs
- RowVisual.cs
- RadioButtonList.cs
- URLIdentityPermission.cs
- SevenBitStream.cs
- ResourceCategoryAttribute.cs
- HyperLinkDesigner.cs
- Context.cs
- GuidConverter.cs
- AtomServiceDocumentSerializer.cs
- UdpUtility.cs
- RectangleF.cs
- RegexRunner.cs
- PathFigure.cs
- TaiwanCalendar.cs
- validationstate.cs
- GenericAuthenticationEventArgs.cs
- IsolatedStoragePermission.cs
- VisualStyleElement.cs
- ObjectManager.cs
- EncryptedKeyIdentifierClause.cs
- BooleanStorage.cs
- RoleGroupCollection.cs
- ChtmlTextWriter.cs
- ToolStripItemRenderEventArgs.cs
- DataGridViewCellStyle.cs
- Variant.cs
- COM2ComponentEditor.cs
- AnnotationHighlightLayer.cs
- TextParaClient.cs
- TreeWalker.cs
- Scheduling.cs
- RegistrySecurity.cs
- EngineSiteSapi.cs
- WebControlsSection.cs
- NegotiateStream.cs
- DataGridSortCommandEventArgs.cs
- CategoryEditor.cs
- TextAnchor.cs
- EventHandlerService.cs
- TripleDESCryptoServiceProvider.cs
- StateMachineAction.cs
- X509RecipientCertificateClientElement.cs
- TdsParameterSetter.cs
- BufferBuilder.cs
- CompilationLock.cs
- WinEventQueueItem.cs
- EntityDataSourceContainerNameConverter.cs
- PageContentCollection.cs
- DSASignatureFormatter.cs
- OperationExecutionFault.cs
- DataGridViewCheckBoxCell.cs
- TreeViewItem.cs
- XPathSelectionIterator.cs
- ConnectionStringsExpressionBuilder.cs
- TextElement.cs
- DataGridViewColumnHeaderCell.cs
- NamedElement.cs
- SelectedPathEditor.cs
- BinaryEditor.cs
- SqlCacheDependencySection.cs
- UnicastIPAddressInformationCollection.cs
- HttpModule.cs
- LoadRetryHandler.cs
- PresentationSource.cs
- ParenthesizePropertyNameAttribute.cs
- TextHidden.cs