public const int DefaultBlockSize           = 4 * 1024 * 1024; // 4MB

        public static Configure AzureDataBus(this Configure config)
        {
            var container = Defaultcontainer;

            CloudBlobClient cloudBlobClient;

            var configSection = Configure.GetConfigSection <AzureDataBusConfig>();

            if (configSection != null)
            {
                cloudBlobClient = CloudStorageAccount.Parse(configSection.ConnectionString).CreateCloudBlobClient();

                container = configSection.Container;
            }
            else
            {
                cloudBlobClient = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();
            }

            var dataBus = new BlobStorageDataBus(cloudBlobClient.GetContainerReference(container));

            if (configSection != null)
            {
                dataBus.BasePath          = configSection.BasePath;
                dataBus.MaxRetries        = configSection.MaxRetries;
                dataBus.NumberOfIOThreads = configSection.NumberOfIOThreads;
                dataBus.BlockSize         = configSection.BlockSize;
            }

            config.Configurer.RegisterSingleton <IDataBus>(dataBus);

            return(config);
        }
Beispiel #2
0
        /// <summary>
        /// Exports the list of containers in a given storage account
        /// </summary>
        /// <param name="account">Storage account to get the name and key of the storage account whose blobs are to be exported</param>
        /// <returns>List of storage account containers</returns>
        private List <Container> ExportStorageAccountContainers(Microsoft.WindowsAzure.Management.Storage.Models.StorageAccount account)
        {
            string           methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            List <Container> containers = new List <Container>();

            try
            {
                string srcStorageAccountKey = GetStorageAccountKeysFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, account.Name).PrimaryKey;

                Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount =
                    new Microsoft.WindowsAzure.Storage.CloudStorageAccount(
                        new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(account.Name, srcStorageAccountKey), true);
                CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

                foreach (var item in cloudBlobClient.ListContainers())
                {
                    List <Blob> blobs = new List <Blob>();
                    containers.Add(new Container
                    {
                        ContainerName = item.Name,
                        BlobDetails   = ExportBlobs(item.ListBlobs(null, false), blobs)
                    });
                }

                return(containers);
            }
            catch (Exception ex)
            {
                Logger.Error(methodName, ex);
                throw;
            }
        }
        public bool BackUp(string name, string content)
        {
            if (BlobClient == null)
            {
                AzureBlobConfiguration = new AzureBlobConfiguration();
                var connectionString = AzureBlobConfiguration.StorageConnectionStringSettings;
                var storageAccount   = CloudStorageAccount.Parse(connectionString);
                BlobClient = storageAccount.CreateCloudBlobClient();

                BlobClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 5);
            }

            var containerReference = AzureBlobConfiguration.StorageContainerReference;
            var container          = BlobClient.GetContainerReference(containerReference);

            if (container == null)
            {
                throw new Exception("Null ContainerReference");
            }

            var blockBlob = container.GetBlockBlobReference(name);

            blockBlob.UploadText(content);
            return(true);
        }
        public FileStreamResult File(string filename)
        {
            var stockpickFormsAzurequeueConnectionstring = "Stockpick.Forms.AzureQueue.Connectionstring";
            var connectionstring = Sitecore.Configuration.Settings.GetSetting(stockpickFormsAzurequeueConnectionstring);

            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionstring);

            var cloudBlobClient = storageAccount.CreateCloudBlobClient();
            var blobContainer   = cloudBlobClient.GetContainerReference("stockpickformsblob");

            blobContainer.CreateIfNotExists();

            var cloudResolver = new KeyVaultKeyResolver(Keyvault.GetToken);
            var url           = Sitecore.Configuration.Settings.GetSetting("Stockpick.Forms.KeyFault.Key.URL");

            if (string.IsNullOrEmpty(url))
            {
                Log.Error("config key Stockpick.Forms.KeyFault.Key.URL is emty", this);
            }
            var key = cloudResolver.ResolveKeyAsync(url, CancellationToken.None).GetAwaiter().GetResult();

            CloudBlockBlob blob = blobContainer.GetBlockBlobReference(filename);


            BlobEncryptionPolicy policy  = new BlobEncryptionPolicy(null, cloudResolver);
            BlobRequestOptions   options = new BlobRequestOptions()
            {
                EncryptionPolicy = policy
            };

            Stream blobStream = blob.OpenRead(null, options);

            return(new FileStreamResult(blobStream, "application/x-binary"));
        }
Beispiel #5
0
        static BsmController()
        {
            Trace.TraceInformation("[TRACE] Entering BsmController::BsmController() static initializer...");

            // NOTE: Need to fully qualify System.Configuration to disambiguate from ApiController.Configuration
            //string strStorageAccountConnectionString =
            //    System.Configuration.ConfigurationManager.AppSettings["StorageAccountConnectionString"];

            string strStorageAccountConnectionString =
                Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("StorageAccountConnectionString");

            if (strStorageAccountConnectionString == null)
            {
                Trace.TraceError("Unable to retrieve storage account connection string");
            }
            else if (strStorageAccountConnectionString.Length <= 0)
            {
                Trace.TraceError("Storage account connection string empty");
            }
            else  //connect to the cloud storage account
            {
                try
                {
                    srStorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(strStorageAccountConnectionString);
                }
                catch (Exception e)
                {
                    Trace.TraceError("Exception occurred when parsing storage account connection string\n{0}\n{1}",
                                     strStorageAccountConnectionString, e.Message);
                }

                if (srStorageAccount != null)
                {
                    srCloudQueueClient = srStorageAccount.CreateCloudQueueClient();
                    srBsmQueue         = srCloudQueueClient.GetQueueReference(srBsmQueueName);

                    try
                    {
                        if (srBsmQueue.CreateIfNotExists())
                        {
                            Trace.TraceInformation("Created Azure BSM queue '{0}'", srBsmQueueName);
                        }
                        else
                        {
                            Trace.TraceInformation("Got reference to existing BSM queue '{0}'", srBsmQueueName);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError("Exception occurred when creating queue for inbound BSM bundles\n{0}",
                                         e.Message);

                        srBsmQueue = null;
                    }
                }
            }

            Trace.TraceInformation("[TRACE] Exiting BsmController::BsmController() static initializer...");
            return;
        }
 static BlobUtility()
 {
     CloudStorage       = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Startup.AzureStorageConnectionString);
     CloudBlobClient    = CloudStorage.CreateCloudBlobClient();
     CloudBlobContainer = CloudBlobClient.GetContainerReference(Startup.BlobName);
     var res = CloudBlobContainer.CreateIfNotExistsAsync().Result;
 }
Beispiel #7
0
        public async Task Upload(IFormFile file, string name)
        {
            try
            {
                Microsoft.WindowsAzure.Storage.CloudStorageAccount cloudStorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(_constr);
                CloudBlobClient    cloudBlobClient    = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(_container);

                if (await cloudBlobContainer.CreateIfNotExistsAsync())
                {
                    await cloudBlobContainer.SetPermissionsAsync(
                        new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    });
                }

                CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(name);
                cloudBlockBlob.Properties.ContentType = file.ContentType;
                await cloudBlockBlob.UploadFromStreamAsync(file.OpenReadStream());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #8
0
        public static void Run([CosmosDBTrigger(
                                    databaseName: "IoT",
                                    collectionName: "IoT",
                                    ConnectionStringSetting = "DBConnection",
                                    LeaseCollectionName = "leases")] IReadOnlyList <Document> documents, TraceWriter log)
        {
            Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient queueClient;
            Microsoft.WindowsAzure.Storage.Queue.CloudQueue       queue;
            Microsoft.WindowsAzure.Storage.CloudStorageAccount    storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=scmrstorage;AccountKey=FtW5Qlz/5rWiqX0MPlGO0X2anGs5t7ea/H/ZkdcIEHlTA9isEinpscnuuhw8GwKR+7+Eo2IDRG1jwdMoDsRTqg==;EndpointSuffix=core.windows.net");
            queueClient = storageAccount.CreateCloudQueueClient();
            queue       = queueClient.GetQueueReference("trafficqueue");

            foreach (var doc in documents)
            {
                if (doc.GetPropertyValue <string>("accident") == "true")
                {
                    string m = String.Format("{{ \"lat\": {0}, \"long\": {1}, \"carId\": \"{2}\" }}",
                                             doc.GetPropertyValue <string>("lat"),
                                             doc.GetPropertyValue <string>("longitude"),
                                             doc.GetPropertyValue <string>("carid"));
                    Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage message = new Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage
                                                                                         (m);
                    queue.AddMessage(message);
                }
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public async Task <Uri> UploadBlob(Stream blobContent, bool isVideo, string reviewId, UploadProgress progressUpdater)
        {
            Uri blobAddress = null;

            try
            {
                var writeCredentials = await ObtainStorageCredentials(StoragePermissionType.Write);

                var csa = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(writeCredentials, APIKeys.StorageAccountName, APIKeys.StorageAccountUrlSuffix, true);

                var blobClient = csa.CreateCloudBlobClient();

                var container = blobClient.GetContainerReference(APIKeys.PhotosContainerName);

                var extension = isVideo ? "mp4" : "png";
                var blockBlob = container.GetBlockBlobReference($"{Guid.NewGuid()}.{extension}");

                blockBlob.Metadata.Add("reviewId", reviewId);
                await blockBlob.UploadFromStreamAsync(blobContent, null, null, null, progressUpdater, new CancellationToken());

                blobAddress = blockBlob.Uri;
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"*** Error {ex.Message}");

                return(null);
            }

            return(blobAddress);
        }
Beispiel #11
0
        private void GenerateLuceneIndex(List <Entry> entries)
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=diningsearchstorage;AccountKey=xeYMzXThFxrU7SsAMGbSWLdy9psLFRMk5NI8x0bx24xtEg9MPIstf/xwPdjvDm6HpHZaCPxxVFCv/7DDd5wymA==");
            AzureDirectory azureDirectory = new AzureDirectory(storageAccount, "diningsearchindex");
            Analyzer       analyzer       = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
            IndexWriter    indexWriter    = new IndexWriter(azureDirectory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
            ////
            int c = 0;

            foreach (var entry in entries)
            {
                c++;
                var item = new Document();
                item.Add(new Field("Id", c.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                item.Add(new Field("Dish", entry.DishName, Field.Store.YES, Field.Index.ANALYZED));
                item.Add(new Field("Cafe/Restaurant", string.Format("{0}/{1}", entry.CafeName, entry.RestaurantName), Field.Store.YES, Field.Index.ANALYZED));
                item.Add(new Field("URL", entry.CafeUrl, Field.Store.YES, Field.Index.NOT_ANALYZED));
                item.Add(new Field("Description", entry.Description ?? string.Empty, Field.Store.YES, Field.Index.ANALYZED));
                item.Add(new Field("Price", entry.Price, Field.Store.YES, Field.Index.NOT_ANALYZED));
                indexWriter.AddDocument(item);
            }



            ////

            indexWriter.Dispose();
            azureDirectory.Dispose();
        }
        public CloudBlobContainer GetCloudBlobContainer()
        {
            Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCreds;
            if (!string.IsNullOrEmpty(SasToken))
            {
                storageCreds = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(SasToken);
            }
            else
            {
                storageCreds = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(StorageAccountName, StorageAccountKey);
            }

            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCreds, StorageAccountName, null, true);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            //Get container reference
            var containerRef = blobClient.GetContainerReference(ContainerName);

            if (containerRef == null)
            {
                throw new Exception($"The container {ContainerName} cannot be found in storage account {StorageAccountName}");
            }

            return(containerRef);
        }
Beispiel #13
0
        } // DeleteQueueItem

        /// <summary>
        /// Creates the storage and gets a reference (once)
        /// </summary>
        public static Microsoft.WindowsAzure.Storage.Queue.CloudQueue ConnectToQueueStorage(string queueName, string cloudAccountName, string cloudKey)
        {
            try
            {
                Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
                    cloudAccountName, cloudKey);

                Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);

                Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();

                queueStorage.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(DEFAULT_SAVE_QUEUE_RETRY_WAIT_IN_MILLISECONDS), DEFAULT_SAVE_QUEUE_RETRY_ATTEMPTS);

                queueStorage.DefaultRequestOptions.ServerTimeout = new TimeSpan(0, DEFAULT_SAVE_AND_READ_QUEUE_TIMEOUT_IN_MINUTES, 0);

                Microsoft.WindowsAzure.Storage.Queue.CloudQueue cloudQueue = queueStorage.GetQueueReference(queueName);
                cloudQueue.CreateIfNotExistsAsync();

                return(cloudQueue);
            }
            catch (Exception ex)
            {
                throw new Exception("Storage services initialization failure. "
                                    + "Check your storage account configuration settings. If running locally, "
                                    + "ensure that the Development Storage service is running. \n"
                                    + ex.Message);
            }
        } // ConnectToQueueStorage
Beispiel #14
0
        private static Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient InitializeClient()
        {
            var accountInfo = AccountInfo.Instance;
            var credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountInfo.AccountName, accountInfo.SharedKey);
            var account     = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(credentials, false);

            return(account.CreateCloudBlobClient());
        }
 public AzureBlobHelper(string accountName, string accessKey, string groupName, bool useHttps = false)
 {
     var credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accessKey);
     var storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(credentials, useHttps);
     this.CloudBlobClient = storageAccount.CreateCloudBlobClient();
     this.Container = new ContainerLogic(this, groupName);
     this.Blob = new BlobLogic(this, groupName);
 }
Beispiel #16
0
        /// <summary>
        /// Creates the storage and gets a reference (once)
        /// </summary>
        private static void InitializeStorage(string blobContainer)
        {
            string containerName = blobContainer.ToString().ToLower(); // must be lower case!

            if (storageInitializedDictionary.ContainsKey(containerName) && storageInitializedDictionary[containerName] == true)
            {
                return;
            }

            lock (gate)
            {
                if (storageInitializedDictionary.ContainsKey(containerName) && storageInitializedDictionary[containerName] == true)
                {
                    return;
                }

                try
                {
                    Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
                        Sample.Azure.Common.Setting.SettingService.CloudStorageAccountName,
                        Sample.Azure.Common.Setting.SettingService.CloudStorageKey);

                    Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials,
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageBlobEndPoint),
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageQueueEndPoint),
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageTableEndPoint),
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageFileEndPoint));

                    Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();

                    int    blobSaveTimeoutInMinutes = DEFAULT_SAVE_AND_READ_BLOB_TIMEOUT_IN_MINUTES;
                    string timeOutOverRide          = Sample.Azure.Common.Setting.SettingService.SaveAndReadBlobTimeoutInMinutes;
                    if (timeOutOverRide != null)
                    {
                        blobSaveTimeoutInMinutes = int.Parse(timeOutOverRide);
                    }
                    blobStorage.DefaultRequestOptions.ServerTimeout = TimeSpan.FromMinutes(blobSaveTimeoutInMinutes);

                    blobStorage.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(1), 10);
                    Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer cloudBlobContainer = blobStorage.GetContainerReference(containerName);
                    cloudBlobContainer.CreateIfNotExists();

                    Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions permissions = new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions();
                    permissions.PublicAccess = Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Off;
                    cloudBlobContainer.SetPermissions(permissions);

                    blobStorageDictionary.Add(containerName, blobStorage);
                    storageInitializedDictionary.Add(containerName, true);
                }
                catch (Exception ex)
                {
                    throw new Exception("Storage services initialization failure. "
                                        + "Check your storage account configuration settings. If running locally, "
                                        + "ensure that the Development Storage service is running. \n"
                                        + ex.Message);
                }
            } // lock
        }     // InitializeStorage
Beispiel #17
0
            public AzureBlobStore(string connectionString)
            {
                var csa        = CloudStorageAccount.Parse(connectionString);
                var blobClient = csa.CreateCloudBlobClient();

                azureGacContainer = blobClient.GetContainerReference(GACContainerName);
                azureGacContainer.CreateIfNotExists();
                Trace.Log.Connected(AppDomain.CurrentDomain.Id, "azure", azureGacContainer.Uri.ToString());
            }
Beispiel #18
0
        } // PutQueueItem

        /// <summary>
        /// Creates the storage and gets a reference (once)
        /// </summary>
        private static void InitializeStorage(string queueContainer)
        {
            string containerName = queueContainer.ToString().ToLower(); // must be lower case!

            if (storageInitializedDictionary.ContainsKey(containerName) && storageInitializedDictionary[containerName] == true)
            {
                return;
            }

            lock (gate)
            {
                if (storageInitializedDictionary.ContainsKey(containerName) && storageInitializedDictionary[containerName] == true)
                {
                    return;
                }

                try
                {
                    Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
                        Sample.Azure.Common.Setting.SettingService.CloudStorageAccountName,
                        Sample.Azure.Common.Setting.SettingService.CloudStorageKey);

                    Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials,
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageBlobEndPoint),
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageQueueEndPoint),
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageTableEndPoint),
                                                                                                                                               new Uri(Sample.Azure.Common.Setting.SettingService.CloudStorageFileEndPoint));

                    Microsoft.WindowsAzure.Storage.Queue.CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();

                    queueStorage.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(DEFAULT_SAVE_QUEUE_RETRY_WAIT_IN_MILLISECONDS), DEFAULT_SAVE_QUEUE_RETRY_ATTEMPTS);

                    int    queueSaveTimeoutInMinutes = DEFAULT_SAVE_AND_READ_QUEUE_TIMEOUT_IN_MINUTES;
                    string timeOutOverRide           = Sample.Azure.Common.Setting.SettingService.SaveAndReadQueueTimeoutInMinutes;
                    if (timeOutOverRide != null)
                    {
                        queueSaveTimeoutInMinutes = int.Parse(timeOutOverRide);
                    }
                    queueStorage.DefaultRequestOptions.ServerTimeout = TimeSpan.FromMinutes(queueSaveTimeoutInMinutes);

                    queueStorage.DefaultRequestOptions.ServerTimeout = new TimeSpan(0, DEFAULT_SAVE_AND_READ_QUEUE_TIMEOUT_IN_MINUTES, 0);

                    Microsoft.WindowsAzure.Storage.Queue.CloudQueue cloudQueue = queueStorage.GetQueueReference(containerName);
                    cloudQueue.CreateIfNotExists();

                    queueStorageDictionary.Add(containerName, queueStorage);
                    storageInitializedDictionary.Add(containerName, true);
                }
                catch (Exception ex)
                {
                    throw new Exception("Storage services initialization failure. "
                                        + "Check your storage account configuration settings. If running locally, "
                                        + "ensure that the Development Storage service is running. \n"
                                        + ex.Message);
                }
            } // lock
        }     // InitializeStorage
Beispiel #19
0
        public AzureBlobHelper(string accountName, string accessKey, string groupName, bool useHttps = false)
        {
            var credentials    = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accessKey);
            var storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(credentials, useHttps);

            this.CloudBlobClient = storageAccount.CreateCloudBlobClient();
            this.Container       = new ContainerLogic(this, groupName);
            this.Blob            = new BlobLogic(this, groupName);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureServerPackageRepository"/> class.
 /// </summary>
 /// <param name="packageLocator">The package locator.</param>
 /// <param name="packageSerializer">The package serializer.</param>
 public AzureServerPackageRepository(IPackageLocator packageLocator, IAzurePackageSerializer packageSerializer)
 {
     _packageLocator = packageLocator;
     _packageSerializer = packageSerializer;
     var azureConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
     _storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(azureConnectionString);
     _blobClient = _storageAccount.CreateCloudBlobClient();
     _helper = Microsoft.WindowsAzure.CloudStorageAccount.Parse(azureConnectionString);
 }
Beispiel #21
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;
        }
        public AzureServerPackageRepository(IPackageLocator packageLocator, 
                                            IAzurePackageSerializer packageSerializer,
                                            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount)
        {
            _packageLocator = packageLocator;
            _packageSerializer = packageSerializer;

            _storageAccount = storageAccount;
            _blobClient = _storageAccount.CreateCloudBlobClient();
        }
        public AzureServerPackageRepository(IPackageLocator packageLocator,
                                            IAzurePackageSerializer packageSerializer,
                                            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount)
        {
            _packageLocator    = packageLocator;
            _packageSerializer = packageSerializer;

            _storageAccount = storageAccount;
            _blobClient     = _storageAccount.CreateCloudBlobClient();
        }
Beispiel #24
0
        public static IActionsProvider GetActionProvider(Microsoft.WindowsAzure.Storage.CloudStorageAccount WaterMarkStorageAcc)
        {
            int embeddedmessagecount = int.Parse(System.Configuration.ConfigurationManager.AppSettings["embeddedmessagecount"] ?? "10");

            if (embeddedmessagecount > 32)
            {
                embeddedmessagecount = 32;
            }
            return(new ActionProvider(WaterMarkStorageAcc, embeddedmessagecount));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureServerPackageRepository"/> class.
        /// </summary>
        /// <param name="packageLocator">The package locator.</param>
        /// <param name="packageSerializer">The package serializer.</param>
        public AzureServerPackageRepository(IPackageLocator packageLocator, IAzurePackageSerializer packageSerializer)
        {
            _packageLocator    = packageLocator;
            _packageSerializer = packageSerializer;
            var azureConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");

            _storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(azureConnectionString);
            _blobClient     = _storageAccount.CreateCloudBlobClient();
            _helper         = Microsoft.WindowsAzure.CloudStorageAccount.Parse(azureConnectionString);
        }
Beispiel #26
0
        private static async Task <CloudBlockBlob> CreateBlobAsync(string blobName)
        {
            var account    = CloudStorageAccount.Parse(_connection);
            var blobClient = account.CreateCloudBlobClient();

            var container = blobClient.GetContainerReference("userdetails");
            await container.CreateIfNotExistsAsync();

            return(container.GetBlockBlobReference(blobName));
        }
        public ReportGroupCompletnessBolt()
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = GetStorageAccount();

            // Create the table client.
            Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            this.table = tableClient.GetTableReference("reportCompletness");

            this.table.CreateIfNotExists();
        }
Beispiel #28
0
        public TagIdGroupBolt()
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = GetStorageAccount();

            // Create the table client.
            Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            this.table = tableClient.GetTableReference("tagId");

            this.table.CreateIfNotExists();
        }
Beispiel #29
0
        public static CloudQueue GetQueue(string name)
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = GetStorageAccount();

            CloudQueueClient client = storageAccount.CreateCloudQueueClient();

            CloudQueue queue = client.GetQueueReference(name);

            queue.CreateIfNotExists();

            return(queue);
        }
Beispiel #30
0
        private static CloudBlobContainer GetBlobContainer(Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount)
        {
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container  = blobClient.GetContainerReference(new T().BlobContainer.ToString());

            container.CreateIfNotExistsAsync();
            container.SetPermissionsAsync(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });
            return(container);
        }
Beispiel #31
0
        public static CloudTable GetTable(string name)
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = GetStorageAccount();

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference(name);

            table.CreateIfNotExists();

            return(table);
        }
Beispiel #32
0
        public WordCountBolt()
        {
            name = (new Random(DateTime.Now.Millisecond)).Next();

            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = GetStorageAccount();

            // Create the table client.
            Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            this.table = tableClient.GetTableReference("wordcount");

            this.table.CreateIfNotExists();
        }
Beispiel #33
0
        private static CloudStorageAccount GetStorageAccountFromConfiguration(string name)
        {
            var storageAccountStr = StringHelper.FirstNonEmpty(
                () => CloudConfigurationManager.GetSetting(name),
                () => ConfigurationManager.ConnectionStrings[name].ConnectionString,
                () => ConfigurationManager.AppSettings[name],
                () => { throw new Exception("No storage connection string found."); });

            storageAccountStr = Regex.Replace(storageAccountStr, @"\s+", m => m.Value.Contains("\n") ? "" : m.Value);

            var storageAccount = CloudStorageAccount.Parse(storageAccountStr);

            return(storageAccount);
        }
Beispiel #34
0
        private static Microsoft.WindowsAzure.Storage.CloudStorageAccount GetStorageAccount()
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = null;

            if (RoleEnvironment.IsEmulated)
            {
                storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.DevelopmentStorageAccount;
            }
            else
            {
                // Retrieve the storage account from the connection string.
                storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));
            }
            return(storageAccount);
        }
Beispiel #35
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;
        }
Beispiel #36
0
    /// <summary>
    /// Copy the blobs to blob destination endpoint
    /// </summary>
    /// <param name="storageAccounts">storage accounts from where the blobs need to be migrated</param>
    public void CopyVMIndependentBlob(List<Azure.DataCenterMigration.Models.StorageAccount> storageAccounts)
    {
      string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
      ////Stopwatch for tracking time taken to copy all the storage accounts.
      Stopwatch swAllCopyStorageAccounts = new Stopwatch();
      swAllCopyStorageAccounts.Start();

      Parallel.ForEach(storageAccounts, storageAccount =>
      {
        string sourceStorageAccountName = GetSourceResourceName(ResourceType.StorageAccount, storageAccount.StorageAccountDetails.Name);
        string destStorageAccountName = GetDestinationResourceName(ResourceType.StorageAccount, sourceStorageAccountName);

        string sourceStorageAccountKey = GetStorageAccountKeysFromMSAzure(importParameters.SourceSubscriptionSettings.Credentials,
             sourceStorageAccountName).PrimaryKey;
        string destStorageAccountKey = GetStorageAccountKeysFromMSAzure(importParameters.DestinationSubscriptionSettings.Credentials,
           destStorageAccountName).PrimaryKey;

        var containers = storageAccount.Containers.ToList();
        ////Stopwatch for tracking time taken to copy all the blobs in each storage account.
        Stopwatch swCopyEachStorageAccount = new Stopwatch();
        swCopyEachStorageAccount.Start();

        BlobRequestOptions requestOptions = Retry.GetBlobRequestOptions(importParameters.DeltaBackOff, importParameters.RetryCount);
        foreach (var container in containers)
        {
          ////Stopwatch for tracking time taken to copy all the blobs in each container.
          Stopwatch swCopyContainer = new Stopwatch();
          swCopyContainer.Start();

          //// if the container has no blobs create the empty container
          if (container.BlobDetails.Count == 0)
          {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccountObj =
              new Microsoft.WindowsAzure.Storage.CloudStorageAccount(
                  new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(destStorageAccountName, destStorageAccountKey), true);

            CloudBlobClient cloudBlobClient = storageAccountObj.CreateCloudBlobClient();
            CloudBlobContainer emptyContainer = cloudBlobClient.GetContainerReference(container.ContainerName);

            if (!emptyContainer.Exists())
            {
              lock (thisLockContainer)
              {
                if (!emptyContainer.Exists())
                {
                  emptyContainer.Create();

                }
              }
            }
          }
          foreach (var item in container.BlobDetails.Where(a => ! a.IsExcluded && ! ExcludeVMVHDList.Contains(a.BlobURI)))
          {
            try
            {
              ////Stopwatch for tracking time taken to copy each blob
              Stopwatch swCopyEachBlob = new Stopwatch();
              swCopyEachBlob.Start();

              bool deletedPendingBlob = false;
              if (item.BlobType == BlobType.PageBlob.ToString())
              {
                //// get all details of destination blob.
                CloudPageBlob destBlob = GetCloudBlob(item.BlobName, container.ContainerName, destStorageAccountKey, destStorageAccountName, false);
                //// Check the status of blob if it is already present. Delete the blob if the status is pending.
                if (destBlob.Exists())
                {
                  CloudPageBlob destBlobInfo = (CloudPageBlob)destBlob.Container.GetBlobReferenceFromServer(item.BlobName);
                  if (destBlobInfo.CopyState.Status == CopyStatus.Pending)
                  {
                    Logger.Info(methodName, string.Format(ProgressResources.DeleteNonSuccessBlob, destBlobInfo.CopyState.Status),
                  ResourceType.Blob.ToString(), item.BlobName);
                    destBlobInfo.AbortCopy(destBlobInfo.CopyState.CopyId, null, requestOptions);
                    destBlobInfo.Delete(DeleteSnapshotsOption.IncludeSnapshots, null, requestOptions, null);
                    deletedPendingBlob = true;
                  }
                }

                if (!destBlob.Exists() || (deletedPendingBlob))
                {
                  Logger.Info(methodName, String.Format(ProgressResources.CopyBlobToDestinationStarted, container.ContainerName, item.BlobName, destStorageAccountName),
                    ResourceType.Blob.ToString(), item.BlobName);

                  //// get all details of source blob.
                  Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob sourceBlob = GetCloudBlob(item.BlobName, container.ContainerName,
                      sourceStorageAccountKey, sourceStorageAccountName, true);
                  destBlob = GetCloudBlob(item.BlobName, container.ContainerName, destStorageAccountKey, destStorageAccountName, false);

                  //// get Shared Access Signature for private containers.
                  var sas = sourceBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                  {
                    SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
                    SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7),
                    Permissions = SharedAccessBlobPermissions.Read,
                  });

                  var srcBlobSasUri = string.Format("{0}{1}", sourceBlob.Uri, sas);
                  string destUri = string.Format(Constants.StorageAccountMediaLink, destStorageAccountName, container.ContainerName, item.BlobName);

                  //// copy blob from source to destination.
                  string copyId = destBlob.StartCopyFromBlob(new Uri(srcBlobSasUri), null, null, requestOptions, null);

                  dcMigration.ReportProgress(string.Format(ProgressResources.BlobCopyStarted, item.BlobURI, destUri));
                  WaitForBlobCopy(destBlob.Container, item.BlobName, item.BlobType);

                }
              }
              else if (item.BlobType == BlobType.BlockBlob.ToString())
              {
                // get all details of destination blob.
                CloudBlockBlob destBlob = GetCloudBlockBlob(item.BlobName, container.ContainerName, destStorageAccountKey, destStorageAccountName, false);
                // Check the status of blob if it is already present. Delete the blob if the status is pending.
                if (destBlob.Exists())
                {
                  CloudBlockBlob destBlobInfo = (CloudBlockBlob)destBlob.Container.GetBlobReferenceFromServer(item.BlobName);
                  if (destBlobInfo.CopyState.Status == CopyStatus.Pending)
                  {
                    Logger.Info(methodName, string.Format(ProgressResources.DeleteNonSuccessBlob, destBlobInfo.CopyState.Status),
                    ResourceType.Blob.ToString(), item.BlobName);

                    destBlobInfo.AbortCopy(destBlobInfo.CopyState.CopyId, null, requestOptions);
                    destBlobInfo.Delete(DeleteSnapshotsOption.IncludeSnapshots, null, requestOptions, null);
                    deletedPendingBlob = true;
                  }
                }

                if (!destBlob.Exists() || (deletedPendingBlob))
                {
                  Logger.Info(methodName, String.Format(ProgressResources.CopyBlobToDestinationStarted, container.ContainerName, item.BlobName, destStorageAccountName),
                ResourceType.Blob.ToString(), item.BlobName);

                  // get all details of source blob.
                  Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob sourceBlob = GetCloudBlockBlob(item.BlobName, container.ContainerName,
                      sourceStorageAccountKey, sourceStorageAccountName, true);
                  destBlob = GetCloudBlockBlob(item.BlobName, container.ContainerName, destStorageAccountKey, destStorageAccountName, false);

                  // get Shared Access Signature for private containers.
                  var sas = sourceBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                  {
                    SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
                    SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7),
                    Permissions = SharedAccessBlobPermissions.Read,
                  });

                  var srcBlobSasUri = string.Format("{0}{1}", sourceBlob.Uri, sas);
                  string destUri = string.Format(Constants.StorageAccountMediaLink, destStorageAccountName, container.ContainerName, item.BlobName);

                  // copy blob from source to destination.
                  string copyId = destBlob.StartCopyFromBlob(new Uri(srcBlobSasUri), null, null, requestOptions, null);

                  dcMigration.ReportProgress(string.Format(ProgressResources.BlobCopyStarted, item.BlobURI, destUri));
                  WaitForBlobCopy(destBlob.Container, item.BlobName, item.BlobType);

                }
              }
              swCopyEachBlob.Stop();
              Logger.Info(methodName, string.Format(ProgressResources.ExecutionCompletedWithTime, swCopyEachBlob.Elapsed.Days, swCopyEachBlob.Elapsed.Hours,
                  swCopyEachBlob.Elapsed.Minutes, swCopyEachBlob.Elapsed.Seconds), ResourceType.Blob.ToString());
            }
            catch (AggregateException exAgg)
            {
              foreach (var ex in exAgg.InnerExceptions)
              {
                Logger.Error(methodName, exAgg, ResourceType.StorageAccount.ToString(), item.BlobName);
              }
              throw;
            }
            catch (Exception ex)
            {
              Logger.Error(methodName, ex, ResourceType.StorageAccount.ToString(), item.BlobName);
              throw;
            }
          }
          swCopyContainer.Stop();
          Logger.Info(methodName, string.Format(ProgressResources.ExecutionCompletedWithTime, swCopyContainer.Elapsed.Days, swCopyContainer.Elapsed.Hours,
              swCopyContainer.Elapsed.Minutes, swCopyContainer.Elapsed.Seconds), ResourceType.Blob.ToString());
        }

        swCopyEachStorageAccount.Stop();
        Logger.Info(methodName, string.Format(ProgressResources.ExecutionCompletedWithTime, swCopyEachStorageAccount.Elapsed.Days, swCopyEachStorageAccount.Elapsed.Hours,
              swCopyEachStorageAccount.Elapsed.Minutes, swCopyEachStorageAccount.Elapsed.Seconds), ResourceType.Blob.ToString());

      });

      swAllCopyStorageAccounts.Stop();
      Logger.Info(methodName, string.Format(ProgressResources.ExecutionCompletedWithTime, swAllCopyStorageAccounts.Elapsed.Days, swAllCopyStorageAccounts.Elapsed.Hours,
            swAllCopyStorageAccounts.Elapsed.Minutes, swAllCopyStorageAccounts.Elapsed.Seconds), ResourceType.Blob.ToString());

    }
Beispiel #37
0
        /// <summary>
        /// Used to pull back the cloud blob that should be copied from or to
        /// </summary>
        /// <param name="blobName">blob name</param>
        /// <param name="containerName">container name</param>
        /// <param name="storageKey">storage key</param>
        /// <param name="storageAccountName">storage account name</param>
        /// <param name="sourceSubscription">true if it is getting blob value for source subscription</param>
        /// <returns>the cloud blob that should be copied from or to</returns>
        private CloudPageBlob GetCloudBlob(string blobName, string containerName, string storageKey,
            string storageAccountName, bool sourceSubscription)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            Logger.Info(methodName, string.Format(ProgressResources.GetCloudBlobStarted, blobName, storageAccountName),
                ResourceType.Blob.ToString(), blobName);

            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount =
                new Microsoft.WindowsAzure.Storage.CloudStorageAccount(
                    new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccountName, storageKey), true);
            CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

            CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerName);
            if (!container.Exists() && sourceSubscription == false)
            {
                lock (thisLockContainer)
                {
                    if (!container.Exists())
                    {
                        container.Create();
                    }
                }
            }
            Logger.Info(methodName, string.Format(ProgressResources.CloudBlobInfoRecieved, blobName, storageAccountName),
                ResourceType.Blob.ToString(), blobName);
            return (container.GetPageBlobReference(blobName));
        }
Beispiel #38
0
        /// <summary>
        /// Exports the list of containers in a given storage account
        /// </summary>
        /// <param name="account">Storage account to get the name and key of the storage account whose blobs are to be exported</param>
        /// <returns>List of storage account containers</returns>
        private List<Container> ExportStorageAccountContainers(Microsoft.WindowsAzure.Management.Storage.Models.StorageAccount account)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            List<Container> containers = new List<Container>();
            try
            {
                string srcStorageAccountKey = GetStorageAccountKeysFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, account.Name).PrimaryKey;

                Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount =
                           new Microsoft.WindowsAzure.Storage.CloudStorageAccount(
                               new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(account.Name, srcStorageAccountKey), true);
                CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

                foreach (var item in cloudBlobClient.ListContainers())
                {

                    List<Blob> blobs = new List<Blob>();
                    containers.Add(new Container
                    {
                        ContainerName = item.Name,
                        BlobDetails = ExportBlobs(item.ListBlobs(null, false), blobs)
                    });
                }

                return containers;
            }
            catch (Exception ex)
            {
                Logger.Error(methodName, ex);
                throw;
            }
        }