/// <summary> /// The Authentication server operation did fail. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="error"> /// The error. /// </param> public void AuthenticateServerOperationDidFail(AuthenticateServerOperation operation, Exception error) { if (error != null) { this.Logger.LogError($"AuthenticateServerOperation {error.Message}"); } this.CleanUpFinishedServerOperation(); PasswordChangeResult passwordChangeResult; if (!string.IsNullOrEmpty(this.newPassword)) { this.newPassword = null; passwordChangeResult = PasswordChangeResult.PasswordNotChanged; } else { passwordChangeResult = PasswordChangeResult.NoPasswordChangeRequested; } this.Delegate?.ServerOperationManagerDidFailServerLogin(this, error, passwordChangeResult); }
/// <summary> /// Performs the login operation and Start processing the operation queue. /// </summary> public void Login() { if (this.serverOperations == null) { return; } if (this.ConnectionWatchDog != null && (this.ConnectionWatchDog.HasServerConnection == false || this.ConnectionWatchDog.HasInternetConnection == false)) { this.TimeoutLogin(); return; } var alreadyQueued = false; var queuePosition = 0; foreach (var operation in this.serverOperations) { if (operation is AuthenticateServerOperation) { alreadyQueued = true; break; } if (operation is RevolutionCookieServerOperation) { alreadyQueued = true; break; } ++queuePosition; } if (alreadyQueued) { if ((this.currentServerOperation == null && queuePosition > 0) || queuePosition > 1) { var serverOperation = this.serverOperations[queuePosition]; this.serverOperations.RemoveAt(queuePosition); this.serverOperations.Insert(this.currentServerOperation != null ? 1 : 0, serverOperation); } this.StartNextOperation(); } else { ServerOperation serverOperation; if (this.crmServer.AuthenticationType == ServerAuthenticationType.Revolution) { string usedRasUsername; if (!string.IsNullOrEmpty(this.RasInstanceName) && this.loginName.IndexOf("\\", StringComparison.OrdinalIgnoreCase) < 0 && !this.startingUp) { this.Logger.LogDebug($"ServerOperationManager RAS relogon with prefix: {this.RasInstanceName}", LogFlag.LogNetwork); usedRasUsername = $"{this.RasInstanceName}\\{this.loginName}"; } else { this.Logger.LogDebug($"ServerOperationManager RAS logon with loginName: {this.loginName}", LogFlag.LogNetwork); usedRasUsername = this.loginName; } serverOperation = new RevolutionCookieServerOperation(usedRasUsername, this.Password, this); } else { serverOperation = new AuthenticateServerOperation( this.loginName, this.Password, true, true, this.languageKey, this); if (!string.IsNullOrEmpty(this.newPassword)) { ((AuthenticateServerOperation)serverOperation).ChangePasswordTo(this.newPassword); } } this.QueueServerOperationAtTopOfTheQueue(serverOperation); } }
/// <summary> /// The Authentication server operation did finish. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="json"> /// The json. /// </param> public void AuthenticateServerOperationDidFinish(AuthenticateServerOperation operation, Dictionary <string, object> json) { if (json == null) { return; } var passwordChanged = json.ContainsKey("passwordChanged") ? (bool?)json["passwordChanged"] : null; PasswordChangeResult passwordChangeResult; if (!string.IsNullOrEmpty(this.newPassword)) { if (!passwordChanged.HasValue) { passwordChangeResult = PasswordChangeResult.PasswordChangeNotSupported; } else { passwordChangeResult = passwordChanged.Value ? PasswordChangeResult.PasswordChanged : PasswordChangeResult.PasswordNotChanged; } } else { passwordChangeResult = PasswordChangeResult.NoPasswordChangeRequested; } var statusInfo = json.ContainsKey("StatusInfo") ? (List <object>)json["StatusInfo"] : null; if (statusInfo != null && ((string)statusInfo[1]).Equals("Error")) { this.CleanUpFinishedServerOperation(); // var error = NSError.ErrorFromServerErrorResponse(statusInfo); this.Delegate?.ServerOperationManagerDidFailServerLogin( this, new Exception("ErrorFromServerErrorResponse"), passwordChangeResult); return; } List <ServerLanguage> availableServerLanguages = null; var serverInformation = (List <object>)json.ValueOrDefault("serverinfo"); var serverLanguageInformation = (List <object>)serverInformation?[2]; if (serverLanguageInformation != null) { availableServerLanguages = new List <ServerLanguage>(); foreach (List <object> lang in serverLanguageInformation) { availableServerLanguages.Add( new ServerLanguage( (string)lang[0], (string)lang[1], (int)lang[2], (int)lang[3], (string)lang[4])); } } Dictionary <string, object> sessionAttributeDictionary = null; var sessionInfo = (List <object>)json.ValueOrDefault("sessioninfo"); var serverUserDefaultLanguage = string.Empty; if (sessionInfo?.Count > 1) { if (sessionInfo[0] != null) { serverUserDefaultLanguage = (string)sessionInfo[0]; } var sessionInfoAttributes = (List <object>)sessionInfo[1]; sessionAttributeDictionary = this.AttributeDictionaryForSession( sessionInfoAttributes, serverUserDefaultLanguage); } if (sessionAttributeDictionary == null) { sessionAttributeDictionary = new Dictionary <string, object>(); } if (!string.IsNullOrEmpty(this.newPassword) && passwordChanged != null) { this.Password = this.newPassword; this.newPassword = null; } if (this.languageKey == null) { this.suspended = true; this.Delegate?.ServerOperationManagerRequiresLanguageForSession( this, availableServerLanguages, sessionAttributeDictionary, serverInformation, passwordChangeResult); } else { this.Delegate?.ServerOperationManagerDidPerformServerLogin( this, availableServerLanguages, sessionAttributeDictionary, serverInformation, passwordChangeResult); } }