Esempio n. 1
0
 private DiscSpace CreateDiscSpace(DiscSpaceManager manager, DiscSpace parent, String name, String fullname)
 {
     if (CreateNewDiscSpace != null)
     {
         return(CreateNewDiscSpace.Invoke(manager, parent, name, fullname));
     }
     return(new DiscSpace(manager, parent, name, fullname));
 }
Esempio n. 2
0
 public IInfoCache MapBack(DiscSpace space)
 {
     if (!mapping.ContainsValue(space))
     {
         return(null);
     }
     return(mapping.FirstOrDefault(x => x.Value == space).Key);
 }
Esempio n. 3
0
 private void UpdateCurrentAndAllParents(DiscSpace current)
 {
     Update(current);
     Updated?.Invoke(current);
     if (current.Parent != null)
     {
         UpdateCurrentAndAllParents(current.Parent);
     }
 }
Esempio n. 4
0
 public DiscSpace(DiscSpaceManager manager, DiscSpace parent, string name, string fullname)
 {
     this.Parent = parent;
     Name        = name;
     FullName    = fullname;
     Manager     = manager;
     Children    = new List <DiscSpace>();
     parent?.Children.Add(this);
     IsLoaded = false;
 }
Esempio n. 5
0
 private void AddLengthToAllParents(DiscSpace space, long length)
 {
     if (space == null)
     {
         return;
     }
     space.OrderedChildren = space.Children.OrderByDescending(x => x.Length).Where(x => x.Length >= space.Manager.MinimalLimit).ToList();
     space.Length         += length;
     if (!IsRoot(space))
     {
         AddLengthToAllParents(space.Parent, length);
     }
 }
Esempio n. 6
0
        private void RaiseCreatedForArgumentAndAllParentsIfNotAlreadyRaised(DiscSpace space)
        {
            var parent = space.Parent;

            if (!IsRoot(space))
            {
                RaiseCreatedForArgumentAndAllParentsIfNotAlreadyRaised(parent);;
            }

            if (!CreatedAlreadyRaised.Contains(space))
            {
                CreatedAlreadyRaised.Add(space);
                Created?.Invoke(space);
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
 private void Update(IInfoCache info, DiscSpace space)
 {
     space.Count = info.Count;
 }
Esempio n. 9
0
 private void Update(DiscSpace space)
 {
     Update(MapBack(space), space);
 }
Esempio n. 10
0
 public bool IsRoot(DiscSpace space)
 {
     return(space.Parent == null);
 }