Exemplo n.º 1
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            if (!(await GetServiceAsync(typeof(DTE)) is DTE2 dte2))
            {
                return;
            }
            _dte2 = dte2;

            // Initialize DependencyResolver
            _dependencyResolver = await GetDependencyResolverAsync();

            _dependencyResolver.RegisterPackage(this);

            // Initialize DTE event handlers
            AttachToDteEvents();

            // Initialize commands
            ScriptCreationWindowCommand.Initialize(_dependencyResolver.Get <ScriptCreationWindowCommand>());
            VersionHistoryWindowCommand.Initialize(_dependencyResolver.Get <VersionHistoryWindowCommand>());
            ConfigurationWindowCommand.Initialize(_dependencyResolver.Get <ConfigurationWindowCommand>());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            var tt = AppDomain.CurrentDomain.GetAssemblies().ToList();

            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await Enable.InitializeAsync(this);

            await ConfigurationWindowCommand.InitializeAsync(this);

            Dte = (DTE2) await GetServiceAsync(typeof(DTE));

            Assumes.Present(Dte);
            if (Dte == null)
            {
                throw new ArgumentNullException(nameof(Dte));
            }

            Pane = Dte.ToolWindows.OutputWindow.OutputWindowPanes.Add("Dotnetsafer Shield");

            OutputPane = Dte.ToolWindows.OutputWindow.OutputWindowPanes.Add("Dotnetsafer Shield Output");

            ErrorListProvider = new ErrorListProvider(this);

            solutionEvents = Dte.Events.SolutionEvents;

            buildEvents = Dte.Events.BuildEvents;

            buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;

            buildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;

            //buildEvents.OnBuildDone += (scope, action) => ActivePane();

            var isSolutionLoaded = await IsSolutionLoadedAsync();

            solutionEvents.AfterClosing += SolutionEvents_AfterClosing;

            AddOptionKey(ShieldConfiguration);

            var solutionPersistenceService = (IVsSolutionPersistence) await GetServiceAsync(typeof(IVsSolutionPersistence));

            if (solutionPersistenceService == null)
            {
                throw new ArgumentNullException(nameof(solutionPersistenceService));
            }

            solutionPersistenceService.LoadPackageUserOpts(this, ShieldConfiguration);

            if (isSolutionLoaded)
            {
                SolutionEventsOnOpened();
            }

            solutionEvents.Opened += SolutionEventsOnOpened;

            TryReloadStorage();
        }