static async Task Main(string[] args) { string response; do { await Out.WriteAsync("Enter number of messages, or leave it blank to exit. # "); response = await In.ReadLineAsync(); if (IsNullOrEmpty(response)) { break; // exit the program } var validNumberOfMessages = int.TryParse(response, out var messages); if (!validNumberOfMessages) { await Out.WriteLineAsync("Please enter a valid number"); continue; } for (var index = 0; index < messages; index++) { var shouldBeFaulted = index % 4 == 0; var orderId = NewId.NextGuid(); var customerNumber = shouldBeFaulted ? "INVALIDCustomer" : "Customer"; const string paymentCardNumber = "4000-1234-1234-1234"; await Out.WriteLineAsync($"Order: {orderId} STATUS: " + (shouldBeFaulted ? "Faulted" : "Completed")); var createRequest = new HttpRequestMessage(HttpMethod.Post, new Uri($"{BaseUrl}/Order/{orderId}/{customerNumber}?paymentCardNumber={paymentCardNumber}")); // Creat new Order await Client.SendAsync(createRequest); var acceptRequest = new HttpRequestMessage(HttpMethod.Put, new Uri($"{BaseUrl}/Order/{orderId}/accept")); // Accept the Order await Client.SendAsync(acceptRequest); } await Out.WriteLineAsync(""); } while (!IsNullOrEmpty(response)); }
private static async Task MainAsync() { File.WriteAllLines("secrets.txt", new[] { "Secret password: 12345" }); await Out.WriteLineAsync("Enter in your script - type \"STOP\" to quit:").ConfigureAwait(false); var context = new ScriptingContext(); var options = ScriptOptions.Default .AddImports( typeof(ImmutableArrayExtensions).Namespace) .AddReferences( typeof(ImmutableArrayExtensions).Assembly); while (true) { var code = await In.ReadLineAsync().ConfigureAwait(false); if (code == "STOP") { break; } var script = CSharpScript.Create( code, globalsType: typeof(ScriptingContext), options: options); var compilation = script.GetCompilation(); var diagnostics = compilation.GetDiagnostics().Union( VerifyCompilation(compilation)).ToImmutableArray(); if (diagnostics.Length > 0) { foreach (var diagnostic in diagnostics) { Out.WriteLine(diagnostic); } } else { var result = await CSharpScript.RunAsync(code, globals : context, options : options).ConfigureAwait(false); if (result.ReturnValue != null) { await Out.WriteLineAsync($"\t{result.ReturnValue}").ConfigureAwait(false); } } } }
/* * private static async Task EvaluateCodeAsync() * { * Out.WriteLine("Enter in your script:"); * var code = In.ReadLine(); * Out.WriteLine( * await CSharpScript.EvaluateAsync(code).ConfigureAwait(false)); * } */ /* * private static async Task EvaluateCodeWithContextAsync() * { * Out.WriteLine("Enter in your script:"); * var code = In.ReadLine(); * Out.WriteLine( * await CSharpScript.EvaluateAsync(code, ScriptOptions.Default * .AddReferences(typeof (Context).Assembly) * .AddImports(typeof (Context).Namespace)).ConfigureAwait(false)); * } */ /* * private static async Task EvaluateCodeWithGlobalContextAsync() * { * Out.WriteLine("Enter in your script:"); * var code = In.ReadLine(); * Out.WriteLine( * await * CSharpScript.EvaluateAsync(code, globals: new CustomContext(new Context(4), Out)) * .ConfigureAwait(false)); * } */ /* * private static async Task CompileScriptAsync() * { * Out.WriteLine("Enter in your script:"); * var code = In.ReadLine(); * var script = CSharpScript.Create(code); * var compilation = script.GetCompilation(); * var diagnostics = compilation.GetDiagnostics(); * * if (diagnostics.Length > 0) * { * foreach (var diagnostic in diagnostics) * { * Out.WriteLine(diagnostic); * } * } * else * { * foreach (var tree in compilation.SyntaxTrees) * { * var model = compilation.GetSemanticModel(tree); * foreach (var node in tree.GetRoot().DescendantNodes(_ => true)) * { * var symbol = model.GetSymbolInfo(node).Symbol; * Out.WriteLine( * $"{node.GetType().Name} {node.GetText()}"); * * if (symbol != null) * { * var symbolKind = Enum.GetName(typeof (SymbolKind), symbol.Kind); * Out.WriteLine( * $"\t{symbolKind} {symbol.Name}"); * } * } * } * * Out.WriteLine((await script.RunAsync().ConfigureAwait(false)).ReturnValue); * } * } */ /* * private static async Task ExecuteScriptsWithStateAsync() * { * Out.WriteLine("Enter in your script - type \"STOP\" to quit:"); * * ScriptState<object> state = null; * * while (true) * { * var code = In.ReadLine(); * * if (code == "STOP") * { * break; * } * * state = state == null * ? await CSharpScript.RunAsync(code).ConfigureAwait(false) * : await state.ContinueWithAsync(code).ConfigureAwait(false); * * foreach (var variable in state.Variables) * { * Out.WriteLine( * $"\t{variable.Name} - {variable.Type.Name}"); * } * * if (state.ReturnValue != null) * { * Out.WriteLine( * $"\tReturn value: {state.ReturnValue}"); * } * } * } */ private static async Task ExecuteScriptsWithGlobalContextAsync() { WriteLine("Enter in your script - type \"STOP\" to quit:"); var session = new DictionaryContext(); while (true) { var code = await In.ReadLineAsync().ConfigureAwait(false); if (code == "STOP") { break; } var result = await CSharpScript.RunAsync(code, globals : session).ConfigureAwait(false); if (result.ReturnValue != null) { WriteLine($"\t{result.ReturnValue}"); } } }
static async Task stdioCommands() { var root = new RootCommand("OpenTabletDriver Console Client") { Name = "otd" }; root.AddRange(GenerateIOCommands()); root.AddRange(GenerateActionCommands()); root.AddRange(GenerateDebugCommands()); root.AddRange(GenerateModifyCommands()); root.AddRange(GenerateRequestCommands()); root.AddRange(GenerateListCommands()); root.AddRange(GenerateScriptingCommands()); while (true) { string stdiocmd = await In.ReadLineAsync(); await root.InvokeAsync(stdiocmd); } }
public static Task <string> ReadLineAsync() { return(In.ReadLineAsync()); }
public override async Task <DeliverableResponse> Run(string command, string[] args) { var connectionString = settings.ConnectionString; if (connectionString == null || string.IsNullOrEmpty(connectionString.ConnectionString)) { await Out.WriteLineAsync("No connection string is setup for your Umbraco instance. Chauffeur expects your web.config to be setup in your deployment package before you try and install."); return(DeliverableResponse.Continue); } if (connectionString.ProviderName == "System.Data.SqlServerCe.4.0") { var dataDirectory = (string)AppDomain.CurrentDomain.GetData("DataDirectory"); var dataSource = connectionString.ConnectionString.Split(';').FirstOrDefault(s => s.ToLower().Contains("data source")); if (!string.IsNullOrEmpty(dataSource)) { var dbFileName = dataSource.Split('=') .Last() .Split('\\') .Last() .Trim(); var location = fileSystem.Path.Combine(dataDirectory, dbFileName); if (!fileSystem.File.Exists(location)) { await Out.WriteLineAsync("The SqlCE database specified in the connection string doesn't appear to exist."); var response = args.Length > 0 ? args[0] : null; if (string.IsNullOrEmpty(response)) { await Out.WriteAsync("Create it? (Y/n) "); response = await In.ReadLineAsync(); } if (string.IsNullOrEmpty(response) || response.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { await Out.WriteLineAsync("Creating the database"); var engine = sqlCeEngineFactory(connectionString.ConnectionString); engine.CreateDatabase(); } else { await Out.WriteLineAsync("Installation is being aborted"); return(DeliverableResponse.Continue); } } } } await Out.WriteLineAsync("Preparing to install Umbraco's database"); context.Database.CreateDatabaseSchema(false); await Out.WriteLineAsync("Database installed and ready to go"); return(DeliverableResponse.Continue); }