/// <summary>
        /// Logs the current CodeSteam user our
        /// </summary>
        /// <returns></returns>
        private async System.Threading.Tasks.Task LogoutAsync(SessionSignedOutReason reason = SessionSignedOutReason.UserSignedOutFromWebview, JToken payload = null)
        {
            try {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                var componentModel = _serviceProvider.GetService(typeof(SComponentModel)) as IComponentModel;
                Assumes.Present(componentModel);
                if (componentModel == null)
                {
                    Log.Error(nameof(componentModel) + " is null");
                }
                var authenticationServiceFactory = componentModel.GetService <IAuthenticationServiceFactory>();

                if (authenticationServiceFactory != null)
                {
                    var authService = authenticationServiceFactory.Create();
                    if (authService == null)
                    {
                        Log.Error(nameof(LogoutAsync) + " " + nameof(authService) + " is null");
                    }
                    else
                    {
                        await authService.LogoutAsync(reason, payload);
                    }
                }
            }
            catch (Exception ex) {
                Log.Error(ex, nameof(LogoutAsync));
            }
        }
示例#2
0
 public void Logout(SessionSignedOutReason reason)
 {
     User   = null;
     State  = null;
     TeamId = null;
     SetState(SessionState.UserSignedOut);
 }
示例#3
0
        public void Logout(SessionSignedOutReason reason)
        {
            if (reason != SessionSignedOutReason.MaintenanceMode)
            {
                WebViewDidInitialize = false;
            }

            User   = null;
            State  = null;
            TeamId = null;
            SetState(SessionState.UserSignedOut);
        }
示例#4
0
        public async System.Threading.Tasks.Task LogoutAsync(SessionSignedOutReason reason = SessionSignedOutReason.UserSignedOutFromWebview, JToken payload = null)
        {
            Log.Information($"{nameof(LogoutAsync)} starting");
            try {
                try {
                    SessionService.SetState(SessionState.UserSigningOut);
                }
                catch (Exception ex) {
                    Log.Warning(ex, $"{nameof(LogoutAsync)} - SetState");
                }

                try {
                    EventAggregator.Publish(new SessionDidStartSignOutEvent());
                }
                catch (Exception ex) {
                    Log.Warning(ex, $"{nameof(LogoutAsync)} - {nameof(SessionDidStartSignOutEvent)}");
                }

                if (
                    reason == SessionSignedOutReason.UserSignedOutFromWebview ||
                    reason == SessionSignedOutReason.UserSignedOutFromExtension ||
                    reason == SessionSignedOutReason.MaintenanceMode ||
                    reason == SessionSignedOutReason.ReAuthenticating)
                {
                    try {
                        var settingsService = SettingsServiceFactory.GetOrCreate(nameof(AuthenticationService));
                        await CredentialsService.DeleteAsync(settingsService.ServerUrl.ToUri(), settingsService.Email);
                    }
                    catch (Exception ex) {
                        Log.Warning(ex, $"{nameof(LogoutAsync)} - credentials");
                    }
                    try {
                        WebviewUserSettingsService.DeleteTeamId(SessionService.SolutionName);
                    }
                    catch (Exception ex) {
                        Log.Error(ex, "could not delete teamId");
                    }
                }

                try {
                    await CodeStreamAgentService.LogoutAsync();
                }
                catch (Exception ex) {
                    Log.Error(ex, $"{nameof(LogoutAsync)} - agent");
                }

                if (reason == SessionSignedOutReason.UserSignedOutFromWebview ||
                    reason == SessionSignedOutReason.UserSignedOutFromExtension
                    )
                {
                    //don't call this when ReAuthenticating -- don't want to show the login screen
                    try {
#pragma warning disable VSTHRD103 // Call async methods when in an async method
                        // it's possible that this method is called before the webview is ready -- enqueue it
                        WebviewIpc.EnqueueNotification(new HostDidLogoutNotificationType());
#pragma warning restore VSTHRD103 // Call async methods when in an async method
                    }
                    catch (Exception ex) {
                        Log.Error(ex, $"{nameof(LogoutAsync)} - {nameof(HostDidLogoutNotificationType)}");
                    }
                }
                else if (reason == SessionSignedOutReason.MaintenanceMode)
                {
                    try {
#pragma warning disable VSTHRD103 // Call async methods when in an async method
                        // it's possible that this method is called before the webview is ready -- enqueue it
                        WebviewIpc.EnqueueNotification(new DidEncounterMaintenanceModeNotificationType(payload));
#pragma warning restore VSTHRD103 // Call async methods when in an async method
                    }
                    catch (Exception ex) {
                        Log.Error(ex, $"{nameof(LogoutAsync)} - {nameof(HostDidLogoutNotificationType)}");
                    }
                }

                try {
                    SessionService.Logout(reason);
                }
                catch (Exception ex) {
                    Log.Error(ex, $"{nameof(LogoutAsync)} - session");
                }

                try {
                    EventAggregator.Publish(new SessionLogoutEvent());
                }
                catch (Exception ex) {
                    Log.Error(ex, $"{nameof(LogoutAsync)} - {nameof(SessionLogoutEvent)}");
                }

                if (reason == SessionSignedOutReason.UserSignedOutFromWebview ||
                    reason == SessionSignedOutReason.UserSignedOutFromExtension ||
                    reason == SessionSignedOutReason.ReAuthenticating)
                {
                    var componentModel = _serviceProvider.GetService(typeof(SComponentModel)) as IComponentModel;
                    Assumes.Present(componentModel);
                    var languageServerClientManager = componentModel.GetService <ILanguageServerClientManager>();
                    if (languageServerClientManager != null)
                    {
                        await languageServerClientManager.RestartAsync();
                    }
                    else
                    {
                        Log.IsNull(nameof(ILanguageServerClientManager));
                    }
                }
                Log.Information($"{nameof(LogoutAsync)} completed");
            }
            catch (Exception ex) {
                Log.Fatal(ex, nameof(LogoutAsync));
            }
        }