Пример #1
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static Error.Types OnUploading(
            Column column,
            Libraries.DataTypes.Attachments attachments,
            ICollection <IFormFile> files)
        {
            if (!Contract.Attachments())
            {
                return(Error.Types.BadRequest);
            }
            if (OverLimitQuantity(attachments.Count(), files.Count(), column.LimitQuantity))
            {
                return(Error.Types.OverLimitQuantity);
            }
            if (OverLimitSize(files, column.LimitSize))
            {
                return(Error.Types.OverLimitSize);
            }
            var newTotalFileSize = files.Sum(x => x.Length);

            if (OverTotalLimitSize(
                    attachments.Select(x => x.Size.ToLong()).Sum(),
                    newTotalFileSize,
                    column.TotalLimitSize))
            {
                return(Error.Types.OverTotalLimitSize);
            }
            if (OverTenantStorageSize(
                    BinaryUtilities.UsedTenantStorageSize(),
                    newTotalFileSize,
                    Contract.TenantStorageSize()))
            {
                return(Error.Types.OverTenantStorageSize);
            }
            return(Error.Types.None);
        }
        /// <summary>
        /// Fixed:
        /// </summary>
        public static Error.Types OnUploading(
            Column column,
            Libraries.DataTypes.Attachments attachments,
            System.Web.HttpPostedFileBase[] files)
        {
            if (!Contract.Attachments())
            {
                return(Error.Types.BadRequest);
            }
            if (OverLimitQuantity(attachments.Count(), files.Count(), column.LimitQuantity))
            {
                return(Error.Types.OverLimitQuantity);
            }
            if (OverLimitSize(files, column.LimitSize))
            {
                return(Error.Types.OverLimitSize);
            }
            var newTotalFileSize = files.Sum(x => x.ContentLength);

            if (OverTotalLimitSize(
                    attachments.Select(x => x.Size.ToLong()).Sum(),
                    newTotalFileSize,
                    column.TotalLimitSize))
            {
                return(Error.Types.OverTotalLimitSize);
            }
            if (OverTenantTotalLimitSize(
                    BinaryUtilities.TenantBinSize(),
                    newTotalFileSize,
                    Contract.TenantAttachmentsSize()))
            {
                return(Error.Types.OverTenantTotalLimitSize);
            }
            return(Error.Types.None);
        }
Пример #3
0
 /// <summary>
 /// Fixed:
 /// </summary>
 private static bool OverLimitQuantity(
     Libraries.DataTypes.Attachments attachments, decimal?limitQuantity)
 {
     return(attachments
            .Where(o => o.Deleted != true)
            .Count()
            > limitQuantity);
 }
Пример #4
0
 /// <summary>
 /// Fixed:
 /// </summary>
 private static bool OverTotalLimitSize(
     Libraries.DataTypes.Attachments attachments, decimal?totalLimitSize)
 {
     return(attachments
            .Where(o => o.Deleted != true)
            .Select(o => o.Size)
            .Sum()
            > totalLimitSize * 1024 * 1024);
 }
Пример #5
0
 /// <summary>
 /// Fixed:
 /// </summary>
 private static bool OverLimitSize(
     Libraries.DataTypes.Attachments attachments, decimal?limitSize)
 {
     return(attachments.Any(o =>
                            o.Added == true &&
                            o.Deleted != true &&
                            o.Size
                            > limitSize * 1024 * 1024));
 }
Пример #6
0
 /// <summary>
 /// Fixed:
 /// </summary>
 private static bool OverTotalLimitSize(
     Libraries.DataTypes.Attachments attachments,
     System.Func <Attachment, bool> storageSelector,
     decimal?totalLimitSize)
 {
     return(attachments
            .Where(o => o.Deleted != true)
            .Where(storageSelector)
            .Select(o => o.Size)
            .Sum()
            > totalLimitSize * 1024 * 1024);
 }
Пример #7
0
        /// <summary>
        /// Fixed:
        /// </summary>
        private static Error.Types OverTotalLimitSize(
            Libraries.DataTypes.Attachments attachments, Column column)
        {
            long limitSize = (long)(column.LimitSize ?? 0);

            if (attachments.Where(o => o.Deleted != true)
                .Select(o => o.Size)
                .Sum(i => i <= (limitSize * 1024 * 1024) ? i : 0) > column.TotalLimitSize * 1024 * 1024)
            {
                return(Error.Types.OverTotalLimitSize);
            }
            return(Error.Types.None);
        }
Пример #8
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static Error.Types OnUploading(
     Context context,
     Column column,
     Libraries.DataTypes.Attachments attachments)
 {
     if (!context.ContractSettings.Attachments())
     {
         return(Error.Types.BadRequest);
     }
     if (OverLimitQuantity(
             attachments: attachments,
             limitQuantity: column.LimitQuantity))
     {
         return(Error.Types.OverLimitQuantity);
     }
     if (OverLimitSize(
             attachments: attachments,
             limitSize: column.LimitSize))
     {
         return(Error.Types.OverLimitSize);
     }
     if (OverTotalLimitSize(
             attachments: attachments,
             totalLimitSize: column.TotalLimitSize))
     {
         return(Error.Types.OverTotalLimitSize);
     }
     if (OverTenantStorageSize(
             totalFileSize: BinaryUtilities.UsedTenantStorageSize(context: context),
             newTotalFileSize: attachments
             .Select(o => o.Added == true
                 ? o.Size
                 : o.Deleted == true
                     ? o.Size * -1
                     : 0)
             .Sum()
             .ToDecimal(),
             storageSize: context.ContractSettings.StorageSize))
     {
         return(Error.Types.OverTenantStorageSize);
     }
     return(Error.Types.None);
 }
Пример #9
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static Error.Types OnUploading(
            Context context,
            Column column,
            Libraries.DataTypes.Attachments attachments)
        {
            if (!context.ContractSettings.Attachments())
            {
                return(Error.Types.BadRequest);
            }
            if (OverLimitQuantity(
                    attachments?.Count().ToDecimal() ?? 0,
                    context.PostedFiles?.Count().ToDecimal() ?? 0,
                    column.LimitQuantity))
            {
                return(Error.Types.OverLimitQuantity);
            }
            if (OverLimitSize(context, column.LimitSize))
            {
                return(Error.Types.OverLimitSize);
            }
            var newTotalFileSize = context.PostedFiles.Sum(x => x.Size.ToDecimal());

            if (OverTotalLimitSize(
                    attachments?.Select(x => x.Size.ToDecimal()).Sum() ?? 0,
                    newTotalFileSize,
                    column.TotalLimitSize))
            {
                return(Error.Types.OverTotalLimitSize);
            }
            if (OverTenantStorageSize(
                    BinaryUtilities.UsedTenantStorageSize(context: context),
                    newTotalFileSize,
                    context.ContractSettings.StorageSize))
            {
                return(Error.Types.OverTenantStorageSize);
            }
            return(Error.Types.None);
        }
Пример #10
0
 /// <summary>
 /// Fixed:
 /// </summary>
 private static Error.Types OverLimitSize(
     Libraries.DataTypes.Attachments attachments, Column column)
 {
     foreach (var attachment in attachments
              .Where(o => o.Added == true && o.Deleted != true))
     {
         if (BinaryUtilities.BinaryStorageProvider(column, attachment.Size ?? 0) == "LocalFolder")
         {
             if (attachment.Size > column.LocalFolderLimitSize * 1024 * 1024)
             {
                 return(Error.Types.OverLocalFolderLimitSize);
             }
         }
         else
         {
             if (attachment.Size > column.LimitSize * 1024 * 1024)
             {
                 return(Error.Types.OverLimitSize);
             }
         }
     }
     return(Error.Types.None);
 }
Пример #11
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static Error.Types OnUploading(
            Context context,
            Column column,
            Libraries.DataTypes.Attachments attachments,
            IList <PostedFile> files,
            System.Collections.Generic.IEnumerable <System.Net.Http.Headers.ContentRangeHeaderValue> contentRanges)
        {
            if (!context.ContractSettings.Attachments())
            {
                return(Error.Types.BadRequest);
            }
            if (files.Count != contentRanges.Count())
            {
                return(Error.Types.BadRequest);
            }
            if (OverLimitQuantity(
                    attachments: attachments,
                    limitQuantity: column.LimitQuantity,
                    newFileCount: files.Count()))
            {
                return(Error.Types.OverLimitQuantity);
            }
            var totalLength = default(long);

            foreach (var length in contentRanges.Select(r => r.Length ?? default(long)))
            {
                if (BinaryUtilities.BinaryStorageProvider(column, length) == "LocalFolder")
                {
                    if (OverLimitSize(
                            length: length,
                            limitSize: column.LocalFolderLimitSize))
                    {
                        return(Error.Types.OverLocalFolderLimitSize);
                    }
                }
                else
                {
                    if (OverLimitSize(
                            length: length,
                            limitSize: column.LimitSize))
                    {
                        return(Error.Types.OverLimitSize);
                    }
                }
                totalLength += length;
            }
            switch (BinaryUtilities.BinaryStorageProvider(column))
            {
            case "LocalFolder":
                if (OverTotalLimitSize(
                        attachments: attachments,
                        totalLimitSize: column.LocalFolderTotalLimitSize,
                        newFileTotalSize: totalLength))
                {
                    return(Error.Types.OverLocalFolderTotalLimitSize);
                }
                break;

            case "AutoDataBaseOrLocalFolder":
                if (OverTotalLimitSize(
                        attachments: attachments,
                        totalLimitSize: column.TotalLimitSize,
                        newFileTotalSize: totalLength))
                {
                    return(Error.Types.OverTotalLimitSize);
                }
                break;

            default:
                if (OverTotalLimitSize(
                        attachments: attachments,
                        totalLimitSize: column.TotalLimitSize,
                        newFileTotalSize: totalLength))
                {
                    return(Error.Types.OverTotalLimitSize);
                }
                break;
            }
            if (OverTenantStorageSize(
                    BinaryUtilities.UsedTenantStorageSize(context),
                    totalLength,
                    context.ContractSettings.StorageSize))
            {
                return(Error.Types.OverTenantStorageSize);
            }
            return(Error.Types.None);
        }
Пример #12
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static Error.Types OnUploading(
            Context context,
            Column column,
            Libraries.DataTypes.Attachments attachments)
        {
            if (!context.ContractSettings.Attachments())
            {
                return(Error.Types.BadRequest);
            }
            if (OverLimitQuantity(
                    attachments: attachments,
                    limitQuantity: column.LimitQuantity))
            {
                return(Error.Types.OverLimitQuantity);
            }
            var errorType = OverLimitSize(
                attachments: attachments,
                column: column);

            if (errorType != Error.Types.None)
            {
                return(errorType);
            }
            switch (BinaryUtilities.BinaryStorageProvider(column))
            {
            case "LocalFolder":
                if (OverTotalLimitSize(
                        attachments: attachments,
                        totalLimitSize: column.LocalFolderTotalLimitSize))
                {
                    return(Error.Types.OverLocalFolderTotalLimitSize);
                }
                break;

            case "AutoDataBaseOrLocalFolder":
                if (OverTotalLimitSize(
                        attachments: attachments,
                        totalLimitSize: column.TotalLimitSize))
                {
                    return(Error.Types.OverTotalLimitSize);
                }
                break;

            default:
                if (OverTotalLimitSize(
                        attachments: attachments,
                        totalLimitSize: column.TotalLimitSize))
                {
                    return(Error.Types.OverTotalLimitSize);
                }
                break;
            }
            if (OverTenantStorageSize(
                    totalFileSize: BinaryUtilities.UsedTenantStorageSize(context: context),
                    newTotalFileSize: attachments
                    .Select(o => o.Added == true
                        ? o.Size
                        : o.Deleted == true
                            ? o.Size * -1
                            : 0)
                    .Sum()
                    .ToDecimal(),
                    storageSize: context.ContractSettings.StorageSize))
            {
                return(Error.Types.OverTenantStorageSize);
            }
            return(Error.Types.None);
        }