Beispiel #1
0
        //public WebViewPackage() {
        //	OptionsDialogPage = GetDialogPage(typeof(OptionsDialogPage)) as OptionsDialogPage;
        //}

        //protected override int QueryClose(out bool pfCanClose)
        //{
        //    pfCanClose = true;
        //    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
        //    if (pfCanClose)
        //    {
        //    }
        //    return VSConstants.S_OK;
        //}

        /// <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)
        {
            try {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                _componentModel = GetGlobalService(typeof(SComponentModel)) as IComponentModel;

                var settingsServiceFactory = _componentModel?.GetService <ISettingsServiceFactory>();
                _settingsManager = settingsServiceFactory.Create();
                if (_settingsManager != null)
                {
                    _settingsManager.DialogPage.PropertyChanged += DialogPage_PropertyChanged;
                }

                _solutionEventListener         = _componentModel.GetService <ISolutionEventsListener>();
                _solutionEventListener.Opened += SolutionOrFolder_Opened;
                _solutionEventListener.Closed += SolutionOrFolder_Closed;
                _solutionEventListener.Loaded += SolutionOrFolder_Loaded;

                _themeEventsService = _componentModel.GetService <IThemeEventsListener>();
                _themeEventsService.ThemeChangedEventHandler += Theme_Changed;

                AsyncPackageHelper.InitializeLogging(_settingsManager);
                AsyncPackageHelper.InitializePackage(GetType().Name);

                await base.InitializeAsync(cancellationToken, progress);

                var isSolutionLoaded = await IsSolutionLoadedAsync();

                Log.Debug($"{nameof(isSolutionLoaded)}={isSolutionLoaded}");
                if (isSolutionLoaded)
                {
                    await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, () => {
                        return(AsyncPackageHelper.TryTriggerLspActivationAsync(Log));
                    });
                }

                Log.Debug($"{nameof(InitializeAsync)} completed");
            }
            catch (Exception ex) {
                Log.Fatal(ex, nameof(InitializeAsync));
            }
        }
Beispiel #2
0
        //public WebViewPackage() {
        //	OptionsDialogPage = GetDialogPage(typeof(OptionsDialogPage)) as OptionsDialogPage;
        //}

        //protected override int QueryClose(out bool pfCanClose)
        //{
        //    pfCanClose = true;
        //    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
        //    if (pfCanClose)
        //    {
        //    }
        //    return VSConstants.S_OK;
        //}

        /// <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)
        {
            try {
                _componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

                Assumes.Present(_componentModel);

                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                _solutionEventListener         = _componentModel.GetService <ISolutionEventsListener>();
                _solutionEventListener.Opened += SolutionOrFolder_Opened;
                _solutionEventListener.Closed += SolutionOrFolder_Closed;
                _solutionEventListener.Loaded += SolutionOrFolder_Loaded;

                _themeEventsService = _componentModel.GetService <IThemeEventsListener>();
                _themeEventsService.ThemeChangedEventHandler += Theme_Changed;

                var manager = _componentModel.GetService <ISettingsServiceFactory>()?.GetOrCreate(nameof(WebViewPackage));
                if (manager != null)
                {
                    AsyncPackageHelper.InitializeLogging(manager.GetExtensionTraceLevel());
                }

                AsyncPackageHelper.InitializePackage(GetType().Name);

                await base.InitializeAsync(cancellationToken, progress);

                var isSolutionLoaded = await IsSolutionLoadedAsync();

                Log.Debug($"{nameof(isSolutionLoaded)}={isSolutionLoaded}");
                if (isSolutionLoaded)
                {
                    await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority,
                                                       () => AsyncPackageHelper.TryTriggerLspActivationAsync(Log));
                }

                Log.Debug($"{nameof(WebViewPackage)} {nameof(InitializeAsync)} completed");
            }
            catch (Exception ex) {
                Log.Fatal(ex, nameof(InitializeAsync));
            }
        }