private static void ReceivedMessage(IrssMessage received) { Log.Debug("TV3BlasterPlugin: Received Message \"{0}\"", received.Type); try { switch (received.Type) { case MessageType.BlastIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { Log.Debug("TV3BlasterPlugin: Blast successful"); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { Log.Error("TV3BlasterPlugin: Failed to blast IR command"); } break; case MessageType.RegisterClient: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { _irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes()); _registered = true; Log.Debug("TV3BlasterPlugin: Registered to IR Server"); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; Log.Error("TV3BlasterPlugin: IR Server refused to register"); } break; case MessageType.LearnIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { Log.Debug("TV3BlasterPlugin: Learned IR Successfully"); byte[] dataBytes = received.GetDataAsBytes(); using (FileStream file = File.Create(_learnIRFilename)) file.Write(dataBytes, 0, dataBytes.Length); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { Log.Error("TV3BlasterPlugin: Failed to learn IR command"); } else if ((received.Flags & MessageFlags.Timeout) == MessageFlags.Timeout) { Log.Error("TV3BlasterPlugin: Learn IR command timed-out"); } _learnIRFilename = null; break; case MessageType.ServerShutdown: Log.Info("TV3BlasterPlugin: IR Server Shutdown - Plugin disabled until IR Server returns"); _registered = false; break; case MessageType.Error: _learnIRFilename = null; Log.Error("TV3BlasterPlugin: Received error: {0}", received.GetDataAsString()); break; } if (_handleMessage != null) { _handleMessage(received); } } catch (Exception ex) { _learnIRFilename = null; Log.Error(ex.ToString()); } }
void ReceivedMessage(IrssMessage received) { ServiceRegistration.Get <ILogger>().Debug("IrInputPlugin: Received Message '{0}' {1}", received.Type, received.GetDataAsString()); try { switch (received.Type) { case MessageType.RemoteEvent: string keyCode = received.MessageData[IrssMessage.KEY_CODE] as string; RemoteHandler(keyCode); break; // TODO: What to do with this code? /* * case MessageType.BlastIR: * if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) * ServiceRegistration.Get<ILogger>().Info("IrInputPlugin: Blast successful"); * else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) * ServiceRegistration.Get<ILogger>().Warn("IrInputPlugin: Failed to blast IR command"); * break; */ case MessageType.RegisterClient: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { _irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes()); ServiceRegistration.Get <ILogger>().Info("IrInputPlugin: Registered to Input Service '{0}'", _irServerInfo); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { ServiceRegistration.Get <ILogger>().Warn("IrInputPlugin: Input Service refused to register plugin"); } break; // TODO: What to do with this code? /* * case MessageType.LearnIR: * if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) * { * ServiceRegistration.Get<ILogger>().Info("IrInputPlugin: Learned IR Successfully"); * * byte[] dataBytes = received.GetDataAsBytes(); * * using (FileStream file = File.Create(_learnIRFilename)) * file.Write(dataBytes, 0, dataBytes.Length); * } * else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) * ServiceRegistration.Get<ILogger>().Error("IrInputPlugin: Failed to learn IR command"); * else if ((received.Flags & MessageFlags.Timeout) == MessageFlags.Timeout) * ServiceRegistration.Get<ILogger>().Error("IrInputPlugin: Learn IR command timed-out"); * break; */ case MessageType.ServerShutdown: ServiceRegistration.Get <ILogger>().Warn("IrInputPlugin: Input Service shutdown - IrInputPlugin is disabled until Input Service returns"); break; case MessageType.Error: ServiceRegistration.Get <ILogger>().Error("IrInputPlugin: Received error '{0}'", received.GetDataAsString()); break; } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Problem receiving IR message: {0}", ex); } }
//------------------------------------------------------------------------------------------------------------------ #region callbacks /// <summary> /// Socket-communication callback to receive message from the IRSS server. /// </summary> /// <param name="received">received message, defined mostly by a Type and Flags</param> private void ReceivedMessage(IrssMessage received) { // default (most common) values RemoteEventArgs args = new RemoteEventArgs(); args.Sender = RemoteEventArgs.IrServer; args.Key = received.Type.ToString(); args.Data = received.Flags.ToString() + ": " + received.GetDataAsString(); try { switch (received.Type) { case MessageType.RegisterClient: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { Connected = true; ServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes()); irss.Send(new IrssMessage(MessageType.ActiveReceivers, MessageFlags.Request)); irss.Send(new IrssMessage(MessageType.ActiveBlasters, MessageFlags.Request)); _connectedEvent.Set(); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { Connected = false; } break; case MessageType.ActiveBlasters: LogInfo(received.GetDataAsString()); break; case MessageType.ActiveReceivers: LogInfo(received.GetDataAsString()); break; case MessageType.RemoteEvent: // raise the event args.Sender = received.MessageData[IrssMessage.DEVICE_NAME] as string; args.Key = received.MessageData[IrssMessage.KEY_CODE] as string; args.Data = ""; break; case MessageType.LearnIR: _learnSuccess = (received.Flags & MessageFlags.Success) == MessageFlags.Success; if (_learnSuccess) { byte[] dataBytes = received.GetDataAsBytes(); if (_irFile != null && _irFile != "") { string DebugIRFile = Path.Combine(Common.FolderIRCommands, _irFile); using (FileStream file = File.Create(DebugIRFile)) file.Write(dataBytes, 0, dataBytes.Length); } } _learntEvent.Set(); break; case MessageType.ServerShutdown: Connected = false; LogInfo("Disconnected by host " + ServerHost); LogInfo(received.GetDataAsString()); break; case MessageType.Error: LogErr(received.GetDataAsString()); break; } } catch (Exception ex) { LogErr(ex.Message); args.Key = "Error"; args.Data = "ex.Message"; } LogDebug(String.Format("rise RemoteEvent: Sender: {0} - Key: {1} - Data: {2}", args.Sender, args.Key, args.Data)); OnRemoteEvent(args); }
private void ReceivedMessage(IrssMessage received) { Invoke(_addStatusLine, new Object[] { String.Format("Received Message: \"{0}, {1}\"", received.Flags, received.Type) }); try { switch (received.Type) { case MessageType.RegisterClient: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { _registered = true; _irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes()); comboBoxPort.Items.Clear(); comboBoxPort.Items.AddRange(_irServerInfo.Ports); comboBoxPort.SelectedIndex = 0; _client.Send(new IrssMessage(MessageType.ActiveReceivers, MessageFlags.Request)); _client.Send(new IrssMessage(MessageType.ActiveBlasters, MessageFlags.Request)); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; } return; case MessageType.ActiveBlasters: Invoke(_addStatusLine, new Object[] { received.GetDataAsString() }); break; case MessageType.ActiveReceivers: Invoke(_addStatusLine, new Object[] { received.GetDataAsString() }); break; case MessageType.RemoteEvent: string deviceName = received.MessageData[IrssMessage.DEVICE_NAME] as string; string keyCode = received.MessageData[IrssMessage.KEY_CODE] as string; Invoke(_addStatusLine, new Object[] { String.Format("{0} ({1})", deviceName, keyCode) }); return; case MessageType.LearnIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { byte[] dataBytes = received.GetDataAsBytes(); using (FileStream file = File.Create(_learnIRFilename)) file.Write(dataBytes, 0, dataBytes.Length); } _learnIRFilename = null; break; case MessageType.ServerShutdown: _registered = false; return; case MessageType.Error: _learnIRFilename = null; Invoke(_addStatusLine, new Object[] { received.GetDataAsString() }); return; } } catch (Exception ex) { Invoke(_addStatusLine, new Object[] { ex.Message }); } }
private static void ReceivedMessage(IrssMessage received) { IrssLog.Debug("Received Message \"{0}\"", received.Type); try { switch (received.Type) { case MessageType.RegisterClient: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { _irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes()); _registered = true; IrssLog.Info("Registered to IR Server"); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; IrssLog.Warn("IR Server refused to register"); } break; case MessageType.RemoteEvent: string deviceName = received.MessageData[IrssMessage.DEVICE_NAME] as string; string keyCode = received.MessageData[IrssMessage.KEY_CODE] as string; RemoteHandlerCallback(deviceName, keyCode); break; case MessageType.BlastIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { IrssLog.Debug("Blast successful"); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { IrssLog.Error("Failed to blast IR command"); } break; case MessageType.LearnIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { IrssLog.Debug("Learned IR Successfully"); byte[] dataBytes = received.GetDataAsBytes(); using (FileStream file = File.Create(_learnIRFilename)) file.Write(dataBytes, 0, dataBytes.Length); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { IrssLog.Error("Failed to learn IR command"); } else if ((received.Flags & MessageFlags.Timeout) == MessageFlags.Timeout) { IrssLog.Error("Learn IR command timed-out"); } _learnIRFilename = null; break; case MessageType.ServerShutdown: IrssLog.Warn("IR Server Shutdown - Media Center Blaster disabled until IR Server returns"); _registered = false; break; case MessageType.Error: IrssLog.Error("Received error: {0}", received.GetDataAsString()); break; } if (_handleMessage != null) { _handleMessage(received); } } catch (Exception ex) { IrssLog.Error("ReceivedMessage(): {0}", ex.ToString()); } }
private void ReceivedMessage(IrssMessage received) { IrssLog.Debug("Received Message \"{0}\"", received.Type); try { switch (received.Type) { case MessageType.RegisterClient: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { _irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes()); _registered = true; string message = "Connected"; IrssLog.Info(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { _registered = false; string message = "Failed to connect"; IrssLog.Warn(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); } return; case MessageType.BlastIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { string message = "Blast successful"; IrssLog.Info(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { string message = "Failed to blast IR command"; IrssLog.Error(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); } break; case MessageType.LearnIR: if ((received.Flags & MessageFlags.Success) == MessageFlags.Success) { byte[] dataBytes = received.GetDataAsBytes(); _code = IrCode.FromByteArray(dataBytes); _fileName = null; string message = "Learned IR Successfully"; IrssLog.Info(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); RefreshForm(); } else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure) { string message = "Failed to learn IR command"; IrssLog.Warn(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); } else if ((received.Flags & MessageFlags.Timeout) == MessageFlags.Timeout) { string message = "Learn IR command timed-out"; IrssLog.Warn(message); Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message }); } break; case MessageType.ServerShutdown: _registered = false; Invoke(new UpdateWindowDel(UpdateWindow), new string[] { "Server shut down" }); return; case MessageType.Error: IrssLog.Error("Error from server: " + received.GetDataAsString()); return; } } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show(this, ex.Message, "IR File Tool Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }