protected virtual IEnumerable <LibraryHierarchyNode> GetNodesCore(LibraryHierarchy libraryHierarchy, string filter) { this.State |= LibraryHierarchyBrowserState.Loading; try { using (var database = this.DatabaseFactory.Create()) { using (var transaction = database.BeginTransaction(database.PreferredIsolationLevel)) { var nodes = database.ExecuteEnumerator <LibraryHierarchyNode>(database.Queries.GetLibraryHierarchyNodes(filter), (parameters, phase) => { switch (phase) { case DatabaseParameterPhase.Fetch: parameters["libraryHierarchyId"] = libraryHierarchy.Id; break; } }, transaction); foreach (var node in nodes) { node.InitializeComponent(this.Core); yield return(node); } } } } finally { this.State &= ~LibraryHierarchyBrowserState.Loading; } }
public async Task <int> Write(LibraryHierarchy libraryHierarchy, int libraryItemId, int?parentId, string value, bool isLeaf) { var libraryHierarchyItemId = default(int); if (!isLeaf && this.Store.TryGetValue(libraryHierarchy.Id, parentId, value, out libraryHierarchyItemId)) { this.UpdateCommand.Parameters["libraryHierarchyItemId"] = libraryHierarchyItemId; this.UpdateCommand.Parameters["libraryItemId"] = libraryItemId; await this.UpdateCommand.ExecuteNonQueryAsync().ConfigureAwait(false); } else { this.AddCommand.Parameters["libraryHierarchyId"] = libraryHierarchy.Id; this.AddCommand.Parameters["libraryItemId"] = libraryItemId; this.AddCommand.Parameters["parentId"] = parentId; this.AddCommand.Parameters["value"] = value; this.AddCommand.Parameters["isLeaf"] = isLeaf; if (isLeaf) { await this.AddCommand.ExecuteNonQueryAsync().ConfigureAwait(false); } else { this.Store.Add( libraryHierarchy.Id, parentId, value, libraryHierarchyItemId = Converter.ChangeType <int>(await this.AddCommand.ExecuteScalarAsync().ConfigureAwait(false)) ); } } return(libraryHierarchyItemId); }
public LibraryHierarchyNode GetNode(LibraryHierarchy libraryHierarchy, LibraryHierarchyNode libraryHierarchyNode) { var libraryHierarchyNodes = new List <LibraryHierarchyNode>() { libraryHierarchyNode }; while (libraryHierarchyNode.Parent != null) { libraryHierarchyNodes.Insert(0, libraryHierarchyNode.Parent); libraryHierarchyNode = libraryHierarchyNode.Parent; } for (var a = 0; a < libraryHierarchyNodes.Count; a++) { if (a == 0) { libraryHierarchyNodes[a] = this.GetNodes(libraryHierarchy).Find(libraryHierarchyNodes[a]); } else { libraryHierarchyNodes[a] = this.GetNodes(libraryHierarchyNodes[a - 1]).Find(libraryHierarchyNodes[a]); } libraryHierarchyNode = libraryHierarchyNodes[a]; if (libraryHierarchyNode == null) { //A node failed to refresh, cannot continue as we don't know what the new parent is. return(null); } } return(libraryHierarchyNode); }
public IEnumerable <LibraryHierarchyNode> GetNodes(LibraryHierarchy libraryHierarchy) { var key = new LibraryHierarchyCacheKey(libraryHierarchy, this.Filter); var nodes = this.LibraryHierarchyCache.GetNodes(key, () => this.GetNodesCore(libraryHierarchy)); if (this.LibraryManager.SelectedItem != null) { this.ApplySelection(nodes); } return(nodes); }
private Task <int> Populate(LibraryItem libraryItem, LibraryHierarchy libraryHierarchy, LibraryHierarchyLevel libraryHierarchyLevel, int?parentId, bool isLeaf) { var runner = new LibraryItemScriptRunner( this.GetOrAddContext(), libraryItem, libraryHierarchyLevel.Script ); runner.Prepare(); var value = Convert.ToString(runner.Run()); return(this.Populate(libraryItem, libraryHierarchy, value, parentId, isLeaf)); }
private async Task <int> Populate(LibraryItem libraryItem, LibraryHierarchy libraryHierarchy, string value, int?parentId, bool isLeaf) { #if NET40 this.Semaphore.Wait(); #else await this.Semaphore.WaitAsync().ConfigureAwait(false); #endif try { return(await this.Writer.Write(libraryHierarchy, libraryItem.Id, parentId, value, isLeaf).ConfigureAwait(false)); } finally { this.Semaphore.Release(); } }
private void AssertLibraryHierarchy(LibraryHierarchy hierarchy, IEnumerable <LibraryHierarchyNode> nodes, string[] fileNames) { var selector = default(Func <LibraryHierarchyNode, IEnumerable <LibraryHierarchyNode> >); selector = node => { if (node.IsLeaf) { return(new[] { node }); } node.IsExpanded = true; return(node.Children.SelectMany(selector)); }; var leaves = nodes.SelectMany(selector); Assert.AreEqual(fileNames.Count(), leaves.Count()); }
public static Task RemoveHierarchies(IDatabaseComponent database, LibraryHierarchy libraryHierarchy, LibraryItemStatus?status, ITransactionSource transaction) { return(database.ExecuteAsync(database.Queries.RemoveLibraryHierarchyItems, (parameters, phase) => { switch (phase) { case DatabaseParameterPhase.Fetch: if (libraryHierarchy != null) { parameters["libraryHierarchyId"] = libraryHierarchy.Id; } if (status.HasValue) { parameters["status"] = status; } break; } }, transaction)); }
protected virtual void RefreshSelectedItem(LibraryHierarchy libraryHierarchy) { if (this._SelectedItem == null) { return; } var selectedItem = default(LibraryHierarchyNode); if (!this._SelectedItem.TryGetValue(libraryHierarchy, out selectedItem)) { return; } if (selectedItem != null) { selectedItem = this.HierarchyBrowser.GetNode(libraryHierarchy, selectedItem); if (selectedItem != null) { Logger.Write(this, LogLevel.Debug, "Refreshed selected item: {0} => {1}", selectedItem.Id, selectedItem.Value); } else { Logger.Write(this, LogLevel.Debug, "Failed to refresh selected item, it was removed."); } } if (selectedItem == null) { selectedItem = this.HierarchyBrowser.GetNodes(libraryHierarchy).FirstOrDefault(); if (selectedItem != null) { Logger.Write(this, LogLevel.Debug, "Selected first item: {0} => {1}", selectedItem.Id, selectedItem.Value); } else { Logger.Write(this, LogLevel.Warn, "Failed to select an item, perhaps none are available?"); } } if (object.ReferenceEquals(this._SelectedItem[libraryHierarchy], selectedItem)) { return; } this._SelectedItem[libraryHierarchy] = selectedItem; }
private async Task Populate(LibraryItem libraryItem, LibraryHierarchy libraryHierarchy, LibraryHierarchyLevel[] libraryHierarchyLevels) { var parentId = default(int?); switch (libraryHierarchy.Type) { case LibraryHierarchyType.Script: for (int a = 0, b = libraryHierarchyLevels.Length - 1; a <= b; a++) { parentId = await this.Populate(libraryItem, libraryHierarchy, libraryHierarchyLevels[a], parentId, a == b); } break; case LibraryHierarchyType.FileSystem: var pathSegments = this.GetPathSegments(libraryItem.FileName); for (int a = 0, b = pathSegments.Length - 1; a <= b; a++) { parentId = await this.Populate(libraryItem, libraryHierarchy, pathSegments[a], parentId, a == b); } break; } }
public LibraryHierarchyNode[] GetNodes(LibraryHierarchy libraryHierarchy, string filter) { var key = new LibraryHierarchyCacheKey(libraryHierarchy, null, filter); return(this.LibraryHierarchyCache.GetNodes(key, () => this.GetNodesCore(libraryHierarchy, filter))); }
public LibraryHierarchyNode[] GetNodes(LibraryHierarchy libraryHierarchy) { return(this.GetNodes(libraryHierarchy, this.Filter)); }
private IEnumerable <LibraryHierarchyNode> GetNodesCore(LibraryHierarchy libraryHierarchy) { return(this.GetNodes(libraryHierarchy.Id)); }