Esempio n. 1
0
        static bool UploadFileWithAzcopyDLL(string filesource, string contentType, string storageAccountName, string storageAccountKey, string containerName, string blobName)
        {
            bool bResult = false;

            try
            {
                System.Net.ServicePointManager.Expect100Continue      = false;
                System.Net.ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 8;


                Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(
                    new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccountName, storageAccountKey), true);

                Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container  = blobClient.GetContainerReference(containerName);

                // Create the container if it doesn't already exist.
                container.CreateIfNotExists();
                Microsoft.WindowsAzure.Storage.Blob.CloudBlob cloudBlob = container.GetBlockBlobReference(blobName);

                Microsoft.WindowsAzure.Storage.DataMovement.TransferOptions option = new Microsoft.WindowsAzure.Storage.DataMovement.TransferOptions();

                //option.ParallelOperations = 64;
                //option.MaximumCacheSize = 500000000;

                Microsoft.WindowsAzure.Storage.DataMovement.TransferManager manager = new Microsoft.WindowsAzure.Storage.DataMovement.TransferManager(option);

                var fileStream = System.IO.File.OpenRead(filesource);
                Microsoft.WindowsAzure.Storage.DataMovement.TransferLocation source      = new Microsoft.WindowsAzure.Storage.DataMovement.TransferLocation(fileStream);
                Microsoft.WindowsAzure.Storage.DataMovement.TransferLocation destination = new Microsoft.WindowsAzure.Storage.DataMovement.TransferLocation(cloudBlob);

                //source.SourceUri = new Uri("file://" + sourceFileName);
                Microsoft.WindowsAzure.Storage.DataMovement.TransferJob job = new Microsoft.WindowsAzure.Storage.DataMovement.TransferJob(source, destination, Microsoft.WindowsAzure.Storage.DataMovement.TransferMethod.SyncCopy);
                System.Threading.CancellationToken token = new System.Threading.CancellationToken();


                //Microsoft.WindowsAzure.Storage.DataMovement.TransferManager.UseV1MD5 = false;

                job.ContentType      = contentType;
                job.Starting        += Job_Starting;
                job.ProgressUpdated += Job_ProgressUpdated;
                job.Finished        += Job_Finished;

                Task t = manager.ExecuteJobAsync(job, token);
                t.Wait();
                if (job.IsCompleted == true)
                {
                    bResult = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine("Exception: " + e.InnerException.Message);
                }
            }
            return(bResult);
        }
Esempio n. 2
0
        internal static void CheckMD5(string containerName, string filePath)
        {
            string    blobName = Path.GetFileName(filePath);
            CloudBlob blob     = BlobHelper.QueryBlob(containerName, blobName);
            string    localMd5 = FileUtil.GetFileContentMD5(filePath);

            Test.Assert(localMd5 == blob.Properties.ContentMD5,
                        string.Format("blob content md5 should be {0}, and actually it's {1}", localMd5, blob.Properties.ContentMD5));
        }
        public static BlobAttributes MapAttributes(Microsoft.WindowsAzure.Storage.Blob.CloudBlob blobReference)
        {
            var attributes = new BlobAttributes
            {
                AbsoluteUri  = blobReference.Uri.AbsoluteUri,
                Etag         = blobReference.Properties.ETag,
                LastModified = blobReference.Properties.LastModified.Value.DateTime,
                Length       = blobReference.Properties.Length,
                Metadata     = blobReference.Metadata
            };

            return(attributes);
        }
Esempio n. 4
0
        static bool UploadFileWithNuggetDLL(string filesource, string contentType, string storageAccountName, string storageAccountKey, string containerName, string blobName)
        {
            bool bResult = false;

            try
            {
                System.Net.ServicePointManager.Expect100Continue      = false;
                System.Net.ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 8;
//                Microsoft.WindowsAzure.Storage.DataMovement.TransferManager.Configurations.ParallelOperations = 64;


                Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(
                    new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccountName, storageAccountKey), true);

                Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container  = blobClient.GetContainerReference(containerName);

                // Create the container if it doesn't already exist.
                container.CreateIfNotExists();
                Microsoft.WindowsAzure.Storage.Blob.CloudBlob cloudBlob = container.GetBlockBlobReference(blobName);

                Microsoft.WindowsAzure.Storage.DataMovement.UploadOptions options = new Microsoft.WindowsAzure.Storage.DataMovement.UploadOptions();
                options.ContentType = contentType;

                Microsoft.WindowsAzure.Storage.DataMovement.TransferContext context = new Microsoft.WindowsAzure.Storage.DataMovement.TransferContext();
                context.ProgressHandler = new Progress <Microsoft.WindowsAzure.Storage.DataMovement.TransferProgress>((progress) =>
                {
                    Console.WriteLine("Bytes Uploaded: {0}", progress.BytesTransferred);
                });
                StartTime = DateTime.Now;
                Console.WriteLine(string.Format("Starting upload at {0:d/M/yyyy HH:mm:ss.fff}", StartTime));
                // Start the upload
                Task t = Microsoft.WindowsAzure.Storage.DataMovement.TransferManager.UploadAsync(filesource, cloudBlob, options, context);
                t.Wait();
                bResult = true;
                Console.WriteLine(string.Format("Upload finished at {0:d/M/yyyy HH:mm:ss.fff}", DateTime.Now));
                Console.WriteLine(string.Format("Time Elapsed in seconds: " + (DateTime.Now - StartTime).TotalSeconds.ToString()));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine("Exception: " + e.InnerException.Message);
                }
            }
            return(bResult);
        }