public async Task <VercorsSmartView> UpdateSmartView(VercorsSmartView vercorsSmartView) { this.CheckCancellation(); try { vercorsSmartView.UserId = this.mobileService.CurrentUser.UserId; await this.mobileService.GetTable <VercorsSmartView>().UpdateAsync(vercorsSmartView); var result = await this.mobileService.GetTable <VercorsSmartView>().Where(t => t.Name == vercorsSmartView.Name).ToListAsync(); if (result.Count == 1) { return(result[0]); } else { return(null); } } catch (Exception e) { LogService.Log(LogSource, e.ToString()); return(null); } }
public async Task <bool> DeleteSmartView(VercorsSmartView vercorsSmartView) { this.CheckCancellation(); try { await this.mobileService.GetTable <VercorsSmartView>().DeleteAsync(vercorsSmartView); var result = await this.mobileService.GetTable <VercorsSmartView>().Where(t => t.Name == vercorsSmartView.Name).ToListAsync(); return(result.Count == 0); } catch (Exception e) { LogService.Log(LogSource, e.ToString()); return(false); } }
private async Task SmartViewSync() { // add new local smartViews in Vercors // use ToList() to have a copy of the list as each statement in the loop will change the collection foreach (var id in this.Metadata.AddedSmartViews.ToList()) { ISmartView smartView = this.Workbook.SmartViews.FirstOrDefault(c => c.Id == id); // we should never have a folder in the PendingAdded list that does not exist // but who knows... if (smartView != null) { this.OnSynchronizationProgressChanged(string.Format(StringResources.SyncProgress_AddingSmartViewFormat, smartView.Name)); VercorsSmartView vercorsSmartView = await this.service.AddSmartView(new VercorsSmartView(smartView)); if (vercorsSmartView != null) { smartView.SyncId = vercorsSmartView.Id; this.Changes.WebAdd++; } } this.Metadata.AddedSmartViews.Remove(id); } // remove deleted local smartViews from Vercors this.UpdateDeletedSmartViews(); foreach (var deletedEntry in this.Metadata.DeletedSmartViews.ToList()) { this.OnSynchronizationProgressChanged(StringResources.SyncProgress_DeletingSmartView); await this.service.DeleteSmartView(new VercorsSmartView { ItemId = deletedEntry.SyncId }); this.Changes.WebDelete++; this.Metadata.DeletedSmartViews.Remove(deletedEntry); } // is LastFolderEdit newer than the last sync if (this.account.SmartViewEditTimestamp > this.smartViewEditTimestamp) { this.OnSynchronizationProgressChanged(StringResources.SyncProgress_GettingSmartViews); // there are probably changes in Vercors we must perform in the workbook... // start by fetching smartViews var vercorsSmartViews = await this.service.GetSmartViews(); // does the server have smartViews we don't have ? this.EnsureWorkbookHasSmartView(vercorsSmartViews); // does the server misses smartViews that we have); foreach (var smartView in this.Workbook.SmartViews.ToList()) { var vercorsSmartView = vercorsSmartViews.FirstOrDefault(f => f.Id == smartView.SyncId); bool hasId = !string.IsNullOrWhiteSpace(smartView.SyncId); if (vercorsSmartView == null && hasId) { // this smartView is no longer in Vercors, delete it from the workbook this.DeleteSmartView(smartView.Name); this.Changes.LocalDelete++; } } foreach (var smartView in this.Workbook.SmartViews) { // does a smartView exist in both place var vercorsSmartView = vercorsSmartViews.FirstOrDefault(f => f.Id == smartView.SyncId); // if the name is not the same locally and in Vercors if (!this.Metadata.EditedSmartViews.Contains(smartView.Id) && vercorsSmartView != null && !smartView.Name.Equals(vercorsSmartView.Name, StringComparison.OrdinalIgnoreCase)) { // Vercors has the latest value try { vercorsSmartView.UpdateTarget(smartView); } catch (Exception ex) { LogService.Log("VercorsSync", $"Error while updating smart view: {ex}"); TrackingManagerHelper.Exception(ex, $"Error while updating smart view: {ex}"); } } } this.smartViewEditTimestamp = this.account.SmartViewEditTimestamp; } // do we need to edit smartViews foreach (var smartViewId in this.Metadata.EditedSmartViews.ToList()) { ISmartView smartView = this.Workbook.SmartViews.FirstOrDefault(c => c.Id == smartViewId); if (smartView != null) { this.OnSynchronizationProgressChanged(string.Format(StringResources.SyncProgress_UpdatingSmartViewFormat, smartView.Name)); await this.service.UpdateSmartView(new VercorsSmartView(smartView)); this.Changes.WebEdit++; this.Metadata.EditedSmartViews.Remove(smartViewId); } } }