示例#1
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            try {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                ((IServiceContainer)this).AddService(typeof(SToolWindowProvider), CreateService, true);

                _componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

                _sessionService = _componentModel.GetService <ISessionService>();

                var settingsServiceFactory = _componentModel?.GetService <ISettingsServiceFactory>();
                _settingsManager = settingsServiceFactory.GetOrCreate(nameof(CommandsPackage));

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

                await base.InitializeAsync(cancellationToken, progress);

                await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, InitializeCommandsAsync);

                Log.Debug($"{nameof(CommandsPackage)} {nameof(InitializeAsync)} completed");
            }
            catch (Exception ex) {
                Log.Fatal(ex, nameof(InitializeAsync));
            }
        }
        /// <summary>
        /// From project settings this can be triggered with `/codestream codestream-vs://codestream/codemark/5d39c1c093008d247116bf94/open`
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            try {
                AsyncPackageHelper.InitializePackage(GetType().Name);

                _componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

                Assumes.Present(_componentModel);
                var settingsFactory = _componentModel.GetService <ISettingsServiceFactory>();
                _settingsManager = settingsFactory.Create();
                var sessionService = _componentModel.GetService <ISessionService>();

                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                AsyncPackageHelper.InitializeLogging(_settingsManager);

                //ensure the ToolWindow is visible
                var toolWindowProvider = GetGlobalService(typeof(SToolWindowProvider)) as IToolWindowProvider;
                toolWindowProvider?.ShowToolWindowSafe(Guids.WebViewToolWindowGuid);

                await AsyncPackageHelper.TryTriggerLspActivationAsync(Log);

                await InfoBarProvider.InitializeAsync(this);

                if (_settingsManager?.AutoSignIn != true)
                {
                    InfoBarProvider.Instance.ShowInfoBar($"Please enable {Application.Name}'s AutoSignin feature (Tools > Options > CodeStream > Settings) to open this file");
                    return;
                }

                Log.Debug($"{nameof(sessionService.WebViewDidInitialize)}={sessionService.WebViewDidInitialize} {nameof(sessionService.IsReady)}={sessionService.IsReady} {nameof(sessionService.IsAgentReady)}={sessionService.IsAgentReady}");
                if (sessionService.WebViewDidInitialize == true)
                {
                    await HandleAsync();
                }
                else
                {
                    var eventAggregator = _componentModel.GetService <IEventAggregator>();
                    _disposables = new List <IDisposable>()
                    {
                        eventAggregator.GetEvent <WebviewDidInitializeEvent>().Subscribe(e => {
                            Log.Debug(nameof(WebviewDidInitializeEvent));

                            ThreadHelper.JoinableTaskFactory.Run(async delegate {
                                await HandleAsync();
                            });
                        })
                    };
                }
            }
            catch (Exception ex) {
                Log.Error(ex, nameof(InitializeAsync));
            }
        }
示例#3
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));
            }
        }
示例#4
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));
            }
        }
示例#5
0
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            _componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            Assumes.Present(_componentModel);

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // can only get a dialog page from a package
            _optionsDialogPage = (IOptionsDialogPage)GetDialogPage(typeof(OptionsDialogPage));
            _settingsManager   = new SettingsManager(_optionsDialogPage);
            ((IServiceContainer)this).AddService(typeof(SSettingsManagerAccessor), CreateService, true);

            AsyncPackageHelper.InitializeLogging(_settingsManager.GetExtensionTraceLevel());
            AsyncPackageHelper.InitializePackage(GetType().Name);
            if (_settingsManager?.DialogPage != null)
            {
                _settingsManager.DialogPage.PropertyChanged += DialogPage_PropertyChanged;
            }

            await base.InitializeAsync(cancellationToken, progress);
        }