public void SingleQueueControllerTest()
        {
            var manager = new QueueMessageManagerSql();

            // sample - create 3 message
            for (int i = 0; i < 3; i++)
            {
                var item = new QueueMessageItem()
                {
                    QueueName = "Queue1",
                    Message = "Print Image",
                    Action = "PRINTIMAGE",
                    TextInput = "4334333" // image Id
                };

                // sets appropriate settings for submit on item
                manager.SubmitRequest(item);

                // item has to be saved
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
                Console.WriteLine("added " + manager.Item.Id);
            }

            Console.WriteLine("Starting... Async Manager Processing");

            // create a new Controller to process in the background
            // on separate threads
            var controller = new QueueController()
            {
                ConnectionString = "QueueMessageManager",
                ThreadCount = 2,
                WaitInterval = 200,
                QueueName = "Queue1"
            };
        

            Console.WriteLine("Wait: " + controller.WaitInterval);

            // ExecuteStart Event is where your processing logic goes
            controller.ExecuteStart += controller_ExecuteStart;

            // ExecuteFailed and ExecuteComplete let you take actions on completion
            controller.ExecuteComplete += controller_ExecuteComplete;
            controller.ExecuteFailed += controller_ExecuteFailed;

            // actually start the queue
            controller.StartProcessingAsync();

            // For test we have to keep the threads alive 
            // to allow the 3 requests to process
            Thread.Sleep(2000);

            // shut down
            controller.StopProcessing();

            Thread.Sleep(200);  

            Console.WriteLine("Stopping... Async Manager Processing");
            Assert.IsTrue(true);
        }
示例#2
0
        public void SubmitRequestsToQueueTest()
        {
            var manager    = new QueueMessageManagerSql();
            int queueCount = 30;

            bool res = true;

            for (int i = 0; i < queueCount; i++)
            {
                var msg = new QueueMessageItem()
                {
                    QueueName = "MPWF",
                    Message   = "Xml Message #" + i + " @ " +
                                DateTime.Now.ToString("t"),
                    Action = "NEWXMLORDER"
                };

                if (!manager.SubmitRequest(msg))
                {
                    Console.WriteLine(manager.ErrorMessage);
                }

                res = manager.Save(msg);
                if (!res)
                {
                    break;
                }
            }
        }
        public void SingleQueueControllerTest()
        {
            var manager = new QueueMessageManagerSql();

            // sample - create 3 message
            for (int i = 0; i < 3; i++)
            {
                var item = new QueueMessageItem()
                {
                    QueueName = "Queue1",
                    Message   = "Print Image",
                    Action    = "PRINTIMAGE",
                    TextInput = "4334333" // image Id
                };

                // sets appropriate settings for submit on item
                manager.SubmitRequest(item);

                // item has to be saved
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
                Console.WriteLine("added " + manager.Item.Id);
            }

            Console.WriteLine("Starting... Async Manager Processing");

            // create a new Controller to process in the background
            // on separate threads
            var controller = new QueueController()
            {
                ConnectionString = "QueueMessageManager",
                ThreadCount      = 2,
                WaitInterval     = 200,
                QueueName        = "Queue1"
            };


            Console.WriteLine("Wait: " + controller.WaitInterval);

            // ExecuteStart Event is where your processing logic goes
            controller.ExecuteStart += controller_ExecuteStart;

            // ExecuteFailed and ExecuteComplete let you take actions on completion
            controller.ExecuteComplete += controller_ExecuteComplete;
            controller.ExecuteFailed   += controller_ExecuteFailed;

            // actually start the queue
            controller.StartProcessingAsync();

            // For test we have to keep the threads alive
            // to allow the 3 requests to process
            Thread.Sleep(2000);

            // shut down
            controller.StopProcessing();

            Thread.Sleep(200);

            Console.WriteLine("Stopping... Async Manager Processing");
            Assert.IsTrue(true);
        }
示例#4
0
        public void SubmitRequestTest()
        {
            var manager = new QueueMessageManagerSql();

            string imageId = "10";

            // Create a message object
            // item contains many properties for pushing
            // values back and forth as well as a  few message fields
            var item = manager.CreateItem();

            item.Action          = "PRINTIMAGE";
            item.TextInput       = imageId;
            item.Message         = "Print Image operation started at " + DateTime.Now.ToString();
            item.PercentComplete = 10;

            // *** you can also serialize objects directly into the Xml property
            // manager.Serialization.SerializeToXml(SomeObjectToSerialize);

            // add an arbitrary custom properties - serialized to Xml
            manager.Properties.Add("Time", DateTime.Now);
            manager.Properties.Add("User", "ricks");

            // Set the message status and timestamps as submitted
            manager.SubmitRequest(item);

            // actually save the queue message to disk
            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
示例#5
0
        public void SubmitRequestWithPropertiesTest()
        {
            var manager = new QueueMessageManagerSql();

            manager.SubmitRequest(messageText: "New Entry with Properties");

            // add a custom property
            manager.Properties.Add("Time", DateTime.Now);

            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
        public void SubmitRequestWithPresetObjectTest()
        {
            string xml = "<doc><value>Hello</value></doc>";
            var manager = new QueueMessageManagerSql();

                var msg = new QueueMessageItem()
                {
                    QueueName="MPWF",
                    Message = "Xml Message  @ " + DateTime.Now.ToString("t"),
                    Action = "NEWXMLORDER",                    
                    Xml = xml
                };
                manager.SubmitRequest(msg);
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
示例#7
0
        public void SubmitRequestWithPresetObjectTest()
        {
            string xml     = "<doc><value>Hello</value></doc>";
            var    manager = new QueueMessageManagerSql();

            var msg = new QueueMessageItem()
            {
                QueueName = "MPWF",
                Message   = "Xml Message  @ " + DateTime.Now.ToString("t"),
                Action    = "NEWXMLORDER",
                Xml       = xml
            };

            manager.SubmitRequest(msg);
            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
        public void AddQueueItem()
        {
            var qm = new QueueMessageManagerSql(connectionString);

            var item = new QueueMessageItem()
            {
                Message   = "Single SQL Entry",
                TextInput = "Process This",
                QueueName = "MPWF",
                Action    = "HELLOWORLD",
                Xml       = @"<doc>
    <company>West Wind</company>
    <name>Rick</name>    
</doc>
"
            };

            Assert.IsTrue(qm.SubmitRequest(item, null, true), qm.ErrorMessage);
        }
        public void AddQueueItem()
        {
            var qm = new QueueMessageManagerSql(connectionString);

            var item = new QueueMessageItem()
            {
                Message = "Single SQL Entry",
                TextInput = "Process This",
                QueueName="MPWF",
                Action="HELLOWORLD",
                Xml = @"<doc>
    <company>West Wind</company>
    <name>Rick</name>    
</doc>
" 
            };
            Assert.IsTrue(qm.SubmitRequest(item, null, true), qm.ErrorMessage);
            
        }
        public void AddManyQueueItems()
        {
            var qm = new QueueMessageManagerSql(connectionString);

            for (int i = 0; i < 10; i++)
            {
                var item2 = new QueueMessageItem()
                {
                    Message = "Sql Queue Entry",
                    TextInput = "Process This",
                    QueueName = "MPWF",
                    Action = "GOBIG",
                    Xml = string.Format(@"<doc>
    <company>East Wind</company>
    <name>Rick</name> 
    <time>{0}</time>
</doc>
",DateTime.Now.ToString("MMM dd - HH:mm:ss"))
                };
                Thread.Sleep(300);

                Assert.IsTrue(qm.SubmitRequest(item2, null, true), qm.ErrorMessage);
            }
        }
示例#11
0
        public void GetNextQueueMessageItemWithAddedItemTest()
        {
            using (var manager = new QueueMessageManagerSql())
            {
                // delete all pending requests
                int res = manager.Db.ExecuteNonQuery("delete from queuemessageItems where IsNull(started,'') = '' or started < '01/01/2000'");
                Console.WriteLine(res);

                manager.SubmitRequest(messageText: "Next Complete Test " + DateTime.Now.ToString("t"));
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }

            using (var manager = new QueueMessageManagerSql())
            {
                var item = manager.GetNextQueueMessage();
                Assert.IsNotNull(item, manager.ErrorMessage);

                Console.WriteLine(item.Message);

                manager.CompleteRequest(item, "Next Complete complete " + DateTime.Now.ToString("t"));

                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }
        }
        public void AddManyQueueItems()
        {
            var qm = new QueueMessageManagerSql(connectionString);

            for (int i = 0; i < 10; i++)
            {
                var item2 = new QueueMessageItem()
                {
                    Message   = "Sql Queue Entry",
                    TextInput = "Process This",
                    QueueName = "MPWF",
                    Action    = "GOBIG",
                    Xml       = string.Format(@"<doc>
    <company>East Wind</company>
    <name>Rick</name> 
    <time>{0}</time>
</doc>
", DateTime.Now.ToString("MMM dd - HH:mm:ss"))
                };
                Thread.Sleep(300);

                Assert.IsTrue(qm.SubmitRequest(item2, null, true), qm.ErrorMessage);
            }
        }
        public void SubmitRequestsToQueueTest()
        {
            var manager = new QueueMessageManagerSql();
            int queueCount = 30;

            bool res = true;
            for (int i = 0; i < queueCount; i++)
            {
                var msg = new QueueMessageItem()
                {
                    QueueName = "MPWF",
                    Message = "Xml Message #" + i + " @ " + 
                              DateTime.Now.ToString("t"),
                    Action = "NEWXMLORDER"                                 
                };
                
                if (!manager.SubmitRequest(msg))
                    Console.WriteLine(manager.ErrorMessage);

                res = manager.Save(msg);
                if (!res)
                    break;
            }            
        }
        public void SubmitRequestWithPropertiesTest()
        {
            var manager = new QueueMessageManagerSql();
            manager.SubmitRequest(messageText: "New Entry with Properties");

            // add a custom property
            manager.Properties.Add("Time", DateTime.Now);

            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
示例#15
0
        public void ScaleRetrievalTest()
        {
            var manager = new QueueMessageManagerSql();

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 30000; i++)
            {
                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted
                manager.SubmitRequest(item, autoSave: true);
            }

            Console.WriteLine("Insert time: " + sw.ElapsedMilliseconds);

            IdList   = new List <string>();
            IdErrors = new List <string>();

            for (int i = 0; i < 20; i++)
            {
                var thread = new Thread(ProcessGetNextItem);
                thread.Start();
            }


            for (int i = 0; i < 10000; i++)
            {
                if (CancelProcessing)
                {
                    break;
                }

                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted
                manager.SubmitRequest(item, autoSave: true);

                Thread.Sleep(2);
            }


            Console.WriteLine("Waiting for 5 seconds");
            Thread.Sleep(5000);
            CancelProcessing = true;
            Thread.Sleep(100);

            Console.WriteLine("Done");

            Console.WriteLine("Items processed: " + IdList.Count);

            var grouped = IdList.GroupBy(s => s);

            Console.WriteLine("Unique Count: " + grouped.Count());

            foreach (var error in IdErrors)
            {
                Console.WriteLine("  " + error);
            }
        }
        public void QueueControllerMultipleTest()
        {
            var manager = new QueueMessageManagerSql();

            // sample - create 3 message in 'default' queue
            for (int i = 0; i < 3; i++)
            {
                var item = new QueueMessageItem()
                {
                    Message = "Print Image",
                    Action = "PRINTIMAGE",
                    TextInput = "4334333", // image Id
                    QueueName = "Queue1"
                };

                // sets appropriate settings for submit on item
                manager.SubmitRequest(item);

                // item has to be saved
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
                Console.WriteLine("added to Queue1:" + manager.Item.Id);
            }

            // sample - create 3 message in 'default' queue
            for (int i = 0; i < 3; i++)
            {
                var item = new QueueMessageItem()
                {
                    Message = "Print Image (2nd)",
                    Action = "PRINTIMAGE",
                    TextInput = "5334333", // image Id
                    QueueName = "Queue2"
                };

                // sets appropriate settings for submit on item
                manager.SubmitRequest(item);

                // item has to be saved
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
                Console.WriteLine("added to Queue2: " + manager.Item.Id);
            }

            

            // create a new Controller to process in the background
            // on separate threads
            var controller = new QueueControllerMultiple(new List<QueueController>()
            {
                new QueueControllerMultiple()
                {
                    QueueName = "Queue1",
                    WaitInterval = 300,
                    ThreadCount = 5
                },
                new QueueControllerMultiple()
                {
                    QueueName = "Queue2",
                    WaitInterval = 500,
                    ThreadCount = 3
                }
            });                     
                        

            // Point all controllers at the same execution handlers
            // Alternately you can configure each controller with their
            // own event handlers or implement custom controller subclasses
            // that use the OnXXX handlers to handle the events
            controller.ExecuteStart += controller_ExecuteStart;
            controller.ExecuteComplete += controller_ExecuteComplete;
            controller.ExecuteFailed += controller_ExecuteFailed;
            
            // actually start the queue
            Console.WriteLine("Starting... Async Manager Processing");

            controller.StartProcessingAsync();

            // For test we have to keep the threads alive 
            // to allow the 10 requests to process
            Thread.Sleep(2000);

            // shut down
            controller.StopProcessing();
            
            Thread.Sleep(200);

            Console.WriteLine("Stopping... Async Manager Processing");
            Assert.IsTrue(true);

            Console.WriteLine("Processed: " + controller.MessagesProcessed);
        }
        public void QueueControllerMultipleTest()
        {
            var manager = new QueueMessageManagerSql();

            // sample - create 3 message in 'default' queue
            for (int i = 0; i < 3; i++)
            {
                var item = new QueueMessageItem()
                {
                    Message   = "Print Image",
                    Action    = "PRINTIMAGE",
                    TextInput = "4334333", // image Id
                    QueueName = "Queue1"
                };

                // sets appropriate settings for submit on item
                manager.SubmitRequest(item);

                // item has to be saved
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
                Console.WriteLine("added to Queue1:" + manager.Item.Id);
            }

            // sample - create 3 message in 'default' queue
            for (int i = 0; i < 3; i++)
            {
                var item = new QueueMessageItem()
                {
                    Message   = "Print Image (2nd)",
                    Action    = "PRINTIMAGE",
                    TextInput = "5334333", // image Id
                    QueueName = "Queue2"
                };

                // sets appropriate settings for submit on item
                manager.SubmitRequest(item);

                // item has to be saved
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
                Console.WriteLine("added to Queue2: " + manager.Item.Id);
            }



            // create a new Controller to process in the background
            // on separate threads
            var controller = new QueueControllerMultiple(new List <QueueController>()
            {
                new QueueControllerMultiple()
                {
                    QueueName    = "Queue1",
                    WaitInterval = 300,
                    ThreadCount  = 5
                },
                new QueueControllerMultiple()
                {
                    QueueName    = "Queue2",
                    WaitInterval = 500,
                    ThreadCount  = 3
                }
            });


            // Point all controllers at the same execution handlers
            // Alternately you can configure each controller with their
            // own event handlers or implement custom controller subclasses
            // that use the OnXXX handlers to handle the events
            controller.ExecuteStart    += controller_ExecuteStart;
            controller.ExecuteComplete += controller_ExecuteComplete;
            controller.ExecuteFailed   += controller_ExecuteFailed;

            // actually start the queue
            Console.WriteLine("Starting... Async Manager Processing");

            controller.StartProcessingAsync();

            // For test we have to keep the threads alive
            // to allow the 10 requests to process
            Thread.Sleep(2000);

            // shut down
            controller.StopProcessing();

            Thread.Sleep(200);

            Console.WriteLine("Stopping... Async Manager Processing");
            Assert.IsTrue(true);

            Console.WriteLine("Processed: " + controller.MessagesProcessed);
        }
        public void SubmitRequestTest()
        {
            var manager = new QueueMessageManagerSql();

            string imageId = "10";
           
            // Create a message object
            // item contains many properties for pushing
            // values back and forth as well as a  few message fields
            var item = manager.CreateItem();
            item.Action = "PRINTIMAGE";
            item.TextInput = imageId;
            item.Message = "Print Image operation started at " + DateTime.Now.ToString();
            item.PercentComplete = 10;

            // *** you can also serialize objects directly into the Xml property
            // manager.Serialization.SerializeToXml(SomeObjectToSerialize);

            // add an arbitrary custom properties - serialized to Xml
            manager.Properties.Add("Time", DateTime.Now);
            manager.Properties.Add("User", "ricks");

            // Set the message status and timestamps as submitted             
            manager.SubmitRequest(item);

            // actually save the queue message to disk
            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
        public void GetNextQueueMessageItemWithAddedItemTest()
        {
            using (var manager = new QueueMessageManagerSql())
            {
                // delete all pending requests
                int res = manager.Db.ExecuteNonQuery("delete from queuemessageItems where IsNull(started,'') = '' or started < '01/01/2000'");
                Console.WriteLine(res);

                manager.SubmitRequest(messageText: "Next Complete Test " + DateTime.Now.ToString("t"));
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }

            using (var manager = new QueueMessageManagerSql())
            {
                var item = manager.GetNextQueueMessage();
                Assert.IsNotNull(item, manager.ErrorMessage);

                Console.WriteLine(item.Message);

                manager.CompleteRequest(item, "Next Complete complete " + DateTime.Now.ToString("t"));

                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }
        }
        public void ScaleRetrievalTest()
        {
            var manager = new QueueMessageManagerSql();

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");            

            var sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < 30000; i++)
            {
                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted             
                manager.SubmitRequest(item,autoSave: true);
            }

            Console.WriteLine("Insert time: " + sw.ElapsedMilliseconds);

            IdList = new List<string>();
            IdErrors = new List<string>();

            for (int i = 0; i < 20; i++)
            {
                var thread = new Thread(ProcessGetNextItem);
                thread.Start();
            }


            for (int i = 0; i < 10000; i++)
            {
                if (CancelProcessing)
                    break;

                string imageId = "10";

                // Create a message object
                // item contains many properties for pushing
                // values back and forth as well as a  few message fields
                var item = manager.CreateItem();
                item.QueueName = "Queue1";
                item.TextInput = DataUtils.GenerateUniqueId(15);

                // Set the message status and timestamps as submitted             
                manager.SubmitRequest(item, autoSave: true);

                Thread.Sleep(2);
            }


            Console.WriteLine("Waiting for 5 seconds");
            Thread.Sleep(5000);
            CancelProcessing = true;
            Thread.Sleep(100);

            Console.WriteLine("Done");

            Console.WriteLine("Items processed: " + IdList.Count);

            var grouped = IdList.GroupBy(s => s);
            Console.WriteLine("Unique Count: " + grouped.Count());

            foreach (var error in IdErrors)
                Console.WriteLine("  " + error);

        }