Ejemplo 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++;
                }
            }
Ejemplo 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++;
                }
            }
Ejemplo n.º 3
0
 public override void Flush()
 {
     if (InnerBuffer != null && InnerBufferOffset > 0)
     {
         md5Hasher.TransformBlock(InnerBuffer, 0, InnerBufferOffset);
         base.Flush();
     }
 }
Ejemplo 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());
        }
Ejemplo n.º 5
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()));
        }
Ejemplo 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++;
            }
        }