Пример #1
0
        public async Task <Storage> GetStorageAsync(BlobAttributes blobAttributes, CancellationToken cancellationToken)
        {
            var blobDbCommand = new BlobDbCommand(ConnectionString);

            var target =
                await
                blobDbCommand.GetAttributesAsync(blobAttributes.Id, cancellationToken).ConfigureAwait(false);

            if (target != null && target.Storage != null && target.Storage != Storage.None)
            {
                return(target.Storage);
            }

            var account = blobAttributes.Container.Account;

            if (account.StorageType == StorageType.Common)
            {
                return(await GetCommonStorageAsync(blobAttributes, cancellationToken).ConfigureAwait(false));
            }

            if (!account.Storages.Any() || account.Storages.All(x => x.IsSuspended || x.ThresholdLength == 0))
            {
                return(Storage.None);
            }

            var storage = account.Storages.OrderBy(x =>
            {
                var threshold   = x.ThresholdLength * 1.0;
                var used        = x.UsedLength;
                var thisTimeUse = blobAttributes.Properties.Length;

                return((used + thisTimeUse) / threshold);
            }).First();

            return(storage);
        }