private async Task ExecuteCommand(IAppCommand cmd) { if (await cmd.CanExecute(Arguments.ToArray())) { await cmd.Execute(Arguments.ToArray()); } }
public void AddCommand(IAppCommand appCommand) { if (this.AppCommands.Any(p => string.Equals(p.Name, appCommand.Name, StringComparison.OrdinalIgnoreCase))) { throw new Exception($"A command named {appCommand.Name} has already been installed"); } this.AppCommands.Add(appCommand); }
public void Run(IAppDataView appData, IAppCommand command) { if (_plugin == null) { Console.WriteLine("Plugin not loaded"); return; } _plugin.Run(appData, command); }
public void AddCommand(IAppCommand command, bool execute = true) { if(execute) command.Execute(); _undoList.Add(command); _redoList.Clear(); if(UndoLevel > 0 && _undoList.Count > UndoLevel) _undoList.RemoveAt(0); UpdateChanges(); }
private async Task <CommandContext> HandleAsync(IAppCommand command) { command.AppId = appId; var commandContext = new CommandContext(command, A.Fake <ICommandBus>()); await sut.HandleAsync(commandContext); return(commandContext); }
static int Main(string[] args) { int exitCode = 1; var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); using (var serviceProvider = serviceCollection.BuildServiceProvider()) { var config = new AppConfig() .UseCommandLine(args); if (config.ShowHelp) { AppConfig.OutputHelp(); if (config.ShowConfig) { config.OutputConfig(); } } else { if (config.ShowConfig) { config.OutputConfig(); } var ctx = new AppContext { Config = config }; IAppCommand command = default; if (config.ListStores) { command = serviceProvider.GetRequiredService <ListStoresCommand>(); } else { command = serviceProvider.GetRequiredService <SaveAttachmentsCommand>(); } if (command != default) { exitCode = command.Run(ctx); } } } return(exitCode); }
public void AddCommand(IAppCommand command, bool execute = true) { if (execute) { command.Execute(); } _undoList.Add(command); _redoList.Clear(); if (UndoLevel > 0 && _undoList.Count > UndoLevel) { _undoList.RemoveAt(0); } UpdateChanges(); }
/// <summary> /// Add a command to be processed /// </summary> /// <param name="command">the command to be processed</param> /// <returns>true if added, false is the add failed</returns> public async Task <bool> AddCommand(IAppCommand command) { if (!IsInitialized) { Init(); IsInitialized = true; } await Task.Run(() => { CommandSpooler.AddItem(command); }); return(true); }
public static AppCommandButton FromAppCommand(IAppCommand appCommand) { var ret = new AppCommandButton { Command = appCommand, IconSource = appCommand.IconSource }; var iconElement = appCommand.IconSource?.GetIconElement(); if (iconElement != null) { switch (iconElement) { case VectorIcon vi: vi.Foreground = new SolidColorBrush(Color.FromArgb(255, 80, 80, 80)); ret.Content = iconElement; break; case null: break; default: ret.Content = iconElement; break; } } else { ret.Content = appCommand.Name; } ret.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); ret.Foreground = new SolidColorBrush(Color.FromArgb(255, 10, 10, 10)); ret.BorderThickness = default(Thickness); var hover = appCommand.Name; if (appCommand.Shortcut != null) { hover += $" ({appCommand.Shortcut})"; } ret.ToolTip = hover; ret.Margin = new Thickness(3, 0, 3, 0); return(ret); }
public int AddCommand(IAppCommand command) { command.Sb = _stringBuilder; _commands.Add(command); return(_commands.IndexOf(command)); }
public void Run(IAppDataView appData, IAppCommand command) { Console.WriteLine("Running in: " + AppDomain.CurrentDomain.FriendlyName); command.CommandNumber = appData.Content*6; }
public static Task QueueCommandAsync(this IMessageBus bus, IAppCommand command) => bus.QueueCommandAsync(command, () => Task.CompletedTask, e => Task.CompletedTask);
public Message(IAppCommand command, Func <Task> onCompleted, Func <Exception, Task> onError) { Command = command ?? throw new ArgumentNullException(nameof(command)); OnCompleted = onCompleted ?? throw new ArgumentNullException(nameof(onCompleted)); OnError = onError ?? throw new ArgumentNullException(nameof(onError)); }
public Task QueueCommandAsync(IAppCommand command, Func <Task> onCompleted, Func <Exception, Task> onError) => Processor.SendAsync(new Message(command, onCompleted, onError));
public IAppCommand AddCommand(IAppCommand command) { CommandList.Add(command); return(CommandList.Last()); }
void AddCommand(IAppCommand cmd, bool execute = true) { _commandManager.AddCommand(cmd); IsModified = _commandManager.CanUndo; InvalidateVisual(); }
public static Task QueueCommandAsync(this IMessageBus bus, IAppCommand command, Func <Exception, Task> onError) => bus.QueueCommandAsync(command, () => Task.CompletedTask, onError);
public IAppCommand GetCommandAt(IAppCommand addCommandReference) { var index = CommandList.IndexOf(addCommandReference); return(CommandList[index]); }
static async Task Main(string[] args) { var appCommands = new Abstractions.Common.Interfaces.IAppCommand[] { #region FullyConcrete // Our first implementation: very purpose-built new Abstractions.FullyConcrete.AppCommand(), #endregion #region MultipleFullyConcrete // Our second-generation implementations: clipboard inherited code // from the original AppCommand, now in four delicious flavors new Abstractions.MultipleFullyConcrete.AddAppCommand(), new Abstractions.MultipleFullyConcrete.SubtractAppCommand(), new Abstractions.MultipleFullyConcrete.MultiplyAppCommand(), new Abstractions.MultipleFullyConcrete.DivideAppCommand(), #endregion #region MoreAbstract // The third generation: recognizing that we had a lot of // duplicate code, the implementations leverage an abstract base // class and an ICalculation Strategy Pattern implementation new Abstractions.MoreAbstract.AddAppCommand(), new Abstractions.MoreAbstract.SubtractAppCommand(), new Abstractions.MoreAbstract.MultiplyAppCommand(), new Abstractions.MoreAbstract.DivideAppCommand(), new Abstractions.MoreAbstract.ExponentiationAppCommand(), #endregion #region VeryAbstract new Abstractions.VeryAbstract.AppCommand <double>(new Abstractions.VeryAbstract.Calculations.AddCalculation(), new Abstractions.VeryAbstract.Providers.PairwiseNumericFileProvider(typeof(Abstractions.Common.NumericFile).Assembly, "Abstractions.Common.SourceData.Numerics.txt")), new Abstractions.VeryAbstract.AppCommand <double>(new Abstractions.VeryAbstract.Calculations.SubtractCalculation(), new Abstractions.VeryAbstract.Providers.PairwiseNumericFileProvider(typeof(Abstractions.Common.NumericFile).Assembly, "Abstractions.Common.SourceData.Numerics.txt")), new Abstractions.VeryAbstract.AppCommand <double>(new Abstractions.VeryAbstract.Calculations.MultiplyCalculation(), new Abstractions.VeryAbstract.Providers.PairwiseNumericFileProvider(typeof(Abstractions.Common.NumericFile).Assembly, "Abstractions.Common.SourceData.Numerics.txt")), new Abstractions.VeryAbstract.AppCommand <double>(new Abstractions.VeryAbstract.Calculations.DivideCalculation(), new Abstractions.VeryAbstract.Providers.PairwiseNumericFileProvider(typeof(Abstractions.Common.NumericFile).Assembly, "Abstractions.Common.SourceData.Numerics.txt")), new Abstractions.VeryAbstract.AppCommand <double>(new Abstractions.VeryAbstract.Calculations.ExponentiationCalculation(), new Abstractions.VeryAbstract.Providers.PairwiseNumericFileProvider(typeof(Abstractions.Common.NumericFile).Assembly, "Abstractions.Common.SourceData.Numerics.txt")) #endregion }; var exitLoop = false; while (!exitLoop) { DisplayMenu(); var input = Console.ReadLine(); if (int.TryParse(input, out var menuSelection)) { IAppCommand appCommand = null; if (menuSelection > 0 && menuSelection < appCommands.Length + 1) { appCommand = appCommands[menuSelection - 1]; } else if (menuSelection == 0) { Console.WriteLine("Fine. Be that way."); exitLoop = true; } else { Console.WriteLine("Wut?"); } if (appCommand != null) { var retval = await appCommand.ExecAsync(); Console.WriteLine($"appCommand output:\r\n{retval}"); } } else { Console.WriteLine("Wut?"); } } }
private void _commandSpooler_ItemSpooled(IAppCommand cmd) { ExecuteCommand(cmd).Wait(); }
public AppHostedService(IAppCommand appCommand) { _appCommand = appCommand; }
public static Task QueueCommandAsync(this IMessageBus bus, IAppCommand command, Func <Task> onCompleted) => bus.QueueCommandAsync(command, onCompleted, e => Task.CompletedTask);