예제 #1
0
        public void SynchronousSendReceiveTest()
        {
            string  messageToSend = "This is a test message";
            Message outbound      = new Message(Encoding.ASCII.GetBytes(messageToSend));

            string queueName = "queue";

            P2PMessageQueue sendQueue = new P2PMessageQueue(false, queueName);

            Assert.IsNotNull(sendQueue, "ctor failed");

            P2PMessageQueue recvQueue = new P2PMessageQueue(true, queueName);

            Assert.IsNotNull(recvQueue, "ctor failed");

            Message inbound = new Message();

            ReadWriteResult result = sendQueue.Send(outbound);

            Assert.AreEqual(result, ReadWriteResult.OK, "Send failed");

            Assert.AreEqual(recvQueue.MessagesInQueueNow, 1, "MessagesInQueueNow failure (not added)");

            result = recvQueue.Receive(inbound, 1000);
            Assert.AreEqual(result, ReadWriteResult.OK, "Message was not received");

            string messageReceived = Encoding.ASCII.GetString(inbound.MessageBytes, 0, inbound.MessageBytes.Length);

            Assert.AreEqual(messageToSend, messageReceived, "Received data did not match sent data");

            Assert.AreEqual(recvQueue.MessagesInQueueNow, 0, "MessagesInQueueNow failure (not removed)");
            Assert.AreEqual(recvQueue.MostMessagesSoFar, 1, "MostMessagesSoFar failure");
        }
예제 #2
0
        void m_queue_DataOnQueueChanged(object sender, EventArgs e)
        {
            var msg = new TraceMessage(m_serializer);

            try
            {
                Thread.Sleep(100);
                var result = m_queue.Receive(msg);

                if (result == ReadWriteResult.OK)
                {
                    OnMessage.Fire(this, new GenericEventArgs <TraceMessage>(msg));
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #3
0
        protected override void checkForMessage()
        {
            Message         message  = new Message();
            ReadWriteResult result   = m_fromClientQueue.Receive(message);
            IClientMethod   clMethod = null;

            if (result == ReadWriteResult.OK)
            {
                string data = Encoding.UTF8.GetString(message.MessageBytes, 0, message.MessageBytes.GetLength(0));

                Logger.Write("receive data from client: " + data);

                clMethod = (IClientMethod)m_methodSelector.selectMethod(data);

                clMethod.setQueueForAnswer(m_toClientQueue);
            }

            processMessage(clMethod);
        }
예제 #4
0
            protected override void checkForMessage()
            {
                Message         message = new Message();
                ReadWriteResult result  = m_serviceClientQueue.Receive(message);
                //ReadWriteResult result = ReadWriteResult.OK;
                IServerCommand clMethod = null;

                if (result == ReadWriteResult.OK)
                {
                    string data = Encoding.UTF8.GetString(message.MessageBytes, 0, message.MessageBytes.GetLength(0));
                    //string data = "{ \"Name\": \"registerClient\", \"PrinterID\": \"\", \"rhoString\": \"manual_common_spec\" }";

                    Logger.Write("[manager] receive data from client: " + data);

                    clMethod = (IServerCommand)m_methodSelector.selectMethod(data);
                }

                processMessage(clMethod);
            }
예제 #5
0
        void DataOnQueueChanged(object sender, EventArgs e)
        {
            while (m_ndisQueue != null && m_ndisQueue.MessagesInQueueNow > 0)
            {
                // Each notification will be of this type.
                NDISUIO_DEVICE_NOTIFICATION notification = new NDISUIO_DEVICE_NOTIFICATION();

                // Read the event data.
                if (m_ndisQueue.Receive(notification, -1) == ReadWriteResult.OK)
                {
                    if (InterfaceStatusChange != null)
                    {
                        InterfaceStatusChange(notification.ptcDeviceName, (InterfaceStatus)(notification.dwNotificationType & 0x3F));
                    }
                }
                else
                {
                    TeardownQueueListener();
                    throw new System.IO.IOException("Fatal error receiving data from the NDIS notification queue");
                }
            }
        }
예제 #6
0
        public static void checkForMessage()
        {
            ///if (Settings.Instance.InstanceId == null) continue;
            Message         message = new Message();
            ReadWriteResult result  = queue.Receive(message);

            if (result == ReadWriteResult.OK)
            {
                string  data = Encoding.UTF8.GetString(message.MessageBytes, 0, message.MessageBytes.GetLength(0));
                AppInfo ai   = JsonConvert.DeserializeObject <AppInfo>(data);
                Debug.WriteLine("Received Command: " + data + ", " + DateTime.Now.ToString());

                // find if we already have ai with matching key and use it
                ai = Settings.Instance.findAndUpdateAppInfo(ai);

                Debug.WriteLine("AppInfo: " + ai.User + ", " + ai.Pass + ", at " + DateTime.Now.ToString());

                //int index = Settings.Instance.getServerIndexByToken(ai.Token);
                int index = Settings.Instance.getServerIndexByUrl(ai.ServerUrl);
                if (index == -1)
                {
                    Settings.Instance.Servers.Add(new ServerInfo(ai.ServerUrl, ai.User, ai.Pass));
                    Settings.Save(Settings.Instance);
                    serverThreads.Add(new ServerThread(Settings.Instance, Settings.Instance.Servers.Count() - 1));
                    index = serverThreads.Count() - 1;
                }

                if (ai.Command.Equals("Register"))
                {
                    serverThreads[index].Register(ai);
                }
                else if (ai.Command.Equals("Unregister"))
                {
                    serverThreads[index].Unregister(ai);
                }
            }
        }
예제 #7
0
 void p2pmq_DataOnQueueChanged(object sender, EventArgs e)
 {
     try
     {
         // Read the event data.
         while (m_p2pmq != null && m_p2pmq.MessagesInQueueNow > 0)
         {
             DeviceDetail devDetail = new DeviceDetail();
             if (m_p2pmq.Receive(devDetail, 0) == ReadWriteResult.OK)
             {
                 // Handle the event.
                 OnDeviceNotification(new DeviceNotificationArgs(devDetail.guidDevClass, devDetail.fAttached, devDetail.szName));
             }
             else
             {
                 this.StopStatusMonitoring();
             }
         }
     }
     catch (ApplicationException)
     {
         this.StopStatusMonitoring();
     }
 }