public MainPage(ConsoleProgram program) : base("Main Page", program) { AddOption(new Option("Exercises", () => program.NavigateTo <ExercisePage>())); AddOption(new Option("Tuning", () => program.NavigateTo <TuningPage>())); AddOption(new Option("Exit", () => Environment.Exit(0))); }
public override bool ConfirmStart() { if (string.IsNullOrEmpty(Filename)) { if (string.IsNullOrEmpty(Name)) { Console.WriteLine($"RunPackage requires either a name or a filename to execute"); return(false); } else { //activate & load the package Console.WriteLine($"Activating Package {Name}"); package = PackageLibrary.GetPackage(Name); if (package == null) { Console.WriteLine($"Package [{Name}] not found.\n\nSC> GetPackages\n"); // run GetPackages for the user ConsoleProgram.StartTask("GetPackages"); Console.WriteLine($"\n\n"); return(false); } } } else { package = new TaskPackageFile(Filename); } return(base.ConfirmStart()); }
public ChapterThreePage(ConsoleProgram program) : base("Chapter Three", program) { //AddOption(new Option("Invert Identity Matrix", () => //{ // var chapter = new ChapterThree(); // chapter.InverseIdentity(); // Input.ReadString("Press [Enter] to navigate home"); // Program.NavigateTo<ChapterThreePage>(); //})); //AddOption(new Option("Multiple By the Inverse", () => //{ // var chapter = new ChapterThree(); // chapter.MultipliedByInverse(); // Input.ReadString("Press [Enter] to navigate home"); // Program.NavigateTo<ChapterThreePage>(); //})); //AddOption(new Option("Compare Inverse/Transpose vs Transpose/Inverse", () => //{ // var chapter = new ChapterThree(); // chapter.CompareInverseTranspose(); // Input.ReadString("Press [Enter] to navigate home"); // Program.NavigateTo<ChapterThreePage>(); //})); }
private static void UnregisterService() { Console.WriteLine("Unregistering service..."); ExecSc($"delete {_serviceName}"); Console.WriteLine("Service Unregistered!"); ConsoleProgram.PressToContinue(); }
private static void StartService() { Console.WriteLine("Starting service..."); ExecSc($"start {_serviceName}"); Console.WriteLine("Service Started!"); ConsoleProgram.PressToContinue(); }
private static void UpdateConfig(JObject config) { var appSettingsFile = Path.Join(ConsoleProgram.GetBasePath(), "appSettings.json"); File.WriteAllText(appSettingsFile, config.ToString()); Console.WriteLine("Configuration updated!"); }
internal static void UpdateFile(string setting, object value) { var appSettingsFile = Path.Join(ConsoleProgram.GetBasePath(), "appSettings.json"); Console.WriteLine($"Updating {setting}..."); Console.WriteLine($"Getting current settings from {appSettingsFile}"); var fileContents = File.ReadAllText(appSettingsFile); dynamic jsonObj = JsonConvert.DeserializeObject(fileContents); Console.WriteLine($"Previous setting: {jsonObj[setting]}"); Console.WriteLine($"New setting: {value}"); if (value is string stringValue) { jsonObj[setting] = stringValue; } if (value is int intValue) { jsonObj[setting] = intValue; } if (value is bool boolValue) { jsonObj[setting] = boolValue; } var outContents = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(appSettingsFile, outContents); Console.WriteLine($"Updated {setting}!"); }
private static void DisableService() { Console.WriteLine("Disabling service..."); ExecSc($"config {_serviceName} start=disabled"); Console.WriteLine("Service disabled!"); ConsoleProgram.PressToContinue(); }
private static void QueryService() { Console.WriteLine("Querying service..."); ExecSc($"query {_serviceName}"); Console.WriteLine("Service queried!"); ConsoleProgram.PressToContinue(); }
void RunTestGroup(List <string> testGroup) { foreach (var test in testGroup) { Console.WriteLine($" Command: {test}"); ConsoleProgram.StartTask(test); } }
private static void SetTwitchApiClientId() { Console.WriteLine("Enter Twitch App Client ID: "); var clientId = Console.ReadLine(); UpdateFile("TwitchApiClientId", clientId); ConsoleProgram.PressToContinue(); }
private static void SetTwitchApiClientSecret() { Console.WriteLine("Enter Twitch App Client Secret: "); var secret = Console.ReadLine(); UpdateFile("TwitchApiClientSecret", secret); ConsoleProgram.PressToContinue(); }
private static void SetDiscordWebHookUri() { Console.WriteLine("Enter Discord Webhook Uri: "); var webhook = Console.ReadLine(); UpdateFile("DiscordWebHookUri", webhook); ConsoleProgram.PressToContinue(); }
private static dynamic GetConfig() { var appSettingsFile = Path.Join(ConsoleProgram.GetBasePath(), "appSettings.json"); Console.WriteLine($"Getting current settings from {appSettingsFile}"); var fileContents = File.ReadAllText(appSettingsFile); var jsonObj = JObject.Parse(fileContents); return(jsonObj); }
static int Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; if (!Utils.FfFilesExist) { Console.WriteLine(Properties.Resources.FFmpegFFprobeIsMissing); return(-1); } var cp = new ConsoleProgram(); var result = cp.Run(args); return(result); }
private static void RegisterService() { System.Console.WriteLine("Registering service..."); var processPath = ConsoleProgram.GetBasePath(); var exePath = Path.Join(processPath, _exeName); var args = $"create {_serviceName} start=auto binpath=\"{exePath}\" displayname=\"{_serviceDisplayName}\""; ExecSc(args); args = $"description {_serviceName} \"{_serviceDescription}\""; ExecSc(args); args = $"failure {_serviceName} actions= restart/60000ms/restart/60000/restart/60000ms// reset= 3600"; ExecSc(args); System.Console.WriteLine("Service Registered!"); ConsoleProgram.PressToContinue(); }
static async Task Main(string[] args) => await ConsoleProgram <Resource, object, SourceLiason, MQTTLiason> .ExecuteAsync(args, envs : new Dictionary <string, string>() { { $"{Models.Options.MQTTOpts.Section}:{nameof(Models.Options.MQTTOpts.TopicPrefix)}", Models.Options.MQTTOpts.TopicPrefixDefault }, { $"{Models.Options.MQTTOpts.Section}:{nameof(Models.Options.MQTTOpts.DiscoveryName)}", Models.Options.MQTTOpts.DiscoveryNameDefault }, }, configureServices : (HostBuilderContext context, IServiceCollection services) => { services .AddMemoryCache() .AddOptions <Models.Options.SharedOpts>(Models.Options.SharedOpts.Section, context.Configuration) .AddOptions <Models.Options.SourceOpts>(Models.Options.SourceOpts.Section, context.Configuration) .AddOptions <TwoMQTT.Models.MQTTManagerOptions>(Models.Options.MQTTOpts.Section, context.Configuration) .AddSingleton <IThrottleManager, ThrottleManager>(x => { var opts = x.GetRequiredService <IOptions <Models.Options.SourceOpts> >(); return(new ThrottleManager(opts.Value.PollingInterval)); }) .AddTypeNamedHttpClient <ApiControllerDetection>() .AddTypeNamedHttpClient <Api>(lifetime: System.Threading.Timeout.InfiniteTimeSpan) .AddSingleton <Api>(x => { var opts = x.GetRequiredService <IOptions <Models.Options.SourceOpts> >(); var hcf = x.GetRequiredService <IHttpClientFactory>(); // Hopefully this only exists until KoenZomers.UniFi.Api is updated. return(new Api(new Uri(opts.Value.Host), opts.Value.Site, hcf)); }) .AddSingleton <ISourceDAO>(x => { var logger = x.GetRequiredService <ILogger <SourceDAO> >(); var cache = x.GetRequiredService <IMemoryCache>(); var api = x.GetRequiredService <DataAccess.Api>(); var opts = x.GetRequiredService <IOptions <Models.Options.SourceOpts> >(); return(new SourceDAO(logger, cache, api, opts.Value.Username, opts.Value.Password, opts.Value.AwayTimeout)); }); });
public TuningPage(ConsoleProgram program) : base("Tuning", program) { //AddOption(new Option("Matrix Multiplication", () => //{ // var tuning = new MatricesTuning(); // tuning.Multiplication(); //})); AddOption(new Option("Build Image from Chapter Five", () => { var tuning = new MatricesTuning(); tuning.BuildImageFromChapterFix(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); }
public ChapterSixPage(ConsoleProgram program) : base("Chapter Six", program) { AddOption(new Option("Regular", () => { var chapter = new ChapterSix(); chapter.NormalSphere(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ChapterSixPage>(); })); AddOption(new Option("Custom", () => { var chapter = new ChapterSix(); chapter.Custom(); Program.NavigateTo <ChapterSixPage>(); })); AddOption(new Option("Shrink it along the y axis", () => { var chapter = new ChapterSix(); chapter.ShrinkAlongYAxis(); Program.NavigateTo <ChapterSixPage>(); })); AddOption(new Option("Shrink it along the x axis", () => { var chapter = new ChapterSix(); chapter.ShrinkAlongXAxis(); Program.NavigateTo <ChapterSixPage>(); })); AddOption(new Option("Shrink and Rotate", () => { var chapter = new ChapterSix(); chapter.ShrinkAndRotate(); Program.NavigateTo <ChapterSixPage>(); })); AddOption(new Option("Shrink and skew", () => { var chapter = new ChapterSix(); chapter.ShrinkAndSkew(); Program.NavigateTo <ChapterSixPage>(); })); }
private static void SetTwitchApiCheckIntervalSeconds() { bool isNumber = false; int interval; do { Console.WriteLine("Enter Twitch API Check Interval Seconds: "); var webhook = Console.ReadLine(); isNumber = int.TryParse(webhook, out interval); if (!isNumber) { Console.WriteLine("Response must be a number."); } } while (!isNumber); UpdateFile("TwitchApiCheckIntervalSeconds", interval); ConsoleProgram.PressToContinue(); }
public static IHelloWorldService GetHelloWorldService(string apiType) { IHelloWorldService service = null; switch (apiType) { case "Console": service = new ConsoleProgram(); break; case "Web": service = new HelloWorldController(); break; case "Database": service = new DatabaseProgram(); break; default: throw new ArgumentException("Invalid apiType"); } return(service); }
/// <summary> /// Runs Eraser as a command-line application. /// </summary> /// <param name="commandLine">The command line parameters passed to Eraser.</param> private static int CommandMain(string[] commandLine) { using (ConsoleProgram program = new ConsoleProgram(commandLine)) try { program.Handlers.Add("help", new ConsoleActionData(CommandHelp, new ConsoleArguments())); program.Handlers.Add("erase", new ConsoleActionData(CommandErase, new EraseArguments())); program.Handlers.Add("addtask", new ConsoleActionData(CommandAddTask, new TaskArguments())); program.Handlers.Add("importtasklist", new ConsoleActionData(CommandImportTaskList, new ConsoleArguments())); program.Handlers.Add("shell", new ConsoleActionData(CommandShell, new ShellArguments())); program.Run(); return(0); } catch (UnauthorizedAccessException) { return(Win32ErrorCode.AccessDenied); } catch (Win32Exception e) { Console.WriteLine(e.Message); return(e.ErrorCode); } catch (ArgumentException e) { Console.WriteLine(e.Message); return(Win32ErrorCode.BadArguments); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); throw; } }
public ChannelConfigPage(Program program) : base("Twitch Channels Configuration", program, new Option("Show channels", () => { ShowChannels(); ConsoleProgram.PressToContinue(); program.NavigateTo <ChannelConfigPage>(); }), new Option("Add channel", () => { AddChannel(); ConsoleProgram.PressToContinue(); program.NavigateTo <ChannelConfigPage>(); }), new Option("Remove channel", () => { RemoveChannel(); ConsoleProgram.PressToContinue(); program.NavigateTo <ChannelConfigPage>(); }), new Option("Exit Configtool", () => Environment.Exit(0))) { }
static void Main(string[] args) { // prebuild some Dynamic ConsoleTasks ConsoleProgram.Start(args); }
public ConsoleActionData(ConsoleProgram.ActionHandler handler, ConsoleArguments arguments) { Handler = handler; Arguments = arguments; }
static void Main(string[] args) { ConsoleProgram.Start(args); }
public MenuPage(string title, ConsoleProgram program) : base(title, program) { }
public override TaskResult StartTask() { // Read a command line and perform the tasks over // and over string command; const string helpCommand = "help -Usagetext \"SHELL Usage: <Task Name> [task options]\n\""; Console.WriteLine($"{System.AppDomain.CurrentDomain.FriendlyName} Shell\n"); Console.WriteLine("'exit', 'quit' or 'q' to quit"); Console.WriteLine("'?' or 'help' for help\n"); do { Console.Write("SC> "); { command = Console.ReadLine().Trim(); } if (command.ToLower() == "quit") { break; } if (command.ToLower() == "q") { break; } if (command.ToLower() == "exit") { break; } // augment requests for help if ( command.Equals("?") || command.ToLower().Equals("help")) { command = helpCommand; } if (command.Length > 0) { try { var result = ConsoleProgram.StartTask(command); if (!string.IsNullOrEmpty(result.Message)) { Console.WriteLine($"[{result.ResultCode}]:\n{result.Message}\n"); } } catch (Exception ex) { Console.WriteLine($"An exception ocurred: {ex.Message}"); } } } while (true); return(new TaskResult() { IsSuccessful = true, Message = "exiting SmartConsole Shell" }); }
private static int CommandMain(string[] commandLine) { using (ConsoleProgram program = new ConsoleProgram(commandLine)) using (ManagerLibrary library = new ManagerLibrary(new Settings())) try { program.Handlers.Add("help", new ConsoleActionData(CommandHelp, new ConsoleArguments())); program.Handlers.Add("querymethods", new ConsoleActionData(CommandQueryMethods, new ConsoleArguments())); program.Handlers.Add("addtask", new ConsoleActionData(CommandAddTask, new AddTaskArguments())); program.Handlers.Add("importtasklist", new ConsoleActionData(CommandImportTaskList, new ConsoleArguments())); program.Run(); return 0; } catch (UnauthorizedAccessException) { return Win32ErrorCode.AccessDenied; } catch (Win32Exception e) { Console.WriteLine(e.Message); return e.ErrorCode; } catch (Exception e) { Console.WriteLine(e.Message); return 1; } }
public ExercisePage(ConsoleProgram program) : base("Exercises", program) { AddOption(new Option("Chapter One", () => { var chapter = new ChapterOne(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Two", () => { var chapter = new ChapterTwo(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Three", () => program.NavigateTo <ChapterThreePage>())); AddOption(new Option("Chapter Four", () => { var chapter = new ChapterFour(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Five", () => Program.NavigateTo <ChapterFivePage>())); AddOption(new Option("Chapter Six", () => Program.NavigateTo <ChapterSixPage>())); AddOption(new Option("Chapter Seven and Eight", () => { var chapter = new ChapterSeven(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Nine", () => { var animation = new Animation() { FrameCount = 13, StartFrame = 1 }; var chapter = new ChapterNine(animation); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Thirteen", () => { var chapter = new ChapterThirteen(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Fourteen", () => { var chapter = new ChapterFourteen(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Chapter Fifteen", () => { var chapter = new ChapterFifteen(); chapter.Run(); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateTo <ExercisePage>(); })); AddOption(new Option("Bonus - Area Light", () => { var bonus = new BonusAreaLight(); var canvas = bonus.Run(); PpmOutput.WriteToFile("world.ppm", canvas.GetPPMContent()); Program.NavigateTo <ExercisePage>(); })); }
public BotConfigPage(Program program) : base("Bot Settings Configuration", program, new Option("Set TwitchApiClientId", () => { SetTwitchApiClientId(); program.NavigateTo <BotConfigPage>(); }), new Option("Set TwitchApiClientSecret", () => { SetTwitchApiClientSecret(); program.NavigateTo <BotConfigPage>(); }), new Option("Set DiscordWebHookUri", () => { SetDiscordWebHookUri(); program.NavigateTo <BotConfigPage>(); }), new Option("Set TwitchApiCheckIntervalSeconds", () => { SetTwitchApiCheckIntervalSeconds(); program.NavigateTo <BotConfigPage>(); }), new Option("Enable console logging", () => { UpdateFile("EnableConsoleLogging", true); ConsoleProgram.PressToContinue(); program.NavigateTo <BotConfigPage>(); }), new Option("Disable console logging", () => { UpdateFile("EnableConsoleLogging", false); ConsoleProgram.PressToContinue(); program.NavigateTo <BotConfigPage>(); }), new Option("Enable file logging", () => { UpdateFile("EnableFileLogging", true); ConsoleProgram.PressToContinue(); program.NavigateTo <BotConfigPage>(); }), new Option("Disable file logging", () => { UpdateFile("EnableFileLogging", false); ConsoleProgram.PressToContinue(); program.NavigateTo <BotConfigPage>(); }), new Option("Skip active streams on startup", () => { UpdateFile("SkipActiveStreamsOnStartup", true); ConsoleProgram.PressToContinue(); program.NavigateTo <BotConfigPage>(); }), new Option("Notify active streams on startup", () => { UpdateFile("SkipActiveStreamsOnStartup", false); ConsoleProgram.PressToContinue(); program.NavigateTo <BotConfigPage>(); }), new Option("Manage Channels", () => program.NavigateTo <ChannelConfigPage>()), new Option("Exit Configtool", () => Environment.Exit(0))) { }