public DiscSpace Map(IInfoCache info) { if (info == null || !mapping.ContainsKey(info)) { return(null); } return(mapping[info]); }
public DirectoryCache(DirectoryInfo directoryInfo, DirectoryCache parent) { this.Info = directoryInfo; this.parent = parent; if (parent == null) { return; } parent?.directories.Add(this); }
private void RaiseLoadedEvent(IInfoCache cache) { if (_uiContext == null) { Loaded?.Invoke(cache); } else { _uiContext.Send(x => Loaded?.Invoke(cache), null); } }
private void DiscCache_Loaded(IInfoCache element) { if (!element.IsRoot) { Assert.IsNotNull(element.Parent); if (element is DirectoryCache) { Assert.IsTrue(((DirectoryCache)element.Parent).directories.Contains(element)); } else { Assert.IsTrue(((DirectoryCache)element.Parent).files.Contains(element)); } } }
/// <summary> /// A new cache info is added to the disc space manager. /// This results in a new disc space, if a new info is given ans the info is not under the minimal limit. /// The manager updates all the parent disc spaces. /// </summary> /// <param name="info"></param> /// <param name="forceCreation"> if this parameter is set to true, the mimimal limit is virtually set to 0.</param> public void Create(IInfoCache info) { var parentSpace = Map(info.Parent); var space = CreateDiscSpace(this, parentSpace, info.Name, info.FullName); mapping[info] = space; if (info is FileCache) { space.OwnLength = info.Length; space.Length = space.OwnLength; AddLengthToAllParents(parentSpace, space.OwnLength); } if (info.Parent == null) { Root = space; } if (space.Length >= MinimalLimit) { RaiseCreatedForArgumentAndAllParentsIfNotAlreadyRaised(space); } }
public void Load(IInfoCache info) { var space = Map(info); Update(info, space); space.IsLoaded = true; if (info is DirectoryCache) { var smallChildren = space.Children.Where(x => x.Length < MinimalLimit).ToList(); smallChildren.ForEach(x => mapping.Remove(MapBack(x))); space.OwnLength = smallChildren.Sum(x => x.Length); space.Children = space.Children.Where(x => x.Length >= MinimalLimit).ToList(); space.ChildrenLength = space.Children.Sum(x => x.Length); } if (space.Length >= MinimalLimit) { RaiseCreatedForArgumentAndAllParentsIfNotAlreadyRaised(space); Loaded?.Invoke(space); } }
private void Update(IInfoCache info, DiscSpace space) { space.Count = info.Count; }
private void DiscCache_Created(IInfoCache element) { CreatedEvents.Add(element); }