public void SayHelloTest() { IHelloWorldGenerator generator = null; try { IMessagePrinter printer = MessagePrinterFactory.GetMessagePrinterInstance(PrinterType.Console); generator = HelloWorldGeneratorFactory.GetHelloWorldGeneratorInstance(GeneratorType.Console, printer); } catch (Exception ex) { Assert.Fail(ex.Message); } Assert.IsTrue(generator != null, "Failed to create HelloWorldGenerator for {0} type.", GeneratorType.Console); Assert.IsTrue(generator.SayHello(), "Can't Say Hello World! Something went wrong!"); try { IMessagePrinter printer = MessagePrinterFactory.GetMessagePrinterInstance(PrinterType.Console); generator = HelloWorldGeneratorFactory.GetHelloWorldGeneratorInstance(GeneratorType.Mobile, printer); } catch (Exception ex) { if (!(ex is NotImplementedException)) { Assert.Fail(ex.Message); } } }
public void Initialize() { _Clock = new Mock<IClock>(); _Console = new Mock<IConsole>(); _Clock.Setup(a => a.CurrentDateAndTime).Returns(_Now); _MessagePrinter = new MessagePrinter(_Console.Object, _Clock.Object); }
public void Execute() { IMessagePrinter printer = uiFactory.CreateMessagePrinter(); List <String> args = new List <string>(); args.Add("Number"); args.Add("Error"); IDialogView dialog = uiFactory.CreateDialogView(); List <string> results = dialog.ShowSelectionDialog(args); double number = 0; double error = 0; if (!double.TryParse(results.ElementAt(0), out number)) { printer.Print("First input is not a number"); } if (!double.TryParse(results.ElementAt(1), out error)) { printer.Print("Second input is not a number"); } ITaylorExpansion exp = new ArctgExpansion(error, number); Result result = exp.Calculate(); printer.Print("Answer " + result.Answer); }
public OhceService(IDateTimeProvider dateTimeProvider, IMessagePrinter messagePrinter, Action onStopAction) { _dateTimeProvider = dateTimeProvider; _messagePrinter = messagePrinter; _onStopAction = onStopAction; _userName = "******"; }
protected DeepLearningRunner(DeviceDescriptor device, TrainingSessionConfiguration configuration, IMessagePrinter printer) { Device = device ?? throw new System.ArgumentNullException(nameof(device)); //TODO: User more detailed validation, ie. check all required props/fields for runner to work Configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration)); this.MessagePrinter = printer ?? throw new ArgumentNullException(nameof(printer)); }
public void Initialize() { _Clock = new Mock<IClock>(); _Console = new Mock<Console> (); _MessagePrinter = new MessagePrinter(_Console.Object, _Clock.Object); _UserRepository = new UserRepository(); _MessageRepository = new MessageRepository(_Clock.Object); _SubscriptionRepository = new SubscriptionRepository(); _CommandParser = new CommandParser(GetAllCommands(), _UserRepository, _MessageRepository, _SubscriptionRepository, _MessagePrinter); }
public static PowerShell WithOutput(this PowerShell powerShell, IMessagePrinter printer) { powerShell.Streams.Information.DataAdded += (stream, eventArgs) => printer.PrintMessage(GetMessageToPrint <InformationRecord>(stream !, eventArgs)); powerShell.Streams.Error.DataAdded += (stream, eventArgs) => printer.PrintError(GetMessageToPrint <ErrorRecord>(stream !, eventArgs)); powerShell.Streams.Warning.DataAdded += (stream, eventArgs) => printer.PrintWarning(GetMessageToPrint <WarningRecord>(stream !, eventArgs)); return(powerShell); }
public static void TryDeleteDirectoryIfExists(string path, IMessagePrinter printer) { try { DeleteDirectoryIfExists(path); } catch (Exception exc) { printer.PrintError($"删除文件夹时发生错误 {path}: {exc.Message}"); } }
public static void TryDeleteDirectoryIfExists(string path, IMessagePrinter printer) { try { DeleteDirectoryIfExists(path); } catch (Exception exc) { printer.PrintError($"An error occurred when deleting folder {path}: {exc.Message}"); } }
public static IMessageClient GetClient(IMessagePrinter messagePrinter) { if (messagePrinter == null) { return(new MessageClient(GetMessagePrinter())); } else { return(new MessageClient(messagePrinter)); } }
public ICommand CreateCommand(string[] inputParts, IUserRepository userRepository, IMessageRepository messageRepository, ISubscriptionRepository subscriptionRepository, IMessagePrinter messagePrinter) { return new CreateSubscriptionCommand { FollowerName = inputParts[0], FolloweeName = inputParts[2], SubscriptionRepository = subscriptionRepository, UserRepository = userRepository }; }
public ICommand CreateCommand(string[] inputParts, IUserRepository userRepository, IMessageRepository messageRepository, ISubscriptionRepository subscriptionRepository, IMessagePrinter messagePrinter) { return new ShowWallCommand { MessagePrinter = messagePrinter, UserName = inputParts[0], MessageRepository = messageRepository, UserRepository = userRepository, SubscriptionRepository = subscriptionRepository }; }
public CommandParser( IEnumerable<ICommandFactory> allCommands, IUserRepository userRepository, IMessageRepository messageRepository, ISubscriptionRepository subscriptionRepository, IMessagePrinter messagePrinter) { _AllCommands = allCommands; _UserRepository = userRepository; _MessageRepository = messageRepository; _SubscriptionRepository = subscriptionRepository; _MessagePrinter = messagePrinter; }
public ICommand CreateCommand( string[] inputParts, IUserRepository userRepository, IMessageRepository messageRepository, ISubscriptionRepository subscriptionRepository, IMessagePrinter messagePrinter) { return new PostMessageCommand { UserName = inputParts[0], MessageText = inputParts[2], UserRepository = userRepository, MessageRepository = messageRepository }; }
static void Main(string[] args) { PrinterType printerType = PrinterType.Console; if (args.Length > 0) { printerType = (PrinterType)Enum.Parse(typeof(PrinterType), args[0], true); } IMessagePrinter printer = MessagePrinterFactory.GetMessagePrinterInstance(printerType); IHelloWorldGenerator generator = HelloWorldGeneratorFactory.GetHelloWorldGeneratorInstance(GeneratorType.Console, printer); if (generator != null) { generator.SayHello(); } }
public void Execute() { IMessagePrinter printer = uiFactory.CreateMessagePrinter(); List <String> args = new List <string>(); args.Add("Error"); args.Add("Number"); args.Add("Power"); IDialogView dialog = uiFactory.CreateDialogView(); List <string> results = dialog.ShowSelectionDialog(args); double number = 0; double error = 0; double power = 0; bool parsingfailed = false; if (!double.TryParse(results.ElementAt(0), out error)) { parsingfailed = true; printer.Print("First input is not a number"); } if (!double.TryParse(results.ElementAt(1), out number)) { parsingfailed = true; printer.Print("Second input is not a number"); } if (!double.TryParse(results.ElementAt(1), out power)) { parsingfailed = true; printer.Print("Third input is not a number"); } if (!parsingfailed) { ITaylorExpansion exp = new Power(error, number, power); Result result = exp.Calculate(); if (result.Exist) { printer.Print("Answer " + result.Answer); } else { printer.Print("Answer does not exist"); } } }
public static IMessagePrinter GetMessagePrinterInstance(PrinterType type) { IMessagePrinter printer = null; switch (type) { case PrinterType.Console: { printer = new ConsoleMessagePrinter(); break; } default: { throw new NotImplementedException(); } } return(printer); }
public void RemoveComponentIfAllowed(string component, IMessagePrinter printer) { if (!HasBeenExtracted()) { ExtractAndLock(); } printer.PrintHeading($"Running install-wim-tweak to remove {component}..."); int exitCode = SystemUtils.RunProcessBlockingWithOutput(extractedFilePath, $"/o /c {component} /r", printer); if (exitCode == SystemUtils.EXIT_CODE_SUCCESS) { printer.PrintMessage("Install-wim-tweak executed successfully!"); } else { printer.PrintError($"An error occurred during the removal of {component}: " + "install-wim-tweak exited with a non-zero status."); } }
public static int RunProcessBlockingWithOutput(string name, string args, IMessagePrinter printer) { using var process = CreateProcessInstance(name, args); process.OutputDataReceived += (_, evt) => { if (!string.IsNullOrEmpty(evt.Data)) { printer.PrintMessage(evt.Data); } }; process.ErrorDataReceived += (_, evt) => { if (!string.IsNullOrEmpty(evt.Data)) { printer.PrintError(evt.Data); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); return(process.ExitCode); }
public MessageClient(IMessagePrinter service) { this._service = service; }
protected HelloWorldGenerator(IMessagePrinter printer) { _printer = printer; }
public Listener(IConnectionFactory connectionFactory, IMessagePrinter messagePrinter, ILogger logger) { _connectionFactory = connectionFactory; _messagePrinter = messagePrinter; _logger = logger; }
public static void ExecuteWindowsPromptCommand(string command, IMessagePrinter printer) { Debug.WriteLine($"Command executed: {command}"); RunProcessBlockingWithOutput("cmd.exe", $@"/c ""{command}""", printer); }
public static IHelloWorldGenerator GetHelloWorldGeneratorInstance(GeneratorType type, IMessagePrinter printer) { IHelloWorldGenerator generator = null; switch (type) { case GeneratorType.Console: { generator = new HelloWorldGeneratorConsole(printer); break; } default: { throw new NotImplementedException(); } } return(generator); }
public Usage(bool color, IMessagePrinter printMessage) : base(color, printMessage) { }
public ConsoleTestManager() { tests = new List <ITestBase>(); msgPrinter = new ConsoleMessagePrinter(); }
protected ConsoleTestBase() { Name = GetType().Name; msgPrinter = new ConsoleMessagePrinter(); }
public void RemoveComponentIfAllowed(string component, IMessagePrinter printer) { printer.PrintNotice($"Skipped removal of {component} component(s) using install-wim-tweak since " + @"option ""AllowInstallWimTweak"" is set to false."); }
public void RemoveComponentIfAllowed(string component, IMessagePrinter printer) { printer.PrintNotice($"Requested removal of component {component} through install-wim-tweak."); }
protected APrint(bool color, IMessagePrinter printer) { Color = color; Printer = printer; }
private static EventHandler <DataAddedEventArgs>[] AddOutputStreamsEventHandlers(this PowerShell psInstance, IMessagePrinter printer) { var handlers = new EventHandler <DataAddedEventArgs>[] { (sender, eventArgs) => printer.PrintMessage(GetMessageToPrint <InformationRecord>(sender !, eventArgs)), (sender, eventArgs) => printer.PrintWarning(GetMessageToPrint <ErrorRecord>(sender !, eventArgs)), (sender, eventArgs) => printer.PrintMessage(GetMessageToPrint <WarningRecord>(sender !, eventArgs)) }; psInstance.Streams.Information.DataAdded += handlers[0]; psInstance.Streams.Error.DataAdded += handlers[1]; psInstance.Streams.Warning.DataAdded += handlers[2]; return(handlers); }
/* * Runs a script on the given PowerShell instance and prints the messages written to info, * error and warning streams asynchronously. */ public static void RunScriptAndPrintOutput(this PowerShell psInstance, string script, IMessagePrinter printer) { // Streams can be used by the caller to check for errors in the current script execution psInstance.Streams.ClearStreams(); // By default PowerShell spawns one thread for each command, we must avoid it if (psInstance.Runspace.ThreadOptions != PSThreadOptions.UseCurrentThread) { psInstance.CreateNewSingleThreadedRunspace(); } var handlers = psInstance.AddOutputStreamsEventHandlers(printer); psInstance.AddScript(script); psInstance.Invoke(); psInstance.RemoveOutputStreamsEventHandlers(handlers); // Clear PowerShell pipeline to avoid the script being re-executed the next time we use this instance psInstance.Commands.Clear(); }
public ConvolutionalNeuralNetworkRunner(DeviceDescriptor device, TrainingSessionConfiguration configuration, IMessagePrinter printer) : base(device, configuration, printer) { }
public HelloWorldGeneratorConsole(IMessagePrinter printer) : base(printer) { }
protected ConsoleTestBase(string title) { Name = title; msgPrinter = new ConsoleMessagePrinter(); }
public CheckoutMessagePrinter(IMessagePrinter messagePrinter) { _messagePrinter = messagePrinter; }