public void AddStatus(StatusFrameDecoded newStatus) { List <DeviceStatusInfo> statusList = null; lock (statusMap) { if (!statusMap.ContainsKey(newStatus.DeviceId)) { statusList = new List <DeviceStatusInfo>(); statusMap.Add(newStatus.DeviceId, statusList); } else { try { statusMap.TryGetValue(newStatus.DeviceId, out statusList); } catch //si no pudo obtener la lista desde el mapa { statusList = new List <DeviceStatusInfo>(); statusMap.Add(newStatus.DeviceId, statusList); } } } //para agreagr se hace lock en la lista seleccionada lock (statusList) { statusList.Add(new DeviceStatusInfo() { DeviceId = newStatus.DeviceId, StatusOnOff = newStatus.StatusOnOff, UpTime = newStatus.UpTime }); } }
private void CallRemotingGestionServer(StatusFrameDecoded message) { TcpChannel tcpChannel = null; try { tcpChannel = new TcpChannel(); ChannelServices.RegisterChannel(tcpChannel, false); Type requiredType = typeof(ICommServer); ICommServer remoteObject = (ICommServer)Activator.GetObject(requiredType, "tcp://localhost:9998/CommServer"); remoteObject.SetDeviceStatus(message.DeviceId, message.StatusOnOff, message.UpTime); } catch (Exception e) { log.Error("Se cagó", e); } finally { if (tcpChannel != null) { ChannelServices.UnregisterChannel(tcpChannel); } } }
private void OnReceiveCompleted(Object source, ReceiveCompletedEventArgs asyncResult) { try { MessageQueue mq = (MessageQueue)source; if (mq != null) { try { System.Messaging.Message message = null; try { message = mq.EndReceive(asyncResult.AsyncResult); } catch (Exception ex) { log.Error(ex.Message); } if (message != null) { MessageBean messageBean = message.Body as MessageBean; if (messageBean != null) { if (messageBean.MessageType == MessageTypeEnum.FAULT) { FaultFrameDecoded tmp = new FaultFrameDecoded(); tmp.Parse(messageBean.Message); SingletonStatsHistory.GetInstance().AddFault(tmp); log.InfoFormat("Fault: {0}", tmp.ToString()); } else { StatusFrameDecoded tmp = new StatusFrameDecoded(); tmp.Parse(messageBean.Message); SingletonStatsHistory.GetInstance().AddStatus(tmp); log.InfoFormat("Status: {0}", tmp.ToString()); } } else { log.Info("Message vino null"); } } } finally { if (isRunning) { mq.BeginReceive(); } } } return; } catch (Exception exc) { log.Error(exc.Message); } }
private void CommandREQStatusReport(Connection clientConnection, Data dato) { StatusFrameDecoded message = new StatusFrameDecoded(); message.Parse(dato.Payload.Message); SingletonDeviceInfoHandler.GetInstance().UpdateDeviceStatus(message); log.DebugFormat("Llego REQ STATUS con {0}", message.ToString()); log.DebugFormat("Notificar a server estadisticas"); MessageBean messageBean = new MessageBean() { Message = dato.Payload.Message, MessageType = MessageTypeEnum.STATUS }; StatisticsQueueClient.GetInstance().SendMessages(messageBean); }
public void UpdateDeviceStatus(StatusFrameDecoded message) { DeviceStatusInfo newStatus = new DeviceStatusInfo() { DeviceId = message.DeviceId, StatusOnOff = message.StatusOnOff, UpTime = message.UpTime }; try { DeviceInfo deviceInfo = null; devicesInfo.TryGetValue(message.DeviceId, out deviceInfo); deviceInfo.LastStatusInfo = newStatus; } catch (Exception) { this.devicesInfo.Add(message.DeviceId, new DeviceInfo() { DeviceId = message.DeviceId, LastStatusInfo = newStatus }); } }