Exemplo n.º 1
0
        public void SubmitRequestsToQueueTest()
        {
            var manager    = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);
            int queueCount = 10;

            bool res = true;

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

                manager.SubmitRequest(msg);

                res = manager.Save(msg);
                if (!res)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void SubmitRequestTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);

            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);
        }
Exemplo n.º 3
0
        public void GetNextQueueMessageItemWithAddedItemTest()
        {
            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH))
            {
                // delete all pending requests
                int res = manager.Db.ExecuteNonQuery("delete from queuemessageItems where started is null");
                Console.WriteLine(res);

                // delete all queued ids - otherwise no items will match :-)
                var queue = manager.GetQueue("");
                queue.Purge();

                // creates sql and msmq items
                manager.SubmitRequest(messageText: "Next Complete Test " + DateTime.Now.ToString("t"));
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }

            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH))
            {
                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);
            }
        }
Exemplo n.º 4
0
        public void LoadRequestTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);
            var db      = manager.Db;

            var item = db.Find <QueueMessageItem>("select TOP 1 * from queueMessageItems where Started is null");

            // no pending items - nothing to do
            if (item == null)
            {
                Console.WriteLine("No pending items... nothing to do.");
                return;
            }

            string reqId = item.Id;

            // clear out item
            item = null;

            // load through manager
            item = manager.Load(reqId);

            Assert.IsNotNull(item, manager.ErrorMessage);

            item.Message         = "Updated @ " + DateTime.Now.ToString("t");
            item.PercentComplete = 10;

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

            var item = qm.GetNextQueueMessage("MPWF");

            Console.WriteLine(qm.ErrorMessage);
            Console.WriteLine(JsonSerializationUtils.Serialize(item, true));
        }
Exemplo n.º 6
0
        public void SubmitRequestWithPropertiesTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);

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

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

            Assert.IsTrue(manager.Save(), manager.ErrorMessage);
        }
Exemplo n.º 7
0
 public void GetRecentMessagesTest()
 {
     using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH))
     {
         var items = manager.GetRecentQueueItems();
         foreach (var item in items)
         {
             Console.WriteLine(item.Id + " " + item.Message);
         }
     }
 }
Exemplo n.º 8
0
        public void ConstructorOverrideTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);

            Console.WriteLine(manager.ConnectionString);
            Assert.IsTrue(manager.ConnectionString == CONNECTION_STRING, "ConnectionString is not set");


            manager = new QueueMessageManagerSqlMsMq("MyApplicationConnectionString", BASE_QUEUE_PATH);
            Console.WriteLine(manager.ConnectionString);
            Assert.IsTrue(manager.ConnectionString == "MyApplicationConnectionString");
        }
        public void ConstructorOverrideTest()
        {

            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);
            Console.WriteLine(manager.ConnectionString);
            Assert.IsTrue(manager.ConnectionString == CONNECTION_STRING,"ConnectionString is not set");


            manager = new QueueMessageManagerSqlMsMq("MyApplicationConnectionString",BASE_QUEUE_PATH);
            Console.WriteLine(manager.ConnectionString);
            Assert.IsTrue(manager.ConnectionString == "MyApplicationConnectionString");
        }
        public void SubmitRequestWithPresetObjectTest()
        {
            string xml = "<doc><value>Hello</value></doc>";
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);

                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);
        }
Exemplo n.º 11
0
        public void SubmitRequestWithPresetObjectTest()
        {
            string xml     = "<doc><value>Hello</value></doc>";
            var    manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);

            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 AddManyQueueSqlMsMqItems()
        {
            var qm = new QueueMessageManagerSqlMsMq(connectionString);

            qm.MsMqQueuePath = @".\Private$\";

            for (int i = 0; i < 10; i++)
            {
                var item2 = new QueueMessageItem()
                {
                    Message   = "MSMQ New Entry",
                    TextInput = "Process This",
                    QueueName = "MPWF",
                    Action    = "HELLOWORLD",
                    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);
            }

            for (int i = 0; i < 10; i++)
            {
                var item2 = new QueueMessageItem()
                {
                    Message   = "MSMQ New Entry",
                    TextInput = "Process This",
                    QueueName = "MPWF_VFP",
                    Action    = "HELLOWORLD",
                    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);
            }
        }
Exemplo n.º 13
0
        void ProcessGetNextItem()
        {
            while (!CancelProcessing)
            {
                var manager = new QueueMessageManagerSqlMsMq();
                var item    = manager.GetNextQueueMessage("Queue1");
                if (item != null)
                {
                    lock (GetNextItemLock)
                    {
                        IdList.Add(item.Id);
                    }
                }
                else
                {
                    IdErrors.Add(manager.ErrorMessage);
                }

                Thread.Yield();
            }
        }
        public void SubmitRequestsToQueueTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);
            int queueCount = 10;

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

                manager.SubmitRequest(msg);

                res = manager.Save(msg);
                if (!res)
                    break;
            }
            
        }
        public void SubmitRequestWithPropertiesTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);
            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 GetNextQueueMessageItemWithAddedItemTest()
        {
            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH))
            {
                // delete all pending requests
                int res = manager.Db.ExecuteNonQuery("delete from queuemessageItems where started is null");
                Console.WriteLine(res);

                // delete all queued ids - otherwise no items will match :-)
                var queue = manager.GetQueue("");
                queue.Purge();

                // creates sql and msmq items
                manager.SubmitRequest(messageText: "Next Complete Test " + DateTime.Now.ToString("t"));
                Assert.IsTrue(manager.Save(), manager.ErrorMessage);
            }

            using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH))
            {
                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()
        {
            string queueName = "Queue1";

            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");
            manager.GetQueue(queueName).Purge();

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

            for (int i = 0; i < 40000; 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 = queueName;
                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();
            }

            //Task.Run(() =>
            //{
            //    for (int i = 0; i < 100; i++)
            //    {
            //        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.QueueName = "Queue1";
            //        item.TextInput = DataUtils.GenerateUniqueId(15);

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

            //    Thread.Sleep(60);
            //});

            for (int i = 0; i < 500; 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 = queueName;
                item.TextInput = DataUtils.GenerateUniqueId(15);

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

                Thread.Sleep(4);
            }


            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);

        }
        void ProcessGetNextItem()
        {
            while (!CancelProcessing)
            {
                var manager = new QueueMessageManagerSqlMsMq();
                var item = manager.GetNextQueueMessage("Queue1");
                if (item != null)
                    lock (GetNextItemLock)
                    {
                        IdList.Add(item.Id);
                    }
                else
                    IdErrors.Add(manager.ErrorMessage);

                Thread.Yield();
            }
        }        
 public void GetRecentMessagesTest()
 {
     using (var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH))
     {
         var items = manager.GetRecentQueueItems();
         foreach (var item in items)
         {
             Console.WriteLine(item.Id + " " + item.Message);
         }
     }          
 }
        public void SubmitRequestTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);

            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);
        }
Exemplo n.º 21
0
        public void ScaleRetrievalTest()
        {
            string queueName = "Queue1";

            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING, BASE_QUEUE_PATH);

            manager.Db.ExecuteNonQuery("delete from queuemessageitems");
            manager.GetQueue(queueName).Purge();

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 40000; 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 = queueName;
                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();
            }

            //Task.Run(() =>
            //{
            //    for (int i = 0; i < 100; i++)
            //    {
            //        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.QueueName = "Queue1";
            //        item.TextInput = DataUtils.GenerateUniqueId(15);

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

            //    Thread.Sleep(60);
            //});

            for (int i = 0; i < 500; 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 = queueName;
                item.TextInput = DataUtils.GenerateUniqueId(15);

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

                Thread.Sleep(4);
            }


            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 LoadRequestTest()
        {
            var manager = new QueueMessageManagerSqlMsMq(CONNECTION_STRING,BASE_QUEUE_PATH);
            var db = manager.Db;

            var item = db.Find<QueueMessageItem>("select TOP 1 * from queueMessageItems where Started is null");

            // no pending items - nothing to do
            if (item == null)
            {
                Console.WriteLine("No pending items... nothing to do.");
                return;
            }

            string reqId = item.Id;

            // clear out item
            item = null;

            // load through manager
            item = manager.Load(reqId);

            Assert.IsNotNull(item, manager.ErrorMessage);

            item.Message = "Updated @ " + DateTime.Now.ToString("t");
            item.PercentComplete = 10;            
            
            Assert.IsTrue(manager.Save(), manager.ErrorMessage);            
        }