public void Initialize() { this.workbook = new Workbook(new TestDatabaseContext(), new TestSettings()); this.folder = this.workbook.AddFolder("f1"); this.context = this.workbook.AddContext("@context"); this.smartview = this.workbook.AddSmartView("SV1", "(Priority is Low)"); }
private static void AddSmartView(ISmartView obj) { foreach (ExtendedPropertyDefinition propDef in obj.SupportedProperties) { smartViews.Add(propDef, obj); } }
public void AddSmartView(ISmartView view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } var target = this.smartViews.FirstOrDefault(t => t.Id == view.Id); if (target != null) { return; } this.objectTracker.EnsureIsTracked(view); if (this.preventDuplicates) { target = this.connection.Table <SmartView>().FirstOrDefault(i => i.Id == view.Id); } if (target == null) { this.connection.Insert(view); } this.smartViews.Add(view); }
public SmartView(IWorkbook workbook, ISmartView view) : base(workbook, view, view.Name) { this.smartviewOwner = view; this.rules = view.Rules; this.handler = SmartViewHandler.FromString(this.rules); this.Ready(); }
public void AddSmartView(ISmartView view) { if (view.Id == 0) { view.Id = smartviewId++; } this.smartViews.Add(view); }
public void RemoveSmartView(ISmartView view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } this.Delete(view); this.smartViews.Remove(view); }
public EditSmartViewViewModel(ISmartView smartView, IWorkbook workbook, INavigationService navigationService, IMessageBoxService messageBoxService, ITrackingManager trackingManager) : base(workbook, navigationService, messageBoxService, trackingManager) { this.smartView = smartView; this.Name = smartView.Name; this.RuleContent = smartView.Rules; this.LoadStringAsync(smartView.Rules); }
private void StartTrackingSmartView(ISmartView smartview) { if (this.trackedSmartViews.Contains(smartview)) { return; } smartview.PropertyChanged += this.OnSmartViewPropertyChanged; this.trackedSmartViews.Add(smartview); }
public void UpdateTarget(ISmartView smartView) { if (smartView == null) { throw new ArgumentNullException("context"); } smartView.SyncId = this.Id; smartView.Name = this.Name; smartView.Order = this.Order; smartView.Rules = this.Rules; }
public void SmartViewEdited(ISmartView smartview) { if (this.ShouldIgnoreSmartView(smartview.Name)) { return; } if (!this.EditedSmartViews.Contains(smartview.Id) && !this.AddedSmartViews.Contains(smartview.Id)) { this.EditedSmartViews.Add(smartview.Id); } }
public VercorsSmartView(ISmartView smartView) { if (smartView == null) { throw new ArgumentNullException("context"); } this.ItemId = smartView.SyncId; this.Name = smartView.Name; this.Order = smartView.Order; this.Rules = smartView.Rules; }
public void SmartViewRemoved(ISmartView smartview) { if (this.ShouldIgnoreSmartView(smartview.Name)) { return; } if (this.AddedSmartViews.Contains(smartview.Id)) { // smartview has been added then deleted this.AddedSmartViews.Remove(smartview.Id); this.EditedSmartViews.Remove(smartview.Id); } else { this.DeletedSmartViews.Add(new DeletedEntry(smartview.Id, smartview.SyncId)); } }
public static string GetSmartView(ServiceObject owner, PropertyDefinitionBase propDef) { ExtendedPropertyDefinition exPropDef = propDef as ExtendedPropertyDefinition; if (exPropDef != null) { object value = null; if (owner.TryGetProperty(propDef, out value)) { // See if we have any SmartViews for this property. if (value != null) { ISmartView smartView = SmartViewFinder.GetSmartView(exPropDef); if (smartView != null) { return(smartView.GetSmartView(value)); } } } } return(string.Empty); }
public void RemoveSmartView(ISmartView view) { this.smartViews.Remove(view); }
protected void RemoveSmartView(ISmartView SmartView) { this.Workbook.RemoveSmartView(SmartView.Name); }
public void AddSmartView(ISmartView view) { this.smartViews.Add(view); }
public async Task <bool> AdvancedSync() { if (this.synchronizationManager.ActiveProvider == null) { return(false); } var provider = this.synchronizationManager.ActiveProvider; // try to keep color and icon if current provider do not support syncing them bool colorSupported = (provider.SupportedFeatures & SyncFeatures.Colors) == SyncFeatures.Colors; bool iconSupported = (provider.SupportedFeatures & SyncFeatures.Icons) == SyncFeatures.Icons; bool contextSupported = (provider.SupportedFeatures & SyncFeatures.Context) == SyncFeatures.Context; bool smartViewSupported = (provider.SupportedFeatures & SyncFeatures.SmartView) == SyncFeatures.SmartView; // key is the folder name, value is the item kept (color code or icon id) var colorMap = new Dictionary <string, string>(); var iconMap = new Dictionary <string, int>(); var orderMap = new Dictionary <string, int>(); var smartviewMap = new Dictionary <string, FolderBaseEntry>(); var contextMap = new Dictionary <string, FolderBaseEntry>(); foreach (var folder in this.workbook.Folders) { if (!colorSupported && !colorMap.ContainsKey(folder.Name)) { colorMap.Add(folder.Name, folder.Color); } if (!iconSupported && !iconMap.ContainsKey(folder.Name)) { iconMap.Add(folder.Name, folder.IconId); } if (!iconSupported && !orderMap.ContainsKey(folder.Name)) { orderMap.Add(folder.Name, folder.Order); } } if (!contextSupported) { foreach (var task in this.Workbook.Tasks) { if (task.Context != null) { string key = this.GetTaskKey(task); if (!contextMap.ContainsKey(key)) { contextMap.Add(key, new FolderBaseEntry(task.Context)); } } } } if (!smartViewSupported) { foreach (var smartView in this.Workbook.SmartViews) { if (!smartviewMap.ContainsKey(smartView.Name)) { smartviewMap.Add(smartView.Name, new FolderBaseEntry(smartView, smartView.Rules)); } } } bool result = await this.AdvancedSyncCore(); foreach (var kvp in colorMap) { var folder = this.workbook.Folders.FirstOrDefault(f => f.Name.Equals(kvp.Key, StringComparison.OrdinalIgnoreCase)); if (folder != null) { folder.Color = kvp.Value; } } foreach (var kvp in iconMap) { var folder = this.workbook.Folders.FirstOrDefault(f => f.Name.Equals(kvp.Key, StringComparison.OrdinalIgnoreCase)); if (folder != null) { folder.IconId = kvp.Value; } } foreach (var kvp in orderMap) { var folder = this.workbook.Folders.FirstOrDefault(f => f.Name.Equals(kvp.Key, StringComparison.OrdinalIgnoreCase)); if (folder != null) { folder.Order = kvp.Value; } } if (orderMap.Count > 0) { this.workbook.ApplyFolderOrder(this.workbook.Folders.OrderBy(f => f.Order).ToList()); } foreach (var kvp in contextMap) { string key = kvp.Key; FolderBaseEntry folderEntry = kvp.Value; ITask task = this.Workbook.Tasks.FirstOrDefault(t => this.GetTaskKey(t) == key); if (task != null) { IContext context = this.workbook.Contexts.FirstOrDefault(c => c.Name.Equals(folderEntry.Name, StringComparison.OrdinalIgnoreCase)); if (context == null) { context = this.workbook.AddContext(folderEntry.Name); context.GroupAscending = folderEntry.GroupAscending; context.TaskGroup = folderEntry.Group; } if (context != null) { task.Context = context; } } } foreach (var kvp in smartviewMap) { FolderBaseEntry folderEntry = kvp.Value; ISmartView smartview = this.workbook.SmartViews.FirstOrDefault(t => t.Name.Equals(kvp.Key, StringComparison.OrdinalIgnoreCase)); if (smartview == null && !string.IsNullOrEmpty(folderEntry.Parameter)) { smartview = this.workbook.AddSmartView(kvp.Key, folderEntry.Parameter); smartview.GroupAscending = folderEntry.GroupAscending; smartview.TaskGroup = folderEntry.Group; } } return(result); }
protected void StopTrackingSmartView(ISmartView smartview) { smartview.PropertyChanged -= this.OnSmartViewPropertyChanged; this.trackedSmartViews.Remove(smartview); }
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); } } }