protected override sealed void CheckValidity(string[] args, out ArgumentsValues arguments, out OptionsValues options) { var argumentsDictionary = new ArgumentsDictionary(); var optionsDictionary = new OptionsDictionary(); int j = 0; for (int i = 0; i < args.Length; i++) { if (Options[args[i]].HasValue) { Option o = Options[args[i]].Value; var optionArgs = new ArgumentsDictionary(); foreach (IArgument argument in o.Arguments) { i++; IArgument a = argument; if (!a.IsValid(args[i])) throw new ArgumentNotValidException(a, j); optionArgs.Add(a.Name, args[i]); } optionsDictionary.Add(o.Key, new ArgumentsValues(optionArgs)); continue; } argumentsDictionary.Add(j.ToString(CultureInfo.InvariantCulture), args[i]); j++; } arguments = new ArgumentsValues(argumentsDictionary); options = new OptionsValues(optionsDictionary); }
protected override void Action(ArgumentsValues args, OptionsValues options) { MiniMALClient.DeleteRequestResult result = Client.DeleteAnime(args.Value<int>("id")); switch (result) { case MiniMALClient.DeleteRequestResult.Deleted: System.Console.WriteLine("Deleted"); break; } }
// Use this for initialization void Awake() { if (optionValues == null) { optionValues = this; setVolume(1);; DontDestroyOnLoad(this.gameObject); } else if (optionValues != this) { Destroy(gameObject); } }
protected override void Action(ArgumentsValues args, OptionsValues options) { try { List<MangaSearchEntry> search = Client.SearchManga(string.Join(" ", args.Values)); foreach (MangaSearchEntry a in search) System.Console.WriteLine(a.Title); System.Console.WriteLine(search.Count + " entries"); } catch (UserNotConnectedException e) { System.Console.WriteLine(e.Message); } }
public override void Configure(Menu menu, Menu.MenuElement element) { if (element.Action.Type == Menu.ActionType.ChangeValue) { this.Text.text = element.Text + StringExtensions.SPACE + OptionsValues.GetDisplaySuffix(element.Action.Param); } else { this.Text.text = element.Text; } _t = 0; _highlighted = false; updateColor(); }
protected override void Action(ArgumentsValues args, OptionsValues options) { if (args.ContainsKey("command")) { Console.WriteLine(); Console.Write(Commands[args.Value<string>("command")].CompleteDescription()); } else { Console.WriteLine(); foreach (ICommand c in Commands.Values) { Console.Write("\t" + c.Keyword + " : " + c.Description); Console.WriteLine(); } } }
private void handleAction(Menu.Action action, int dir = 1) { switch (action.Type) { default: case Menu.ActionType.None: break; case Menu.ActionType.OpenMenu: _pastMenuStack.Add(_currentMenu.Name); configureForState(action.Param); break; case Menu.ActionType.SceneTransition: this.Hide(); _actionTimer = new Timer(this.SceneTransitionDelay, false, true, onDelayedAction); _timerParam = action.Param; _changingScene = true; LocalEventNotifier.Event e = new LocalEventNotifier.Event(); e.Name = this.EndSceneEvent; GlobalEvents.Notifier.SendEvent(e); break; case Menu.ActionType.CloseMenuWithEvent: this.Hide(); _actionTimer = new Timer(this.EventSendDelay, false, true, onDelayedAction); _timerParam = action.Param; break; case Menu.ActionType.ChangeValue: OptionsValues.ChangeValue(action.Param, dir); refreshState(); break; case Menu.ActionType.Reload: for (int i = 0; i < _pastMenuStack.Count; ++i) { menuByStateName(_pastMenuStack[i]).Reload(); } _currentMenu.Reload(); refreshState(); break; } }
protected override void Action(ArgumentsValues args, OptionsValues options) { System.Console.Write("Enter your username : "******"Enter your password : "******""; ConsoleKeyInfo key; do { key = System.Console.ReadKey(true); if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter) { password += key.KeyChar; System.Console.Write("*"); } else if (key.Key == ConsoleKey.Backspace && password.Length > 0) { password = password.Substring(0, (password.Length - 1)); System.Console.Write("\b \b"); } } while (key.Key != ConsoleKey.Enter); System.Console.WriteLine(); try { Client.Login(username, password); System.Console.WriteLine("Success"); } catch (UnauthorizedAccessException e) { System.Console.WriteLine(e.Message); } Client.SaveConfig(); }
protected override void Action(ArgumentsValues args, OptionsValues options) { MangaRequestData data = MangaRequestData.DefaultAddRequest(args.Value<ReadingStatus>("status")); if (options.ContainsKey("score")) data.Score = options["score"].Value<int>("value"); if (options.ContainsKey("priority")) data.Priority = options["priority"].Value<Priority>("value"); MiniMALClient.AddRequestResult result = Client.AddManga(args.Value<int>("id"), data); switch (result) { case MiniMALClient.AddRequestResult.Created: System.Console.WriteLine("Created"); break; case MiniMALClient.AddRequestResult.AlreadyInTheList: System.Console.WriteLine("Already in your list."); break; } }
protected override void Action(ArgumentsValues args, OptionsValues options) { var data = new MangaRequestData(); if (options.ContainsKey("score")) data.Score = options["score"].Value<int>("value"); if (options.ContainsKey("status")) data.Status = options["status"].Value<ReadingStatus>("value"); MiniMALClient.UpdateRequestResult result = Client.UpdateManga(args.Value<int>("id"), data); switch (result) { case MiniMALClient.UpdateRequestResult.Updated: System.Console.WriteLine("Updated"); break; case MiniMALClient.UpdateRequestResult.NoParametersPassed: System.Console.WriteLine("Empty request - use options"); break; } }
protected override void Action(ArgumentsValues args, OptionsValues options) { AnimeList animelist = args.ContainsKey("user") ? MiniMALClient.LoadAnimelist(args.Value<string>("user")) : Client.LoadAnimelist(); IEnumerable<Anime.Anime> list = new List<Anime.Anime>(); foreach (Option.OptionKeys opt in options.Keys) switch (opt.Long) { case "watching": list = list.Concat(animelist[WatchingStatus.Watching]); break; case "completed": list = list.Concat(animelist[WatchingStatus.Completed]); break; case "hold": list = list.Concat(animelist[WatchingStatus.OnHold]); break; case "dropped": list = list.Concat(animelist[WatchingStatus.Dropped]); break; case "planned": list = list.Concat(animelist[WatchingStatus.PlanToWatch]); break; } IList<Anime.Anime> enumerable = list as IList<Anime.Anime> ?? list.ToList(); if (!enumerable.Any()) enumerable = animelist.ToList(); System.Console.WriteLine(); foreach (Anime.Anime a in enumerable) System.Console.WriteLine("({0}) {1}", a.Id, a.Title); System.Console.WriteLine(); System.Console.WriteLine(enumerable.Count + " entries"); }
protected override void Action(ArgumentsValues args, OptionsValues options) { MangaList mangalist = args.ContainsKey("user") ? MiniMALClient.LoadMangalist(args.Value<string>("user")) : Client.LoadMangalist(); IEnumerable<Manga.Manga> list = new List<Manga.Manga>(); foreach (Option.OptionKeys opt in options.Keys) switch (opt.Long) { case "reading": list = list.Concat(mangalist[ReadingStatus.Reading]); break; case "completed": list = list.Concat(mangalist[ReadingStatus.Completed]); break; case "hold": list = list.Concat(mangalist[ReadingStatus.OnHold]); break; case "dropped": list = list.Concat(mangalist[ReadingStatus.Dropped]); break; case "planned": list = list.Concat(mangalist[ReadingStatus.PlanToRead]); break; } IList<Manga.Manga> enumerable = list as IList<Manga.Manga> ?? list.ToList(); if (!enumerable.Any()) enumerable = mangalist.ToList(); System.Console.WriteLine(); foreach (Manga.Manga m in enumerable) System.Console.WriteLine("({0}) {1}", m.Id, m.Title); System.Console.WriteLine(); System.Console.WriteLine(enumerable.Count + " entries"); }
protected override void Action(ArgumentsValues args, OptionsValues options) { if (ExitRequest != null) ExitRequest(this, new EventArgs()); }
protected override sealed void CheckValidity(string[] args, out ArgumentsValues arguments, out OptionsValues options) { var argumentsDictionary = new ArgumentsDictionary(); var optionsDictionary = new OptionsDictionary(); int argsCount = 0; for (int i = 0; i < args.Length; i++) { if (Options[args[i]].HasValue) { i += Options[args[i]].Value.Arguments.Count; continue; } argsCount++; } if (argsCount < RequiredArguments.Count) throw new NumberOfArgumentsException(argsCount, RequiredArguments.Count); if (argsCount > RequiredArguments.Count + OptionalArguments.Count) throw new NumberOfArgumentsException(argsCount, RequiredArguments.Count + OptionalArguments.Count); int j = 0; int k = 0; for (int i = 0; i < args.Length; i++) { if (Options[args[i]].HasValue) { Option o = Options[args[i]].Value; var optionArgs = new ArgumentsDictionary(); foreach (IArgument argument in o.Arguments) { i++; IArgument a = argument; if (!a.IsValid(args[i])) throw new ArgumentNotValidException(a, j); optionArgs.Add(a.Name, args[i]); } optionsDictionary.Add(o.Key, new ArgumentsValues(optionArgs)); continue; } if (j < RequiredArguments.Count) { if (!RequiredArguments[j].IsValid(args[i])) throw new ArgumentNotValidException(RequiredArguments[j], j); argumentsDictionary.Add(RequiredArguments[j].Name, args[i]); j++; } else { if (!OptionalArguments[k].IsValid(args[i])) throw new ArgumentNotValidException(OptionalArguments[k], j + k); argumentsDictionary.Add(OptionalArguments[k].Name, args[i]); k++; } } arguments = new ArgumentsValues(argumentsDictionary); options = new OptionsValues(optionsDictionary); }