Ejemplo n.º 1
0
        protected override void HandleTransfer(CAP_CQRSEntities entities, TransferMessage transfer)
        {
            Console.WriteLine(String.Format("Increase {0}.", transfer.ToAccount));

            AccountBalance to = GetAccountEntity(transfer.ToAccount, entities);
            to.Balance += transfer.Amount;
        }
Ejemplo n.º 2
0
        protected override void HandleTransfer(CAP_CQRSEntities entities, TransferMessage transfer)
        {
            Console.WriteLine(String.Format("Decrease {0}.", transfer.FromAccount));

            AccountBalance from = GetAccountEntity(transfer.FromAccount, entities);
            from.Balance -= transfer.Amount;
        }
Ejemplo n.º 3
0
        protected override void HandleTransfer(CAP_CQRSEntities entities, TransferMessage transfer)
        {
            Console.WriteLine(String.Format("Decrease {0}.", transfer.FromAccount));

            AccountBalance from = GetAccountEntity(transfer.FromAccount, entities);

            from.Balance -= transfer.Amount;
        }
Ejemplo n.º 4
0
        protected override void HandleTransfer(CAP_CQRSEntities entities, TransferMessage transfer)
        {
            Console.WriteLine(String.Format("Increase {0}.", transfer.ToAccount));

            AccountBalance to = GetAccountEntity(transfer.ToAccount, entities);

            to.Balance += transfer.Amount;
        }
Ejemplo n.º 5
0
 protected static AccountBalance GetAccountEntity(string account, CAP_CQRSEntities entities)
 {
     IQueryable<AccountBalance> query =
         from b in entities.AccountBalances
         where b.Account == account
         select b;
     AccountBalance entity = query.FirstOrDefault();
     if (entity == null)
         throw new ApplicationException("No such account.");
     return entity;
 }
Ejemplo n.º 6
0
        protected static AccountBalance GetAccountEntity(string account, CAP_CQRSEntities entities)
        {
            IQueryable <AccountBalance> query =
                from b in entities.AccountBalances
                where b.Account == account
                select b;
            AccountBalance entity = query.FirstOrDefault();

            if (entity == null)
            {
                throw new ApplicationException("No such account.");
            }
            return(entity);
        }
Ejemplo n.º 7
0
        private void ThreadProc()
        {
            while (!_stopping.WaitOne(10))
            {
                try
                {
                    using (CAP_CQRSEntities entities = new CAP_CQRSEntities())
                    {
                        using (var tx = new TransactionScope())
                        {
                            using (MessageQueue queue = new MessageQueue(_queueName))
                            {
                                Message message = queue.Receive(TimeSpan.FromSeconds(1.0), MessageQueueTransactionType.Automatic);
                                _wroteEmptyMessage = false;

                                message.Formatter = Formatter;
                                TransferMessage transfer = (TransferMessage)message.Body;

                                HandleTransfer(entities, transfer);

                                entities.SaveChanges();
                                tx.Complete();
                            }
                        }
                    }
                }
                catch (MessageQueueException mqex)
                {
                    if (mqex.ErrorCode != TimeoutErrorCode)
                    {
                        Console.WriteLine(mqex.Message);
                    }
                    else
                    {
                        if (!_wroteEmptyMessage)
                        {
                            Console.WriteLine(String.Format("{0} queue empty.", _threadName));
                        }
                        _wroteEmptyMessage = true;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Ejemplo n.º 8
0
 protected abstract void HandleTransfer(CAP_CQRSEntities entities, TransferMessage transfer);
Ejemplo n.º 9
0
        private void ThreadProc()
        {
            while (!_stopping.WaitOne(10))
            {
                try
                {
                    using (CAP_CQRSEntities entities = new CAP_CQRSEntities())
                    {
                        using (var tx = new TransactionScope())
                        {
                            using (MessageQueue queue = new MessageQueue(_queueName))
                            {
                                Message message = queue.Receive(TimeSpan.FromSeconds(1.0), MessageQueueTransactionType.Automatic);
                                _wroteEmptyMessage = false;

                                message.Formatter = Formatter;
                                TransferMessage transfer = (TransferMessage)message.Body;

                                HandleTransfer(entities, transfer);

                                entities.SaveChanges();
                                tx.Complete();
                            }
                        }
                    }
                }
                catch (MessageQueueException mqex)
                {
                    if (mqex.ErrorCode != TimeoutErrorCode)
                        Console.WriteLine(mqex.Message);
                    else
                    {
                        if (!_wroteEmptyMessage)
                            Console.WriteLine(String.Format("{0} queue empty.", _threadName));
                        _wroteEmptyMessage = true;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Ejemplo n.º 10
0
 protected abstract void HandleTransfer(CAP_CQRSEntities entities, TransferMessage transfer);