Пример #1
0
 public RelationOn(Type from, MemberInfo on, Type to, Declared declared)
     : base(from, to, declared)
 {
     if (on == null)
     {
         throw new ArgumentNullException("on");
     }
     On       = on;
     hashCode = On.GetHashCode();
 }
Пример #2
0
		public RelationOn(Type from, MemberInfo on, Type to, Declared declared)
			: base(from, to, declared)
		{
			if (on == null)
			{
				throw new ArgumentNullException("on");
			}
			On = on;
			hashCode = On.GetHashCode();
		}
Пример #3
0
            void OnMessage(AmqpMessage message)
            {
                Outcome outcome;

                if (message.ValueBody.Value is Declare)
                {
                    int txnId = this.CreateTransaction();
                    outcome = new Declared()
                    {
                        TxnId = new ArraySegment <byte>(BitConverter.GetBytes(txnId))
                    };
                }
                else if (message.ValueBody.Value is Discharge)
                {
                    Discharge   discharge = (Discharge)message.ValueBody.Value;
                    int         txnId     = BitConverter.ToInt32(discharge.TxnId.Array, discharge.TxnId.Offset);
                    Transaction txn;
                    if (this.transactions.TryGetValue(txnId, out txn))
                    {
                        lock (this.transactions)
                        {
                            this.transactions.Remove(txnId);
                        }

                        txn.Discharge(discharge.Fail ?? false);
                        outcome = AmqpConstants.AcceptedOutcome;
                    }
                    else
                    {
                        outcome = new Rejected()
                        {
                            Error = new Error()
                            {
                                Condition = AmqpErrorCode.NotFound
                            }
                        };
                    }
                }
                else
                {
                    outcome = new Rejected()
                    {
                        Error = new Error()
                        {
                            Condition = AmqpErrorCode.NotAllowed
                        }
                    };
                }

                message.Link.DisposeDelivery(message, true, outcome);
            }
 public Relation(Type @from, Type to, Declared declaredAs)
 {
     if (from == null)
     {
         throw new ArgumentNullException("from");
     }
     if (to == null)
     {
         throw new ArgumentNullException("to");
     }
     From = from;
     To = to;
     DeclaredAs = declaredAs;
     hashCode = (37 * from.GetHashCode()) ^ to.GetHashCode();
 }
Пример #5
0
 public Relation(Type @from, Type to, Declared declaredAs)
 {
     if (from == null)
     {
         throw new ArgumentNullException("from");
     }
     if (to == null)
     {
         throw new ArgumentNullException("to");
     }
     From       = from;
     To         = to;
     DeclaredAs = declaredAs;
     hashCode   = (37 * from.GetHashCode()) ^ to.GetHashCode();
 }
Пример #6
0
            static void OnMessage(ListenerLink link, Message message, DeliveryState deliveryState, object state)
            {
                var    thisPtr = (TxnManager)state;
                object body;

                try
                {
                    body = Message.Decode(((BrokerMessage)message).Buffer).Body;
                }
                catch (Exception exception)
                {
                    Trace.WriteLine(TraceLevel.Error, exception.Message);
                    link.DisposeMessage(
                        message,
                        new Rejected()
                    {
                        Error = new Error()
                        {
                            Condition = ErrorCode.DecodeError, Description = "Cannot decode txn message"
                        }
                    },
                        true);

                    return;
                }

                if (body is Declare)
                {
                    int txnId   = thisPtr.CreateTransaction();
                    var outcome = new Declared()
                    {
                        TxnId = BitConverter.GetBytes(txnId)
                    };
                    link.DisposeMessage(message, outcome, true);
                }
                else if (body is Discharge)
                {
                    Discharge   discharge = (Discharge)body;
                    int         txnId     = BitConverter.ToInt32(discharge.TxnId, 0);
                    Transaction txn;
                    if (thisPtr.transactions.TryGetValue(txnId, out txn))
                    {
                        lock (thisPtr.transactions)
                        {
                            thisPtr.transactions.Remove(txnId);
                        }

                        txn.Discharge(discharge.Fail);
                        link.DisposeMessage(message, new Accepted(), true);
                    }
                    else
                    {
                        link.DisposeMessage(
                            message,
                            new Rejected()
                        {
                            Error = new Error()
                            {
                                Condition = ErrorCode.NotFound, Description = "Transaction not found"
                            }
                        },
                            true);
                    }
                }
                else
                {
                    link.DisposeMessage(
                        message,
                        new Rejected()
                    {
                        Error = new Error()
                        {
                            Condition = ErrorCode.NotImplemented, Description = "Unsupported message body"
                        }
                    },
                        true);
                }
            }
Пример #7
0
            static void OnMessage(ListenerLink link, Message message, DeliveryState deliveryState, object state)
            {
                var thisPtr = (TxnManager)state;
                object body;
                try
                {
                    body = Message.Decode(((BrokerMessage)message).Buffer).Body;
                }
                catch (Exception exception)
                {
                    Trace.WriteLine(TraceLevel.Error, exception.Message);
                    link.DisposeMessage(
                        message,
                        new Rejected() { Error = new Error() { Condition = ErrorCode.DecodeError, Description = "Cannot decode txn message" } },
                        true);

                    return;
                }

                if (body is Declare)
                {
                    int txnId = thisPtr.CreateTransaction();
                    var outcome = new Declared() { TxnId = BitConverter.GetBytes(txnId) };
                    link.DisposeMessage(message, outcome, true);
                }
                else if (body is Discharge)
                {
                    Discharge discharge = (Discharge)body;
                    int txnId = BitConverter.ToInt32(discharge.TxnId, 0);
                    Transaction txn;
                    if (thisPtr.transactions.TryGetValue(txnId, out txn))
                    {
                        lock (thisPtr.transactions)
                        {
                            thisPtr.transactions.Remove(txnId);
                        }

                        txn.Discharge(discharge.Fail);
                        link.DisposeMessage(message, new Accepted(), true);
                    }
                    else
                    {
                        link.DisposeMessage(
                            message,
                            new Rejected() { Error = new Error() { Condition = ErrorCode.NotFound, Description = "Transaction not found" } },
                            true);
                    }
                }
                else
                {
                    link.DisposeMessage(
                        message,
                        new Rejected() { Error = new Error() { Condition = ErrorCode.NotImplemented, Description = "Unsupported message body" } },
                        true);
                }
            }
Пример #8
0
 public override int GetHashCode()
 {
     unchecked {
         return(Declared.GetHashCode() + (Injected.GetHashCode() * 17));
     }
 }
Пример #9
0
 public IAssertSignature ThatIs(Declared instanceOrStatic)
 {
     InstanceOrStatic = instanceOrStatic;
     return(this);
 }