public RedirectedRunAsyncResult(ProcessStartInfo info, ConsoleOutputHandler stdoutCallback, ConsoleOutputHandler stderrCallback, AsyncCallback callback, object state)
            {
                this._stdoutCallback = stdoutCallback;
                this._stderrCallback = stderrCallback;
                this._callback       = callback;
                this.AsyncState      = state;

                info.UseShellExecute        = false;
                info.RedirectStandardOutput = true;
                info.RedirectStandardError  = true;
                info.CreateNoWindow         = true;
                info.WindowStyle            = ProcessWindowStyle.Hidden;

                var process = this._process = new Process {
                    StartInfo = info, EnableRaisingEvents = true
                };

                process.OutputDataReceived += this._process_OutputDataReceived;
                process.ErrorDataReceived  += this._process_ErrorDataReceived;
                process.Exited             += this._process_Exited;

                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }
示例#2
0
        private ConsoleCrawlerApp CreateTarget()
        {
            var crawler    = new WebCrawler(new NodeFactory(new LinkExtractor()), _httpMock.Object);
            var output     = new ConsoleOutputHandler(new TextOutputGenerator(), _fileMock.Object, _consoleMock.Object);
            var consoleApp = new ConsoleCrawlerApp(new ConsoleInputHandler(_clockMock.Object), output, crawler);

            return(consoleApp);
        }
示例#3
0
        public static void Main(string[] args)
        {
            var outputHandler = new ConsoleOutputHandler();
            var inputHandler  = new ConsoleInputHandler(outputHandler);

            var game = new Game(outputHandler, inputHandler);

            game.Run();
        }
        static void Main(string[] args)
        {
            String command;
            bool   quitNow = false;

            Grid                 grid                 = new Grid(5, 5);
            Robot                robot                = new Robot();
            CommandsHandler      commandHandler       = new CommandsHandler(robot, grid);
            ConsoleOutputHandler consoleOutputHandler = new ConsoleOutputHandler();

            Console.WriteLine("Please insert a command(file filename.txt|place x,y,f|move|left|right|report) or /quit to exit!");

            bool isEndOfFile = false;

            while (!quitNow)
            {
                if (commandHandler.IsFileInput && !isEndOfFile)
                {
                    command = commandHandler.FileHandler.ReadLineFromFile(out isEndOfFile);
                }
                else
                {
                    if (isEndOfFile)
                    {
                        consoleOutputHandler.PrintMessage("File parsing finished! You can find the output in output.txt file.");
                    }
                    command = Console.ReadLine();
                }

                if (command == "/quit")
                {
                    quitNow = true;
                    continue;
                }

                commandHandler.HandleInput(command);
            }
        }
示例#5
0
        static int Main(string[] args)
        {
            Console.WriteLine("My.Data.Bandwidth Initialising...");

            var arguments = args.Select(x => x.ToLower()).ToList();

            var test    = new SpeedTestHandler();
            var persist = new PersistenceHandler <SpeedTestDataModel>();

            var httpClientFactory = new ServiceCollection()
                                    .AddHttpClient()
                                    .BuildServiceProvider()
                                    .GetService <IHttpClientFactory>();

            var transmit = new TransmitHandler <SpeedTestDataModel>(httpClientFactory);
            var announce = new ConsoleOutputHandler <SpeedTestDataModel>();
            var process  = new ResultHandler <SpeedTestDataModel>();

            var success = true;

            Console.WriteLine("My.Data.Bandwidth Starting...");
            while (success)
            {
                var result = test.Execute(DateTimeOffset.UtcNow).GetAwaiter().GetResult();

                // abort on error if instructed, else continue forever
                if (
                    arguments.Any() &&
                    arguments.Contains("abortonerror") &&
                    result.IsError)
                {
                    // error and exit
                    success = !result.IsError;
                    persist.Execute(result).Wait();
                    bool transmitViaAPI = false; // TODO via settings
                    if (transmitViaAPI)
                    {
                        transmit.Execute(result).Wait();
                    }
                    announce.Execute(result).Wait();
                }
                else if (result.IsError)
                {
                    // error and repeat
                    persist.Execute(result).Wait();
                    bool transmitViaAPI = false; // TODO via settings
                    if (transmitViaAPI)
                    {
                        transmit.Execute(result).Wait();
                    }
                    announce.Execute(result).Wait();
                }
                else
                {
                    // all is well
                    persist.Execute(result).Wait();
                    bool transmitViaAPI = false; // TODO via settings
                    if (transmitViaAPI)
                    {
                        transmit.Execute(result).Wait();
                    }
                    announce.Execute(result).Wait();
                    process.Execute(result).Wait();
                }
            }
            return(1); // always returns an error - because it should run forever.
        }
 public static IAsyncResult BeginRedirectedRun(this ProcessStartInfo @this, ConsoleOutputHandler stdoutCallback = null, ConsoleOutputHandler stderrCallback = null, AsyncCallback callback = null, object state = null)
 => new RedirectedRunAsyncResult(@this, stdoutCallback, stderrCallback, callback, state)
 ;