Esempio n. 1
0
            public async Task Execute()
            {
                while (true)
                {
                    var totalSizeRead = await inputStream.ReadAsync(buffer);

                    TotalSizeRead += totalSizeRead;

                    if (totalSizeRead == 0)                     // nothing left to read
                    {
                        storage.Batch(accessor => accessor.CompleteFileUpload(filename));
                        FileHash = IOExtensions.GetMD5Hex(md5Hasher.TransformFinalBlock());
                        return;                         // task is done
                    }

                    ConcurrencyAwareExecutor.Execute(() => storage.Batch(accessor =>
                    {
                        var hashKey = accessor.InsertPage(buffer, totalSizeRead);
                        accessor.AssociatePage(filename, hashKey, pos, totalSizeRead);
                    }));

                    md5Hasher.TransformBlock(buffer, 0, totalSizeRead);

                    pos++;
                }
            }
Esempio n. 2
0
            public async Task Execute()
            {
                while (true)
                {
                    var read = await inputStream.ReadAsync(buffer);

                    TotalSizeRead += read;

                    if (read == 0)                     // nothing left to read
                    {
                        FileHash = IOExtensions.GetMD5Hex(md5Hasher.TransformFinalBlock());
                        headers["Content-MD5"] = FileHash;
                        storage.Batch(accessor =>
                        {
                            accessor.CompleteFileUpload(filename);
                            putTriggers.Apply(trigger => trigger.AfterUpload(filename, headers));
                        });
                        return;                         // task is done
                    }

                    ConcurrencyAwareExecutor.Execute(() => storage.Batch(accessor =>
                    {
                        var hashKey = accessor.InsertPage(buffer, read);
                        accessor.AssociatePage(filename, hashKey, pos, read);
                        putTriggers.Apply(trigger => trigger.OnUpload(filename, headers, hashKey, pos, read));
                    }));

                    md5Hasher.TransformBlock(buffer, 0, read);

                    pos++;
                }
            }
Esempio n. 3
0
        private string ComputeHash(IHashEncryptor hash, params string[] blocks)
        {
            foreach (var block in blocks)
            {
                hash.TransformBlock(Encoding.UTF8.GetBytes(block), 0, block.Length);
            }

            return IOExtensions.GetMD5Hex(hash.TransformFinalBlock());
        }
Esempio n. 4
0
        private string ComputeHash(IHashEncryptor hash, params string[] blocks)
        {
            foreach (var block in blocks)
            {
                hash.TransformBlock(Encoding.UTF8.GetBytes(block), 0, block.Length);
            }

            return(IOExtensions.GetMD5Hex(hash.TransformFinalBlock()));
        }
Esempio n. 5
0
        protected override void Dispose(bool disposing)
        {
            if (!PreventUploadComplete)
            {
                base.Dispose(disposing);

                FileHash = IOExtensions.GetMD5Hex(md5Hasher.TransformFinalBlock());
                md5Hasher.Dispose();
            }
        }
Esempio n. 6
0
        public async Task Execute()
        {
            while (true)
            {
                var read = await inputStream.ReadAsync(buffer).ConfigureAwait(false);

                TotalSizeRead += read;

                if (read == 0) // nothing left to read
                {
                    FileHash = IOExtensions.GetAsHex(md5Hasher.TransformFinalBlock());
                    headers["Content-MD5"] = FileHash;
                    storage.Batch(accessor =>
                    {
                        accessor.CompleteFileUpload(filename);
                        putTriggers.Apply(trigger => trigger.AfterUpload(filename, headers));
                    });
                    return; // task is done
                }

                int  retries = 50;
                bool shouldRetry;

                do
                {
                    try
                    {
                        storage.Batch(accessor =>
                        {
                            var hashKey = accessor.InsertPage(buffer, read);
                            accessor.AssociatePage(filename, hashKey, pos, read);
                            putTriggers.Apply(trigger => trigger.OnUpload(filename, headers, hashKey, pos, read));
                        });

                        shouldRetry = false;
                    }
                    catch (ConcurrencyException)
                    {
                        if (retries-- > 0)
                        {
                            shouldRetry = true;
                            Thread.Sleep(50);
                            continue;
                        }

                        throw;
                    }
                } while (shouldRetry);

                md5Hasher.TransformBlock(buffer, 0, read);

                pos++;
            }
        }