/// <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); }
/// <summary> /// Fixed: /// </summary> public static Error.Types OnUploading( Context context, SiteSettings ss, Dictionary <string, Libraries.DataTypes.Attachments> attachmentsHash) { if (!context.ContractSettings.Attachments()) { return(Error.Types.BadRequest); } foreach (var keyValue in attachmentsHash) { var column = ss.GetColumn( context: context, columnName: keyValue.Key); var attachments = keyValue.Value; if (OverLimitQuantity( attachments: attachments, limitQuantity: column.LimitQuantity)) { return(Error.Types.OverLimitQuantity); } 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: attachmentsHash .Select(o => o.Value.Where(p => p.Added == true).Select(p => p.Size).Sum() - o.Value.Where(p => p.Deleted == true).Select(p => p.Size).Sum()) .Sum() .ToDecimal(), storageSize: context.ContractSettings.StorageSize)) { return(Error.Types.OverTenantStorageSize); } } return(Error.Types.None); }
/// <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); }
/// <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); }