Exemplo n.º 1
0
        /// <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));
            }
        }
Exemplo n.º 2
0
        private async Task InitializeCommandsAsync()
        {
            try {
                var userCommand = new UserCommand(_sessionService, _settingsManager);

                _commands = new List <VsCommandBase> {
#if DEBUG
                    new WebViewDevToolsCommand(),
#endif
                    new AddCodemarkCommentCommand(PackageGuids.guidWebViewPackageCodeWindowContextMenuCmdSet),
                    new AddCodemarkIssueCommand(PackageGuids.guidWebViewPackageCodeWindowContextMenuCmdSet),
                    new AddCodemarkPermalinkCommand(PackageGuids.guidWebViewPackageCodeWindowContextMenuCmdSet),
                    new AddCodemarkPermalinkInstantCommand(PackageGuids.guidWebViewPackageCodeWindowContextMenuCmdSet),

                    new AddCodemarkCommentCommand(PackageGuids.guidWebViewPackageShortcutCmdSet),
                    new AddCodemarkIssueCommand(PackageGuids.guidWebViewPackageShortcutCmdSet),
                    new AddCodemarkPermalinkCommand(PackageGuids.guidWebViewPackageShortcutCmdSet),
                    new AddCodemarkPermalinkInstantCommand(PackageGuids.guidWebViewPackageShortcutCmdSet),

                    new WebViewReloadCommand(),
                    new WebViewToggleCommand(),
                    new AuthenticationCommand(_componentModel),
                    userCommand
                };
                await JoinableTaskFactory.SwitchToMainThreadAsync();

                await InfoBarProvider.InitializeAsync(this);

                var menuCommandService = (IMenuCommandService)(await GetServiceAsync(typeof(IMenuCommandService)));
                foreach (var command in _commands)
                {
                    menuCommandService.AddCommand(command);
                }
                await BookmarkShortcutRegistration.InitializeAllAsync(this);

                var eventAggregator = _componentModel.GetService <IEventAggregator>();
                _disposables = new List <IDisposable> {
                    //when a user has logged in/out we alter the text of some of the commands
                    eventAggregator?.GetEvent <SessionReadyEvent>()
                    .ObserveOnApplicationDispatcher()
                    .Subscribe(_ => {
                        userCommand.Update();
                    }),
                    eventAggregator?.GetEvent <SessionLogoutEvent>()
                    .ObserveOnApplicationDispatcher()
                    .Subscribe(_ => {
                        userCommand.Update();
                    }),
                    eventAggregator?.GetEvent <LanguageServerDisconnectedEvent>()
                    .ObserveOnApplicationDispatcher()
                    .Subscribe(_ => {
                        userCommand.Update();
                    }),

                    //eventAggregator?.GetEvent<SessionDidStartSignInEvent>().Subscribe(_ => {
                    //	ThreadHelper.JoinableTaskFactory.Run(async delegate {
                    //		await JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken.None);
                    //	userCommand.Update();
                    //	});
                    //}),
                    //eventAggregator?.GetEvent<SessionDidFailSignInEvent>().Subscribe(_ => {
                    //	ThreadHelper.JoinableTaskFactory.Run(async delegate {
                    //		await JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken.None);
                    //	userCommand.Update();
                    //	});
                    //}),
                    //eventAggregator?.GetEvent<SessionDidStartSignOutEvent>().Subscribe(_ => {
                    //	ThreadHelper.JoinableTaskFactory.Run(async delegate {
                    //		await JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken.None);
                    //		userCommand.Update();
                    //	});
                    //})
                };
            }
            catch (Exception ex) {
                Log.Error(ex, nameof(InitializeCommandsAsync));
            }
        }