Ejemplo n.º 1
0
 // This thread procedure performs the task.
 static void SendMessage(object stateInfo)
 {
     var key = Guid.NewGuid();
     var client = new HttpDeviceClient(Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName));
     for (int i = 0; i < 10; i++)
     {
         client.SendMessage(key.ToString(), i);
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var client = new HttpDeviceClient(Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName));

            Console.WriteLine("Starting client");
            Console.WriteLine("Started");
            Console.WriteLine("Enter message (key|value) or");
            Console.WriteLine("R for repeating last message or");
            Console.WriteLine("exit for ending or");
            Console.WriteLine("S for simulation mode - stopping with ESC (default R): ");

            while (true)
            {
                string[] line = Console.ReadLine().Split('|');
                if (line.Length == 1 && line[0] == "exit")
                {
                    break;
                }
                if (line.Length == 1 && line[0] == "json")
                {
                    client.SendMessage("{\"Data\":[{\"Time\":\"07 / 12 / 2016 11:47:25\",\"T10\":0},{\"Time\":\"07 / 12 / 2016 11:47:26\",\"T119\":-0.144675925374031,\"T125\":1.30208337306976}]}");
                }
                if (line.Length == 1 && line[0] == "p")
                {
                    for (int i = 0; i < 5; i++)
                    {
                        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMessage));
                    }
                }
                if (line.Length == 1 && line[0].Equals("s", StringComparison.InvariantCultureIgnoreCase))
                {
                    Random rand = new Random(DateTime.Now.Millisecond);
                    do
                    {
                        while (!Console.KeyAvailable)
                        {
                            var value = rand.Next(1, 100);
                            client.SendMessage("T_E_S_T", value);
                            System.Threading.Thread.Sleep(250);
                        }
                    } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
                }
                else if (line.Length == 1 && (string.IsNullOrEmpty(line[0]) || line[0].Equals("R", StringComparison.InvariantCultureIgnoreCase)) && _lastMessage != null)
                {
                    client.SendMessage(_lastMessage[0], _lastMessage[1]);
                }
                else if (line.Length == 2)
                {
                    _lastMessage = line;
                    client.SendMessage(_lastMessage[0], _lastMessage[1]);
                }
            }
        }