private static void ReceivedMessage(IrssMessage received)
    {
      Log.Debug("TV2BlasterPlugin: Received Message \"{0}\"", received.Type);

      try
      {
        switch (received.Type)
        {
          case MessageType.BlastIR:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
            {
              Log.Debug("TV2BlasterPlugin: Blast successful");
            }
            else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
            {
              Log.Error("TV2BlasterPlugin: 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("TV2BlasterPlugin: Registered to IR Server");
            }
            else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
            {
              _registered = false;
              Log.Error("TV2BlasterPlugin: IR Server refused to register");
            }
            break;

          case MessageType.LearnIR:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
            {
              Log.Debug("TV2BlasterPlugin: 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("TV2BlasterPlugin: Failed to learn IR command");
            }
            else if ((received.Flags & MessageFlags.Timeout) == MessageFlags.Timeout)
            {
              Log.Error("TV2BlasterPlugin: Learn IR command timed-out");
            }

            _learnIRFilename = null;
            break;

          case MessageType.ServerShutdown:
            Log.Info("TV2BlasterPlugin: IR Server Shutdown - Plugin disabled until IR Server returns");
            _registered = false;
            break;

          case MessageType.Error:
            _learnIRFilename = null;
            Log.Error("TV2BlasterPlugin: Received error: {0}", received.GetDataAsString());
            break;
        }

        if (_handleMessage != null)
          _handleMessage(received);
      }
      catch (Exception ex)
      {
        _learnIRFilename = null;
        Log.Error(ex);
      }
    }
예제 #2
0
    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.DataAsBytes);
              _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.ServerShutdown:
            IrssLog.Warn("IR Server Shutdown - Web Remote disabled until IR Server returns");
            _registered = false;
            break;

          case MessageType.Error:
            IrssLog.Error(received.GetDataAsString());
            break;
        }
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
      }
    }
예제 #3
0
    private static void ReceivedMessage(IrssMessage received)
    {
      IrssLog.Debug("Received Message \"{0}\"", received.Type);

      try
      {
        switch (received.Type)
        {
          case MessageType.BlastIR:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
              Info("Blast Success");
            else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
              Warn("Blast Failed!");
            break;

          case MessageType.RegisterClient:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
            {
              Info("Registered to IR Server");
              _registered = true;
              //_irServerInfo = TransceiverInfo.FromString(received.Data);
            }
            else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
            {
              _registered = false;
              Warn("IR Server refused to register");
            }
            break;

          case MessageType.ServerShutdown:
            _registered = false;
            Warn("IR Server Shutdown - Blasting disabled until IR Server returns");
            break;

          case MessageType.Error:
            Warn(received.GetDataAsString());
            break;
        }
      }
      catch (Exception ex)
      {
        Error(ex);
      }
    }
예제 #4
0
    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);
      }
    }
예제 #5
0
    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});
      }
    }
예제 #6
0
    private static void ReceivedMessage(IrssMessage received)
    {
      IrssLog.Debug("Received Message \"{0}\"", received.Type);

      try
      {
        switch (received.Type)
        {
          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.KeyboardEvent:
            {
              int vKey = (int)received.MessageData[IrssMessage.V_KEY];
              bool keyUp = (bool)received.MessageData[IrssMessage.KEY_UP];

              KeyboardHandlerCallback("TODO", vKey, keyUp);
              break;
            }

          case MessageType.MouseEvent:
            {
              int deltaX = (int)received.MessageData[IrssMessage.DELTA_X];
              int deltaY = (int)received.MessageData[IrssMessage.DELTA_Y];
              int buttons = (int)received.MessageData[IrssMessage.BUTTONS];

              MouseHandlerCallback("TODO", deltaX, deltaY, buttons);
              break;
            }

          case MessageType.BlastIR:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
              IrssLog.Info("Blast successful");
            else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
              IrssLog.Error("Failed to blast IR command");
            break;

          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.LearnIR:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
            {
              IrssLog.Info("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.Warn("Learn IR command timed-out");
            }

            _learnIRFilename = null;
            break;

          case MessageType.ServerShutdown:
            IrssLog.Warn("IR Server Shutdown - Translator disabled until IR Server returns");
            _registered = false;

            _notifyIcon.Icon = Resources.Icon16Connecting;
            _notifyIcon.Text = "Translator - Connecting ...";

            break;

          case MessageType.Error:
            _learnIRFilename = null;
            IrssLog.Error("Received error: {0}", received.GetDataAsString());
            break;
        }

        if (_handleMessage != null)
          _handleMessage(received);
      }
      catch (Exception ex)
      {
        _learnIRFilename = null;
        IrssLog.Error(ex);
      }
    }
예제 #7
0
    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("Learnt 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());
      }
    }
예제 #8
0
    private void ReceivedMessage(IrssMessage received)
    {
      IrssLog.Debug("Received Message \"{0}\"", received.Type);

      try
      {
        switch (received.Type)
        {
          case MessageType.RemoteEvent:
            if (listViewButtons.SelectedItems.Count == 1)
            {
              string keyCode = received.MessageData[IrssMessage.KEY_CODE] as string;

              listViewButtons.SelectedItems[0].SubItems[1].Text = keyCode;
            }
            return;

          case MessageType.RegisterClient:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
            {
              _registered = true;
            }
            else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
            {
              _registered = false;
              MessageBox.Show(this, "Failed to register with server", "Virtual Remote Skin Editor Error",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return;

          case MessageType.ServerShutdown:
            MessageBox.Show(this, "Server has been shut down", "Virtual Remote Skin Editor Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
            return;

          case MessageType.Error:
            MessageBox.Show(this, received.GetDataAsString(), "Virtual Remote Skin Editor Error from Server",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
        MessageBox.Show(this, ex.Message, "Virtual Remote Skin Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }
예제 #9
0
        //------------------------------------------------------------------------------------------------------------------
        #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);

        }
예제 #10
0
    private void ReceivedMessage(IrssMessage received)
    {
      Invoke(_addStatusLine, String.Format("Received Message: \"{0}, {1}\"", received.Type, received.Flags));

      try
      {
        switch (received.Type)
        {
          case MessageType.RegisterClient:
            if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
            {
              _registered = true;
              //_irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes());

              _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, received.GetDataAsString());
            break;

          case MessageType.ActiveReceivers:
            Invoke(_addStatusLine, received.GetDataAsString());

            string[] receivers = received.GetDataAsString().Split(new[] { ',' },
                                                                  StringSplitOptions.RemoveEmptyEntries);

            Invoke(_setDevices, receivers, "ActiveReceivers");
            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);
            return;

          case MessageType.ServerShutdown:
            _registered = false;
            return;

          case MessageType.Error:
            Invoke(_addStatusLine, received.GetDataAsString());
            return;
        }
      }
      catch (Exception ex)
      {
        Invoke(_addStatusLine, ex.Message);
      }
    }
예제 #11
0
    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.DataAsBytes);
              _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.ServerShutdown:
            IrssLog.Warn("IR Server Shutdown - Tray Launcher 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());
      }
    }