public void Execute(string request, out string result) { var serializer = new XmlSerializer(typeof(Argument[])); var tempPath = Environment.CurrentDirectory + "TempFile"; File.WriteAllText(tempPath, request); using (var reader = new StreamReader(tempPath)) _args = (Argument[])serializer.Deserialize(reader); File.Delete(tempPath); if (!File.Exists(_args[0].Value) && !File.Exists($"{_args[0].Value}.pls")) { var requestCommand = new RequestCommand("result"); result = requestCommand.Serialize(); var argument = new Argument("Result", "Playlist not found"); result += "\n" + argument.Serialize(); return; } _args[1].Value = string.IsNullOrWhiteSpace(_args[1].Value) ? "" : _args[1].Value; _args[2].Value = string.IsNullOrWhiteSpace(_args[1].Value) ? "" : _args[2].Value; _args[3].Value = string.IsNullOrWhiteSpace(_args[1].Value) ? "" : _args[3].Value; var playlist = new Playlist(_args[0].Value.EndsWith(".pls") ? _args[0].Value : $"{_args[0].Value}.pls"); List <Composition> compositions = playlist.Compositions.FindAll(x => x.Path.Contains(_args[1].Value) && x.Author.Contains(_args[2].Value) && x.Title.Contains(_args[3].Value)); if (compositions.Any()) { var requestCommand = new RequestCommand("compositions"); result = requestCommand.Serialize(); serializer = new XmlSerializer(typeof(List <Composition>)); using (var writer = new StreamWriter(tempPath)) serializer.Serialize(writer, compositions); result += "\n" + File.ReadAllText(tempPath); File.Delete(tempPath); } else { var requestCommand = new RequestCommand("result"); result = requestCommand.Serialize(); var argument = new Argument("Result", "Not found"); result += "\n" + argument.Serialize(); } }
public void Execute(string request, out string result) { var serializer = new XmlSerializer(typeof(Argument[])); var tempPath = Environment.CurrentDirectory + "TempFile"; File.WriteAllText(tempPath, request); using (var reader = new StreamReader(tempPath)) _args = (Argument[])serializer.Deserialize(reader); File.Delete(tempPath); if (!File.Exists(_args[0].Value) && !File.Exists($"{_args[0].Value}.pls")) { var requestCommand = new RequestCommand("result"); result = requestCommand.Serialize(); var argument = new Argument("Result", "Playlist not found"); result += "\n" + argument.Serialize(); return; } var playlist = new Playlist(_args[0].Value.EndsWith(".pls") ? _args[0].Value : $"{_args[0].Value}.pls"); if (playlist.Compositions.Any()) { var requestCommand = new RequestCommand("compositions"); result = requestCommand.Serialize(); serializer = new XmlSerializer(playlist.Compositions.GetType()); using (var writer = new StreamWriter(tempPath)) serializer.Serialize(writer, playlist.Compositions); result += "\n" + File.ReadAllText(tempPath); File.Delete(tempPath); } else { var requestCommand = new RequestCommand("result"); result = requestCommand.Serialize(); var argument = new Argument("Result", "Not found"); result += "\n" + argument.Serialize(); } }
public bool Execute() { var input = new Input(); var output = new Output(); output.Execute("Input command: "); var commandName = input.Execute(); var retrn = commands.Any(x => x.GetName() == commandName); if (retrn) { command = commands.FirstOrDefault(x => x.GetName() == commandName); if (commandName == "exit") { command.Execute(Environment.CurrentDirectory, out _result); } else { var requestCommand = new RequestCommand(command.GetName()); _result = requestCommand.Serialize(); var result = command.ReadArgs(); if (command.GetArgsCount() == 0) { } else if (result == null) { retrn = false; } else { _result += "\n" + result; } } } return(retrn); }