Beispiel #1
0
        void ExecuteSendSendKeyCommand(object sender, GeneralCommandEventArgs e)
        {
            _logger.Debug("ExecuteSendStringCommand {0}", e.Command.Arguments != null && e.Command.Arguments.Count > 0 ? e.Command.Arguments.First().Value : null);
            if (e.Command.Arguments == null || e.Command.Arguments.Count() != 1)
            {
                throw new ArgumentException("ExecuteSendStringCommand: expecting a single string argurment for send Key");
            }

            var input = e.Command.Arguments.First().Value;

            // now the key can be
            // 1. An integer value of the  System.Windows.Input.Key enum, 0 to 172
            // 2. The text representation of System.Windows.Input.Key ie. Key.None..Key.DeadCharProcessed
            // 3. A single Char value

            // try int first
            int intVal;

            if (int.TryParse(input, out intVal))
            {
                System.Windows.Input.Key key;

                if (!IsWindowsKeyEnum(intVal, out key))
                {
                    throw new ArgumentException(String.Format("ExecuteSendStringCommand: integer argument {0} does not map to  System.Windows.Input.Key", intVal));
                }

                _userInputManager.SendKeyDownEventToFocusedElement(key);
            }
            else if (input.StartsWith("Key.")) // check if the string maps to a enum element name i.e Key.A
            {
                System.Windows.Input.Key key;
                try
                {
                    key = (System.Windows.Input.Key)System.Enum.Parse(typeof(System.Windows.Input.Key), input);
                }
                catch (Exception)
                {
                    throw new ArgumentException(String.Format("ExecuteSendStringCommand: Argument '{0}' must be a Single Char or a Windows Key literial (i.e Key.A)  or the Integer value for Key literial", input));
                }

                _userInputManager.SendKeyDownEventToFocusedElement(key);
            }
            else if (input.Length == 1)
            {
                _userInputManager.SendTextInputToFocusedElement(input);
            }
            else
            {
                throw new ArgumentException(String.Format("ExecuteSendStringCommand: Argument '{0}' must be a Single Char or a Windows Key literial (i.e Key.A)  or the Integer value for Key literial", input));
            }
        }
Beispiel #2
0
        void socket_GeneralCommand(object sender, GeneralCommandEventArgs e)
        {
            _logger.Debug("socket_GeneralCommand {0} {1}", e.KnownCommandType, e.Command.Arguments);

            if (e.KnownCommandType.HasValue)
            {
                switch (e.KnownCommandType.Value)
                {
                case GeneralCommandType.MoveUp:
                    _userInputManager.SendKeyDownEventToFocusedElement(Key.Up);
                    break;

                case GeneralCommandType.MoveDown:
                    _userInputManager.SendKeyDownEventToFocusedElement(Key.Down);
                    break;

                case GeneralCommandType.MoveLeft:
                    _userInputManager.SendKeyDownEventToFocusedElement(Key.Left);
                    break;

                case GeneralCommandType.MoveRight:
                    _userInputManager.SendKeyDownEventToFocusedElement(Key.Right);
                    break;

                case GeneralCommandType.PageUp:
                    _userInputManager.SendKeyDownEventToFocusedElement(Key.PageUp);
                    break;

                case GeneralCommandType.PreviousLetter:
                    _commandManager.ExecuteCommand(Command.Null, null);     //todo
                    break;

                case GeneralCommandType.NextLetter:
                    _commandManager.ExecuteCommand(Command.Null, null);     //todo
                    break;

                case GeneralCommandType.ToggleOsd:
                    _commandManager.ExecuteCommand(Command.ToggleOsd, null);
                    break;

                case GeneralCommandType.ToggleContextMenu:
                    _commandManager.ExecuteCommand(Command.ToggleInfoPanel, null);            // todo generalise - make work not just for meida playing
                    break;

                case GeneralCommandType.Select:
                    _userInputManager.SendKeyDownEventToFocusedElement(Key.Enter);
                    _userInputManager.SendKeyUpEventToFocusedElement(Key.Enter);
                    break;

                case GeneralCommandType.Back:
                    _navigationService.NavigateBack();
                    break;

                case GeneralCommandType.TakeScreenshot:
                    _commandManager.ExecuteCommand(Command.ScreenDump, null);
                    break;

                case GeneralCommandType.SendKey:
                    ExecuteSendSendKeyCommand(sender, e);
                    break;

                case GeneralCommandType.GoHome:
                    _commandManager.ExecuteCommand(Command.GotoHome, null);
                    break;

                case GeneralCommandType.GoToSettings:
                    _commandManager.ExecuteCommand(Command.GotoSettings, null);
                    break;

                case GeneralCommandType.VolumeDown:
                    _commandManager.ExecuteCommand(Command.VolumeDown, null);
                    break;

                case GeneralCommandType.VolumeUp:
                    _commandManager.ExecuteCommand(Command.VolumeUp, null);
                    break;

                case GeneralCommandType.Mute:
                    _commandManager.ExecuteCommand(Command.Mute, null);
                    break;

                case GeneralCommandType.Unmute:
                    _commandManager.ExecuteCommand(Command.UnMute, null);
                    break;

                case GeneralCommandType.ToggleMute:
                    _commandManager.ExecuteCommand(Command.ToggleMute, null);
                    break;

                case GeneralCommandType.ToggleFullscreen:
                    _commandManager.ExecuteCommand(Command.ToggleFullScreen, null);
                    break;

                case GeneralCommandType.DisplayContent:
                    ExecuteDisplayContent(e.Command.Arguments);
                    break;

                default:
                    _logger.Warn("Unrecognized command: " + e.KnownCommandType.Value);
                    break;
                }
            }
        }
Beispiel #3
0
        private void OnGeneralCommand(string json)
        {
            var args = new GeneralCommandEventArgs
            {
                Command = JsonSerializer.DeserializeFromString <WebSocketMessage <GeneralCommand> >(json).Data
            };

            try
            {
                args.KnownCommandType = (GeneralCommandType)Enum.Parse(typeof(GeneralCommandType), args.Command.Name, true);
            }
            catch
            {
                // Could be a custom name.
            }

            if (args.KnownCommandType.HasValue)
            {
                if (args.KnownCommandType.Value == GeneralCommandType.DisplayContent)
                {
                    string itemId;
                    string itemName;
                    string itemType;

                    args.Command.Arguments.TryGetValue("ItemId", out itemId);
                    args.Command.Arguments.TryGetValue("ItemName", out itemName);
                    args.Command.Arguments.TryGetValue("ItemType", out itemType);

                    FireEvent(BrowseCommand, this, new GenericEventArgs <BrowseRequest>
                    {
                        Argument = new BrowseRequest
                        {
                            ItemId   = itemId,
                            ItemName = itemName,
                            ItemType = itemType
                        }
                    });
                    return;
                }
                if (args.KnownCommandType.Value == GeneralCommandType.DisplayMessage)
                {
                    string header;
                    string text;
                    string timeoutMs;

                    args.Command.Arguments.TryGetValue("Header", out header);
                    args.Command.Arguments.TryGetValue("Text", out text);
                    args.Command.Arguments.TryGetValue("TimeoutMs", out timeoutMs);

                    long?timeoutVal = string.IsNullOrEmpty(timeoutMs) ? (long?)null : long.Parse(timeoutMs, CultureInfo.InvariantCulture);

                    FireEvent(MessageCommand, this, new GenericEventArgs <MessageCommand>
                    {
                        Argument = new MessageCommand
                        {
                            Header    = header,
                            Text      = text,
                            TimeoutMs = timeoutVal
                        }
                    });
                    return;
                }
                if (args.KnownCommandType.Value == GeneralCommandType.SetVolume)
                {
                    string volume;

                    args.Command.Arguments.TryGetValue("Volume", out volume);

                    FireEvent(SetVolumeCommand, this, new GenericEventArgs <int>
                    {
                        Argument = int.Parse(volume, CultureInfo.InvariantCulture)
                    });
                    return;
                }
                if (args.KnownCommandType.Value == GeneralCommandType.SetAudioStreamIndex)
                {
                    string index;

                    args.Command.Arguments.TryGetValue("Index", out index);

                    FireEvent(SetAudioStreamIndexCommand, this, new GenericEventArgs <int>
                    {
                        Argument = int.Parse(index, CultureInfo.InvariantCulture)
                    });
                    return;
                }
                if (args.KnownCommandType.Value == GeneralCommandType.SetSubtitleStreamIndex)
                {
                    string index;

                    args.Command.Arguments.TryGetValue("Index", out index);

                    FireEvent(SetSubtitleStreamIndexCommand, this, new GenericEventArgs <int>
                    {
                        Argument = int.Parse(index, CultureInfo.InvariantCulture)
                    });
                    return;
                }
                if (args.KnownCommandType.Value == GeneralCommandType.SendString)
                {
                    string val;

                    args.Command.Arguments.TryGetValue("String", out val);

                    FireEvent(SendStringCommand, this, new GenericEventArgs <string>
                    {
                        Argument = val
                    });
                    return;
                }
            }

            FireEvent(GeneralCommand, this, new GenericEventArgs <GeneralCommandEventArgs>(args));
        }
Beispiel #4
0
 void _serverEvents_GeneralCommand(object sender, GeneralCommandEventArgs e)
 {
     _presentationManager.Window.Dispatcher.InvokeAsync(OnRemoteControlCommand, DispatcherPriority.Background);
 }