Ejemplo n.º 1
0
        static void client_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e)
        {
            System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;

            string downloadChecksum = null;
            BlobsAPI blobsAPI = new BlobsAPI();
            try
            {
                // Get the content type
                string contentType = ((BlobWebClient)sender).ResponseHeaders["Content-Type"];

                // If the request was not canceled and did not throw any exception or errors
                if (!e.Cancelled && e.Error == null)
                {
                    byte[] data = (byte[])e.Result;

                    if (String.Compare(((BlobWebClient)sender).BlobChecksumAlgorithm, "crc32", true) == 0)
                        downloadChecksum = ChecksumUtil.ComputeCRC32(data);
                    else if (String.Compare(((BlobWebClient)sender).BlobChecksumAlgorithm, "md5", true) == 0)
                        downloadChecksum = ChecksumUtil.ComputeMD5(data);

                    if (String.Compare(downloadChecksum, ((BlobWebClient)sender).BlobChecksum, true) != 0)
                    {
                        // download complete, but corrupt
                        // We should retry
                        blobsAPI.SetBlobStatus(((BlobWebClient)sender).BlobID, (int)Blob.eStatus.CORRUPT);
                        ((BlobWebClient)sender).ErrorCount++;
                        RetryDownload((BlobWebClient)sender);
                    }
                    else
                    {
                        //download complete and successful
                        blobsAPI.StoreBlobData(((BlobWebClient)sender).BlobID, contentType, data);
                        downloadClients.Remove(((BlobWebClient)sender).BlobID);
                    }

                }

                else if (e.Cancelled)
                {
                    //download cancelled
                    //blobsAPI.SetBlobStatus(((BlobWebClient)sender).BlobID, (int)Blob.eStatus.CANCELLED);
                    downloadClients.Remove(((BlobWebClient)sender).BlobID);
                }

                else if (!e.Cancelled && e.Error != null)
                {
                    //downloadHashTable[blobID] = BlobsAPI.eBlobStatus.FAILED;  //download failed
                    //blobsAPI.SetBlobStatus(((BlobWebClient)sender).BlobID, (int)Blob.eStatus.FAILED);
                    ((BlobWebClient)sender).ErrorCount++;
                    //RetryDownload((BlobWebClient)sender);
                }
            }

            catch (System.Net.WebException webEx)
            {
                blobsAPI.SetBlobStatus(((BlobWebClient)sender).BlobID, (int)Blob.eStatus.FAILED);
                ((BlobWebClient)sender).ErrorCount++;
                RetryDownload((BlobWebClient)sender);
                throw webEx;
            }

            catch (Exception ex)
            {
                //blobsAPI.SetBlobStatus(((BlobWebClient)sender).BlobID, (int)Blob.eStatus.FAILED);
                ((BlobWebClient)sender).ErrorCount++;
                //RetryDownload((BlobWebClient)sender);
                throw new Exception("Exception thrown uploading binary data to ESS", ex);
            }

            finally
            {
                // Let the main application thread resume.
                waiter.Set();
            }
        }
Ejemplo n.º 2
0
        static void client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
        {
            System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;

            try
            {
                long blobID = ((BlobWebClient)sender).BlobID;
                if (((BlobWebClient)sender).BlobStatus != (int) Blob.eStatus.DOWNLOADING)
                {
                    BlobsAPI blobsAPI = new BlobsAPI();
                    //blobsAPI.SetBlobStatus(blobID, (int)Blob.eStatus.DOWNLOADING);
                }

            }
            finally
            {
                waiter.Set();
            }
        }