/// <summary> /// Loads the tree. /// </summary> /// <returns>Task.</returns> private async Task LoadTree() { tvwLibrary.Items.Clear(); lblLoading.Visibility = Visibility.Visible; //grab UI context so we can update within the below task var ui = TaskScheduler.FromCurrentSynchronizationContext(); //this whole async thing doesn't really work in this instance since all my work pretty much needs to be on the UI thread... Cursor = Cursors.Wait; await Task.Run(() => { IEnumerable <BaseItem> children = CurrentUser.Name == "Physical" ? _libraryManager.RootFolder.Children : _libraryManager.RootFolder.GetChildren(CurrentUser, true); children = OrderByName(children, CurrentUser); foreach (Folder folder in children) { var currentFolder = folder; Task.Factory.StartNew(() => { var prefs = ddlProfile.SelectedItem != null ? _displayPreferencesManager.GetDisplayPreferences(currentFolder.DisplayPreferencesId, (ddlProfile.SelectedItem as User).Id, "LibraryExplorer") ?? new DisplayPreferences { SortBy = ItemSortBy.SortName } : new DisplayPreferences { SortBy = ItemSortBy.SortName }; var node = new TreeViewItem { Tag = currentFolder }; var subChildren = currentFolder.GetChildren(CurrentUser, true, prefs.IndexBy); subChildren = OrderByName(subChildren, CurrentUser); AddChildren(node, subChildren, CurrentUser); node.Header = currentFolder.Name + " (" + node.Items.Count + ")"; tvwLibrary.Items.Add(node); }, CancellationToken.None, TaskCreationOptions.None, ui); } }); lblLoading.Visibility = Visibility.Hidden; Cursor = Cursors.Arrow; }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> public object Get(GetDisplayPreferences request) { Guid displayPreferencesId; if (!Guid.TryParse(request.Id, out displayPreferencesId)) { displayPreferencesId = request.Id.GetMD5(); } var result = _displayPreferencesManager.GetDisplayPreferences(displayPreferencesId, request.UserId, request.Client); return(ToOptimizedSerializedResultUsingCache(result)); }
/// <summary> /// Adds the children. /// </summary> /// <param name="parent">The parent.</param> /// <param name="children">The children.</param> /// <param name="user">The user.</param> private void AddChildren(TreeNode parent, IEnumerable <BaseItem> children, User user, bool isPhysical) { foreach (var item in children) { var node = new TreeNode { Tag = item }; var subFolder = item as Folder; if (subFolder != null) { var prefs = _displayPreferencesManager.GetDisplayPreferences(subFolder.DisplayPreferencesId, user.Id, "LibraryExplorer"); var subChildren = isPhysical ? subFolder.Children : subFolder.GetChildren(_currentUser, true); AddChildren(node, OrderBy(subChildren, user, prefs.SortBy), user, isPhysical); node.Text = item.Name + " (" + node.Nodes.Count + ")"; } else { node.Text = item.Name; } parent.Nodes.Add(node); } }
/// <summary> /// Gets the specified request. /// </summary> /// <param name="request">The request.</param> public object Get(GetDisplayPreferences request) { var result = _displayPreferencesManager.GetDisplayPreferences(request.Id, request.UserId, request.Client); return(ToOptimizedResult(result)); }