/// <summary> /// Initiates a call to pull available gateways from Air Mesh. All found gateways will be placed on an Azure Queue to be picked up by /// the Controllers Web Job /// </summary> /// <param name="timer"></param> /// <param name="log"></param> public static void PollGateways([TimerTrigger("00:15:00", RunOnStartup = true, UseMonitor = true)] TimerInfo timer, TextWriter log) { try { // Fire up Air Mesh API... var airMesh = new AirMeshService(log); // Get the available sites var siteIDs = airMesh.GetSiteIDs(); // Get the Gateways for each site var gateways = airMesh.GetGateways(siteIDs); // Get the Azure Queue... var queue = QueueService.GetQueue(Constants.REAL_TIME_DEVICE_QUEUE); // Push the Gateways onto the queue foreach (var gateway in gateways) { queue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(gateway))); } } catch (Exception ex) { // TODO: Format logging log.WriteAsync(ex.ToString()); } }
/// <summary> /// Listens on the Azure queue realtimedevicequeue[ENVRIONMENT] /// </summary> /// <param name="gateway">The Gateway to pull controller statuses from</param> /// <param name="log">Azure L</param> public static void ProcessRealtimeQueueMessage([QueueTrigger(Constants.REAL_TIME_DEVICE_QUEUE_TRIGGER)] Gateway gateway, TextWriter log) { try { var ingressService = new IngressService(log); var airMeshService = new AirMeshService(log); foreach (var controllerStatus in airMeshService.GetControllerStatusForGateway(gateway)) { // Check if we have registered this device, if not let's do it... if (!RegisteredDeviceService.IsDeviceRegistered(controllerStatus.UUID)) { // TODO: Confirm this pattern -> Should we poll devices at startup, and get them registered before RegisteredDeviceService.RegisterDevice(controllerStatus.UUID); ingressService.PushDataToPlatform(D2CAPI.DeviceTree, controllerStatus.Controller.controller_id, controllerStatus.GetDeviceTree()); } // Push Realtimes... ingressService.PushDataToPlatform(D2CAPI.Realtimes, controllerStatus.Controller.controller_id, controllerStatus.GetRealTimes()); // Push Trends... ingressService.PushDataToPlatform(D2CAPI.Trends, controllerStatus.Controller.controller_id, controllerStatus.GetTrends()); } } catch (Exception ex) { // TODO: Improve logging text log.WriteAsync(ex.ToString()); } }