/// <summary> /// Searches the class for all fields marked with <see cref="InputField"/>, /// and adds them to the internal dictionary for use in other methods. /// </summary> /// <remarks> /// Important to note: /// Be careful with how you arrange these fields. /// If a field is in a spot that is already occupied, /// It will throw an error. /// </remarks> /// -C protected void RegisterMenuFields() { bool arrows = false; foreach (FieldInfo f in GetType().GetFields()) { if (Attribute.IsDefined(f, typeof(InputField))) { // if it's an input field var InputField info = f.GetCustomAttribute(typeof(InputField)) as InputField; // get it's attribute int page = info.Page; int pos = info.Position; if (!InputFields.ContainsKey(page)) { InputFields[page] = new Dictionary <int, MessageFieldNode>(); } if (InputFields[page].ContainsKey(pos)) { // If there is already an input field here throw new ConflictingFieldException(InputFields[page][pos].Name, info.Name, page, pos); // Throw an error. } // Otherwise, if everything is fine, // Add the field. MessageFieldNode node = new MessageFieldNode(info.Name, info.Page, info.Position, info.Value, info.Type); // create the node node.ClassPtr = this; // give it a pointer to this class, so it can modify the variable it's attached to node.SetValue(info.Value); InputFields[info.Page][info.Position] = node; // And add the appropriate node to the dict where it belongs } } int FieldCount = 0; foreach (int i in InputFields.Keys) { foreach (int j in InputFields[i].Keys) { FieldCount++; if (FieldCount > 1) { arrows = true; } } FieldCount = 0; } if (MenuOptions == null) { MenuOptions = new List <MenuOptionNode>(); } if (arrows) { // if there is more than one field, add up and down buttons if (!MenuOptions.Contains(ReactionHandler.UP)) { AddMenuOptions(ReactionHandler.UP); } if (!MenuOptions.Contains(ReactionHandler.DOWN)) { AddMenuOptions(ReactionHandler.DOWN); } } PageCount = InputFields.Values.Count; // set the number of pages }
private void UpdateMenuOptions() { if (SelectedItems.Count == 1) { navigateMenuItem.IsEnabled = true; } else { navigateMenuItem.IsEnabled = false; } bool bCanFilter = false; bool bCanUnfilter = false; foreach (BaseErrorListItemViewModel v in SelectedItems) { if (!(v is FilterableErrorListItemViewModel)) { bCanFilter = false; bCanUnfilter = false; break; } else { FilterableErrorListItemViewModel filterable = v as FilterableErrorListItemViewModel; if (filteredErrorListData.Contains(filterable)) { bCanUnfilter = true; } else { bCanFilter = true; } } if (bCanFilter && bCanUnfilter) { bCanFilter = false; bCanUnfilter = false; break; } } if (bCanFilter || bCanUnfilter) { if (!MenuOptions.Contains(separatorBeforeFilterItem)) { MenuOptions.Add(separatorBeforeFilterItem); } } else if (MenuOptions.Contains(separatorBeforeFilterItem)) { MenuOptions.Remove(separatorBeforeFilterItem); } if (bCanFilter) { if (!MenuOptions.Contains(filterMenuItem)) { MenuOptions.Add(filterMenuItem); } } else { if (MenuOptions.Contains(filterMenuItem)) { MenuOptions.Remove(filterMenuItem); } } if (bCanUnfilter) { if (!MenuOptions.Contains(unFilterMenuItem)) { MenuOptions.Add(unFilterMenuItem); } } else { if (MenuOptions.Contains(unFilterMenuItem)) { MenuOptions.Remove(unFilterMenuItem); } } }
public static void RunInWizardMode() { Console.WriteLine($"=========== Welcome to Song Downloader ===========\n"); while (true) { Console.WriteLine(StartMenu); var input = Console.ReadKey(); if (!MenuOptions.Contains(input.KeyChar)) { Console.WriteLine("Please type one of the options listed above\n"); Console.ReadKey(); Console.Clear(); continue; } Console.Clear(); switch (input.KeyChar) { case '1': // Download songs one by one passing the name or search string while (true) { Console.WriteLine(OneByOneMenu); var menu1Input = Console.ReadLine(); if (string.IsNullOrEmpty(menu1Input)) { Console.WriteLine("Please type some search string\n"); Console.ReadKey(); Console.Clear(); continue; } Console.WriteLine($"You typed '{menu1Input.Trim()}'\n" + "Searching for it on database"); } case '2': // Download songs passing Spotify public playlist link Console.WriteLine(SpotifyPlaylistMenu); var menu2Input = Console.ReadLine(); if (string.IsNullOrEmpty(menu2Input)) { Console.WriteLine("Please type some search string\n"); Console.ReadKey(); Console.Clear(); continue; } Console.WriteLine($"You typed '{menu2Input.Trim()}'\n" + "Do you want to set output directory? If yes insert it, if don't just press enter"); var playlistLink = menu2Input.Trim(); var defaultOutput = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Program.GetBaseFolderName(Session.Id)); menu2Input = Console.ReadLine(); var output = string.IsNullOrEmpty(menu2Input) ? defaultOutput : Path.Combine(menu2Input, Program.GetBaseFolderName(Session.Id)); Console.WriteLine("Do you want to run in parallel?(S/N)\n"); menu2Input = Console.ReadLine(); var runInParallel = !string.IsNullOrEmpty(menu2Input) && menu2Input.Trim().ToLowerInvariant() != "n"; Console.WriteLine("Starting"); Thread.Sleep(TimeSpan.FromSeconds(2)); Console.Clear(); using (var musicDownloader = new MusicDownloader(output)) { musicDownloader.DownloadSpotifyPlaylist(playlistLink, runInParallel); } break; } } }