public override async Task <bool> CheckLoginAsync() { ExchangeInfoBuild check = this.BuildExchangeConnectionInfo(); if (check.IsValid) { try { Uri originalServerUri = check.ConnectionInfo.ServerUri; var authResult = await this.SyncService.LoginAsync(check.ConnectionInfo); if (authResult.IsOperationSuccess && authResult.AuthorizationStatus == ExchangeAuthorizationStatus.OK) { // update the server uri as it might have changed this.UpdateSettingsAfterSync(check.ConnectionInfo, authResult.ServerUri.ToString()); return(true); } else { // if if the auth result is not a succes, we might update server uri if (originalServerUri == null && check.ConnectionInfo.ServerUri != null) { this.UpdateSettingsAfterSync(check.ConnectionInfo, authResult.ServerUri.ToString()); } // if the status is "autodisover not found" but we have a server uri, that means credentials are invalid var authorizationStatus = authResult.AuthorizationStatus; if (authorizationStatus == ExchangeAuthorizationStatus.AutodiscoveryServiceNotFound && check.ConnectionInfo.ServerUri != null) { authorizationStatus = ExchangeAuthorizationStatus.UserCredentialsInvalid; } string message = authorizationStatus.ToReadableString(); if (!string.IsNullOrWhiteSpace(authResult.ErrorMessage)) { message += string.Format(",{0}", authResult.ErrorMessage); } this.Manager.TrackEvent("Login failed " + this.Service, message); this.OnSynchronizationFailed(string.Format(ExchangeResources.Exchange_SyncErrorFormat, message)); return(false); } } catch (Exception e) { this.Manager.TrackEvent("Login failed " + this.Service, e.Message); this.OnSynchronizationFailed(string.Format(ExchangeResources.Exchange_ExceptionFormat, e.Message)); return(false); } } else { return(false); } }
private async Task NormalSync(ExchangeInfoBuild exchangeInfo) { this.OnSynchronizationProgressChanged(StringResources.SyncProgress_GettingTasks); var changeSet = this.BuildChangeSetFromMetadata(); var result = await this.SyncService.ExecuteSyncAsync(exchangeInfo.ConnectionInfo, changeSet, this.SyncState, this.FolderId); this.OnSynchronizationProgressChanged(StringResources.SyncProgress_UpdatingTasks); this.ProcessSyncResult(changeSet, result); }
private async Task FirstSync(ExchangeInfoBuild exchangeInfo) { this.OnSynchronizationProgressChanged(StringResources.SyncProgress_SyncInProgress); var changeSet = new ExchangeChangeSet(); // start by sending an empty change set to get all existing task on the service LogService.LogFormat("ExchangeSync", "Performing first sync, step 1, sending empty changeset"); var result = await this.SyncService.ExecuteFirstSyncAsync(exchangeInfo.ConnectionInfo, changeSet); var completedTasks = result.ChangeSet.AddedTasks.Where(t => t.Completed.HasValue).ToList(); if (completedTasks.Count > 100) { // takes only 100 completed tasks, prevent bringing more in 2Day to prevent weird issue like having 3k tasks in the app var tasks = new List <ExchangeTask>(); tasks.AddRange(result.ChangeSet.AddedTasks.Where(t => !t.Completed.HasValue)); // add all non completed tasks tasks.AddRange(result.ChangeSet.AddedTasks.Where(t => t.Completed.HasValue).Take(100)); // add first 100 completed tasks result.ChangeSet.AddedTasks.Clear(); result.ChangeSet.AddedTasks.AddRange(tasks); } this.ProcessSyncResult(changeSet, result, sendCompletedNotification: false); this.OnSynchronizationProgressChanged(StringResources.SyncProgress_UpdatingTasks); // send a changeset for all tasks that does not have a sync id changeSet.AddedTasks.AddRange(this.Workbook.Tasks.Where(t => !t.IsCompleted && string.IsNullOrEmpty(t.SyncId)).Select(t => t.ToExchangeTask(setCategory: true, properties: TaskProperties.All))); LogService.LogFormat("ExchangeSync", "Performing first sync, step 2, sending changeset with {0} added tasks", changeSet.AddedTasks.Count); if (changeSet.AddedTasks.Count > 0) { result = await this.SyncService.ExecuteFirstSyncAsync(exchangeInfo.ConnectionInfo, changeSet); this.ProcessSyncResult(changeSet, result); } else { this.OnSynchronizationCompleted("Exchange"); } this.FolderId = this.SyncService.TaskFolderId; }