public OpResult Execute(String command, string param, ServerSettings settings, RemotedWindowsMediaPlayer remotePlayer) { command = command.ToLower(); if (m_commands.ContainsKey(command)) { try { if (command.Equals("music-list-stats")) { return(ExecuteLibraryStats(settings)); } else if (m_commands[command] is MusicCmd) { //Make sure cache is not being modified before executing any of the music-* commands if (cacheLock.TryEnterReadLock(10)) { try { return(((ICommand)m_commands[command]).Execute(param)); } finally { cacheLock.ExitReadLock(); } } else { return(getSettings(settings, true)); } } else if (m_commands[command] is IExperienceCommand || m_commands[command] is IWmpCommand) { //Only allow one thread at a time to access remoted player waitHandle.WaitOne(); try { if (m_commands[command] is IWmpCommand) { return(((IWmpCommand)m_commands[command]).Execute(remotePlayer, param)); } else { return(((IExperienceCommand)m_commands[command]).ExecuteMediaExperience(param)); } } finally { waitHandle.Set(); } } else { return(((ICommand)m_commands[command]).Execute(param)); } } catch (Exception ex) { OpResult opResult = new OpResult(); opResult.StatusCode = OpStatusCode.Exception; opResult.StatusText = ex.Message; opResult.AppendFormat(ex.Message); return(opResult); } } else { return(new OpResult(OpStatusCode.BadRequest)); } }
/// <summary> /// Executes a command with the given parameter string and returns a string return /// </summary> /// <param name="command">command name string</param> /// <param name="param">parameter string</param> /// <param name="playlist">now playing playlist, may be null</param> /// <param name="result">string</param> /// <returns></returns> public OpResult Execute(String command, string param, ServerSettings settings) { return(Execute(command, param, settings, null)); }