public Delivery(Guid pId, string pUserFrom, string pCustomerName, string pPhone, string pAddress, DateTime pCommitTime, DateTime pDeliveryTime, DeliveryState pState, List<DishQuota> pDishQuotaList)
        {
            id = pId;
            userFrom = pUserFrom;
            customerName = pCustomerName;
            phone = pPhone;
            address = pAddress;
            commitTime = pCommitTime;
            deliveryTime = pDeliveryTime;

            state = pState;
            dishQuotaList = pDishQuotaList;
        }
        public void CompleteDelivery(Guid pId, string pUserFrom, string pCustomerName, string pPhone, string pAddress, DateTime pCommitTime, DateTime pDeliveryTime, DeliveryState pState)
        {
            id = pId;
            userFrom = pUserFrom;
            customerName = pCustomerName;
            phone = pPhone;
            address = pAddress;
            commitTime = pCommitTime;
            deliveryTime = pDeliveryTime;

            state = pState;
        }
        public void ChangeState(DeliveryState pState)
        {
            state = pState;

            //~ synchronize to db, if need to maintain the state in db
            DataContextDataContext dc = new DataContextDataContext();
            dc.update_state_delivery(id, (int?)state);
        }
Exemplo n.º 4
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);
                }
            }
Exemplo n.º 5
0
                static void OnMessage(ListenerLink link, Message message, DeliveryState deliveryState, object state)
                {
                    var thisPtr = (Publisher)state;
                    string errorCondition = null;
                    if (message.ApplicationProperties != null &&
                        (errorCondition = (string)message.ApplicationProperties["errorcondition"]) != null)
                    {
                        link.DisposeMessage(
                            message,
                            new Rejected() { Error = new Error() { Condition = errorCondition, Description = "message was rejected" } },
                            true);
                    }
                    else
                    {
                        var txnState = deliveryState as TransactionalState;
                        if (txnState != null)
                        {
                            Transaction txn = thisPtr.queue.broker.txnManager.GetTransaction(txnState.TxnId);
                            txn.AddOperation(message, onDischarge, thisPtr);
                            txnState.Outcome = new Accepted();
                        }
                        else
                        {
                            thisPtr.queue.Enqueue((BrokerMessage)message);
                            deliveryState = new Accepted();
                        }

                        thisPtr.link.DisposeMessage(message, deliveryState, true);
                    }
                }
Exemplo n.º 6
0
 static void OnDispose(Message message, DeliveryState deliveryState, bool settled, object state)
 {
     var thisPtr = (Consumer)state;
     if (deliveryState is TransactionalState)
     {
         Transaction txn = thisPtr.queue.broker.txnManager.GetTransaction(((TransactionalState)deliveryState).TxnId);
         txn.AddOperation(message, onDischarge, thisPtr);
     }
     else
     {
         if (deliveryState is Released)
         {
             thisPtr.queue.Unlock((BrokerMessage)message);
         }
         else
         {
             thisPtr.queue.Dequeue((BrokerMessage)message);
         }
     }
 }