public async Task <VercorsAccount> AddUserAccount(VercorsAccount vercorsAccount) { this.CheckCancellation(); await this.mobileService.GetTable <VercorsAccount>().InsertAsync(vercorsAccount); var result = await this.mobileService.GetTable <VercorsAccount>().ToListAsync(); if (result.Count == 1) { return(result[0]); } else { return(null); } }
public override async Task <bool> SyncAsync() { this.OnSynchronizationProgressChanged(StringResources.SyncProgress_SyncInProgress); bool result = true; Exception exception = null; if (string.IsNullOrEmpty(this.service.LoginInfo) || this.service.LoginInfo == Constants.DefaultLoginInfo) { try { result = await this.service.LoginAsync(this.Manager.IsBackground); } catch (Exception e) { exception = e; result = false; } } if (!result) { string message = VercorsResources.Vercors_UnableToLogin; if (exception != null) { message += string.Format(" ({0})", exception); } this.OnSynchronizationFailed(message); return(false); } this.account = await this.service.GetUserAccount(); this.Changes.Reset(); if (this.account == null) { this.account = await this.service.AddUserAccount(new VercorsAccount()); } if (this.Metadata.LastSync == DateTime.MinValue) { await this.FirstFolderSync(); await this.FirstContextSync(); await this.FirstSmartViewSync(); await this.FirstTasksSync(); } else { await this.FolderSync(); await this.ContextSync(); await this.SmartViewSync(); await this.TasksSync(); } // If there was any update during sync, // get the last timestamp from Vercors to avoid re-syncing tasks next time if (this.Changes.WebAdd > 0 || this.Changes.WebEdit > 0 || this.Changes.WebDelete > 0) { this.account = await this.service.GetUserAccount(); if (this.account != null) { this.taskEditTimestamp = this.account.TaskEditTimestamp; this.taskDeleteTimestamp = this.account.TaskDeleteTimestamp; this.folderEditTimestamp = this.account.FolderEditTimestamp; this.contextEditTimestamp = this.account.ContextEditTimestamp; } } this.OnSynchronizationCompleted(this.Name); return(true); }