Inheritance: ContextAttribute, IContributeClientContextSink, IContributeServerContextSink
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }
            bool flag = true;

            if (this._flavor == 8)
            {
                return(false);
            }
            SynchronizationAttribute property = (SynchronizationAttribute)ctx.GetProperty("Synchronization");

            if (((this._flavor == 1) && (property != null)) || ((this._flavor == 4) && (property == null)))
            {
                flag = false;
            }
            if (this._flavor == 4)
            {
                this._cliCtxAttr = property;
            }
            return(flag);
        }
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }
            bool result = true;

            if (this._flavor == 8)
            {
                result = false;
            }
            else
            {
                SynchronizationAttribute synchronizationAttribute = (SynchronizationAttribute)ctx.GetProperty("Synchronization");
                if ((this._flavor == 1 && synchronizationAttribute != null) || (this._flavor == 4 && synchronizationAttribute == null))
                {
                    result = false;
                }
                if (this._flavor == 4)
                {
                    this._cliCtxAttr = synchronizationAttribute;
                }
            }
            return(result);
        }
		public void SerializationRoundtrip ()
		{
			SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED, true);
			BinaryFormatter bf = new BinaryFormatter ();
			MemoryStream ms = new MemoryStream ();
			bf.Serialize (ms, sa);

			ms.Position = 0;
			SynchronizationAttribute clone = (SynchronizationAttribute) bf.Deserialize (ms);

			Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
			Assert.IsFalse (sa.Locked, "Locked");
		}
        internal static void ExitContext()
        {
            if (Thread.CurrentContext.IsDefaultContext)
            {
                return;
            }
            SynchronizationAttribute synchronizationAttribute = Thread.CurrentContext.GetProperty("Synchronization") as SynchronizationAttribute;

            if (synchronizationAttribute == null)
            {
                return;
            }
            synchronizationAttribute.Locked = false;
        }
Exemple #5
0
        internal static void EnterContext()
        {
            if (Thread.CurrentContext.IsDefaultContext)
            {
                return;
            }
            SynchronizationAttribute prop = Thread.CurrentContext.GetProperty("Synchronization") as SynchronizationAttribute;

            if (prop == null)
            {
                return;
            }
            prop.Locked = true;
        }
 public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
 {
     if (((this._flavor != 1) && (this._flavor != 2)) && (ctorMsg != null))
     {
         if (this._cliCtxAttr != null)
         {
             ctorMsg.ContextProperties.Add(this._cliCtxAttr);
             this._cliCtxAttr = null;
         }
         else
         {
             ctorMsg.ContextProperties.Add(this);
         }
     }
 }
	    public void SetLocked()
		{
			SynchronizationAttribute sa = new SynchronizationAttribute(SynchronizationAttribute.REQUIRES_NEW);
			sa.Locked = true;
			Assert.IsTrue(sa.Locked, "Locked");
			sa.Locked = false;
			Assert.IsFalse(sa.Locked, "Locked");

			sa.Locked = true;
			Assert.IsTrue(sa.Locked, "Locked");
			sa.Locked = true;
			Assert.IsTrue(sa.Locked, "Locked");
			sa.Locked = false;
			Assert.IsFalse(sa.Locked, "Locked");
		}
Exemple #8
0
 public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
 {
     if (this._flavor == 1 || this._flavor == 2 || ctorMsg == null)
     {
         return;
     }
     if (this._cliCtxAttr != null)
     {
         ctorMsg.ContextProperties.Add((object)this._cliCtxAttr);
         this._cliCtxAttr = (SynchronizationAttribute)null;
     }
     else
     {
         ctorMsg.ContextProperties.Add((object)this);
     }
 }
Exemple #9
0
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            SynchronizationAttribute prop = ctx.GetProperty("Synchronization") as SynchronizationAttribute;

            switch (_flavor)
            {
            case NOT_SUPPORTED: return(prop == null);

            case REQUIRED: return(prop != null);

            case REQUIRES_NEW: return(false);

            case SUPPORTED: return(true);
            }
            return(false);
        }
        public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
        {
            if ((_flavor == NOT_SUPPORTED) || (_flavor == SUPPORTED) || (null == ctorMsg))
            {
                return;
            }

            if (_cliCtxAttr != null)
            {
                Contract.Assert(_flavor == REQUIRED, "Use cli-ctx property only for the REQUIRED flavor");
                ctorMsg.ContextProperties.Add((IContextProperty)_cliCtxAttr);
                _cliCtxAttr = null;
            }
            else
            {
                ctorMsg.ContextProperties.Add((IContextProperty)this);
            }
        }
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }
            Contract.EndContractBlock();

            // <

            bool isOK = true;

            if (_flavor == REQUIRES_NEW)
            {
                isOK = false;
                // Each activation request instantiates a new attribute class.
                // We are relying on that for the REQUIRES_NEW case!
                Contract.Assert(ctx.GetProperty(PROPERTY_NAME) != this,
                                "ctx.GetProperty(PROPERTY_NAME) != this");
            }
            else
            {
                SynchronizationAttribute syncProp = (SynchronizationAttribute)ctx.GetProperty(PROPERTY_NAME);
                if (((_flavor == NOT_SUPPORTED) && (syncProp != null)) ||
                    ((_flavor == REQUIRED) && (syncProp == null))
                    )
                {
                    isOK = false;
                }

                if (_flavor == REQUIRED)
                {
                    // pick up the property from the current context
                    _cliCtxAttr = syncProp;
                }
            }
            return(isOK);
        }
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            SynchronizationAttribute synchronizationAttribute = ctx.GetProperty("Synchronization") as SynchronizationAttribute;

            switch (this._flavor)
            {
            case 1:
                return(synchronizationAttribute == null);

            case 2:
                return(true);

            case 4:
                return(synchronizationAttribute != null);

            case 8:
                return(false);
            }
            return(false);
        }
        // Override ContextAttribute's implementation of IContextAttribute::IsContextOK
        /// <include file='doc\SynchronizedDispatch.uex' path='docs/doc[@for="SynchronizationAttribute.IsContextOK"]/*' />
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            // FUTURE: we should also check for ThreadAffinity!
            // If the context has ThreadAffinity then it is synchronized by default!
            bool isOK = true;

            if (_flavor == REQUIRES_NEW)
            {
                isOK = false;
                // Each activation request instantiates a new attribute class.
                // We are relying on that for the REQUIRES_NEW case!
                BCLDebug.Assert(ctx.GetProperty(PROPERTY_NAME) != this,
                                "ctx.GetProperty(PROPERTY_NAME) != this");
            }
            else
            {
                SynchronizationAttribute syncProp = (SynchronizationAttribute)ctx.GetProperty(PROPERTY_NAME);
                if (((_flavor == NOT_SUPPORTED) && (syncProp != null)) ||
                    ((_flavor == REQUIRED) && (syncProp == null))
                    )
                {
                    isOK = false;
                }

                if (_flavor == REQUIRED)
                {
                    // pick up the property from the current context
                    _cliCtxAttr = syncProp;
                }
            }
            return(isOK);
        }
 internal SynchronizedServerContextSink(SynchronizationAttribute prop, IMessageSink nextSink)
 {
     this._property = prop;
     this._nextSink = nextSink;
 }
 internal SynchronizedClientContextSink(SynchronizationAttribute prop, IMessageSink nextSink)
 {
     this._property = prop;
     this._nextSink = nextSink;
 }
 [System.Security.SecurityCritical]  // auto-generated
 internal SynchronizedClientContextSink(SynchronizationAttribute prop, IMessageSink nextSink)
 {
     _property = prop;
     _nextSink = nextSink;
 }
        public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            if (ctx == null)
                throw new ArgumentNullException("ctx");
            if (msg == null)
                throw new ArgumentNullException("msg");
            Contract.EndContractBlock();

            // <

            bool isOK = true;
            if (_flavor == REQUIRES_NEW)
            {
                isOK = false;
                // Each activation request instantiates a new attribute class.
                // We are relying on that for the REQUIRES_NEW case!
                Contract.Assert(ctx.GetProperty(PROPERTY_NAME) != this,
                    "ctx.GetProperty(PROPERTY_NAME) != this");
            }
            else
            {
                SynchronizationAttribute syncProp = (SynchronizationAttribute) ctx.GetProperty(PROPERTY_NAME);
                if (   ( (_flavor == NOT_SUPPORTED)&&(syncProp != null) )
                    || ( (_flavor == REQUIRED)&&(syncProp == null) )
                    )
                {
                    isOK = false;
                }

                if (_flavor == REQUIRED)
                {
                    // pick up the property from the current context
                    _cliCtxAttr = syncProp;
                }
            }
            return isOK;
        }
Exemple #18
0
 public SynchronizedContextReplySink(IMessageSink next, SynchronizationAttribute att, bool newLock)
 {
     _newLock = newLock;
     _next    = next;
     _att     = att;
 }
		// Constructor.
		public PassThroughSink
					(SynchronizationAttribute attr, IMessageSink nextSink)
				{
					this.attr = attr;
					this.nextSink = nextSink;
				}
		public void Constructor_Default ()
		{
			SynchronizationAttribute sa = new SynchronizationAttribute ();
			Assert.IsFalse (sa.IsReEntrant, "IsReEntrant");
			Assert.IsFalse (sa.Locked, "Locked");
		}
		public SynchronizedContextReplySink (IMessageSink next, SynchronizationAttribute att, bool newLock)
		{
			_newLock = newLock;
			_next = next;
			_att = att;
		}
		public SynchronizedServerContextSink (IMessageSink next, SynchronizationAttribute att)
		{
			_att = att;
			_next = next;
		}
 public SynchronizedClientContextSink(IMessageSink next, SynchronizationAttribute att)
 {
     this._att  = att;
     this._next = next;
 }
 // Constructor.
 public PassThroughSink
     (SynchronizationAttribute attr, IMessageSink nextSink)
 {
     this.attr     = attr;
     this.nextSink = nextSink;
 }
Exemple #25
0
 public SynchronizedServerContextSink(IMessageSink next, SynchronizationAttribute att)
 {
     _att  = att;
     _next = next;
 }
 public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
 {
     if (ctx == null)
     {
         throw new ArgumentNullException("ctx");
     }
     if (msg == null)
     {
         throw new ArgumentNullException("msg");
     }
     bool flag = true;
     if (this._flavor == 8)
     {
         return false;
     }
     SynchronizationAttribute property = (SynchronizationAttribute) ctx.GetProperty("Synchronization");
     if (((this._flavor == 1) && (property != null)) || ((this._flavor == 4) && (property == null)))
     {
         flag = false;
     }
     if (this._flavor == 4)
     {
         this._cliCtxAttr = property;
     }
     return flag;
 }
 [System.Security.SecurityCritical]  // auto-generated
 internal AsyncReplySink(IMessageSink nextSink, SynchronizationAttribute prop)
 {
     _nextSink = nextSink;
     _property = prop;
 }
 public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
 {
     if (((this._flavor != 1) && (this._flavor != 2)) && (ctorMsg != null))
     {
         if (this._cliCtxAttr != null)
         {
             ctorMsg.ContextProperties.Add(this._cliCtxAttr);
             this._cliCtxAttr = null;
         }
         else
         {
             ctorMsg.ContextProperties.Add(this);
         }
     }
 }
        public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
        {
            if ( (_flavor==NOT_SUPPORTED) || (_flavor==SUPPORTED) || (null == ctorMsg) )
            {
                return ;
            }

            if (_cliCtxAttr != null)
            {
                Contract.Assert(_flavor == REQUIRED,"Use cli-ctx property only for the REQUIRED flavor");
                ctorMsg.ContextProperties.Add((IContextProperty)_cliCtxAttr);
                _cliCtxAttr = null;
            }
            else
            {
                ctorMsg.ContextProperties.Add((IContextProperty)this);
            }
        }
 internal AsyncReplySink(IMessageSink nextSink, SynchronizationAttribute prop)
 {
     this._nextSink = nextSink;
     this._property = prop;
 }
		public void Constructor_IntBool ()
		{
			SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED, true);
			Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
			Assert.IsFalse (sa.Locked, "Locked");
		}
 [System.Security.SecurityCritical]  // auto-generated
 internal SynchronizedServerContextSink(SynchronizationAttribute prop, IMessageSink nextSink)
 {
     _property = prop;
     _nextSink = nextSink;
 }