internal override void Run() { Prompter.Style = Styling.Colorful; var prompter = new Prompter() .Input("Name", $"Hi, what's your {Green.BgDkYellow}name? ", q => q .WithInstructions(NameInstructions1, NameInstructions2, NameInstructions3) .ValidateWith((name, _) => name.Length >= 6) .Transform(name => name.ToUpperInvariant()) .DefaultsTo("Jeevan")) .Password("Password", "Enter password: "******"Proceed", "Should we proceed? ", true) .List("Proceed2", "Should we proceed (checkbox)? ", new[] { "Yes", "No" }, selected => selected == 0) .Text("You have decided to proceed", t => t .When(ans => ans.Proceed)) .Text("You have decided not to proceed", t => t .When(ans => !ans.Proceed)); prompter.BetweenPrompts += (sender, args) => PrintBlank(); dynamic answers = prompter.Ask(); PrintLine($"Your name is {Yellow}{answers.Name}"); PrintLine($"Your password is {Red}{answers.Password}"); PrintLine($"Should proceed: {Blue}{answers.Proceed}"); PrintLine($"Should proceed 2: {DkBlue.BgWhite}{answers.Proceed2}"); }
public override string Help(T state, object defaultValue) { var prompt = new Prompter <T>(_field.Template(TemplateUsage.DateTimeHelp), _field.Form, null); var args = HelpArgs(state, defaultValue); return(prompt.Prompt(state, _field.Name, args.ToArray())); }
protected void PrintCommands(IList <CommandMeta> metaList) { var list = metaList.Where(p => p.Method != null); foreach (var meta in list) { Prompter.Write(" {0}", meta.Method); if (meta.Alias != null) { Prompter.Write(", {0}", meta.Alias); } if (meta.MethodInfo != null) { var methodParamAttributes = (Parameter[])Attribute.GetCustomAttributes(meta.MethodInfo, typeof(Parameter)); foreach (var param in methodParamAttributes) { Prompter.Write(param.Required ? " <{0}>" : " [{0}]", param.Attribute); } } if (meta.Description != null) { Prompter.WriteLine("\t{0}", meta.Description); } else { Prompter.WriteLine(); } } }
private void ValidatePattern(string pattern, IField <T> field, int maxArgs) { if (!Prompter <T> .ValidatePattern(_form, pattern, field, maxArgs)) { throw new ArgumentException(string.Format("Illegal pattern: \"{0}\"", pattern)); } }
protected void Add(System.Reflection.PropertyInfo prop, object source, bool isPassword = false, string defaultValue = "") { Add(prop.Name, defaultValue, string.Empty, null, isPassword); var added = Prompter.First(f => f.Prompt == prop.Name); added.Validator.Assignment = new Action <object>(o => prop.SetValue(source, o, null)); }
public override void Execute() { Console.WriteLine("you entered 0: " + Prompter.Get <string>(0)); Console.WriteLine("you entered 1: " + Prompter.Get <int>(1)); Console.WriteLine("done"); Console.ReadKey(); }
/// <summary> /// Primary selector for user options, will either launch new UI or database manager instances depending /// </summary> /// <param name="choice">The integer choice value selected by the user</param> public void select(int choice) { using (var bc = new BusinessContext()) { InfoManager infoManager = new InfoManager(bc); switch (choice) { case 1: new LoginUI().prompt(); break; case 2: var customer = infoManager.customersLike(Prompter.validatedInputString("First Name"), Prompter.validatedInputString("Last Name")); if (customer != null) { var columns = typeof(Customer).GetProperties().Select(property => property.Name).ToList(); for (int i = 0; i < columns.Count - 1; i++) { Console.Write("{0} ", columns[i]); } Console.WriteLine(); Console.WriteLine(customer.ToString()); } else { Console.WriteLine("No results found"); } break; case 3: var result = infoManager.locationDetails(Prompter.validatedInputString("store location name")); if (result != null) { var columns = typeof(Order).GetProperties().Select(property => property.Name).ToList(); for (int i = 0; i < columns.Count - 1; i++) { Console.Write("{0} ", columns[i]); } Console.WriteLine(); foreach (var r in result) { Console.WriteLine(r.ToString()); } } else { Console.WriteLine("No results found"); } break; default: Console.WriteLine("Please select a valid option"); break; } } Console.WriteLine(); }
private static void DispatchBuffer() { CString8 *bufferCopy = CString8.Copy(textBuffer->buffer); Diagnostics.Assert(bufferCopy != null, "Prompter::DispatchBuffer(): INSANITY CHECK: CString8.Copy(byte*) returned NULL"); Prompter.QueueLine(bufferCopy); CString8.DISPOSE(bufferCopy); textBuffer->Clear(); }
public MedicXApplication(UnitOfWork unitOfWork) { if (unitOfWork == null) { throw new ArgumentNullException(nameof(unitOfWork)); } controllerPool = new ControllerPool(unitOfWork, this); prompter = new Prompter(); }
public void ShouldBeValidEachLetter() { var rover = TestableRover.Create(); rover.PositionMock.SetupProperty(x => x.X, 1); rover.PositionMock.SetupProperty(x => x.Y, 2); rover.PositionMock.Setup(x => x.IsValid()).Returns(true); IPrompter prompter = new Prompter("KLMLMLMLM"); _firstRover = new Rover(rover.PositionMock.Object, prompter, DirectionType.N); Assert.IsFalse(_firstRover.IsValid()); }
static void Main(string[] args) { Prompter p = new Prompter(); Resolver r = new Resolver(); while (true) { List <char> input = p.Prompt("Enter expression: "); double result = r.Resolve(input); Console.WriteLine($"Answer: {result}"); } }
//Inserted static void Main(string[] args) { IPrompter firstPrompter = new Prompter("LMLMLMLMM"); IRover firstRover = new Rover(new RoverPosition(1, 2), firstPrompter, DirectionType.N); Console.WriteLine(firstRover.Execute()); Console.WriteLine("-----"); IPrompter secondPrompter = new Prompter("MMRMMRMRRM"); IRover secondRover = new Rover(new RoverPosition(3, 3), secondPrompter, DirectionType.E); Console.WriteLine(secondRover.Execute()); }
/// <summary> /// Adds a Prompt /// </summary> /// <param name="prompt"></param> /// <param name="defaultValue"></param> /// <param name="errorPrompt"></param> /// <param name="validator"></param> /// <param name="isPassword"></param> protected void Add(string prompt, string defaultValue, string errorPrompt, Validators.IValidator validator = null, bool isPassword = false) { if (validator == null) { validator = Validators.BaseValidator <string> .InstanceByType(this, prompt); } Prompter.AddLast(new Prompts.PromptItem() { DefaultValue = defaultValue, ErrorPrompt = string.IsNullOrEmpty(errorPrompt) ? validator.ErrorMessage : errorPrompt, Prompt = prompt, Validator = validator, IsPassword = isPassword }); }
async Task Trigger() { //在调用api之前看自增,避免多次触发 _timeElapsed += (int)timer.Interval; //第0分钟或者第N分钟时的时候 if (_timeElapsed % SyncTimeInterval == 0 || _timeElapsed == (int)timer.Interval) { await DateTimeUpdater.SyncTimeAsync(); } var nowTime = DateTime.Now; var currentMinute = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); var deadline = DateTime.Today.Add(Config.SleepTime); //小于明天6点算作今天 var nextDayStartTime = new TimeSpan(5, 59, 59); if (Config.SleepTime <= nextDayStartTime && nowTime.TimeOfDay > nextDayStartTime) { deadline = deadline.AddDays(1); } var noticeTime = deadline.AddMinutes(-60); var warningTime = deadline.AddMinutes(-30); var sleepTime = deadline.AddMinutes(-5); if (currentMinute == noticeTime && Log.All(i => i != currentMinute)) { _cancelForceSleepCounter = 10; Log.Add(currentMinute); Prompter.SendMsg2User(MsgType.Notice); } if (currentMinute == warningTime && Log.All(i => i != currentMinute)) { Log.Add(currentMinute); Prompter.SendMsg2User(MsgType.Warning); } if (currentMinute == sleepTime && Log.All(i => i != currentMinute)) { Log.Add(currentMinute); Prompter.SendMsg2User(MsgType.Sleep); } // 触发休眠,2小时之内无法开机,如果次数超过了十次则取消强制休眠,避免休眠之前触发多次 var timeDiff = currentMinute - deadline; if (timeDiff <= TimeSpan.FromHours(2) && timeDiff > TimeSpan.FromHours(0) && --_cancelForceSleepCounter > 0) { Sleep(); } }
protected void PrintMessage(IRequest request) { var list = CommandResolver.Find(request); var identity = list.FirstOrDefault(); if (identity.MethodInfo != null) { Prompter.WriteLine("Example of {0}:", request.Command); } else { Prompter.WriteLine("Example: "); } PrintCommands(list); }
public void Move(ICollection <FileSystemInfo> items, DirectoryInfo destination) { foreach (FileSystemInfo item in items) { try { File.Move(item.FullName, destination.FullName + "\\" + item.Name); } catch (IOException e) { Prompter.HandleError(e); } } OnResponse(); }
public void Decompress(ICollection <FileSystemInfo> sources, DirectoryInfo rootDirInfo) { try { RootDirInfo = rootDirInfo; SentSources = sources; ArchiverForm af = new ArchiverForm (OnDecompressInputResponse, SentSources.ElementAt(0).Name); af.Show(); } catch (IOException e) { Prompter.HandleError(e); } }
public void OnDecompressInputResponse(string input, string password) { if (password != "") { Archiver.SetEncryption(password); } try { Archiver.DecompressItem(SentSources.ElementAt(0), RootDirInfo + "\\" + input); } catch (IOException e) { Prompter.HandleError(e); } Archiver.DisableEncryption(); OnResponse(); }
static List <Prompt> GenerateReportsFromPrompt() { List <Prompt> prompts = new List <Prompt>(); try { /*Gets all necessary input and stores it into a list of prompts */ prompts = Prompter.PromptUser(); } catch (Exception e) { ConsoleRep.Log(new string[] { "There was an error collecting the prompt data!", "Error:", e.Message, "Seeing that you have given us absolutely nothing to work with,", "I will just retire to my room until you actually give me something useful!" }, ConsoleColor.Red); throw; } return(prompts); }
/// <summary> /// Prints the contents of the options list to the screen and awaits valid user input /// </summary> public void prompt() { int choice = 0; do { for (int i = 1; i < options.Count; i++) { Console.WriteLine("{0} : {1}", i, options[i]); } Console.WriteLine("{0} : {1}", 0, options[0]); choice = Prompter.validatedInputInteger("selection", options.Count); if (choice != 0) { select(choice); } } while (choice != 0); }
// Use this for initialization void Awake() { SetStandardActivationEffects(); CURRENT = this; this.gameObject.GetComponent <Text> ().text = ""; beep4go = new GameObject(); beep4 = beep4go.AddComponent <AudioSource> (); beep4.clip = Resources.Load("Sounds/Source/prompter_character_sound") as AudioClip; beep4.panStereo = 0f; topVolume = 0.05f; decayWaiter = defaultDecayWaiter; var s = GameObject.Instantiate(Resources.Load("Sounds/TerminalSoundsPrefab")) as GameObject; //sounds = s.GetComponent<TerminalSounds> (); }
public void Archive(ICollection <FileSystemInfo> sources, DirectoryInfo rootDirInfo) { try { RootDirInfo = rootDirInfo; SentSources = sources; ArchiverForm af = new ArchiverForm (OnArchiveNameInputResponse, SentSources.ElementAt(0).Name + ".zip"); af.Show(); } catch (UnauthorizedAccessException e) { Prompter.HandleError(e); } catch (IOException e) { Prompter.HandleError(e); } }
public static async Task promptGoogle(string hitGoogleWith) { Console.WriteLine("Enter your zipcode"); string input = Console.ReadLine(); string Googlekey = "AIzaSyAfdlKioHIQ6X06IfAoNa22KtU1t35Xd_A"; string result = await Prompter.getUrl("https://maps.googleapis.com/maps/api/geocode/json?address=" + input + "=" + Googlekey); Google g = JsonConvert.DeserializeObject <Google>(result); double lat = g.results.ElementAt(0).geometry.location.lat; double lng = g.results.ElementAt(0).geometry.location.lng; string LatLng = (lat.ToString() + "," + lng.ToString()); IJSONAPI googapi = new GooglePlacesAPI(); Google place = await googapi.GetData <Google>(hitGoogleWith, Googlekey, LatLng); Console.WriteLine($"Here's a location nearby that serves your favorite search term: {LatLng}"); // Console.WriteLine(googapi.ToJSON(place)); if (place.results.Count > 0) { Console.WriteLine(place.results[0].name); } }
/// <summary> /// Primary selector following valid user choice input /// </summary> /// <param name="choice">Integer choice value from user</param> public void select(int choice) { using (var bc = new BusinessContext()) { switch (choice) { case 1: Customer returnCustomer = new CustomerManager(bc).login(Prompter.validatedInputString("First Name"), Prompter.validatedInputString("Last Name")); if (returnCustomer == null) { Console.WriteLine("Invalid login"); } else { new CustomerUI(returnCustomer).prompt(); } break; case 2: Customer newCustomer = new CustomerManager(bc).create(Prompter.validatedInputString("First Name"), Prompter.validatedInputString("Last Name")); if (newCustomer == null) { Console.WriteLine("Customer already exists"); } else { new CustomerUI(newCustomer).prompt(); } break; default: Console.WriteLine("Please select a valid option"); break; } } Console.WriteLine(); }
public Waiting(Prompter prompter) { _prompter = prompter; }
public static void Main(string[] args) { Prompter.prompt().Wait(); }
public PrompterCommand(Prompter prompter) { this.prompter = prompter ?? throw new ArgumentNullException(nameof(prompter)); }
private void RemovePrompter(Prompter prompter) { if ((prompter == null) || !prompters.Contains(prompter)) { btnPrmptDelete.Enabled = false; return; } prompters.Remove(prompter); if (lstPrompter.Items.Contains(prompter)) lstPrompter.Items.Remove(prompter); lstPrompter.SelectedIndex = -1; }
private void AddPrompter(string moduleName, string commandName) { if (!modules.ContainsKey(moduleName) && (moduleName !="[ANY]")) return; Prompter prompter = new Prompter(this, moduleName, commandName); if (prompters.Contains(prompter)) return; prompter.ResponseSent += new ResponseSentEventHandler(prompter_ResponseSent); prompters.Add(prompter); lstPrompter.Items.Add(prompter); if (lstPrompter.Items.Contains(prompter)) lstPrompter.SelectedItem = prompter; }
public FoundGame(Prompter prompter) { _prompter = prompter; }
private void SelectPrompter(Prompter prompter) { if (this.InvokeRequired) return; if ((prompter == null) || !prompters.Contains(prompter)) { selectedPrompter = null; btnPrmptDelete.Enabled = false; return; } selectedPrompter = prompter; btnPrmptDelete.Enabled = true; }
public ImportCommand() { prompter = Prompter.Default; SUFFIX = "-" + DateTime.Now.ToString("yyyy_MM_dd-HH_mm") + ".json"; DEFAULT_FILE_NAME = "_backups/backup" + SUFFIX; }
public void Awake() { ui = this; prompt = FindObjectOfType <Prompter>(); inputs = FindObjectOfType <PlayerInput>(); }
public ExportCommand() { prompter = Prompter.Default; }
public static void Execute(CommandExecutionContext *context) { Prompter.DisplayCommandList(); }