Execute() public method

Executes a command with the given parameter string and returns a string return
public Execute ( String command, string param ) : VmcController.AddIn.OpResult
command String command name string
param string parameter string
return VmcController.AddIn.OpResult
Example #1
0
        /// <summary>
        /// Handles the received commands of the m_socketServer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SocketServer.SocketEventArgs"/> instance containing the event data.</param>
        void m_socketServer_NewMessage(object sender, SocketEventArgs e)
        {
            OpResult opResult = new OpResult(OpStatusCode.BadRequest);

            try
            {
                if (e.Message.Length == 0)
                {
                    return;
                }

                if (e.Message.Equals("help", StringComparison.InvariantCultureIgnoreCase))
                {
                    opResult = m_remoteCommands.CommandList(GetPortNumber(m_basePortNumber));
                }
                else if (e.Message.Equals("exit", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_socketServer.CloseClient(e.TcpClient);
                    return;
                }
                else
                {
                    string[] command = e.Message.Split(new char[] { ' ' }, 2);
                    if (command.Length == 0)
                    {
                        return;
                    }

                    opResult = m_remoteCommands.Execute(command[0], (command.Length == 2 ? command[1] : string.Empty));
                }
                m_socketServer.SendMessage(string.Format("{0} {1}\r\n", (int)opResult.StatusCode, opResult.StatusText), e.TcpClient);
                if (opResult.StatusCode == OpStatusCode.Ok)
                {
                    m_socketServer.SendMessage(opResult.ToString(), e.TcpClient);
                    m_socketServer.SendMessage(".\r\n", e.TcpClient);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
Example #2
0
        void StartSendRequestThread(Object o)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;

            SocketAsyncEventArgs e     = (SocketAsyncEventArgs)o;
            DataHolderToken      token = (DataHolderToken)e.UserToken;

            string[] command  = getCommandsFromArgs(e);
            string   sCommand = command[0];
            string   sParam   = (command.Length == 2 ? command[1] : string.Empty);

            Thread http_thread = new Thread(new ParameterizedThreadStart(NewRequestThread));

            http_thread.IsBackground = true;
            http_thread.SetApartmentState(ApartmentState.MTA);

            if (sCommand.Equals("music-list-playing") || sCommand.Equals("music-list-current") || sCommand.StartsWith("play") || sCommand.Equals("music-shuffle"))
            {
                RemotedWindowsMediaPlayer remotedPlayer = null;
                try
                {
                    //Only allow one thread at a time to access remoted player
                    waitHandle.WaitOne();

                    remotedPlayer = new RemotedWindowsMediaPlayer();
                    remotedPlayer.CreateControl();

                    token.opResult = new OpResult();
                    if (sCommand.Equals("music-list-playing"))
                    {
                        if (sParam != null && sParam.Length != 0)
                        {
                            string sIndex = sParam.Substring(sParam.IndexOf("index:") + "index:".Length);
                            if (remotedPlayer.setNowPlaying(Int16.Parse(sIndex)))
                            {
                                token.opResult.StatusCode = OpStatusCode.Success;
                                token.opResult.StatusText = "Current media set to index " + sIndex;
                            }
                            else
                            {
                                token.opResult.StatusCode = OpStatusCode.BadRequest;
                                token.opResult.StatusText = "Current playback item not set";
                            }
                        }
                        else
                        {
                            token.opResult.StatusCode = OpStatusCode.Success;
                            NowPlaying nowPlaying = new NowPlaying(remotedPlayer);
                            token.opResult.ContentObject = nowPlaying;
                        }
                    }
                    else if (sCommand.StartsWith("play"))
                    {
                        //For playrate and playstate-get commands
                        token.opResult = remoteCommands.Execute(remotedPlayer, sCommand, sParam);
                    }
                    else if (sCommand.Equals("music-shuffle"))
                    {
                        remotedPlayer.setShuffleMode();
                        token.opResult.StatusCode = OpStatusCode.Success;
                        token.opResult.StatusText = "Shuffle mode set to true";
                    }
                    else
                    {
                        //"music-list-current" command
                        token.opResult.StatusCode = OpStatusCode.Success;
                        CurrentState state = new CurrentState(remotedPlayer);
                        token.opResult.ContentObject = state;
                    }
                }
                catch (Exception c)
                {
                    logger.Write("Exception in StartSendRequestThread: " + c.Message);
                    token.opResult.StatusCode = OpStatusCode.Exception;
                    token.opResult.StatusText = c.Message;
                }
                finally
                {
                    if (remotedPlayer != null)
                    {
                        remotedPlayer.Dispose();
                    }
                    waitHandle.Set();
                }
            }

            http_thread.Start(e);
        }