예제 #1
0
        private List <dtoFolderSize> GetFolderAvailabilityInfo(dtoFolderSize repository, dtoFolderSize father, dtoDisplayRepositoryItem folder, List <liteRepositoryItem> items)
        {
            List <dtoFolderSize> folders = new List <dtoFolderSize>();
            dtoFolderSize        rFolder = new dtoFolderSize()
            {
                IdFolder = folder.Id, Name = folder.Name, IdentifierPath = folder.IdentifierPath, FolderType = folder.FolderType
            };

            switch (folder.FolderType)
            {
            case FolderType.recycleBin:
                SetRecycleBinInfo(rFolder, folder, items);
                break;

            case FolderType.standard:
                SetStandardFolderInfo(rFolder, folder, items);
                break;
            }

            if (rFolder.Items.Any())
            {
                rFolder.Size = rFolder.Items.Select(i => i.Size).Sum();
            }

            rFolder.Quota           = dtoContainerQuota.Create(father.Quota, rFolder.Size);
            rFolder.UploadAvailable = (rFolder.FolderType == FolderType.standard) && (rFolder.Quota.AvailableSize == -1 || rFolder.FreeSpace > 0);

            switch (rFolder.FolderType)
            {
            case FolderType.standard:
            case FolderType.recycleBin:
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = 0, Type = FolderSizeItemType.fullSize, Size = rFolder.Size
                });
                break;
            }
            rFolder.SetPercentage();


            switch (folder.FolderType)
            {
            case FolderType.recycleBin:
                break;

            case FolderType.standard:
                foreach (dtoDisplayRepositoryItem child in folder.Children.Where(f => f.Type == ItemType.Folder && f.Deleted == BaseStatusDeleted.None))
                {
                    folders.AddRange(GetFolderAvailabilityInfo(repository, rFolder, child, items));
                }
                break;
            }
            folders.Insert(0, rFolder);
            return(folders);
        }
예제 #2
0
        private dtoFolderSize GetRepositoryAvailabilityInfo(String filePath, DiskSettings diskSettings, List <liteRepositoryItem> items, IEnumerable <dtoDisplayRepositoryItem> allItems)
        {
            dtoFolderSize rFolder = new dtoFolderSize()
            {
                FolderType = FolderType.none, IdFolder = 0
            };
            long viewSize     = 0;
            long usedSize     = 0;
            long versionSize  = 0;
            long deletedSize  = 0;
            long childrenSize = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.IsUserAvailable && i.Type == ItemType.Folder).Select(i => i.Size).DefaultIfEmpty().Sum();

            if (items.Any(i => i.Type != ItemType.Folder && i.Type != ItemType.Link))
            {
                usedSize = items.Where(i => i.Type != ItemType.Folder && i.Type != ItemType.Link).Select(i => i.Size + i.VersionsSize).Sum();
            }
            if (allItems.Any(i => i.Deleted == BaseStatusDeleted.None && i.IsUserAvailable && i.Type != ItemType.Folder && i.Type != ItemType.Link))
            {
                viewSize = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.IsUserAvailable && i.Type != ItemType.Folder && i.Type != ItemType.Link).Select(i => i.Size).Sum();
            }

            rFolder.Items.Add(new FolderSizeItem()
            {
                Number = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.IsUserAvailable && i.Type == ItemType.Folder).Count(), Type = FolderSizeItemType.folder
            });
            rFolder.Items.Add(new FolderSizeItem()
            {
                Number = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.Type != ItemType.Folder && i.Type != ItemType.Link).Count(), Type = FolderSizeItemType.file, Size = viewSize
            });
            viewSize += childrenSize;
            if (allItems.Any(i => i.Deleted == BaseStatusDeleted.None && i.Type == ItemType.Link))
            {
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.Type == ItemType.Link).Count(), Type = FolderSizeItemType.link
                });
            }

            if (allItems.Any(i => i.Deleted != BaseStatusDeleted.None))
            {
                deletedSize = allItems.Where(i => i.Deleted == BaseStatusDeleted.Manual).Select(i => i.Size + i.VersionsSize).Sum();
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = allItems.Where(i => i.Deleted != BaseStatusDeleted.None).Count(),
                    Type   = FolderSizeItemType.deleted,
                    Size   = deletedSize
                });
            }
            if (allItems.Any(i => i.Deleted == BaseStatusDeleted.None && i.HasVersions))
            {
                versionSize = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.Type != ItemType.Folder && i.HasVersions).Select(i => i.VersionsSize).Sum();
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = allItems.Where(i => i.Deleted == BaseStatusDeleted.None && i.Type != ItemType.Folder && i.HasVersions).Count(),
                    Type   = FolderSizeItemType.version,
                    Size   = versionSize
                });
            }
            if ((viewSize + versionSize + deletedSize) < usedSize)
            {
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = items.Where(i => !allItems.Any(it => it.Id == i.Id)).Count(), Type = FolderSizeItemType.unavailableItems, Size = usedSize - (viewSize + versionSize + deletedSize)
                });
            }

            if (rFolder.Items.Any())
            {
                rFolder.Size = rFolder.Items.Select(i => i.Size).DefaultIfEmpty(0).Sum();
            }

            rFolder.Quota = CalculateRepositoryMaxSize(filePath, diskSettings, IsValidAdministrator(UC.CurrentUserID), rFolder.Size);

            rFolder.UploadAvailable = (rFolder.Quota.AvailableSize == -1 || rFolder.FreeSpace > 0);
            if (rFolder.OverSize > 0)
            {
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = 0, Type = FolderSizeItemType.overflow, Size = rFolder.OverSize
                });
            }

            if (rFolder.UploadAvailable)
            {
                rFolder.Items.Add(new FolderSizeItem()
                {
                    Number = 0, Size = rFolder.FreeSpace, Type = FolderSizeItemType.freespace
                });
            }
            else if (rFolder.Quota.HasAllowedSpace())
            {
                rFolder.UploadAvailable = true;
            }
            rFolder.SetPercentage();
            return(rFolder);
        }