private static void ReceiveMessageFromCommandTopic(Guid thingId, int thingCommandTopic, string thingConnectionString) { CommandMessage commandMessage; using (var ta = new ThingsAccess(thingId, thingCommandTopic, thingConnectionString)) { if ((commandMessage = ta.ReceiveCommand(TimeSpan.FromSeconds(5))) != null) { Console.WriteLine("Command: {0}", commandMessage.Command); } } }
private static void SendMessageToIngestionTopic(Guid thingId, int thingCommandTopic, string thingConnectionString) { bool broadcast; Guid?to; using (var ta = new ThingsAccess(thingId, thingCommandTopic, thingConnectionString)) { Console.Write("Content Type: "); switch (Console.ReadLine().ToLower()) { case "event": ta.SendEvent(new EventMessage { Type = "Test", Body = Encoding.Unicode.GetBytes("Hello, Event!") }); break; case "control": Console.Write("Broadcast (y/n): "); broadcast = Console.ReadLine().ToLower() == "y"; if (!broadcast) { Console.Write("To: "); to = new Guid(Console.ReadLine()); } else { to = null; } ta.SendControl(new ControlMessage { Command = "Off", Parameters = null }, to, broadcast); break; case "analytics": ta.SendAnalytics(new AnalyticsMessage { Type = "Test", Body = Encoding.Unicode.GetBytes("Hello, Analytics!") }); break; default: Console.WriteLine("Content Type must be: Event, Control, Analytics"); break; } } }