protected override void Initialize()
        {
            base.Initialize();

            //if invalid data, adjust it
            dataAdjuster.Adjust();

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events         = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;
            GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin;

            PrintLine("Build monitor initialized");
            PrintLine("Path to persist data: {0}", Settings.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                Print("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                PrintLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
                PrintLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll);
                System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b));
            };

            monitor.ProjectBuildFinished = b => PrintLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);
            AnalyseBuildTimesCommand.Initialize(this);
        }
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // Switches to the UI thread, which most of this package requires. Even joining the main thread here improves
            // the load time of the package, and it stops a warning popping up when you load vs2019 with the package installed.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await base.InitializeAsync(cancellationToken, progress);

            output = new OutputWindowWrapper(this);

            SettingsManager       settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
            WritableSettingsStore settingsStore   = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            Settings.Instance = new Settings(settingsStore);

            var factory    = new BuildFactory();
            var repository = new BuildRepository(Settings.Instance.RepositoryPath);

            monitor      = new BuildMonitor.Domain.Monitor(factory, repository);
            dataAdjuster = new DataAdjusterWithLogging(repository, output.WriteLine);

            //if invalid data, adjust it
            dataAdjuster.Adjust();


            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events         = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;
            GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin;

            output.WriteLine("Build monitor initialized");
            output.WriteLine("Path to persist data: {0}", Settings.Instance.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                output.Write("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                output.WriteLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
                output.WriteLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll);
                //System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b));
            };

            monitor.ProjectBuildFinished = b => output.WriteLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);

            // In vs 2017 and earlier, this event was always called, but in 2019 it isn't called if you open a solution on startup.
            // I imagine this is because the solution has already loaded before we connect to the events. To get over it we just
            // manually call the event here.
            Solution_Opened();

            AnalyseBuildTimesCommand.Initialize(this);
        }
        protected override void Initialize()
        {
            base.Initialize();

            output = new OutputWindowWrapper(this);

            SettingsManager       settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
            WritableSettingsStore settingsStore   = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            Settings.Instance = new Settings(settingsStore);

            var factory    = new BuildFactory();
            var repository = new BuildRepository(Settings.Instance.RepositoryPath);

            monitor      = new Monitor(factory, repository);
            dataAdjuster = new DataAdjusterWithLogging(repository, output.WriteLine);

            //if invalid data, adjust it
            dataAdjuster.Adjust();


            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events         = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;
            GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin;

            output.WriteLine("Build monitor initialized");
            output.WriteLine("Path to persist data: {0}", Settings.Instance.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                output.Write("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                output.WriteLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
                output.WriteLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll);
                //System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b));
            };

            monitor.ProjectBuildFinished = b => output.WriteLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);
            AnalyseBuildTimesCommand.Initialize(this);
        }
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(Package package)
 {
     Instance = new AnalyseBuildTimesCommand(package);
 }