public string ProcessCommand(string input) { string[] tokens = input.Split(" ".ToCharArray().First()); var command = tokens.First(); var parameters = tokens.Skip(1).ToArray(); string output = String.Empty; switch (command) { case "RegisterSet": output = festivalCоntroller.RegisterSet(parameters); break; case "SignUpPerformer": output = festivalCоntroller.SignUpPerformer(parameters); break; case "RegisterSong": output = festivalCоntroller.RegisterSong(parameters); break; case "AddSongToSet": output = festivalCоntroller.AddSongToSet(parameters); break; case "AddPerformerToSet": output = festivalCоntroller.AddPerformerToSet(parameters); break; case "RepairInstruments": output = festivalCоntroller.RepairInstruments(); break; case "LetsRock": output = setCоntroller.PerformSets(); break; } return(output); /* * var festivalcontrolfunction = this.festivalController.GetType() * .GetMethods() * .FirstOrDefault(x => x.Name == purvoto); * * string a; * * try * { * a = (string)festivalcontrolfunction.Invoke(this.festivalController, new object[] { parametri }); * } * catch (TargetInvocationException up) * { * throw up; // ha ha * } * * return a;*/ }
public string ProcessCommand(string input) { var data = input.Split(); var args = data.Skip(1).ToArray(); var sb = new StringBuilder(); if (data[0].Equals("RegisterSet")) { try { sb.AppendLine(festivalCоntroller.RegisterSet(args)); } catch (Exception e) { sb.AppendLine(string.Format(ErrorMessage, e.Message)); } } else if (data[0] == "SignUpPerformer") { try { sb.AppendLine(festivalCоntroller.SignUpPerformer(args)); } catch (Exception e) { sb.AppendLine(string.Format(ErrorMessage, e.Message)); } } else if (data[0].Equals("RegisterSong")) { try { sb.AppendLine(festivalCоntroller.RegisterSong(args)); } catch (Exception e) { sb.AppendLine(string.Format(ErrorMessage, e.Message)); } } else if (data[0].Equals("AddSongToSet")) { try { sb.AppendLine(festivalCоntroller.AddSongToSet(args)); } catch (Exception e) { sb.AppendLine(string.Format(ErrorMessage, e.Message)); } } else if (data[0].Equals("AddPerformerToSet")) { try { sb.AppendLine(festivalCоntroller.AddPerformerToSet(args)); } catch (Exception e) { sb.AppendLine(string.Format(ErrorMessage, e.Message)); } } else if (data[0].Equals("RepairInstruments")) { try { sb.AppendLine(festivalCоntroller.RepairInstruments(args)); } catch (Exception e) { sb.AppendLine(string.Format(ErrorMessage, e.Message)); throw; } } else if (data[0].Equals("LetsRock")) { sb.AppendLine(setCоntroller.PerformSets()); } return(sb.ToString().TrimEnd()); }
public string ProcessCommand(string input) { string result = string.Empty; try { string[] inputs = input.Split(); string command = inputs[0]; string[] commandInputsList = inputs.Skip(1).ToArray(); switch (command) { case "RegisterSet": result = (festivalCоntroller.RegisterSet(commandInputsList)); break; case "SignUpPerformer": result = (festivalCоntroller.SignUpPerformer(commandInputsList)); break; case "RegisterSong": result = (festivalCоntroller.RegisterSong(commandInputsList)); break; case "AddSongToSet": result = (festivalCоntroller.AddSongToSet(commandInputsList)); break; case "AddPerformerToSet": result = (festivalCоntroller.AddPerformerToSet(commandInputsList)); break; case "RepairInstruments": result = (festivalCоntroller.RepairInstruments(commandInputsList)); break; case "LetsRock": result = (setCоntroller.PerformSets()); break; case "END": result = festivalCоntroller.ProduceReport(); return(result); default: break; } return(result); // string.Intern(input); // var result = this.DoCommand(input); // this.writer.WriteLine(result); } catch (Exception ex) // in case we run out of memory { // Fix this!!!! if needed result = ("ERROR: " + ex.Message); return(result); } }