예제 #1
0
        public void Run()
        {
            const int MaxIterations      = 2000;
            const int PhaseOneIterations = 500;

            const int ReceivedEventsVisualWidth = 100;

            ConsoleWrite.Line();
            ConsoleWrite.Line($"Welcome to {this.GetType().FullName} in {Process.GetCurrentProcess().ProcessName}");

            ConsoleWrite.Line();
            ConsoleWrite.Line($"{nameof(HideDiagnosticSourceAssembly)} = {HideDiagnosticSourceAssembly}");

#pragma warning disable CS0162 // Unreachable code detected: intentional controll via a const bool.
            if (HideDiagnosticSourceAssembly)
            {
                string destination = Path.Combine(DiagnosticSourceAssemblyHiddenPath, DiagnosticSourceAssemblyFilename);

                try
                {
                    Directory.CreateDirectory(DiagnosticSourceAssemblyHiddenPath);

                    if (File.Exists(destination))
                    {
                        File.Delete(destination);
                    }
                }
                catch { }

                File.Move(DiagnosticSourceAssemblyFilename, destination);

                ConsoleWrite.Line($"Moved \"{DiagnosticSourceAssemblyFilename}\" to \"{destination}\".");

                ConsoleWrite.Line();
                ConsoleWrite.Line($"Setting up the AssemblyResolve handler for the current AppDomain.");

                AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveEventHandler;
            }
            else
            {
                ConsoleWrite.Line("Did not hide the DS assembly.");
            }
#pragma warning restore CS0162 // Unreachable code detected

            ConsoleWrite.LineLine($"Setting up {nameof(StubbedDiagnosticEventsCollector)}.");

            var directResultsAccumulator  = new ReceivedEventsAccumulator(MaxIterations);
            var stubbedResultsAccumulator = new ReceivedEventsAccumulator(MaxIterations);
            var stubbedCollector          = new StubbedDiagnosticEventsCollector(directResultsAccumulator, stubbedResultsAccumulator);

            SetPhaseOneCompleted(false);

            ConsoleWrite.LineLine($"Starting {nameof(StubbedDiagnosticEventsGenerator)}.");

            var  stubbedGenerator     = new StubbedDiagnosticEventsGenerator(MaxIterations, PhaseOneIterations);
            Task stubbedGeneratorTask = Task.Run(stubbedGenerator.Run);

            stubbedGenerator.PhaseOneCompletedEvent.Wait();

            ConsoleWrite.LineLine($"Phase one of {nameof(stubbedGenerator)} completed.");
            SetPhaseOneCompleted(true);

            ConsoleWrite.Line($"Starting {nameof(DirectDiagnosticEventsGenerator)}.");

            var  directGenerator     = new DirectDiagnosticEventsGenerator(MaxIterations, PhaseOneIterations);
            Task directGeneratorTask = Task.Run(directGenerator.Run);

            Task.WaitAll(stubbedGeneratorTask, directGeneratorTask);

            ConsoleWrite.LineLine($"Both, {nameof(stubbedGenerator)} and {nameof(directGenerator)} finished.");

            ConsoleWrite.LineLine($"Summary of {nameof(stubbedResultsAccumulator)}:"
                                  + $" Received events: {stubbedResultsAccumulator.ReceivedCount}; Proportion: {stubbedResultsAccumulator.ReceivedProportion}.");
            ConsoleWrite.Line(Environment.NewLine + stubbedResultsAccumulator.GetReceivedVisual(ReceivedEventsVisualWidth));

            ConsoleWrite.LineLine($"Summary of {nameof(directResultsAccumulator)}:"
                                  + $" Received events: {directResultsAccumulator.ReceivedCount}; Proportion: {directResultsAccumulator.ReceivedProportion}.");
            ConsoleWrite.Line(Environment.NewLine + directResultsAccumulator.GetReceivedVisual(ReceivedEventsVisualWidth));

            ConsoleWrite.LineLine("All done. Press enter to exit.");

            Console.ReadLine();
            ConsoleWrite.Line("Good bye.");
        }
예제 #2
0
        public void Run()
        {
            const int MaxIterations      = 2000;
            const int PhaseOneIterations = 500;

            const int ReceivedEventsVisualWidth = 100;

            ConsoleWrite.LineLine($"Welcome to {this.GetType().FullName} in {Process.GetCurrentProcess().ProcessName}");

            ConsoleWrite.Line($"Starting {nameof(DirectDiagnosticEventsGenerator)}.");

            var  directGenerator     = new DirectDiagnosticEventsGenerator(MaxIterations, PhaseOneIterations);
            Task directGeneratorTask = Task.Run(directGenerator.Run);

            ConsoleWrite.LineLine($"Setting up {nameof(StubbedDiagnosticEventsCollector)}.");

            var directResultsAccumulator  = new ReceivedEventsAccumulator(MaxIterations);
            var stubbedResultsAccumulator = new ReceivedEventsAccumulator(MaxIterations);
            var stubbedCollector          = new StubbedDiagnosticEventsCollector(directResultsAccumulator, stubbedResultsAccumulator);

            {
                ConsoleWrite.LineLine($"Kicking off the DS magic.");
                bool prevInit = DiagnosticSourceAssembly.IsInitialized;
                bool nowInit  = DiagnosticSourceAssembly.EnsureInitialized();
                ConsoleWrite.Line($"DiagnosticSourceAssembly-magic status: prevInit={prevInit}, nowInit={nowInit}.");
            }

            directGenerator.PhaseOneCompletedEvent.Wait();

            ConsoleWrite.LineLine($"Phase one of {nameof(directGenerator)} completed.");

            ConsoleWrite.LineLine($"Starting {nameof(StubbedDiagnosticEventsGenerator)}.");

            var  stubbedGenerator     = new StubbedDiagnosticEventsGenerator(MaxIterations, PhaseOneIterations);
            Task stubbedGeneratorTask = Task.Run(stubbedGenerator.Run);

            stubbedGenerator.PhaseOneCompletedEvent.Wait();

            ConsoleWrite.LineLine($"Phase one of {nameof(stubbedGenerator)} completed.");

            ConsoleWrite.LineLine($"Starting Mock Plug-In."
                                  + $" directGen.Iteration={directGenerator.CurrentIteration}; stubbedGen.Iteration={stubbedGenerator.CurrentIteration}.");

            Task pulginTask = Task.Run(Plugin);

            pulginTask.Wait();

            ConsoleWrite.LineLine($"Completed Mock Plug-In."
                                  + $" directGen.Iteration={directGenerator.CurrentIteration}; stubbedGen.Iteration={stubbedGenerator.CurrentIteration}.");

            ConsoleWrite.LineLine($"Waiting for event generators to finish.");

            Task.WaitAll(stubbedGeneratorTask, directGeneratorTask);

            ConsoleWrite.LineLine($"Both, {nameof(stubbedGenerator)} and {nameof(directGenerator)} finished.");

            ConsoleWrite.LineLine($"Summary of {nameof(stubbedResultsAccumulator)}:"
                                  + $" Received events: {stubbedResultsAccumulator.ReceivedCount}; Proportion: {stubbedResultsAccumulator.ReceivedProportion}.");
            ConsoleWrite.Line(Environment.NewLine + stubbedResultsAccumulator.GetReceivedVisual(ReceivedEventsVisualWidth));

            ConsoleWrite.LineLine($"Summary of {nameof(directResultsAccumulator)}:"
                                  + $" Received events: {directResultsAccumulator.ReceivedCount}; Proportion: {directResultsAccumulator.ReceivedProportion}.");
            ConsoleWrite.Line(Environment.NewLine + directResultsAccumulator.GetReceivedVisual(ReceivedEventsVisualWidth));

            ConsoleWrite.LineLine("All done. Press enter to exit.");

            Console.ReadLine();
            ConsoleWrite.Line("Good bye.");
        }