示例#1
0
        private static void Task3(string path, OutputWorker outputWorker, Graph graph)
        {
            InputWorker inputWorker = new InputWorker(Path.Combine(path, "computers.in"));

            outputWorker.SetFileName(Path.Combine(path, "task3.out"));
            outputWorker.DisplayMissingDependencies(graph.GetMissingDependencies(inputWorker.ProcessInputAsList()));
        }
        private void StatusForm_Load(object sender, EventArgs e)
        {
            WireMessage myLogger = new WireMessage(WriteMessage);

            output      = new OutputWorker(myLogger);
            timerWorker = new TimerWorker();
            timerWorker.Run(output);
        }
        /// <summary>
        /// Runs a process.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="workingDirectory">The working directory.</param>
        public void StartProcess(string fileName, string arguments, string workingDirectory)
        {
            //  Create the process start info.
            var processStartInfo = new ProcessStartInfo(fileName)
            {
                Arguments = arguments,

                //  Set the options.
                UseShellExecute = false,
                ErrorDialog     = false,
                CreateNoWindow  = true,

                //  Specify redirection.
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true
            };

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                processStartInfo.WorkingDirectory = workingDirectory;
            }

            //  Create the process.
            Process = new Process
            {
                EnableRaisingEvents = true,
                StartInfo           = processStartInfo
            };

            Process.Exited += CurrentProcess_Exited;

            //  Start the process.
            try
            {
                Process.Start();
            }
            catch (Exception e)
            {
                //  Trace the exception.
                Trace.WriteLine("Failed to start process " + fileName + " with arguments '" + arguments + "'");
                Trace.WriteLine(e.ToString());
                return;
            }

            //  Store name and arguments.
            ProcessFileName  = fileName;
            ProcessArguments = arguments;

            //  Create the readers and writers.
            InputWriter  = Process.StandardInput;
            OutputReader = TextReader.Synchronized(Process.StandardOutput);
            ErrorReader  = TextReader.Synchronized(Process.StandardError);

            //  Run the workers that read output and error.
            OutputWorker.RunWorkerAsync();
            ErrorWorker.RunWorkerAsync();
        }
示例#4
0
        static void Main(string[] args)
        {
            // Init I/O Workers
            string       path         = Directory.GetCurrentDirectory();
            InputWorker  inputWorker  = new InputWorker(Path.Combine(path, "disp.in"));
            OutputWorker outputWorker = new OutputWorker();

            // Init Graph
            Graph graph = new Graph(inputWorker.ProcessInput());

            // Execute Tasks
            Task1(path, outputWorker, graph);
            Task2(path, outputWorker, graph);
            Task3(path, outputWorker, graph);
        }
示例#5
0
        public void Run_RunsUntilSequenceEndsAndNotifiesOnUniqueFound()
        {
            OutputWorker <char, string> worker = new OutputWorker <char, string>(c => c.ToString());

            char[] inputs = new char[] { 'a', 'b', 'b', 'a', 'c' };

            List <char> items = new List <char>();

            worker.Run(inputs, c => items.Add(c));

            Assert.Equal(3, items.Count);
            Assert.Equal('a', items[0]);
            Assert.Equal('b', items[1]);
            Assert.Equal('c', items[2]);
            Assert.Equal(3, worker.UniqueCount);
        }
        /// <summary>
        /// Handles the DoWork event of the outputWorker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs" /> instance containing the event data.</param>
        void OutputWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!OutputWorker.CancellationPending && OutputReader is not null)
            {
                //  Any lines to read?
                int count;
                var buffer = new char[1024];
                do
                {
                    var builder = new StringBuilder();
                    count = OutputReader.Read(buffer, 0, 1024);
                    builder.Append(buffer, 0, count);
                    OutputWorker.ReportProgress(0, builder.ToString());
                } while (count > 0);

                System.Threading.Thread.Sleep(200);
            }
        }
        /// <summary>
        /// Handles the Exited event of the currentProcess control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        void CurrentProcess_Exited(object sender, EventArgs e)
        {
            //  Fire process exited.
            if (Process is not null)
            {
                FireProcessExitEvent(Process.ExitCode);
            }

            //  Disable the threads.
            OutputWorker.CancelAsync();
            ErrorWorker.CancelAsync();
            InputWriter      = null;
            OutputReader     = null;
            ErrorReader      = null;
            Process          = null;
            ProcessFileName  = null;
            ProcessArguments = null;
        }
示例#8
0
 private static void Task2(string path, OutputWorker outputWorker, Graph graph)
 {
     outputWorker.SetFileName(Path.Combine(path, "task2.out"));
     outputWorker.DisplayPackagesAndDependencies(graph.GetPackagesWithDependencies());
 }
示例#9
0
 private static void Task1(string path, OutputWorker outputWorker, Graph graph)
 {
     outputWorker.SetFileName(Path.Combine(path, "task1.out"));
     outputWorker.DisplayUniquePackages(graph.GetUniquePackages());
 }