public static async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log)
        {
            using (BotService.Initialize())
            {
                var subscriptionFacade = new SubscriptionFacade();
                var reportsFacade      = new ReportsFacade();
                var unavailableDevices = await reportsFacade.GetUnavailableDeviceReports();

                var subscriptions = (await subscriptionFacade.GetAllSubscriptions()).ToArray();

                foreach (var subscription in subscriptions.Where(t => t.LastActivity != null && DateTime.UtcNow.Subtract(t.LastActivity.Created) > TimeSpan.FromDays(1)))
                {
                    var connector = new ConnectorClient(new Uri(subscription.ServiceUrl), Environment.GetEnvironmentVariable("MicrosoftAppId"), Environment.GetEnvironmentVariable("MicrosoftAppPassword"));
                    await connector.Conversations.DeleteActivityAsync(subscription.LastActivity.ConversationId, subscription.LastActivity.ActitityId);

                    subscription.LastActivity = null;
                    await subscriptionFacade.UpdateBotSubscription(subscription);
                }

                foreach (var deviceGroup in unavailableDevices.GroupBy(t => t.Group))
                {
                    var message    = new DeviceStatusMessage(deviceGroup.ToList());
                    var recipients = subscriptions.Where(t => t.GroupName == deviceGroup.Key);
                    await message.SendMessageToChannel("Found unavailable devices!", recipients);
                }
            }
        }
Esempio n. 2
0
        private byte[] SerializeMessage(DeviceStatusMessage message)
        {
            var memoryStream = new MemoryStream();
            var streamWriter = new StreamWriter(memoryStream);

            new JsonSerializer().Serialize(streamWriter, message);
            return(memoryStream.ToArray());
        }
 public Task SendMessage(DeviceStatusMessage message)
 {
     // add a message to the send queue
     messageQueue.Add(message);
     if (messageQueue.Count > 25)
     {
         // if the queue size is greater than 25, flush the queue
         Flush();
     }
     return(TaskDone.Done);
 }
Esempio n. 4
0
        public void Publish(DeviceStatusMessage message)
        {
            var messageJson = JsonConvert.SerializeObject(message);
            var body        = Encoding.UTF8.GetBytes(messageJson);

            _channel.ExchangeDeclare(exchange: _responseExchange,
                                     type: "topic");

            _channel.BasicPublish(exchange: _responseExchange,
                                  routingKey: _responseTag,
                                  basicProperties: null,
                                  body: body);
        }
Esempio n. 5
0
        public async Task ProcessMessage(DeviceMessage message)
        {
            if (null == this.lastMessage || this.lastMessage.Latitude != message.Latitude || this.lastMessage.Longitude != message.Longitude)
            {
                // only sent a notification if the position has changed
                var notifier = PushNotifierGrainFactory.GetGrain(0);
                var speed    = GetSpeed(this.lastMessage, message);

                // record the last message
                this.lastMessage = message;

                // forward the message to the notifier grain
                var statusMessage = new DeviceStatusMessage(message, speed, description);
                await notifier.SendMessage(statusMessage);
            }
            else
            {
                // the position has not changed, just record the last message
                this.lastMessage = message;
            }
        }
        private static void DeviceStatus_Tick(object state)
        {
            var devices    = AvailableDevices.Devices;
            var deviceList = new List <JArray>();
            var activeIDs  = MiningManager.GetActiveMinersIndexes();

            foreach (var device in devices)
            {
                try
                {
                    var array = new JArray
                    {
                        device.Index,
                        device.Name
                    };
                    var status = Convert.ToInt32(activeIDs.Contains(device.Index)) + ((int)device.DeviceType + 1) * 2;
                    array.Add(status);
                    array.Add((int)Math.Round(device.Load));
                    array.Add((int)Math.Round(device.Temp));
                    array.Add(device.FanSpeed);

                    deviceList.Add(array);
                }
                catch (Exception e) {
                    NiceHashMinerLegacy.Common.Logger.Error("SOCKET", e.ToString());
                }
            }
            var data = new DeviceStatusMessage
            {
                devices = deviceList
            };
            var sendData = JsonConvert.SerializeObject(data);

            // This function is run every minute and sends data every run which has two auxiliary effects
            // Keeps connection alive and attempts reconnection if internet was dropped
            _socket?.SendData(sendData);
        }
Esempio n. 7
0
 public static void OnDeviceStatus(LiveView liveView, DeviceStatusMessage message)
 {
 }
Esempio n. 8
0
 public void LocationUpdate(DeviceStatusMessage message)
 {
     // Forward a single messages to all clients
     Clients.Group("BROWSERS").locationUpdate(message);
     Clients.Group("DEVICES").locationUpdate(message);
 }