/// <summary> /// Refreshes the linked children. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> private bool RefreshLinkedChildren(IEnumerable <FileSystemInfo> fileSystemChildren) { var currentManualLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Manual).ToList(); var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList(); var newShortcutLinks = fileSystemChildren .Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory && FileSystem.IsShortcut(i.FullName)) .Select(i => { try { Logger.Debug("Found shortcut at {0}", i.FullName); var resolvedPath = FileSystem.ResolveShortcut(i.FullName); if (!string.IsNullOrEmpty(resolvedPath)) { return(new LinkedChild { Path = resolvedPath, Type = LinkedChildType.Shortcut }); } Logger.Error("Error resolving shortcut {0}", i.FullName); return(null); } catch (IOException ex) { Logger.ErrorException("Error resolving shortcut {0}", ex, i.FullName); return(null); } }) .Where(i => i != null) .ToList(); if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer())) { Logger.Info("Shortcut links have changed for {0}", Path); newShortcutLinks.AddRange(currentManualLinks); LinkedChildren = newShortcutLinks; return(true); } foreach (var child in LinkedChildren) { // Reset the cached value if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty) { child.ItemId = null; } } return(false); }
/// <summary> /// Refreshes the linked children. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> private bool RefreshLinkedChildren() { ItemResolveArgs resolveArgs; try { resolveArgs = ResolveArgs; if (!resolveArgs.IsDirectory) { return(false); } } catch (IOException ex) { Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path); return(false); } var currentManualLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Manual).ToList(); var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList(); var newShortcutLinks = resolveArgs.FileSystemChildren .Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory && FileSystem.IsShortcut(i.FullName)) .Select(i => { try { Logger.Debug("Found shortcut at {0}", i.FullName); return(new LinkedChild { Path = FileSystem.ResolveShortcut(i.FullName), Type = LinkedChildType.Shortcut }); } catch (IOException ex) { Logger.ErrorException("Error resolving shortcut {0}", ex, i.FullName); return(null); } }) .Where(i => i != null) .ToList(); if (!newShortcutLinks.SequenceEqual(currentShortcutLinks)) { Logger.Info("Shortcut links have changed for {0}", Path); newShortcutLinks.AddRange(currentManualLinks); LinkedChildren = newShortcutLinks; return(true); } return(false); }
public IEnumerable <BaseItem> GetLinkedChildren(User user) { if (!FilterLinkedChildrenPerUser || user == null) { return(GetLinkedChildren()); } if (LinkedChildren.Count == 0) { return(new List <BaseItem>()); } var allUserRootChildren = user.RootFolder.Children.OfType <Folder>().ToList(); var collectionFolderIds = allUserRootChildren .OfType <CollectionFolder>() .Where(i => i.IsVisible(user)) .Select(i => i.Id) .ToList(); return(LinkedChildren .Select(i => { var child = GetLinkedChild(i); if (child != null) { var childLocationType = child.LocationType; if (childLocationType == LocationType.Remote || childLocationType == LocationType.Virtual) { if (!child.IsVisibleStandalone(user)) { return null; } } else if (childLocationType == LocationType.FileSystem) { var itemCollectionFolderIds = LibraryManager.GetCollectionFolders(child, allUserRootChildren) .Select(f => f.Id).ToList(); if (!itemCollectionFolderIds.Any(collectionFolderIds.Contains)) { return null; } } } return child; }) .Where(i => i != null)); }
public IEnumerable <BaseItem> GetLinkedChildren(User user) { if (!FilterLinkedChildrenPerUser || user == null) { return(GetLinkedChildren()); } var locations = user.RootFolder .Children .OfType <CollectionFolder>() .Where(i => i.IsVisible(user)) .SelectMany(i => i.PhysicalLocations) .ToList(); return(LinkedChildren .Select(i => { var requiresPostFilter = true; if (!string.IsNullOrWhiteSpace(i.Path)) { requiresPostFilter = false; if (!locations.Any(l => FileSystem.ContainsSubPath(l, i.Path))) { return null; } } var child = GetLinkedChild(i); if (requiresPostFilter && child != null) { if (string.IsNullOrWhiteSpace(child.Path)) { Logger.Debug("Found LinkedChild with null path: {0}", child.Name); return child; } if (!locations.Any(l => FileSystem.ContainsSubPath(l, child.Path))) { return null; } } return child; }) .Where(i => i != null)); }
public IEnumerable <BaseItem> GetLinkedChildren(User user) { if (!FilterLinkedChildrenPerUser || user == null) { return(GetLinkedChildren()); } var locations = user.RootFolder .Children .OfType <CollectionFolder>() .Where(i => i.IsVisible(user)) .SelectMany(i => i.PhysicalLocations) .ToList(); return(LinkedChildren .Select(i => { var child = GetLinkedChild(i); if (child != null) { var childLocationType = child.LocationType; if (childLocationType == LocationType.Remote || childLocationType == LocationType.Virtual) { if (!child.IsVisibleStandalone(user)) { return null; } } else if (childLocationType == LocationType.FileSystem && !locations.Any(l => FileSystem.ContainsSubPath(l, child.Path))) { return null; } } return child; }) .Where(i => i != null)); }
/// <summary> /// Gets the linked children. /// </summary> /// <returns>IEnumerable{BaseItem}.</returns> public IEnumerable <Tuple <LinkedChild, BaseItem> > GetLinkedChildrenInfos() { return(LinkedChildren .Select(i => new Tuple <LinkedChild, BaseItem>(i, GetLinkedChild(i))) .Where(i => i.Item2 != null)); }
/// <summary> /// Gets the linked children. /// </summary> /// <returns>IEnumerable{BaseItem}.</returns> public IEnumerable <BaseItem> GetLinkedChildren() { return(LinkedChildren .Select(GetLinkedChild) .Where(i => i != null)); }
/// <summary> /// Refreshes the linked children. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> protected virtual bool RefreshLinkedChildren(IEnumerable <FileSystemMetadata> fileSystemChildren) { var currentManualLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Manual).ToList(); var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList(); List <LinkedChild> newShortcutLinks; if (SupportsShortcutChildren) { newShortcutLinks = fileSystemChildren .Where(i => !i.IsDirectory && FileSystem.IsShortcut(i.FullName)) .Select(i => { try { Logger.Debug("Found shortcut at {0}", i.FullName); var resolvedPath = FileSystem.ResolveShortcut(i.FullName); if (!string.IsNullOrEmpty(resolvedPath)) { return(new LinkedChild { Path = resolvedPath, Type = LinkedChildType.Shortcut }); } Logger.Error("Error resolving shortcut {0}", i.FullName); return(null); } catch (IOException ex) { Logger.ErrorException("Error resolving shortcut {0}", ex, i.FullName); return(null); } }) .Where(i => i != null) .ToList(); } else { newShortcutLinks = new List <LinkedChild>(); } if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer())) { Logger.Info("Shortcut links have changed for {0}", Path); newShortcutLinks.AddRange(currentManualLinks); LinkedChildren = newShortcutLinks; return(true); } foreach (var child in LinkedChildren) { // Reset the cached value child.ItemId = null; } return(false); }