Example #1
0
        public void ReceiveLastMessage()
        {
            Trace.WriteLine("Start Receiving and sending last message from Queue", "ReceiveLastMessage");

            List <Message> messages = mq.GetAllMessages().ToList();

            if (messages.Count > 0)
            {
                Message lastMessage = messages.Last();

                QueueMessage queueMessage = (QueueMessage)mq.ReceiveById(lastMessage.Id).Body;
                String       errorMessage = String.Empty;

                // Get byte array from file
                VanLeeuwen.Framework.IO.File.WaitForRelease(queueMessage.FilePath, 10);
                byte[] fileContents = File.ReadAllBytes(queueMessage.FilePath);

                if (FileSender.SendFile(queueMessage.DatabaseName, fileContents, queueMessage.FileName, out errorMessage))
                {
                    // Succesfully Send!!!
                    // remove file from Queue folder
                    File.Delete(queueMessage.FilePath);
                }
                else
                {
                    AddMessage(queueMessage);
                }

                Trace.WriteLine("Receiving and sending last message from Queue completed", "ReceiveLastMessage");
            }
        }
Example #2
0
        public void BeginReceive()
        {
            Trace.WriteLine("Start receiving and sending messages from Queue", "BeginReceive");

            List <Message> messages = mq.GetAllMessages().ToList();

            foreach (Message message in messages)
            {
                QueueMessage queueMessage = (QueueMessage)mq.Receive().Body;
                String       errorMessage = String.Empty;

                // Get byte array from file
                VanLeeuwen.Framework.IO.File.WaitForRelease(queueMessage.FilePath, 10);
                byte[] fileContents = File.ReadAllBytes(queueMessage.FilePath);

                if (FileSender.SendFile(queueMessage.DatabaseName, fileContents, queueMessage.FileName, out errorMessage))
                {
                    // Succesfully Send!!!
                    // remove file from Queue folder
                    File.Delete(queueMessage.FilePath);
                }
                else
                {
                    // Add to Queue
                    if (queueMessage.NumberOfTries <= this.maxQueueRetry)
                    {
                        AddMessage(queueMessage);
                    }
                    else
                    {
                        MessageFailed(queueMessage);
                    }
                }
            }

            Trace.WriteLine("Receiving and sending messages from Queue completed", "BeginReceive");
        }