static void CertificatesListMenu(SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Certificates"); var certificatesmenu = new SelectableMenu <Action>(options); var certificates = certificatedatarepo.GetAll(); foreach (var cert in certificates) { certificatesmenu.Add(cert.Businessname, () => { CertificateOptions(cert, options); CertificatesListMenu(options); }); } certificatesmenu.Add("Back", () => { Console.Clear(); CreateMainMenu(options); }); certificatesmenu.Draw().Invoke(); }
static void CertificateUpdate(CertificateData cert, SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Certificate edit : {cert.Businessname}"); var certificatesoptions = new SelectableMenu <Action>(options); var props = cert.GetType().GetProperties(); foreach (var prop in props) { var name = prop.Name; var value = prop.GetValue(cert); value = name == "Password" ? "****" : value; certificatesoptions.Add($"{name} : {value}", () => { if (name != "Id") { UpdateCertificateValue(cert, name, options); } else { CertificateUpdate(cert, options); } }); } certificatesoptions.Add("Back", () => { Console.Clear(); }); certificatesoptions.Draw().Invoke(); }
/// <summary> /// Entry point. /// </summary> /// <param name="args">commandline arguments</param> public static void Main(string[] args) { // description Console.WriteLine("It is easy to create a select menu on CommandLine."); Console.WriteLine("You can color selections, place a cursor, etc."); Console.WriteLine(""); // create selectable menu instance. // // 1. When selected, thr color is green. // 2. When selected, clear menu. var options = new SelectableMenuOptions() { SelectedType = new ArrowSelectedType() { SelectedColor = ConsoleColor.Green, }, IsClearAfterSelection = true, }; var selectableMenu = new SelectableMenu <Action>(options); // setup menu item. selectableMenu.Add("Would you choose item A?", () => { Console.WriteLine("item A Selected!!"); }); selectableMenu.Add("Would you choose item B?", () => { Console.WriteLine("item B Selected!!"); }); selectableMenu.Add("Would you choose item C?", () => { Console.WriteLine("item C Selected!!"); }); selectableMenu.Add("Would you choose item D?", () => { Console.WriteLine("item D Selected!!"); }); // Draw a menu in the console. var selected = selectableMenu.Draw(); selected.Invoke(); Console.ReadKey(); }
public void NullOptionsArguments() { var ex = Assert.Throws <ArgumentNullException>(() => { SelectableMenuOptions options = null; var selectableMenu = new SelectableMenu <string>(options); }); ex.Message.Is("Value cannot be null. (Parameter 'options')"); }
static void Setup() { var menuOptions = new SelectableMenuOptions() { SelectedType = new ArrowSelectedType() { SelectedColor = ConsoleColor.Green, }, IsClearAfterSelection = true, }; CreateMainMenu(menuOptions); }
static void NewCertificateValue(CertificateData cert, string Name, SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Editing value : {Name}"); Console.WriteLine($"New value : "); var stin = Console.ReadLine(); var prop = cert.GetType().GetProperties().Where(x => x.Name == Name).FirstOrDefault(); prop.SetValue(cert, stin); NewCertificate(cert, options); }
static void NewCertificate(CertificateData cert, SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"New CertificateData"); var certificatesoptions = new SelectableMenu <Action>(options); var props = cert.GetType().GetProperties(); foreach (var prop in props) { var name = prop.Name; var value = prop.GetValue(cert); value = name == "Password" ? "****" : value; certificatesoptions.Add($"{name} : {value}", () => { if (name != "Id") { NewCertificateValue(cert, name, options); } else { NewCertificate(cert, options); } }); } certificatesoptions.Add("Save", () => { try { certificatedatarepo.Add(cert); _logger?.Info("NewCertificate()", "Certificate added into repository."); CreateMainMenu(options); } catch (Exception ex) { Console.WriteLine($"Validation errors : { ex.Message }"); Console.ReadLine(); NewCertificate(cert, options); } }); certificatesoptions.Add("Cancel", () => { CreateMainMenu(options); }); certificatesoptions.Draw().Invoke(); }
static void CertificateDelete(CertificateData cert, SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Are you sure to delete : {cert.Businessname} ?"); var certificatesoptions = new SelectableMenu <Action>(options); certificatesoptions.Add("Yes", () => { certificatedatarepo.Delete(cert); _logger?.Info("CertificateDelete()", "Certificate deleted from repository."); }); certificatesoptions.Add("No", () => { CertificateOptions(cert, options); }); certificatesoptions.Draw().Invoke(); }
static void UpdateCertificateValue(CertificateData cert, string Name, SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Editing value : {Name}"); Console.WriteLine($"New value : "); var stin = Console.ReadLine(); var certificatesoptions = new SelectableMenu <Action>(options); var prop = cert.GetType().GetProperties().Where(x => x.Name == Name).FirstOrDefault(); prop.SetValue(cert, stin); try { var newcertificate = new CertificateData(cert.Id, cert.Password, cert.Path, cert.Businessname); certificatesoptions.Add("Save", () => { certificatedatarepo.Update(newcertificate); _logger?.Info("UpdateCertificateValue()", "Certificate updated into repository."); CertificateUpdate(newcertificate, options); }); certificatesoptions.Add("Cancel", () => { NewCertificate(newcertificate, options); }); certificatesoptions.Draw().Invoke(); } catch (Exception ex) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Entity validation errors : { ex.Message }"); Console.ReadLine(); UpdateCertificateValue(cert, Name, options); } }
static void CreateMainMenu(SelectableMenuOptions options) { Console.Clear(); var mainmenu = new SelectableMenu <Action>(options); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Main Menu"); // add menu item. mainmenu.Add("List Certificates", () => { CertificatesListMenu(options); }); mainmenu.Add("Add new certificate settings", () => { var certificate = new CertificateData(); NewCertificate(certificate, options); }); mainmenu.Add("Exit ", () => { System.Environment.Exit(1); }); mainmenu.Draw().Invoke(); }
static void CertificateOptions(CertificateData cert, SelectableMenuOptions options) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"Certificate edit : {cert.Businessname}"); var certificatesoptions = new SelectableMenu <Action>(options); certificatesoptions.Add("Update values", () => { CertificateUpdate(cert, options); }); certificatesoptions.Add("Delete", () => { CertificateDelete(cert, options); CertificatesListMenu(options); }); certificatesoptions.Add("Back", () => { Console.Clear(); }); certificatesoptions.Draw().Invoke(); }
public Test_SelectableMenuOptions() { options = new SelectableMenuOptions(); }