public override OperationResult Perform() { var result = OperationResult.Success; if (Context.Next.Settings.SessionMode == SessionMode.Server) { logger.Info("Initializing server..."); StatusChanged?.Invoke(TextKey.OperationStatus_InitializeServer); server.Initialize(Context.Next.Settings.Server); var(abort, fallback, success) = TryPerformWithFallback(() => server.Connect()); if (success) { (abort, fallback, success) = TryPerformWithFallback(() => server.GetAvailableExams(Context.Next.Settings.Server.ExamId), out var exams); if (success) { var exam = default(Exam); if (!string.IsNullOrWhiteSpace(Context.Next.Settings.Server.ExamId)) { exam = exams.First(); logger.Info("Automatically selected exam as defined in configuration."); } else { success = TrySelectExam(exams, out exam); } if (success) { (abort, fallback, success) = TryPerformWithFallback(() => server.GetConfigurationFor(exam), out var uri); if (success) { var info = server.GetConnectionInfo(); var status = TryLoadSettings(uri, UriSource.Server, out _, out var settings); fileSystem.Delete(uri.LocalPath); if (status == LoadStatus.Success) { var serverSettings = Context.Next.Settings.Server; Context.Next.AppConfig.ServerApi = info.Api; Context.Next.AppConfig.ServerConnectionToken = info.ConnectionToken; Context.Next.AppConfig.ServerExamId = exam.Id; Context.Next.AppConfig.ServerOauth2Token = info.Oauth2Token; Context.Next.Settings = settings; Context.Next.Settings.Browser.StartUrl = exam.Url; Context.Next.Settings.Server = serverSettings; Context.Next.Settings.SessionMode = SessionMode.Server; result = OperationResult.Success; } else { result = OperationResult.Failed; } } } else { logger.Info("The user aborted the exam selection."); result = OperationResult.Aborted; } } } if (abort) { result = OperationResult.Aborted; } if (fallback) { Context.Next.Settings.SessionMode = SessionMode.Normal; result = OperationResult.Success; } } return(result); }