/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); var perfCounter = CreatePerformanceCounter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; using (var container = new Bootstrapper(Logger)) { var persistance = new FilePersistance(parser, Logger); container.Initialise(filter, parser, persistance, perfCounter); if (!persistance.Initialise(outputFile, parser.MergeExistingOutputFile)) return returnCodeOffset + 1; returnCode = RunWithContainer(parser, container, persistance); } perfCounter.ResetCounters(); } catch (ExitApplicationWithoutReportingException) { Logger.ErrorFormat("If you are unable to resolve the issue please contact the OpenCover development team"); Logger.ErrorFormat("see https://www.github.com/opencover/opencover/issues"); returnCode = returnCodeOffset + 1; } catch (Exception ex) { Logger.Fatal("At: Program.Main"); Logger.FatalFormat("An {0} occured: {1}", ex.GetType(), ex.Message); Logger.FatalFormat("stack: {0}", ex.StackTrace); Logger.FatalFormat("A report has been sent to the OpenCover development team."); Logger.ErrorFormat("If you are unable to resolve the issue please contact the OpenCover development team"); Logger.ErrorFormat("see https://www.github.com/opencover/opencover/issues"); ReportCrash(ex); returnCode = returnCodeOffset + 1; } return returnCode; }
public void CanCreateInstrumentationModelBuilderFactory() { using (var bootstrapper = new Bootstrapper(_mockLogger.Object)) { bootstrapper.Initialise(_mockFilter.Object, _mockCommandLine.Object, _mockPersistance.Object, _mockPerf.Object); // act var instance = bootstrapper.Resolve<IInstrumentationModelBuilderFactory>(); // assert Assert.IsNotNull(instance); } }
public void CanCreateProfilerCommunication() { using (var bootstrapper = new Bootstrapper(_mockLogger.Object)) { bootstrapper.Initialise(_mockFilter.Object, _mockCommandLine.Object, _mockPersistance.Object, _mockPerf.Object); // act var instance = bootstrapper.Resolve<IProfilerCommunication>(); // assert Assert.IsNotNull(instance); } }
private void ExecuteProfiler(Action<ProcessStartInfo> testProcess) { var bootstrapper = new Bootstrapper(_logger.Object); bootstrapper.Initialise(_filter, _commandLine.Object, _persistance, new NullPerfCounter()); var harness = bootstrapper.Resolve<IProfilerManager>(); harness.RunProcess((environment) => { var startInfo = new ProcessStartInfo(); environment(startInfo.EnvironmentVariables); testProcess(startInfo); startInfo.UseShellExecute = false; var process = Process.Start(startInfo); process.WaitForExit(); }, false); }
public void TrackedMethodStrategyManager_Is_Singleton() { using (var bootstrapper = new Bootstrapper(_mockLogger.Object)) { bootstrapper.Initialise(_mockFilter.Object, _mockCommandLine.Object, _mockPersistance.Object, _mockPerf.Object); // act var instance1 = bootstrapper.Resolve<ITrackedMethodStrategyManager>(); var instance2 = bootstrapper.Resolve<ITrackedMethodStrategyManager>(); // assert Assert.IsNotNull(instance1); Assert.AreSame(instance1, instance2); } }
private void ExecuteProfiler(Action<ProcessStartInfo> testProcess) { var bootstrapper = new Bootstrapper(); bootstrapper.Initialise(_filter, _commandLine.Object, _persistance); var harness = (IProfilerManager)bootstrapper.Container.Resolve(typeof(IProfilerManager), null); harness.RunProcess((environment) => { var startInfo = new ProcessStartInfo(); environment(startInfo.EnvironmentVariables); testProcess(startInfo); startInfo.UseShellExecute = false; var process = Process.Start(startInfo); process.WaitForExit(); }); }
public void CanCreateProfilerCommunication() { // arrange var mockFilter = new Mock<IFilter>(); var mockCommandLine = new Mock<ICommandLine>(); var mockPersistance = new Mock<IPersistance>(); var bootstrapper = new Bootstrapper(); bootstrapper.Initialise(mockFilter.Object, mockCommandLine.Object, mockPersistance.Object); // act var instance = bootstrapper.Container.Resolve(typeof(IProfilerCommunication), null); // assert Assert.IsNotNull(instance); }
public void CanCreateInstrumentationModelBuilderFactory() { // arrange var mockFilter = new Mock<IFilter>(); var mockCommandLine = new Mock<ICommandLine>(); var mockPersistance = new Mock<IPersistance>(); var mockLogger = new Mock<ILog>(); var mockManager = new Mock<IMemoryManager>(); var bootstrapper = new Bootstrapper(mockLogger.Object); bootstrapper.Initialise(mockFilter.Object, mockCommandLine.Object, mockPersistance.Object, mockManager.Object); // act var instance = bootstrapper.Container.Resolve(typeof(IInstrumentationModelBuilderFactory), null); // assert Assert.IsNotNull(instance); }
public void CanCreateProfilerCommunication() { // arrange var mockFilter = new Mock<IFilter>(); var mockCommandLine = new Mock<ICommandLine>(); var mockPersistance = new Mock<IPersistance>(); var mockPerf = new Mock<IPerfCounters>(); var mockLogger = new Mock<ILog>(); using (var bootstrapper = new Bootstrapper(mockLogger.Object)) { bootstrapper.Initialise(mockFilter.Object, mockCommandLine.Object, mockPersistance.Object, mockPerf.Object); // act var instance = bootstrapper.Resolve<IProfilerCommunication>(); // assert Assert.IsNotNull(instance); } }
public void CanCreateInstrumentationModelBuilderFactory() { // arrange var mockFilter = new Mock<IFilter>(); var mockCommandLine = new Mock<ICommandLine>(); var mockPersistance = new Mock<IPersistance>(); var mockPerf = new Mock<IPerfCounters>(); var mockLogger = new Mock<ILog>(); using (var bootstrapper = new Bootstrapper(mockLogger.Object)) { bootstrapper.Initialise(mockFilter.Object, mockCommandLine.Object, mockPersistance.Object, mockPerf.Object); // act var instance = bootstrapper.Resolve<IInstrumentationModelBuilderFactory>(); // assert Assert.IsNotNull(instance); Assert.AreEqual(2, instance.MethodStrategies.Count()); } }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; try { CommandLineParser parser; if (ParseCommandLine(args, out parser)) return returnCode; var filter = BuildFilter(parser); string outputFile; if (GetFullOutputFile(parser, out outputFile)) return returnCode; var container = new Bootstrapper(); var persistance = new FilePersistance(parser); container.Initialise(filter, parser, persistance); persistance.Initialise(outputFile); bool registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.UserRegistration); registered = true; } var harness = (IProfilerManager)container.Container.Resolve(typeof(IProfilerManager), null); harness.RunProcess((environment) => { var startInfo = new ProcessStartInfo(Path.Combine(Environment.CurrentDirectory, parser.Target)); environment(startInfo.EnvironmentVariables); startInfo.Arguments = parser.TargetArgs; startInfo.UseShellExecute = false; startInfo.WorkingDirectory = parser.TargetDir; var process = Process.Start(startInfo); process.WaitForExit(); if (parser.ReturnTargetCode) returnCode = process.ExitCode; }); DisplayResults(persistance, parser); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.UserRegistration); } } catch (Exception ex) { System.Console.WriteLine(); System.Console.WriteLine("An exception occured: {0}", ex.Message); System.Console.WriteLine("stack: {0}", ex.StackTrace); } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; var logger = LogManager.GetLogger(typeof (Bootstrapper)); try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; var container = new Bootstrapper(logger); var persistance = new FilePersistance(parser, logger); container.Initialise(filter, parser, persistance); persistance.Initialise(outputFile); var registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.UserRegistration); registered = true; } var harness = (IProfilerManager)container.Container.Resolve(typeof(IProfilerManager), null); harness.RunProcess((environment) => { returnCode = 0; if (parser.Service) { RunService(parser, environment, logger); } else { returnCode = RunProcess(parser, environment); } }, parser.Service); DisplayResults(persistance, parser, logger); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.UserRegistration); } } catch (Exception ex) { if (logger.IsFatalEnabled) { logger.FatalFormat("An exception occured: {0}", ex.Message); logger.FatalFormat("stack: {0}", ex.StackTrace); } returnCode = returnCodeOffset + 1; } return returnCode; }
private static int RunWithContainer(CommandLineParser parser, Bootstrapper container, IPersistance persistance) { var returnCode = 0; var registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.Registration); registered = true; } var harness = container.Resolve<IProfilerManager>(); var servicePrincipal = (parser.Service ? new[] {ServiceEnvironmentManagement.MachineQualifiedServiceAccountName(parser.Target)} : new string[0]).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); harness.RunProcess(environment => { if (parser.Service) { RunService(parser, environment, Logger); returnCode = 0; } else { returnCode = RunProcess(parser, environment); } }, servicePrincipal); DisplayResults(persistance, parser, Logger); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.Registration); } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { int returnCode; var returnCodeOffset = 0; try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); var perfCounter = CreatePerformanceCounter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; using (var container = new Bootstrapper(Logger)) { var persistance = new FilePersistance(parser, Logger); container.Initialise(filter, parser, persistance, perfCounter); persistance.Initialise(outputFile, parser.MergeExistingOutputFile); returnCode = RunWithContainer(parser, container, persistance); } perfCounter.ResetCounters(); } catch (Exception ex) { if (Logger.IsFatalEnabled) { Logger.FatalFormat("An exception occured: {0}", ex.Message); Logger.FatalFormat("stack: {0}", ex.StackTrace); } returnCode = returnCodeOffset + 1; } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; var logger = LogManager.GetLogger(typeof (Bootstrapper)); try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; IPerfCounters perfCounter = new NullPerfCounter(); if (parser.EnablePerformanceCounters) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { perfCounter = new PerfCounters(); } else { throw new InvalidCredentialException("You must be running as an Administrator to enable performance counters."); } } using (var container = new Bootstrapper(logger)) { var persistance = new FilePersistance(parser, logger); container.Initialise(filter, parser, persistance, perfCounter); persistance.Initialise(outputFile); var registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.Registration); registered = true; } var harness = container.Resolve<IProfilerManager>(); harness.RunProcess((environment) => { returnCode = 0; if (parser.Service) { RunService(parser, environment, logger); } else { returnCode = RunProcess(parser, environment); } }, parser.Service); DisplayResults(persistance, parser, logger); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.Registration); } } perfCounter.ResetCounters(); } catch (Exception ex) { if (logger.IsFatalEnabled) { logger.FatalFormat("An exception occured: {0}", ex.Message); logger.FatalFormat("stack: {0}", ex.StackTrace); } returnCode = returnCodeOffset + 1; } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { int returnCode; var returnCodeOffset = 0; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; try { //throw new NullReferenceException(); CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); var perfCounter = CreatePerformanceCounter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; using (var container = new Bootstrapper(Logger)) { var persistance = new FilePersistance(parser, Logger); container.Initialise(filter, parser, persistance, perfCounter); persistance.Initialise(outputFile, parser.MergeExistingOutputFile); returnCode = RunWithContainer(parser, container, persistance); } perfCounter.ResetCounters(); } catch (Exception ex) { if (Logger.IsFatalEnabled) { Logger.FatalFormat("An exception occured: {0}", ex.Message); Logger.FatalFormat("stack: {0}", ex.StackTrace); Logger.FatalFormat("A report has been sent to the OenCover development team..."); } ReportCrash(ex); returnCode = returnCodeOffset + 1; } return returnCode; }