public void SetAlias_Throws_InvalidOperationException_When_Registered() { Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true; var t = new TestCommand2(); var gc = new GlobalCommand("SomethingTest", "t", Access.Administrator); var added = gc.AddToConsole(); Assert.IsTrue(added); var reg = t.RegisterCommand("SomethingTest"); Assert.IsTrue(reg == RegisterResult.Success); var threw = false; try { t.Alias = "Throws Exception"; } catch (InvalidOperationException) { threw = true; } gc.RemoveFromConsole(); gc.Dispose(); Assert.IsTrue(threw); }
public async Task <SettingsContainer> CaptureSettings(FileSettings settingsIn) { var logger = Substitute.For <IConfigureLogLevel>(); var fileSettings = Substitute.For <IFileSettingsCache>(); SettingsContainer settingsOut = null; var engine = Substitute.For <IGitHubEngine>(); await engine.Run(Arg.Do <SettingsContainer>(x => settingsOut = x)); fileSettings.Get().Returns(settingsIn); var command = new GlobalCommand(engine, logger, fileSettings); command.GitHubToken = "testToken"; if (string.IsNullOrEmpty(settingsIn.Api)) { command.GithubApiEndpoint = "http://github.contoso.com/api"; } if (string.IsNullOrEmpty(settingsIn.Include)) { command.Include = "testRepos"; } await command.OnExecute(); return(settingsOut); }
void ProcessCommand(GlobalCommand cmd) { if (cmd.Code == GlobalCommandCodes.GPSReset) { Init(); _locationManager.RequestLocationUpdates(_providerName, 0, minDistance, this); } }
/// <summary> /// Initializes a new instance of the <see cref="ControlSystem"/> class. /// </summary> public ControlSystem() : base() { try { Thread.MaxNumberOfUserThreads = 20; // Setup the static instance reference for the control system. Instance = this; // Setup the path the options are saved to and loaded from. Options.FilePath = "/USER/pellucid.console-options.toml"; // Setup the global command(s). var appCommand = new GlobalCommand("app", "Application commands.", Access.Programmer); var regResult = appCommand.AddToConsole(); // Add a console writer to the console. // This could be done with the ProConsole class as well, or your own // implementation extending the ConsoleBase class. // Technically if no writer is registered then the CrestronConsoleWriter // gets registered by default, precluding the need for this, but it shows // how to hook your own console writers into the system. ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Terminal.CrestronConsoleWriter()); if (!regResult) { Debug.WriteErrorLine(this, "Unable to add global app to the Crestron Console."); } // Initialize specific global commands. ProConsole.InitializeConsole("app"); var csc = new ControlSystemCommands(); csc.RegisterCommand("app"); var exc = new ExampleCommands(); exc.RegisterCommand("app"); // Register log writers. Logger.RegisterLogWriter(new CrestronLogWriter()); // In addition to the CrestronLogWriter we're registering an additional writer that targets another file. var path = Path.Combine(Directory.GetApplicationRootDirectory(), "/user"); path = Path.Combine(path, "logs"); path = Path.Combine(path, string.Format("App{0}SimpleLog.log", InitialParametersClass.ApplicationNumber)); Logger.RegisterLogWriter(new Evands.Pellucid.Diagnostics.SimpleFileLogger(path)); // Subscribe to the controller events (System, Program, and Ethernet) CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler); } catch (Exception e) { this.LogException(e, "Exception in the constructor."); } }
public void ParseGlobalCommand() { ICommand command = ParseCommand("global x;"); Assert.IsNotNull(command); Assert.IsInstanceOfType(command, typeof(GlobalCommand)); GlobalCommand glbcmd = (GlobalCommand)command; Assert.AreEqual("x", glbcmd.Name); }
public void ExecuteGlobalCommand() { GlobalCommand command = new GlobalCommand("global"); Machine machine = new Machine(); IBindingEnvironment environment = new BindingEnvironment(); command.Execute(environment); environment.SetValue("global", 100); Assert.IsFalse(environment.ContainsName("global")); Assert.IsTrue(machine.Environment.ContainsName("global")); Assert.AreEqual(100, machine.Environment.GetValue("global")); }
static int Main(string[] args) { Console.WriteLine("Toptout-cli 0.1.309-alpha"); var root = GlobalCommand.Create(); root.AddCommand(UpdateCommand.Create()); int errlevel = root.Invoke(args); #if DEBUG // TODO DEBUG only Console.WriteLine("Press [Enter] to close..."); Console.ReadLine(); #endif return(errlevel); }
public async Task ShouldCallEngineAndNotSucceedWithoutParams() { var engine = Substitute.For <IGitHubEngine>(); var logger = Substitute.For <IConfigureLogLevel>(); var fileSettings = Substitute.For <IFileSettingsCache>(); fileSettings.Get().Returns(FileSettings.Empty()); var command = new GlobalCommand(engine, logger, fileSettings); var status = await command.OnExecute(); Assert.That(status, Is.EqualTo(-1)); await engine .DidNotReceive() .Run(Arg.Any <SettingsContainer>()); }
private async void ProcessCommand(GlobalCommand cmd) { if (cmd.Code == GlobalCommandCodes.AskConfirmation) { var answer = await DisplayAlert("Alert", cmd.Message, "Yes", "No"); //var answer = await DisplayAlert("Alert", cmd.Message, "Yes", "No"); if (answer) { MessagingHub.Send(QueueType.Confirmed, GlobalCommand.ReplyConfirmation(cmd.CommandToConfirm)); } else { MessagingHub.Send(QueueType.Canceled, GlobalCommand.ReplyConfirmation(cmd.CommandToConfirm)); } } }
public void UnregisterCommand_ReturnsValue() { Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true; var t = new TestCommand(); var gc = new GlobalCommand("ValueTest", "help", Access.Administrator); var added = gc.AddToConsole(); Assert.IsTrue(added); var reg = t.RegisterCommand("ValueTest"); Assert.IsTrue(reg == RegisterResult.Success); var result = t.UnregisterCommand("ValueTest"); Assert.IsTrue(result); gc.RemoveFromConsole(); gc.Dispose(); }
public async Task ShouldCallEngineAndNotSucceedWithoutParams() { var engine = Substitute.For <ICollaborationEngine>(); var logger = Substitute.For <IConfigureLogger>(); var fileSettings = Substitute.For <IFileSettingsCache>(); fileSettings.GetSettings().Returns(FileSettings.Empty()); var collaborationFactory = GetCollaborationFactory((d, e) => new GitHubSettingsReader(d, e)); var command = new GlobalCommand(engine, logger, fileSettings, collaborationFactory); var status = await command.OnExecute(); Assert.That(status, Is.EqualTo(-1)); await engine .DidNotReceive() .Run(Arg.Any <SettingsContainer>()); }
public void CommandExecute_When_AliasSetManually() { Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true; var t = new TestCommand2(); t.Alias = "NN"; var gc = new GlobalCommand("SomethingTest", "t", Access.Administrator); var added = gc.AddToConsole(); Assert.IsTrue(added); var reg = t.RegisterCommand("SomethingTest"); Assert.IsTrue(reg == RegisterResult.Success); Crestron.SimplSharp.CrestronConsole.Messages = new StringBuilder(); gc.ExecuteCommand("NN Test"); Assert.IsTrue(Crestron.SimplSharp.CrestronConsole.Messages.ToString().Contains("Default test command executed.")); gc.RemoveFromConsole(); gc.Dispose(); }
public async Task ShouldCallEngineAndSucceedWithRequiredGithubParams() { var engine = Substitute.For <IGitHubEngine>(); var logger = Substitute.For <IConfigureLogLevel>(); var fileSettings = Substitute.For <IFileSettingsCache>(); fileSettings.Get().Returns(FileSettings.Empty()); var command = new GlobalCommand(engine, logger, fileSettings); command.GitHubToken = "testToken"; command.Include = "testRepos"; command.GithubApiEndpoint = "http://github.contoso.com/api"; var status = await command.OnExecute(); Assert.That(status, Is.EqualTo(0)); await engine .Received(1) .Run(Arg.Any <SettingsContainer>()); }
protected async Task ExecuteSynchronizeCommand(string manifest) { ServiceCollection services = new ServiceCollection(); services.AddSingleton <SynchronizeCommand>(); Program program = new Program(); program.ConfigureServiceCollection(services); ServiceProvider provider = services.BuildServiceProvider(); GlobalCommand globalCommand = ActivatorUtilities.CreateInstance <GlobalCommand>(provider); CommandOptions commandOptions = provider.GetService <ICommandOptions>() as CommandOptions; commandOptions.RegisterOptions(globalCommand); SynchronizeCommand command = provider.GetRequiredService <SynchronizeCommand>(); CancellationTokenSource cts = new CancellationTokenSource(); string manifestFile = null; try { manifestFile = Path.GetTempFileName(); File.WriteAllText(manifestFile, manifest); command.HandlePositionalArguments(new List <string> { manifestFile }); await command.RunAsync(cts.Token); } finally { if (manifestFile != null) { File.Delete(manifestFile); } } }
public async Task ShouldCallEngineAndSucceedWithRequiredGithubParams() { var engine = Substitute.For <ICollaborationEngine>(); var logger = Substitute.For <IConfigureLogger>(); var fileSettings = Substitute.For <IFileSettingsCache>(); fileSettings.GetSettings().Returns(FileSettings.Empty()); var collaborationFactory = GetCollaborationFactory(); var command = new GlobalCommand(engine, logger, fileSettings, collaborationFactory); command.PersonalAccessToken = "testToken"; command.Include = "testRepos"; command.ApiEndpoint = "https://github.contoso.com"; var status = await command.OnExecute(); Assert.That(status, Is.EqualTo(0)); await engine .Received(1) .Run(Arg.Any <SettingsContainer>()); }
public static async Task <(SettingsContainer settingsContainer, CollaborationPlatformSettings platformSettings)> CaptureSettings(FileSettings settingsIn) { var logger = Substitute.For <IConfigureLogger>(); var fileSettings = Substitute.For <IFileSettingsCache>(); fileSettings.GetSettings().Returns(settingsIn); var collaborationFactory = GetCollaborationFactory(); SettingsContainer settingsOut = null; var engine = Substitute.For <ICollaborationEngine>(); await engine.Run(Arg.Do <SettingsContainer>(x => settingsOut = x)); var command = new GlobalCommand(engine, logger, fileSettings, collaborationFactory) { PersonalAccessToken = "testToken", ApiEndpoint = settingsIn.Api ?? "http://github.contoso.com/", Include = settingsIn.Include ?? "testRepos" }; await command.OnExecute(); return(settingsOut, collaborationFactory.Settings); }
/// <summary> /// Initializes a new instance of the <see cref="ControlSystem"/> class. /// </summary> public ControlSystem() : base() { try { Thread.MaxNumberOfUserThreads = 20; // Setup the static instance reference for the control system. Instance = this; // Setup the path the options are saved to and loaded from. Options.FilePath = "/USER/pellucid.console-options.toml"; // Add a console writer to the console. // This could be done with the ProConsole class as well, or your own // implementation extending the ConsoleBase class. // Technically if no writer is registered then the CrestronConsoleWriter // gets registered by default, precluding the need for this, but it shows // how to hook your own console nodes into the system. ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Terminal.CrestronConsoleWriter()); cws = new Crestron.SimplSharp.WebScripting.HttpCwsServer("/pellucid/"); cws.Register(); // This is the optional CwsConsoleWriter, usually used for something like VC-4 console access. if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Server) { ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Cws.CwsConsoleWriter(cws, string.Format("console/{0}", InitialParametersClass.RoomId), 53000, false)); } else { if (CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series3) { ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Cws.CwsConsoleWriter(cws, true, 53000, false)); } else { ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Cws.CwsConsoleWriter(cws, 53000, false)); } } // Setup the global command(s). var appCommand = new GlobalCommand("app", "Application commands.", Access.Programmer); var regResult = appCommand.AddToConsole(); appCommand.CommandExceptionEncountered += (o, a) => appCommand.LogException(a.Exception, "Exception while executing command '{0}'.", a.CommandContent); if (!regResult) { Debug.WriteErrorLine(this, "Unable to add global app to the Crestron Console."); } // Initialize specific global commands. ProConsole.InitializeConsole("app"); var csc = new ControlSystemCommands(); csc.RegisterCommand("app"); var exc1 = new ExampleCommands("1"); exc1.RegisterCommand("app"); var exc2 = new ExampleCommands("2"); exc2.RegisterCommand("app"); var cn1 = new CustomNameCommand("XCommand"); cn1.RegisterCommand("app"); var cn2 = new CustomNameCommand("ZedCommand"); cn2.RegisterCommand("app"); // Register log nodes. Logger.RegisterLogWriter(new CrestronLogWriter()); // In addition to the CrestronLogWriter we're registering an additional writer that targets another file. var path = Path.Combine(Directory.GetApplicationRootDirectory(), "/user"); path = Path.Combine(path, "logs"); path = Path.Combine(path, string.Format("App{0}SimpleLog.log", InitialParametersClass.ApplicationNumber)); Logger.RegisterLogWriter(new Evands.Pellucid.Diagnostics.SimpleFileLogger(path)); // Subscribe to the controller events (System, Program, and Ethernet) CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler); } catch (Exception e) { this.LogException(e, "Exception in the constructor."); } }
public void UseMaterialUILightTheme() => GlobalCommand.UseMaterialUILightTheme();
public void OpenProjectRepoLink() => GlobalCommand.OpenProjectRepoLink();
public void UseMaterialUIDarkTheme() => GlobalCommand.UseMaterialUIDarkTheme();
private async void LoadModuleInfo(string ModuleName) { string namespace_name = "Cloure.Modules." + ModuleName; string class_name = "mod_" + ModuleName; ActiveModule = ModuleName; ModuleInfo moduleInfo = new ModuleInfo(); try { var module_obj = Activator.CreateInstance(Type.GetType(namespace_name + "." + class_name)); if (module_obj is CloureModule) { CloureModule module = (CloureModule)module_obj; List <CloureParam> cloureParams = new List <CloureParam>(); cloureParams.Add(new CloureParam("topic", "get_module_info")); cloureParams.Add(new CloureParam("module", ModuleName)); string api_response = await CloureManager.ExecuteAsync(cloureParams); JsonObject ApiResponse = JsonObject.Parse(api_response); moduleInfo.Title = ApiResponse.GetNamedString("title"); JsonArray globalCommandsArr = ApiResponse.GetNamedArray("global_commands"); JsonArray filtersArr = ApiResponse.GetNamedArray("filters"); foreach (JsonValue value in globalCommandsArr) { JsonObject jobj = value.GetObject(); int cmd_id = (int)jobj.GetNamedNumber("Id"); string cmd_name = jobj.GetNamedString("Name"); string cmd_title = jobj.GetNamedString("Title"); GlobalCommand globalCommand = new GlobalCommand(cmd_id, cmd_name, cmd_title); moduleInfo.globalCommands.Add(globalCommand); } JsonValue localesValue = ApiResponse.GetNamedValue("locales"); if (localesValue.ValueType != JsonValueType.Null) { moduleInfo.locales = ApiResponse.GetNamedObject("locales"); } if (filtersArr.Count > 0) { foreach (JsonValue value in filtersArr) { JsonObject jobj = value.GetObject(); string filter_name = jobj.GetNamedString("Name"); string filter_title = jobj.GetNamedString("Title"); string filter_type = jobj.GetNamedString("Type"); string filter_default = jobj.GetNamedString("Default"); ModuleFilter moduleFilter = new ModuleFilter(filter_name, filter_title, filter_type, filter_default); JsonArray filterItems = jobj.GetNamedArray("Items"); foreach (JsonValue item in filterItems) { JsonObject item_obj = item.GetObject(); JsonValue item_id = item_obj.GetNamedValue("Id"); string item_title = item_obj.GetNamedString("Title"); string item_id_str = ""; if (item_id.ValueType.ToString() == "String") { item_id_str = item_id.GetString(); } if (item_id.ValueType.ToString() == "Number") { item_id_str = item_id.GetNumber().ToString(); } string item_title_str = item_title.ToString(); ModuleFilterItem moduleFilterItem = new ModuleFilterItem(item_id_str, item_title_str); moduleFilter.AddItem(moduleFilterItem); } moduleInfo.moduleFilters.Add(moduleFilter); } } //Core.Core.ModuleInfo = moduleInfo; CloureManager.SetModuleInfo(moduleInfo); module.OnModuleCreated(); } else { var dialog = new MessageDialog("Module " + ModuleName + " doesn't implement CloureModule interface"); await dialog.ShowAsync(); } } catch (Exception e) { var dialog = new MessageDialog(e.Message); await dialog.ShowAsync(); } }
public GlobalCommand(GlobalCommandCodes code, GlobalCommand cmdToConfirm, string message = null) { Code = code; Message = message; CommandToConfirm = cmdToConfirm; }
public static GlobalCommand ReplyConfirmation(GlobalCommand cmdToConfirm) { return(new GlobalCommand(GlobalCommandCodes.ReplyConfirmation, cmdToConfirm)); }
public static GlobalCommand AskConfirmation(GlobalCommand cmdToConfirm, string message) { return(new GlobalCommand(GlobalCommandCodes.AskConfirmation, cmdToConfirm, message)); }