Beispiel #1
0
            public void Work(object state)
            {
                IGraphable data                 = (IGraphable)state;
                MessageQueueTransaction tx      = null;
                IFormatterGraphResult   gResult = null;

                try
                {
                    // Create a message and prepare for sending
                    Message msg = new Message();
                    Result = new MsmqSendResult();

                    // Format and prepare result
                    gResult        = Formatter.Graph(msg.BodyStream, data);
                    Result.Code    = gResult.Code;
                    Result.Details = gResult.Details;

                    // Accepted messages get sent
                    if (Result.Code == ResultCode.Accepted || Result.Code == ResultCode.AcceptedNonConformant)
                    {
                        // Create a transaction if the queue is transactional
                        if (Queue.Transactional)
                        {
                            tx = new MessageQueueTransaction();
                            tx.Begin();
                        }

                        // Publish
                        if (tx != null)
                        {
                            Queue.Send(msg, tx);
                        }
                        else
                        {
                            Queue.Send(msg);
                        }

                        // Commit the transaction
                        if (tx != null)
                        {
                            tx.Commit();
                        }
                    }
                }
                catch (MessageValidationException e)
                {
                    Result.Code = ResultCode.Rejected;
                    List <IResultDetail> dtl = new List <IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) });
                    dtl.AddRange(gResult.Details ?? new IResultDetail[0]);
                    Result.Details = dtl.ToArray();
                    if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending)
                    {
                        tx.Abort();
                    }
                }
                catch (FormatException e)
                {
                    Result.Code    = ResultCode.Rejected;
                    Result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                    if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending)
                    {
                        tx.Abort();
                    }
                }
                catch (Exception e)
                {
                    Result.Code    = ResultCode.Error;
                    Result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                    if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending)
                    {
                        tx.Abort();
                    }
                }
                finally
                {
                }

                // Fire completed event
                if (Completed != null)
                {
                    Completed(this);
                }
            }
            public void Work(object state)
            {
                IGraphable data = (IGraphable)state;
                MessageQueueTransaction tx = null;
                IFormatterGraphResult gResult = null;

                try
                {
                    // Create a message and prepare for sending
                    Message msg = new Message();
                    Result = new MsmqSendResult();

                    // Format and prepare result
                    gResult = Formatter.Graph(msg.BodyStream, data);
                    Result.Code = gResult.Code;
                    Result.Details = gResult.Details;

                    // Accepted messages get sent
                    if (Result.Code == ResultCode.Accepted || Result.Code == ResultCode.AcceptedNonConformant)
                    {
                        // Create a transaction if the queue is transactional
                        if (Queue.Transactional)
                        {
                            tx = new MessageQueueTransaction();
                            tx.Begin();
                        }

                        // Publish
                        if (tx != null) Queue.Send(msg, tx);
                        else Queue.Send(msg);

                        // Commit the transaction
                        if (tx != null) tx.Commit();
                    }
                    
                }
                catch (MessageValidationException e)
                {
                    Result.Code = ResultCode.Rejected;
                    List<IResultDetail> dtl = new List<IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) });
                    dtl.AddRange(gResult.Details ?? new IResultDetail[0]);
                    Result.Details = dtl.ToArray();
                    if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending) tx.Abort();
                }
                catch (FormatException e)
                {
                    Result.Code = ResultCode.Rejected;
                    Result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                    if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending) tx.Abort();
                }
                catch (Exception e)
                {
                    Result.Code = ResultCode.Error;
                    Result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                    if (tx != null && tx.Status == MessageQueueTransactionStatus.Pending) tx.Abort();
                }
                finally
                {
                }

                // Fire completed event
                if (Completed != null) Completed(this);
            }