Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Runtime / Remoting / ContextProperty.cs / 2 / ContextProperty.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** File: ContextProperty.cs ** ** A contextProperty is a name-value pair holding the property ** name and the object representing the property in a context. ** An array of these is returned by Context::GetContextProperties() ** ** ** ===========================================================*/ namespace System.Runtime.Remoting.Contexts { using System; using System.Threading; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.Remoting.Activation; using System.Security.Permissions; ///[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)] [System.Runtime.InteropServices.ComVisible(true)] public class ContextProperty { internal String _name; // property name internal Object _property; // property object /// public virtual String Name { get { return _name; } } /// public virtual Object Property { get { return _property; } } /* can't create outside the package */ internal ContextProperty(String name, Object prop) { _name = name; _property = prop; } } // The IContextAttribute interface is implemented by attribute classes. // The attributes contribute a property which resides in a context and // enforces a specific policy for the objects created in that context. /// [System.Runtime.InteropServices.ComVisible(true)] public interface IContextAttribute { /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool IsContextOK(Context ctx, IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void GetPropertiesForNewContext(IConstructionCallMessage msg); } // This interface is exposed by the property contributed to a context // by an attribute. By default, it is also implemented by the ContextAttribute // base class which every attribute class must extend from. /// [System.Runtime.InteropServices.ComVisible(true)] public interface IContextProperty { /// // This is the name under which the property will be added // to the {name,property} table in a context. String Name { [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] get; } /// // After forming the newCtx, we ask each property if it is happy // with the context. We expect most implementations to say yes. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool IsNewContextOK(Context newCtx); /// // New method. All properties are notified when the context // they are in is frozen. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void Freeze(Context newContext); } /// [System.Runtime.InteropServices.ComVisible(true)] public interface IContextPropertyActivator { /// // This method lets properties in the current context have a say in // whether an activation may be done 'here' or not. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool IsOKToActivate(IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void CollectFromClientContext(IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool DeliverClientContextToServerContext(IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void CollectFromServerContext(IConstructionReturnMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool DeliverServerContextToClientContext(IConstructionReturnMessage msg); } // All context attribute classes must extend from this base class. // This class provides the base implementations which the derived // classes are free to over-ride. The base implementations provide // the default answers to various questions. /// [AttributeUsage(AttributeTargets.Class), Serializable] [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)] [System.Runtime.InteropServices.ComVisible(true)] public class ContextAttribute : Attribute, IContextAttribute, IContextProperty { /// protected String AttributeName; // The derived class must call: base(name); /// public ContextAttribute(String name) { AttributeName = name; } // IContextPropery::Name // Default implementation provides AttributeName as the property name. /// public virtual String Name { get {return AttributeName;} } // IContextProperty::IsNewContextOK /// public virtual bool IsNewContextOK(Context newCtx) { // This will be called before entering the newCtx // Default implementation says OK. return true; } // IContextProperty::Freeze // Default implementation does nothing /// public virtual void Freeze(Context newContext) { BCLDebug.Log("ContextAttribute::ContextProperty::Freeze"+ " for context " + newContext ); } // Object::Equals // Default implementation just compares the names /// public override bool Equals(Object o) { IContextProperty prop = o as IContextProperty; return (null != prop) && AttributeName.Equals(prop.Name); } /// public override int GetHashCode() { return this.AttributeName.GetHashCode(); } // IContextAttribute::IsContextOK // Default calls Object::Equals on the property and does not // bother with the ctorMsg. /// public virtual bool IsContextOK( Context ctx, IConstructionCallMessage ctorMsg) { if (ctx == null) throw new ArgumentNullException("ctx"); if (ctorMsg == null) throw new ArgumentNullException("ctorMsg"); BCLDebug.Assert(ctorMsg.ActivationType.IsMarshalByRef, "Activation on a non MarshalByRef object"); if (!ctorMsg.ActivationType.IsContextful) { return true; } Object prop = ctx.GetProperty(AttributeName); if ((prop!=null) && (Equals(prop))) { return true; } return false; } // IContextAttribute::GetPropertiesForNewContext // Default adds the attribute itself w/o regard to the current // list of properties /// public virtual void GetPropertiesForNewContext( IConstructionCallMessage ctorMsg) { if (ctorMsg == null) throw new ArgumentNullException("ctorMsg"); ctorMsg.ContextProperties.Add((IContextProperty)this); } } #if SIMPLEXAACTIVATION /// [AttributeUsage(AttributeTargets.Class)] [System.Runtime.InteropServices.ComVisible(true)] public class new_appdomain : ContextAttribute { internal static int _domain_no = 0; /// public new_appdomain() : base("new_appdomain") {} /// [System.Runtime.InteropServices.ComVisible(true)] public override bool IsContextOK(Context ctx, IConstructionCallMessage msg) { return false; } /// [System.Runtime.InteropServices.ComVisible(true)] public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg) { ctorMsg.GetProperties()["__new_appdomain"] = true; } /// [System.Runtime.InteropServices.ComVisible(true)] public static IConstructionReturnMessage DoSimpleXADActivation(IConstructionCallMessage msg) { int domain_no = Interlocked.Increment(ref _domain_no); AppDomain ad = AppDomain.CreateDomain("AutoDomain #" + domain_no, null, null); activator a = (activator) (ad.CreateInstance(null, typeof(activator).FullName)).Unwrap(); return a.Activate(msg); } /// [System.Runtime.InteropServices.ComVisible(true)] public class activator : MarshalByRefObject, IActivator { /// [System.Runtime.InteropServices.ComVisible(true)] public IConstructionReturnMessage Activate(IConstructionCallMessage msg) { return RemotingServices.DoCrossContextActivation(msg); } /// [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void LoadAssembly(AssemblyName an) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Assembly a = Assembly.InternalLoad(an, false, null, ref stackMark); if (a == null) { throw new RemotingException( String.Format( Environment.GetResourceString( "Remoting_AssemblyLoadFailed"), an)); } } } } /// [new_appdomain] [System.Runtime.InteropServices.ComVisible(true)] public class MBR : MarshalByRefObject { /// public String MyAppDomain() { return Thread.GetDomain().GetFriendlyName(); } } /// [new_appdomain] [System.Runtime.InteropServices.ComVisible(true)] public class CB : ContextBoundObject { /// public String MyAppDomain() { return Thread.GetDomain().GetFriendlyName(); } } #endif } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** File: ContextProperty.cs ** ** A contextProperty is a name-value pair holding the property ** name and the object representing the property in a context. ** An array of these is returned by Context::GetContextProperties() ** ** ** ===========================================================*/ namespace System.Runtime.Remoting.Contexts { using System; using System.Threading; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.Remoting.Activation; using System.Security.Permissions; /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)] [System.Runtime.InteropServices.ComVisible(true)] public class ContextProperty { internal String _name; // property name internal Object _property; // property object /// public virtual String Name { get { return _name; } } /// public virtual Object Property { get { return _property; } } /* can't create outside the package */ internal ContextProperty(String name, Object prop) { _name = name; _property = prop; } } // The IContextAttribute interface is implemented by attribute classes. // The attributes contribute a property which resides in a context and // enforces a specific policy for the objects created in that context. /// [System.Runtime.InteropServices.ComVisible(true)] public interface IContextAttribute { /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool IsContextOK(Context ctx, IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void GetPropertiesForNewContext(IConstructionCallMessage msg); } // This interface is exposed by the property contributed to a context // by an attribute. By default, it is also implemented by the ContextAttribute // base class which every attribute class must extend from. /// [System.Runtime.InteropServices.ComVisible(true)] public interface IContextProperty { /// // This is the name under which the property will be added // to the {name,property} table in a context. String Name { [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] get; } /// // After forming the newCtx, we ask each property if it is happy // with the context. We expect most implementations to say yes. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool IsNewContextOK(Context newCtx); /// // New method. All properties are notified when the context // they are in is frozen. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void Freeze(Context newContext); } /// [System.Runtime.InteropServices.ComVisible(true)] public interface IContextPropertyActivator { /// // This method lets properties in the current context have a say in // whether an activation may be done 'here' or not. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool IsOKToActivate(IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void CollectFromClientContext(IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool DeliverClientContextToServerContext(IConstructionCallMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] void CollectFromServerContext(IConstructionReturnMessage msg); /// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] bool DeliverServerContextToClientContext(IConstructionReturnMessage msg); } // All context attribute classes must extend from this base class. // This class provides the base implementations which the derived // classes are free to over-ride. The base implementations provide // the default answers to various questions. /// [AttributeUsage(AttributeTargets.Class), Serializable] [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)] [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)] [System.Runtime.InteropServices.ComVisible(true)] public class ContextAttribute : Attribute, IContextAttribute, IContextProperty { /// protected String AttributeName; // The derived class must call: base(name); /// public ContextAttribute(String name) { AttributeName = name; } // IContextPropery::Name // Default implementation provides AttributeName as the property name. /// public virtual String Name { get {return AttributeName;} } // IContextProperty::IsNewContextOK /// public virtual bool IsNewContextOK(Context newCtx) { // This will be called before entering the newCtx // Default implementation says OK. return true; } // IContextProperty::Freeze // Default implementation does nothing /// public virtual void Freeze(Context newContext) { BCLDebug.Log("ContextAttribute::ContextProperty::Freeze"+ " for context " + newContext ); } // Object::Equals // Default implementation just compares the names /// public override bool Equals(Object o) { IContextProperty prop = o as IContextProperty; return (null != prop) && AttributeName.Equals(prop.Name); } /// public override int GetHashCode() { return this.AttributeName.GetHashCode(); } // IContextAttribute::IsContextOK // Default calls Object::Equals on the property and does not // bother with the ctorMsg. /// public virtual bool IsContextOK( Context ctx, IConstructionCallMessage ctorMsg) { if (ctx == null) throw new ArgumentNullException("ctx"); if (ctorMsg == null) throw new ArgumentNullException("ctorMsg"); BCLDebug.Assert(ctorMsg.ActivationType.IsMarshalByRef, "Activation on a non MarshalByRef object"); if (!ctorMsg.ActivationType.IsContextful) { return true; } Object prop = ctx.GetProperty(AttributeName); if ((prop!=null) && (Equals(prop))) { return true; } return false; } // IContextAttribute::GetPropertiesForNewContext // Default adds the attribute itself w/o regard to the current // list of properties /// public virtual void GetPropertiesForNewContext( IConstructionCallMessage ctorMsg) { if (ctorMsg == null) throw new ArgumentNullException("ctorMsg"); ctorMsg.ContextProperties.Add((IContextProperty)this); } } #if SIMPLEXAACTIVATION /// [AttributeUsage(AttributeTargets.Class)] [System.Runtime.InteropServices.ComVisible(true)] public class new_appdomain : ContextAttribute { internal static int _domain_no = 0; /// public new_appdomain() : base("new_appdomain") {} /// [System.Runtime.InteropServices.ComVisible(true)] public override bool IsContextOK(Context ctx, IConstructionCallMessage msg) { return false; } /// [System.Runtime.InteropServices.ComVisible(true)] public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg) { ctorMsg.GetProperties()["__new_appdomain"] = true; } /// [System.Runtime.InteropServices.ComVisible(true)] public static IConstructionReturnMessage DoSimpleXADActivation(IConstructionCallMessage msg) { int domain_no = Interlocked.Increment(ref _domain_no); AppDomain ad = AppDomain.CreateDomain("AutoDomain #" + domain_no, null, null); activator a = (activator) (ad.CreateInstance(null, typeof(activator).FullName)).Unwrap(); return a.Activate(msg); } /// [System.Runtime.InteropServices.ComVisible(true)] public class activator : MarshalByRefObject, IActivator { /// [System.Runtime.InteropServices.ComVisible(true)] public IConstructionReturnMessage Activate(IConstructionCallMessage msg) { return RemotingServices.DoCrossContextActivation(msg); } /// [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public void LoadAssembly(AssemblyName an) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Assembly a = Assembly.InternalLoad(an, false, null, ref stackMark); if (a == null) { throw new RemotingException( String.Format( Environment.GetResourceString( "Remoting_AssemblyLoadFailed"), an)); } } } } /// [new_appdomain] [System.Runtime.InteropServices.ComVisible(true)] public class MBR : MarshalByRefObject { /// public String MyAppDomain() { return Thread.GetDomain().GetFriendlyName(); } } /// [new_appdomain] [System.Runtime.InteropServices.ComVisible(true)] public class CB : ContextBoundObject { /// public String MyAppDomain() { return Thread.GetDomain().GetFriendlyName(); } } #endif } // 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
- MarginsConverter.cs
- _ConnectStream.cs
- BamlWriter.cs
- EmbeddedMailObject.cs
- StoreUtilities.cs
- ThicknessKeyFrameCollection.cs
- SignerInfo.cs
- BitmapDownload.cs
- DocumentXPathNavigator.cs
- DropShadowEffect.cs
- GlyphingCache.cs
- EventMappingSettingsCollection.cs
- PropertyGridCommands.cs
- DateTimeFormat.cs
- DataGridTable.cs
- ToolbarAUtomationPeer.cs
- FileDialogCustomPlace.cs
- GB18030Encoding.cs
- MasterPageBuildProvider.cs
- SQLDecimalStorage.cs
- ButtonBaseAdapter.cs
- RuleInfoComparer.cs
- DirectoryRootQuery.cs
- UnsafeNetInfoNativeMethods.cs
- Mapping.cs
- XmlSchemaDatatype.cs
- EventProxy.cs
- DateTimeOffset.cs
- TreeNodeStyle.cs
- DataGridCellAutomationPeer.cs
- PropertyEmitterBase.cs
- log.cs
- DrawListViewItemEventArgs.cs
- SqlDataSourceSelectingEventArgs.cs
- DataSourceCache.cs
- BufferBuilder.cs
- ZipIOModeEnforcingStream.cs
- XpsPartBase.cs
- Attributes.cs
- SmtpMail.cs
- FileLoadException.cs
- QilCloneVisitor.cs
- SqlIdentifier.cs
- ServiceBuildProvider.cs
- Timer.cs
- ParentQuery.cs
- MonitorWrapper.cs
- Rotation3D.cs
- SymbolMethod.cs
- ProcessManager.cs
- TypefaceCollection.cs
- DragStartedEventArgs.cs
- HttpCookieCollection.cs
- HybridDictionary.cs
- ConfigXmlAttribute.cs
- NoPersistProperty.cs
- COMException.cs
- HttpWebRequest.cs
- CreateUserWizardStep.cs
- followingquery.cs
- EventKeyword.cs
- EmptyImpersonationContext.cs
- Model3DCollection.cs
- Rotation3D.cs
- PrinterSettings.cs
- XmlAnyElementAttribute.cs
- Style.cs
- RequestNavigateEventArgs.cs
- TypeLoadException.cs
- RSAOAEPKeyExchangeDeformatter.cs
- NetMsmqSecurity.cs
- DriveNotFoundException.cs
- SynchronizedDispatch.cs
- TrackingDataItemValue.cs
- ServiceCredentialsSecurityTokenManager.cs
- GeometryModel3D.cs
- ScrollEvent.cs
- DefaultClaimSet.cs
- DateTimeConstantAttribute.cs
- COM2PictureConverter.cs
- SymLanguageType.cs
- TextElementEnumerator.cs
- DataRecordInfo.cs
- RunWorkerCompletedEventArgs.cs
- X509RecipientCertificateClientElement.cs
- PathNode.cs
- HWStack.cs
- ClipboardProcessor.cs
- TextEditorTyping.cs
- ViewEvent.cs
- SizeConverter.cs
- HttpWriter.cs
- PartManifestEntry.cs
- XmlnsDefinitionAttribute.cs
- ContextMenuService.cs
- CacheOutputQuery.cs
- SessionParameter.cs
- IndicShape.cs
- TrustManagerPromptUI.cs
- ProgressBar.cs