Пример #1
0
 private void QueueDeleteIfExist(string name)
 {
     if (MhQueue.IsQueueExist(Name))
     {
         MhQueue.Delete(name);
     }
 }
Пример #2
0
        public void QueueDelete()
        {
            QueueDeleteIfExist(Name);

            MhQueue.Create(Name);
            MhQueue.Delete(Name);
        }
Пример #3
0
        public void MessageGetAll()
        {
            QueueDeleteIfExist(Name);

            var queue    = MhQueue.Create(Name);
            var messages = new List <string> {
                "test 1", "test 2", "test 3"
            };

            foreach (var message in messages)
            {
                queue.Send(message);
            }

            var mhMessages = queue.GetMessages();

            foreach (var mhMessage in mhMessages)
            {
                if (!messages.Contains(mhMessage.Body.ToString()))
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual(mhMessages.Count(), 3);
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Book book = new Book(
                    textBox1.Text,
                    textBox2.Text,
                    textBox3.Text,
                    Convert.ToInt32(textBox4.Text),
                    textBox5.Text,
                    textBox6.Text);
                if (listBox1.SelectedItem != null)
                {
                    string name = listBox1.SelectedItem.ToString();
                    int    pos  = name.LastIndexOf("\\");
                    name = name.Substring(pos + 1, name.Length - pos - 1);
                    MhQueue queue = new MhQueue(name);

                    queue.Send(book);
                }
                else
                {
                    MessageBox.Show("Choose queue");
                }
            }
            catch (Exception er)
            {
            }
        }
Пример #5
0
 private void button2_Click(object sender, EventArgs e)
 {
     listBox1.Items.Clear();
     foreach (MessageQueue q in MhQueue.GetAllQueues())
     {
         listBox1.Items.Add(q.Path);
     }
 }
Пример #6
0
        public void QueueExist()
        {
            QueueDeleteIfExist(Name);

            MhQueue.Create(Name);
            bool isExist = MhQueue.IsQueueExist(Name);

            Assert.IsTrue(isExist);
        }
Пример #7
0
        private void button4_Click(object sender, EventArgs e)
        {
            string name = listBox1.SelectedItem.ToString();
            int    pos  = name.LastIndexOf("\\");

            name = name.Substring(pos + 1, name.Length - pos - 1);
            MhQueue queue = new MhQueue(name);

            queue.Purge();
            button2_Click(sender, e);
        }
Пример #8
0
        public void MessagePeek()
        {
            QueueDeleteIfExist(Name);

            var queue = MhQueue.Create(Name);

            queue.Send("test 1");
            queue.Peek();
            var count = queue.Count;

            Assert.AreEqual(count, 1);
        }
Пример #9
0
        public void MessageSendWithEmptyLabel()
        {
            QueueDeleteIfExist(Name);

            var    queue = MhQueue.Create(Name);
            string msg   = "test";

            queue.Send(msg);
            var count = queue.Count;

            Assert.AreEqual(count, 1);
        }
Пример #10
0
        public void MessagePeekById()
        {
            QueueDeleteIfExist(Name);

            var queue = MhQueue.Create(Name);

            queue.Send("test 1");
            var msg1 = queue.Peek();
            var msg2 = queue.Peek(msg1.Id);

            Assert.AreEqual(msg1.Id, msg2.Id);
        }
Пример #11
0
        public void Purge()
        {
            QueueDeleteIfExist(Name);

            var queue = MhQueue.Create(Name);

            queue.Send("test 1");
            queue.Send("test 2");
            queue.Send("test 2");
            queue.Purge();

            Assert.AreEqual(queue.Count, 0);
        }
Пример #12
0
        public void MessageSend()
        {
            QueueDeleteIfExist(Name);

            var    queue = MhQueue.Create(Name);
            string msg   = "test";
            string label = "group a";

            queue.Send(msg, label);
            var count = queue.Count;

            Assert.AreEqual(count, 1);
        }
Пример #13
0
        public void MessageReceive()
        {
            QueueDeleteIfExist(Name);

            var    queue = MhQueue.Create(Name);
            string msg   = "test";
            string label = "group a";

            queue.Send(msg, label);
            var msgOut = queue.Receive();

            Assert.AreEqual(msg, msgOut.Body);
        }
Пример #14
0
        public void MessageCount()
        {
            QueueDeleteIfExist(Name);

            var queue = MhQueue.Create(Name);

            queue.Send("test 1");
            queue.Send("test 2");
            queue.Send("test 2");
            int count = queue.Count;

            Assert.AreEqual(count, 3);
        }
Пример #15
0
        private static void DeleteQueue()
        {
            try
            {
                Console.WriteLine("\n\tEnter name of queue:");

                string name = Console.ReadLine();
                MhQueue.Delete(name);

                Console.WriteLine($"The {name} was deleted succesfully");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Пример #16
0
        public void MessageReceiveById()
        {
            QueueDeleteIfExist(Name);

            var queue = MhQueue.Create(Name);

            queue.Send("test 1");
            queue.Send("test 2");
            queue.Send("test 3");
            var msgOut = queue.Peek();

            queue.Receive(msgOut.Id);
            var count = queue.Count;

            Assert.AreEqual(count, 2);
        }
Пример #17
0
        private static void PeekMessage()
        {
            try
            {
                Console.WriteLine("\n\tEnter name of queue:");
                string name = Console.ReadLine();

                MhQueue queue   = new MhQueue(name);
                var     message = queue.Peek();

                Console.WriteLine($"Message: {message.Body}    SentTime: {message.SentTime}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Пример #18
0
        public void MessageReceiveByTimePositive()
        {
            QueueDeleteIfExist(Name);
            var      queue   = MhQueue.Create(Name);
            string   msg     = "test";
            TimeSpan timeout = new TimeSpan(0, 0, 3);

            Task.Run(() =>
            {
                Thread.Sleep(1000);
                queue.Send(msg);
            });

            var msgOut = queue.Receive(timeout);

            Assert.AreEqual(msg, msgOut.Body);
        }
Пример #19
0
        private static void DeleteAllMessages()
        {
            try
            {
                Console.WriteLine("\n\tEnter name of queue:");
                string name = Console.ReadLine();

                MhQueue queue = new MhQueue(name);
                queue.Purge();

                Console.WriteLine("Messages were deleted succesfully");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Пример #20
0
        private static void PeekAll()
        {
            try
            {
                Console.WriteLine("\n\tEnter name of queue:");
                string name = Console.ReadLine();

                MhQueue queue = new MhQueue(name);
                IEnumerable <IMhMessage> messages = queue.GetMessages();

                foreach (var message in messages)
                {
                    Console.WriteLine($"Message: {message.Body}    SentTime: {message.SentTime}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Пример #21
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string name = listBox1.SelectedItem.ToString();
                int    pos  = name.LastIndexOf("\\");
                name = name.Substring(pos + 1, name.Length - pos - 1);
                richTextBox1.Text = "";
                MhQueue queue = new MhQueue(name);
                IEnumerable <IMhMessage> messages = queue.GetMessages();

                foreach (var message in messages)
                {
                    richTextBox1.Text += message.Body.ToString();
                }
            }
            catch (Exception ex)
            {
                richTextBox1.Text = ex.Message;
            }
        }
Пример #22
0
        private static void SendMessage()
        {
            try
            {
                Console.WriteLine("\n\tEnter name of queue:");
                string name = Console.ReadLine();
                Console.WriteLine("\n\tEnter message:");
                string message = Console.ReadLine();
                Console.WriteLine("\n\tEnter label:");
                string label = Console.ReadLine();

                MhQueue queue = new MhQueue(name);
                queue.Send(message, label);

                Console.WriteLine($"The {message} was sent succesfully");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Пример #23
0
        public void MessageReceiveByTimeNegative()
        {
            try
            {
                QueueDeleteIfExist(Name);
                var      queue   = MhQueue.Create(Name);
                string   msg     = "test";
                TimeSpan timeout = new TimeSpan(0, 0, 1);

                Task.Run(() =>
                {
                    Thread.Sleep(3000);
                    queue.Send(msg);
                });

                queue.Receive(timeout);
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
        }