Exemplo n.º 1
0
 public DiscSpace Map(IInfoCache info)
 {
     if (info == null || !mapping.ContainsKey(info))
     {
         return(null);
     }
     return(mapping[info]);
 }
Exemplo n.º 2
0
        public DirectoryCache(DirectoryInfo directoryInfo, DirectoryCache parent)
        {
            this.Info   = directoryInfo;
            this.parent = parent;
            if (parent == null)
            {
                return;
            }

            parent?.directories.Add(this);
        }
Exemplo n.º 3
0
 private void RaiseLoadedEvent(IInfoCache cache)
 {
     if (_uiContext == null)
     {
         Loaded?.Invoke(cache);
     }
     else
     {
         _uiContext.Send(x => Loaded?.Invoke(cache), null);
     }
 }
Exemplo n.º 4
0
 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));
         }
     }
 }
Exemplo n.º 5
0
        /// <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);
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
 private void Update(IInfoCache info, DiscSpace space)
 {
     space.Count = info.Count;
 }
Exemplo n.º 8
0
 private void DiscCache_Created(IInfoCache element)
 {
     CreatedEvents.Add(element);
 }