Example #1
0
        static void Main(string[] args)
        {
            List <Disposable> ThingsToDispose;

            ThingsToDispose = new List <Disposable>();
            const string   Broker       = "tcp://10.197.10.32:61616";
            const string   SubTopicName = "SNP.Inbound";
            TopicPublisher MainPublisher;//publishes to the Pac-Light Outbound topic

            MainPublisher = new TopicPublisher(SubTopicName, Broker);
            ThingsToDispose.Add(new Disposable(nameof(MainPublisher), MainPublisher));
            string rootFolder = @"C:\Users\d.paddock\Desktop\";
            string textFile   = @"Messages.txt";

            string[] lines = null;
            try
            {
                lines = File.ReadAllLines(rootFolder + textFile);
                foreach (string line in lines)
                {
                    MainPublisher.SendMessage(line);
                    Thread.Sleep(100);
                }
            }
            catch
            {
            }
            foreach (Disposable disposable in ThingsToDispose)
            {
                disposable.Dispose();
            }
        }
Example #2
0
 public void TestPublish()
 {
     using (IMessageSender publisher = new TopicPublisher(BROKER, TOPIC_NAME))
     {
         publisher.Start();
         for (int i = 0; i < 5; i++)
         {
             publisher.SendMessage("This is an unit test #" + (i + 1));
             //Thread.Sleep(1000);
         }
     }
 }
Example #3
0
        public void Save(TopicPublisher publisher)
        {
            string Message = "ý     { \"Machine\":\"" + MachineName + "\",\"Theo\":\"" + Theoretical.ToString() + "\", \"Line\":\"" + Line + "\", \"Engineer\":\"" + Engineer + "\",\"Errors\": \"";

            foreach (string error in NewErrors)
            {
                Message += error + ",";
            }
            Message  = Message.Substring(0, Message.Length - 1);
            Message += "\"}";
            publisher.SendMessage(Message);
        }
Example #4
0
 public void Delete(TopicPublisher publisher)
 {
     publisher.SendMessage("ü     {\"Machine\": \"" + MachineName + "\", \"Line\":\"" + Line + "\"}");
 }
Example #5
0
 /// <summary>
 /// MQTT Section of the EMP Warning Packet.
 /// </summary>
 private void MQTTEMPWarningPacket(string message)
 {
     Publisher.SendMessage(message);                                                             //forward it to the warning topic
 }
Example #6
0
        public void ReadCallback(IAsyncResult ar)
        {
            string content = String.Empty;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = ar.AsyncState as StateObject;
            Socket      handler = state.workSocket;
            SocketError sckErr;
            // Read data from the client socket.
            int bytesRaed = handler.EndReceive(ar, out sckErr);

            if (sckErr != SocketError.Success)
            {
                return;
            }
            if (bytesRaed > 0)
            {
                // There  might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRaed));

                // Check for end-of-file tag. If it is not there, read
                // more data.
                content = state.sb.ToString();

                if (content.IndexOf("true") > -1)
                {
                    string         brokerURL   = "tcp://10.27.68.155:61616";//localhost:61616";
                    string         destination = "BankAlive";
                    IMessageSender publisher   = new TopicPublisher(brokerURL, destination);
                    publisher.Start();
                    publisher.SendMessage <string>("true");
                    // All the data has been read from the
                    // client. Display it on the console.
                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
                                      content.Length, content);

                    // Echo the data back to the client.
                    Send(handler, content);
                }
                else if (content.IndexOf("false") > -1)
                {
                    string         brokerURL   = "tcp://10.27.68.155:61616";//"tcp://localhost:61616";
                    string         destination = "BankAlive";
                    IMessageSender publisher   = new TopicPublisher(brokerURL, destination);
                    publisher.Start();
                    publisher.SendMessage <string>("false");
                    // All the data has been read from the
                    // client. Display it on the console.
                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
                                      content.Length, content);

                    // Echo the data back to the client.
                    Send(handler, content);
                }
                else
                {
                    // Not all data received. Get more.
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, new AsyncCallback(ReadCallback), state);
                }
            }
        }