예제 #1
0
        // Perform queue storage operations.

        static void TestQueueStorage()
        {
            string      storageConnectionString = ConfigurationManager.ConnectionStrings["Storage"].ConnectionString;
            QueueHelper QueueHelper             = new QueueHelper(storageConnectionString);

            try
            {
                Separator();

                List <CloudQueue> queues;
                Console.Write("List queues ");
                if (QueueHelper.ListQueues(out queues))
                {
                    Console.WriteLine("true");
                    if (queues != null)
                    {
                        foreach (CloudQueue queue in queues)
                        {
                            Console.Write(queue.Name + " ");
                        }
                        Console.WriteLine();
                    }
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Create queue ");
                if (QueueHelper.CreateQueue("samplequeue1"))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Delete queue ");
                if (QueueHelper.DeleteQueue("samplequeue0"))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                NameValueCollection metadata = new NameValueCollection();
                metadata.Add("property1", "Value1");
                metadata.Add("property2", "Value2");
                metadata.Add("property3", "Value3");

                Console.Write("Set queue metadata ");
                if (QueueHelper.SetQueueMetadata("samplequeue1", metadata))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Get queue metadata ");
                if (QueueHelper.GetQueueMetadata("samplequeue1", out metadata))
                {
                    Console.WriteLine("true");
                    if (metadata != null)
                    {
                        for (int i = 0; i < metadata.Count; i++)
                        {
                            Console.WriteLine(metadata.GetKey(i) + ": " + metadata.Get(i));
                        }
                    }
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                CloudQueueMessage message = null;

                Console.Write("Peek message ");
                if (QueueHelper.PeekMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Clear messages ");
                if (QueueHelper.ClearMessages("samplequeue1"))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Peek message ");
                if (QueueHelper.PeekMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = new CloudQueueMessage("<Order id=\"1001\">This is test message 1</Order>");

                Console.Write("Put message ");
                if (QueueHelper.PutMessage("samplequeue1", message))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Get message ");
                if (QueueHelper.GetMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Delete message ");
                if (QueueHelper.DeleteMessage("samplequeue1", message))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Get message ");
                if (QueueHelper.GetMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Get message ");
                if (QueueHelper.GetMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION " + ex.ToString());
            }
        }
예제 #2
0
        // Perform queue storage operations.
        private static void TestQueueStorage()
        {
            string storageConnectionString = ConfigurationManager.ConnectionStrings["Storage"].ConnectionString;
            QueueHelper QueueHelper = new QueueHelper(storageConnectionString);

            try
            {
                Separator();

                List<CloudQueue> queues;
                Console.Write("List queues ");
                if (QueueHelper.ListQueues(out queues))
                {
                    Console.WriteLine("true");
                    if (queues != null)
                    {
                        foreach (CloudQueue queue in queues)
                        {
                            Console.Write(queue.Name + " ");
                        }
                        Console.WriteLine();
                    }
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Create queue ");
                if (QueueHelper.CreateQueue("samplequeue1"))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Delete queue ");
                if (QueueHelper.DeleteQueue("samplequeue0"))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                NameValueCollection metadata = new NameValueCollection();
                metadata.Add("property1", "Value1");
                metadata.Add("property2", "Value2");
                metadata.Add("property3", "Value3");

                Console.Write("Set queue metadata ");
                if (QueueHelper.SetQueueMetadata("samplequeue1", metadata))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Get queue metadata ");
                if (QueueHelper.GetQueueMetadata("samplequeue1", out metadata))
                {
                    Console.WriteLine("true");
                    if (metadata != null)
                    {
                        for (int i = 0; i < metadata.Count; i++)
                        {
                            Console.WriteLine(metadata.GetKey(i) + ": " + metadata.Get(i));
                        }
                    }
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                CloudQueueMessage message = null;

                Console.Write("Peek message ");
                if (QueueHelper.PeekMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Clear messages ");
                if (QueueHelper.ClearMessages("samplequeue1"))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Peek message ");
                if (QueueHelper.PeekMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = new CloudQueueMessage("<Order id=\"1001\">This is test message 1</Order>");

                Console.Write("Put message ");
                if (QueueHelper.PutMessage("samplequeue1", message))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Get message ");
                if (QueueHelper.GetMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                Console.Write("Delete message ");
                if (QueueHelper.DeleteMessage("samplequeue1", message))
                {
                    Console.WriteLine("true");
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Get message ");
                if (QueueHelper.GetMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }

                Separator();

                message = null;

                Console.Write("Get message ");
                if (QueueHelper.GetMessage("samplequeue1", out message))
                {
                    Console.WriteLine("true");
                    Console.WriteLine("MessageId: " + message.Id + " popReceipt=" + message.PopReceipt);
                    Console.WriteLine("POPReceipt; " + message.PopReceipt);
                    Console.WriteLine(message.AsString);
                }
                else
                {
                    Console.WriteLine("false");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION " + ex.ToString());
            }
        }