Example #1
0
        public void MessageQueueMessageQueueReaderMethodReadMessagesStopAndReload()
        {
            var mockMsmqRepository = new Moq.Mock <IMsmqRepository>();

            mockMsmqRepository.Setup(x => x.Start()).Raises(
                x => x.MessageQueuesProcessed += null,
                new EngineEventArgs(string.Empty));
            mockMsmqRepository.Setup(x => x.Close());
            mockMsmqRepository.Setup(x => x.GetTotalMessages()).Returns(1);

            // add mock repositories to the container
            ServiceLocator.Container.RegisterInstance <IMsmqRepository>(mockMsmqRepository.Object);
            TestHelper.LoadMockFileSystemRepository();

            string queuePath = "private$\\Testing3";

            MessageQueueReader messageQueueReader = new MessageQueueReader(queuePath, true, ".");

            messageQueueReader.MessageQueuesReaderProcessed += this.MessageQueuesProcessed;
            messageQueueReader.Start(this.TransmitQueueWithTimeout);
            messageQueueReader.Stop();
            messageQueueReader.Reload();

            Assert.IsTrue(true);
        }
Example #2
0
        public void MessageQueueMessageQueueReaderMethodReadMessagesRemote()
        {
            var mockMsmqRepository = new Moq.Mock <IMsmqRepository>();

            mockMsmqRepository.Setup(x => x.Exists(It.IsAny <string>())).Returns(true);
            mockMsmqRepository.Setup(x => x.Create(It.IsAny <string>(), It.IsAny <bool>()));
            mockMsmqRepository.Setup(x => x.WriteMessage(
                                         It.IsAny <string>(),
                                         It.IsAny <object>(),
                                         It.IsAny <bool>(),
                                         It.IsAny <bool>(),
                                         It.IsAny <System.Messaging.IMessageFormatter>()));

            mockMsmqRepository.Setup(x => x.Start()).Raises(
                x => x.MessageQueuesProcessed += null,
                new EngineEventArgs(string.Empty));
            mockMsmqRepository.Setup(x => x.Close());
            mockMsmqRepository.Setup(x => x.GetTotalMessages()).Returns(It.IsAny <int>());
            mockMsmqRepository.Raise(
                x => x.MessageQueuesProcessed += null,
                new EngineEventArgs(It.IsAny <string>()));

            // add mock repositories to the container
            ServiceLocator.Container.RegisterInstance <IMsmqRepository>(mockMsmqRepository.Object);
            TestHelper.LoadMockFileSystemRepository();

            string serverName = "sedidevlab02";
            string queuePath  = "private$\\testing";

            MessageQueueReader messageQueueReader =
                new MessageQueueReader(queuePath, false, serverName);

            Assert.IsTrue(true);
        }
        static async Task Main(string[] args)
        {
            using (var setCache = new SetCache())
                using (var messageQueueReader = new MessageQueueReader <Visit>(new PushCampaignConfiguration(), item => DateTime.Now.ToString("u")))
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Title           = CONSOLE_TITLE;
                    Console.WriteLine($" [--- {CONSOLE_TITLE} ---]");
                    if (VERBOSE)
                    {
                        Console.WriteLine(" [*] Waiting for messages.");
                    }

                    var pushNotificationProviderFactory = new PushNotificationProviderFactory(Console.Out);
                    _campaignPusher = new CampaignPusher(setCache, pushNotificationProviderFactory);

                    var commandResult = await messageQueueReader.StartReadingAsync(HandleData);

                    if (commandResult.IsInvalid)
                    {
                        Console.WriteLine(" Error opening connection to read queue.");
                        Console.ReadLine();
                        return;
                    }

                    if (VERBOSE)
                    {
                        Console.WriteLine(" Press [enter] any time to exit.");
                    }
                    Console.ReadLine();
                }
        }
Example #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="bufferSize">BufferSize can't excess <c>MaxBufferSize = 2000</c></param>
 public SyncQueue(uint bufferSize)
 {
     //synchQ = new Queue();
     bool exist = false;
     /*mReadOnlyQueue = new P2PMessageQueue(true, "rfidQueue", 24, 0, out exist);
     mWriteOnlyQueue = new P2PMessageQueue(false, "rfidQueue", 24, 0, out exist);*/
     mReadOnlyQueue = new MessageQueueReader("rfidMessageQueue", 0, 128);
     mWriteOnlyQueue = new MessageQueueWriter("rfidMessageQueue", 0, 128);
     _cnn = new SQLiteConnection();
     _cnn.ConnectionString = databaseName;
     this.BufferSize = bufferSize;
 }
Example #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SyncQueue()
 {
     //synchQ = new Queue();
     bool exist = false;
     /*mReadOnlyQueue = new P2PMessageQueue(true, "rfidQueue", 24, 0, out exist);
     mReadOnlyQueue.DataOnQueueChanged += new EventHandler(mReadOnlyQueue_DataOnQueueChanged);
     mWriteOnlyQueue = new P2PMessageQueue(false, "rfidQueue", 24, 0, out exist);*/
     mReadOnlyQueue = new MessageQueueReader("rfidMessageQueue", 0, 128);
     mWriteOnlyQueue = new MessageQueueWriter("rfidMessageQueue", 0, 128);
     _cnn = new SQLiteConnection();
     _cnn.ConnectionString = databaseName;
 }
        /// <summary>
        /// Create the message queues and system event.
        /// </summary>
        public void InitQueueEndPoints()
        {
            //Create out reader and writer queues.  Since this queue has a name it is accessible
            // by other programs.
            _writer = new MessageQueueWriter(QueueEndpointName, maxItems, maxMessageSize);

            if (_isReader)
            {
                _reader = new MessageQueueReader(QueueEndpointName, maxItems, maxMessageSize);

                //Create an unnamed event.  This will be used to unblock the read thread
                //when the program is terminating.
                _readerWaitEvent = new SystemEvent(null, false, true);

                Thread readThread = new Thread(new ThreadStart(ReaderThread));
                readThread.IsBackground = true;
                readThread.Start();
            }
        }
        /// <summary>
        /// Create the message queues and system event. 
        /// </summary>
        public void InitQueueEndPoints()
        {
            //Create out reader and writer queues.  Since this queue has a name it is accessible
            // by other programs.
            _writer = new MessageQueueWriter(QueueEndpointName, maxItems, maxMessageSize);

            if (_isReader)
            {
                _reader = new MessageQueueReader(QueueEndpointName, maxItems, maxMessageSize);

                //Create an unnamed event.  This will be used to unblock the read thread
                //when the program is terminating.
                _readerWaitEvent = new SystemEvent(null, false, true);

                Thread readThread = new Thread(new ThreadStart(ReaderThread));
                readThread.IsBackground = true;
                readThread.Start();
            }
        }
Example #8
0
        public void MessageQueueMessageQueueReaderMethodReadMessagesNoTransactional()
        {
            var mockMsmqRepository = new Moq.Mock <IMsmqRepository>();

            mockMsmqRepository.Setup(x => x.Exists(It.IsAny <string>())).Returns(true);
            mockMsmqRepository.Setup(x => x.Create(It.IsAny <string>(), It.IsAny <bool>()));
            mockMsmqRepository.Setup(x => x.WriteMessage(
                                         It.IsAny <string>(),
                                         It.IsAny <object>(),
                                         It.IsAny <bool>(),
                                         It.IsAny <bool>(),
                                         It.IsAny <System.Messaging.IMessageFormatter>()));

            mockMsmqRepository.Setup(x => x.Start()).Raises(
                x => x.MessageQueuesProcessed += null,
                new EngineEventArgs(string.Empty));
            mockMsmqRepository.Setup(x => x.Close());
            mockMsmqRepository.Setup(x => x.GetTotalMessages()).Returns(It.IsAny <int>());
            mockMsmqRepository.Raise(
                x => x.MessageQueuesProcessed += null,
                new EngineEventArgs(It.IsAny <string>()));

            // add mock repositories to the container
            ServiceLocator.Container.RegisterInstance <IMsmqRepository>(mockMsmqRepository.Object);
            TestHelper.LoadMockFileSystemRepository();

            string serverName = Environment.MachineName;
            string queuePath  = "private$\\notrans";

            MessageQueueReader messageQueueReader = new MessageQueueReader(queuePath, false, serverName);

            messageQueueReader.PersistMessageToDisk          = false;
            messageQueueReader.MessageQueuesReaderProcessed += this.MessageQueuesProcessed;
            messageQueueReader.Start(this.TransmitQueue);

            Assert.IsTrue(true);
        }