/// <summary> /// create a container with random properties and metadata /// </summary> /// <param name="containerName">container name</param> /// <returns>the created container object with properties and metadata</returns> public StorageBlob.CloudBlobContainer CreateContainer(string containerName = "") { if (String.IsNullOrEmpty(containerName)) { containerName = Utility.GenNameString("container"); } StorageBlob.CloudBlobContainer container = client.GetContainerReference(containerName); container.CreateIfNotExists(); //there is no properties to set container.FetchAttributes(); int minMetaCount = 1; int maxMetaCount = 5; int minMetaValueLength = 10; int maxMetaValueLength = 20; int count = random.Next(minMetaCount, maxMetaCount); for (int i = 0; i < count; i++) { string metaKey = Utility.GenNameString("metatest"); int valueLength = random.Next(minMetaValueLength, maxMetaValueLength); string metaValue = Utility.GenNameString("metavalue-", valueLength); container.Metadata.Add(metaKey, metaValue); } container.SetMetadata(); Test.Info(string.Format("create container '{0}'", containerName)); return(container); }
/// <summary> /// Default constructor. /// </summary> public AzureMediaProvider() { var config = GetConfig() ; account = CloudStorageAccount.Parse(config.Settings.StorageConnectionString.Value) ; client = account.CreateCloudBlobClient() ; mediaContainer = client.GetContainerReference("media") ; mediaContainer.CreateIfNotExists() ; uploadContainer = client.GetContainerReference("uploads") ; uploadContainer.CreateIfNotExists() ; }
public WebJobsStorageAccount(string connectionString) { if (string.IsNullOrWhiteSpace(connectionString)) { throw new InvalidOperationException("connectionString"); } _connectionString = connectionString; _storageAccount = CloudStorageAccount.Parse(connectionString); _blobClient = _storageAccount.CreateCloudBlobClient(); _dashboardContainer = _blobClient.GetContainerReference(DashboardContainerName); _hostsContainer = _blobClient.GetContainerReference(HostsContainerName); }
/// <summary> /// Recursively upload everything in the remote directory. /// </summary> /// <param name="localDirectory"></param> /// <param name="remoteContainerPath"></param> /// <param name="client"></param> /// <returns></returns> private async Task UploadFilesOfDirectory(string localDirectory, string remoteContainerPath, CloudBlobClient client, IEnumerable<string> skipDirectories) { Console.WriteLine(""); Console.WriteLine("Uploading files from " + localDirectory + "..."); CloudBlobContainer container; string filePrefix = ""; if (remoteContainerPath.Contains("/")) { string[] directoryStructure = remoteContainerPath.Split('/'); container = client.GetContainerReference(directoryStructure[0]); filePrefix = string.Join("/", directoryStructure.Skip(1)); } else { container = client.GetContainerReference(remoteContainerPath); try { await container.CreateIfNotExistsAsync(); await container.SetPermissionsAsync(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob }); } catch (Exception ex) { Console.WriteLine(string.Format("Exception configuring container. {0} may be an illegal name. \n Message: {1}. \n Inner exception: {2}. \n\n Press any key to exit.", remoteContainerPath, ex.Message, ex.InnerException)); } } DirectoryInfo local = new DirectoryInfo(localDirectory); List<Task> uploads = new List<Task>(); foreach (FileInfo file in local.GetFiles()) { uploads.Add(ProcessAndUploadFile(file, container, filePrefix)); } if (uploads.Count() > 0) { await Task.WhenAll(uploads); } foreach (DirectoryInfo child in local.GetDirectories()) { //if (!skipDirectories.Contains(child.Name)) //{ string nextContainer = remoteContainerPath.Contains("$root") ? child.Name : remoteContainerPath + "/" + child.Name; await UploadFilesOfDirectory(child.FullName, nextContainer, client, skipDirectories); //} } return; }
public CloudBlobContainer GetBlobContainer(string container) { Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse( StorageConnectionString); ServicePoint tableServicePoint = ServicePointManager.FindServicePoint(storageAccount.TableEndpoint); tableServicePoint.UseNagleAlgorithm = false; Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. CloudBlobContainer blobContainer = blobClient.GetContainerReference(container); // Create the container if it doesn't already exist. blobContainer.CreateIfNotExistsAsync().Wait(); blobContainer.SetPermissionsAsync( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }).Wait(); return(blobContainer); }
public ImageStore() { _client = Account.CreateCloudBlobClient(); _container = _client.GetContainerReference(ContainerName); _container.CreateIfNotExists(BlobContainerPublicAccessType.Blob); }
public AzureBlobController() { var credentials = new StorageCredentials(ConfigurationManager.AppSettings["AzureAccountName"], ConfigurationManager.AppSettings["AzureKeyValue"]); var azureBlobUri = new Uri("https://" + ConfigurationManager.AppSettings["AzureAccountName"] + ".blob.core.windows.net"); var client = new CloudBlobClient(azureBlobUri, credentials); _container = client.GetContainerReference(TestContainerName); }
public HomeController() { storageAccount = CloudStorageAccount.Parse( ConfigurationManager.AppSettings["StorageConnectionString"]); tableClient = storageAccount.CreateCloudTableClient(); table = tableClient.GetTableReference("fouramigos"); table.CreateIfNotExists(); blobClient = storageAccount.CreateCloudBlobClient(); container = blobClient.GetContainerReference("fouramigos"); container.CreateIfNotExists(); BlobContainerPermissions permissions = container.GetPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Container; container.SetPermissions(permissions); //lägga till nya //var tablemodels = new TableModel("Brutus", "Uggla") { Location = "T4", Description="Uggla i träd", Type="Foto" }; //var tablemodels1 = new TableModel("brutus", "Örn") { Location = "T4", Description="Örn som flyger", Type = "Foto" }; //var opreation = TableOperation.Insert(tablemodels); //var operation2 = TableOperation.Insert(tablemodels1); //table.Execute(opreation); //table.Execute(operation2); }
internal void UploadFromString(string accountName, string accountKey, string containerName, string fileName, string sourceFileName, string fileContentType, string content) //, string name, string fileDescription) { { Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse( string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};BlobEndpoint=https://{0}.blob.core.windows.net/", accountName, accountKey) ); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference(containerName); container.CreateIfNotExists(); string ext = System.IO.Path.GetExtension(sourceFileName); //string fileName = String.Format( Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); blockBlob.Properties.ContentType = fileContentType; //blockBlob.Metadata.Add("name", name); blockBlob.Metadata.Add("originalfilename", sourceFileName); //blockBlob.Metadata.Add("userid", userId.ToString()); //blockBlob.Metadata.Add("ownerid", userId.ToString()); DateTime created = DateTime.UtcNow; // https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx // http://stackoverflow.com/questions/114983/given-a-datetime-object-how-do-i-get-a-iso-8601-date-in-string-format //blockBlob.Metadata.Add("username", userName); blockBlob.Metadata.Add("created", created.ToString("yyyy-MM-ddTHH:mm:ss")); // "yyyy-MM-ddTHH:mm:ssZ" blockBlob.Metadata.Add("modified", created.ToString("yyyy-MM-ddTHH:mm:ss")); // "yyyy-MM-ddTHH:mm:ssZ" blockBlob.Metadata.Add("fileext", ext); blockBlob.UploadText(content, Encoding.UTF8); // .UploadFromStream(fileInputStream); blockBlob.SetMetadata(); }
public BlobManager(){ try { storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString")); blobClient = storageAccount.CreateCloudBlobClient(); container = blobClient.GetContainerReference("supstorage"); container.CreateIfNotExists(); } catch (ArgumentNullException) { Trace.TraceInformation("CloudStorageAccount Exception null ou vide"); // Use Application Local Storage Account String } catch (NullReferenceException) { Trace.TraceInformation("CloudBlobClient Or CloudBlobContainer Exception"); // Create Container } catch (FormatException) { Trace.TraceInformation("CloudStorageAccount Exception Connection String Invalid"); } catch (ArgumentException) { Trace.TraceInformation("CloudStorageAccount Exception connectionString ne peut pas être analysée"); } }
protected void Page_Load(object sender, EventArgs e) { //--Connection String -- //storage account CloudStorageAccount objStorage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString")); // get the Client reference using storage blob end point CloudBlobClient objClient = new CloudBlobClient(objStorage.BlobEndpoint, objStorage.Credentials); // Get Container reference CloudBlobContainer blobContainer = objClient.GetContainerReference("mycontainer"); // Create the container if it does not exist blobContainer.CreateIfNotExists(); //set public permission blobContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); //list blobs in the container IEnumerable<IListBlobItem> objBlobList = blobContainer.ListBlobs(); foreach (IListBlobItem objItem in objBlobList) { Response.Write("<img src='" + objItem.Uri + "'/>"); Response.Write("<br>"); } }
private void Init() { var connectionString = ConfigurationManager.ConnectionStrings["BlobStorage"].ConnectionString; var storageAccount = CloudStorageAccount.Parse(connectionString); _blobClient = storageAccount.CreateCloudBlobClient(); _blobContainer = _blobClient.GetContainerReference(ConfigurationManager.AppSettings["PhotoContainer"]); }
/// <summary> /// Upload the generated receipt Pdf to Blob storage. /// </summary> /// <param name="file">Byte array containig the Pdf file contents to be uploaded.</param> /// <param name="fileName">The desired filename of the uploaded file.</param> /// <returns></returns> public string UploadPdfToBlob(byte[] file, string fileName) { // Create the blob client. blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. blobContainer = blobClient.GetContainerReference(receiptBlobName); // Create the container if it doesn't already exist. blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob); string fileUri = string.Empty; CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileName); using (var stream = new MemoryStream(file)) { // Upload the in-memory Pdf file to blob storage. blockBlob.UploadFromStream(stream); } fileUri = blockBlob.Uri.ToString(); return fileUri; }
public async Task LocationModeWithMissingUriAsync() { AssertSecondaryEndpoint(); CloudBlobClient client = GenerateCloudBlobClient(); CloudBlobClient primaryOnlyClient = new CloudBlobClient(client.BaseUri, client.Credentials); CloudBlobContainer container = primaryOnlyClient.GetContainerReference("nonexistingcontainer"); BlobRequestOptions options = new BlobRequestOptions() { LocationMode = LocationMode.SecondaryOnly, RetryPolicy = new NoRetry(), }; Exception e = await TestHelper.ExpectedExceptionAsync<Exception>( async () => await container.FetchAttributesAsync(null, options, null), "Request should fail when an URI is not provided for the target location"); Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException)); options.LocationMode = LocationMode.SecondaryThenPrimary; e = await TestHelper.ExpectedExceptionAsync<Exception>( async () => await container.FetchAttributesAsync(null, options, null), "Request should fail when an URI is not provided for the target location"); Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException)); options.LocationMode = LocationMode.PrimaryThenSecondary; e = await TestHelper.ExpectedExceptionAsync<Exception>( async () => await container.FetchAttributesAsync(null, options, null), "Request should fail when an URI is not provided for the target location"); Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException)); }
public virtual Uri UploadFile( string storageName, Uri blobEndpointUri, string storageKey, string filePath, BlobRequestOptions blobRequestOptions) { StorageCredentials credentials = new StorageCredentials(storageName, storageKey); CloudBlobClient client = new CloudBlobClient(blobEndpointUri, credentials); string blobName = string.Format( CultureInfo.InvariantCulture, "{0}_{1}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture), Path.GetFileName(filePath)); CloudBlobContainer container = client.GetContainerReference(ContainerName); container.CreateIfNotExists(); CloudBlockBlob blob = container.GetBlockBlobReference(blobName); BlobRequestOptions uploadRequestOption = blobRequestOptions ?? new BlobRequestOptions(); if (!uploadRequestOption.ServerTimeout.HasValue) { uploadRequestOption.ServerTimeout = TimeSpan.FromMinutes(300); } using (FileStream readStream = File.OpenRead(filePath)) { blob.UploadFromStream(readStream, AccessCondition.GenerateEmptyCondition(), uploadRequestOption); } return new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}", client.BaseUri, ContainerName, client.DefaultDelimiter, blobName)); }
public BlobContainer(string name) { // hämta connectionsträngen från config // RoleEnviroment bestämmer settingvalue runtime //var connectionString = RoleEnvironment.GetConfigurationSettingValue("PhotoAppStorage"); //var connectionString = CloudConfigurationManager.GetSetting("CloudStorageApp"); // hämtar kontot utfrån connectionsträngens värde //var account = CloudStorageAccount.Parse(connectionString); //var account = CloudStorageAccount.DevelopmentStorageAccount; var cred = new StorageCredentials("jholm", "/bVipQ2JxjWwYrZQfHmzhaBx1p1s8BoD/wX6VWOmg4/gpVo/aALrjsDUKqzXsFtc9utepPqe65NposrXt9YsyA=="); var account = new CloudStorageAccount(cred, true); // skapar en blobclient _client = account.CreateCloudBlobClient(); m_BlobContainer = _client.GetContainerReference(name); // Om det inte finns någon container med det namnet if (!m_BlobContainer.Exists()) { // Skapa containern m_BlobContainer.Create(); var permissions = new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob }; // Sätter public access till blobs m_BlobContainer.SetPermissions(permissions); } }
/// <summary> /// Constructor /// </summary> /// <param name="blobClient">use BlobConn to get blobClient</param> /// <param name="clientContainerName">This should be the ID of the User</param> /// <returns></returns> public Blob(CloudBlobClient blobClient, string clientContainerName) { //Get a reference to a container and create container for first time use user container = blobClient.GetContainerReference(clientContainerName); container.CreateIfNotExists(); indicator = "OK"; }
public StorageHelper() { _adminuser = "******"; _standarduser = "******"; try { var connstring = ConfigurationManager.AppSettings["AzureStorage"]; var acct = CloudStorageAccount.Parse(connstring); client = acct.CreateCloudBlobClient(); var dir = client.GetContainerReference("studentconnect"); var adminpwd = dir.GetBlobReferenceFromServer("_adminpassword"); // If you get a 403 - Forbidden warning here, its because you dont have access to SD's Azure Storage account. // Get your own FREE here. http://www.windowsazure.com/en-us/pricing/free-trial/ var adminpwdText = adminpwd.DownloadText(); var schoolsRef = dir.GetBlobReferenceFromServer("_schools"); var schoolsText = schoolsRef.DownloadText(); _adminpassword = adminpwdText; _schools = this.ParseSchoolText(schoolsText); } finally { } }
/// <summary> /// Occurs when a storage provider operation has completed. /// </summary> //public event EventHandler<StorageProviderEventArgs> StorageProviderOperationCompleted; #endregion // Initialiser method private void Initialise(string storageAccount, string containerName) { if (String.IsNullOrEmpty(containerName)) throw new ArgumentException("You must provide the base Container Name", "containerName"); ContainerName = containerName; _account = CloudStorageAccount.Parse(storageAccount); _blobClient = _account.CreateCloudBlobClient(); _container = _blobClient.GetContainerReference(ContainerName); try { _container.FetchAttributes(); } catch (StorageException) { Trace.WriteLine(string.Format("Create new container: {0}", ContainerName), "Information"); _container.Create(); // set new container's permissions // Create a permission policy to set the public access setting for the container. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // The public access setting explicitly specifies that the container is private, // so that it can't be accessed anonymously. containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off; //Set the permission policy on the container. _container.SetPermissions(containerPermissions); } }
public BlobFileProvider(IEnumerable<string> locations) : base() { _storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString); _blobClient = _storageAccount.CreateCloudBlobClient(); _container = _blobClient.GetContainerReference("data"); _container.CreateIfNotExists(); _strings = new List<string>(); foreach(string location in locations) { foreach (IListBlobItem item in _container.ListBlobs(location,true)) { if (item.GetType() == typeof(CloudBlockBlob)) { CloudBlockBlob blob = (CloudBlockBlob)item; string text; using (var memoryStream = new MemoryStream()) { blob.DownloadToStream(memoryStream); text = Encoding.UTF8.GetString(memoryStream.ToArray()); if (text[0] == _byteOrderMarkUtf8[0]) { text= text.Remove(0,_byteOrderMarkUtf8.Length); } _strings.Add(text); } } } } }
private static async Task<CloudBlockBlob> CreateBlockBlob(CloudBlobClient client, string containerName, string title) { var container = client.GetContainerReference(containerName); await container.CreateIfNotExistsAsync(); await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); return container.GetBlockBlobReference(title); }
public void CloudBlobClientWithUppercaseAccountName() { StorageCredentials credentials = new StorageCredentials(TestBase.StorageCredentials.AccountName.ToUpper(), TestBase.StorageCredentials.ExportKey()); Uri baseAddressUri = new Uri(TestBase.TargetTenantConfig.BlobServiceEndpoint); CloudBlobClient blobClient = new CloudBlobClient(baseAddressUri, TestBase.StorageCredentials); CloudBlobContainer container = blobClient.GetContainerReference("container"); container.Exists(); }
public AzureStorageService() { var connstring = ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString; this.storageAccount = CloudStorageAccount.Parse(connstring); this.blobClient = storageAccount.CreateCloudBlobClient(); this.container = blobClient.GetContainerReference("app-icons"); }
public async Task CloudBlobClientWithUppercaseAccountNameAsync() { StorageCredentials credentials = new StorageCredentials(TestBase.StorageCredentials.AccountName.ToUpper(), Convert.ToBase64String(TestBase.StorageCredentials.ExportKey())); Uri baseAddressUri = new Uri(TestBase.TargetTenantConfig.BlobServiceEndpoint); CloudBlobClient blobClient = new CloudBlobClient(baseAddressUri, TestBase.StorageCredentials); CloudBlobContainer container = blobClient.GetContainerReference("container"); await container.ExistsAsync(); }
public StoreEventProcessor() { var storageAccount = CloudStorageAccount.Parse(StorageConnectionString); blobClient = storageAccount.CreateCloudBlobClient(); blobContainer = blobClient.GetContainerReference("d2ctutorial"); blobContainer.CreateIfNotExists(); queueClient = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, "d2ctutorial"); }
public UpgradeIndexer(IPersistentQueueReader<PersistentQueueMessage> queueReader, IHostIndexer hostIndexer, IFunctionIndexer functionIndexer, IIndexerLogWriter logWriter, IDashboardVersionManager dashboardVersionReader, CloudBlobClient client) : base(queueReader, hostIndexer, functionIndexer, logWriter) { _dashboardVersionManager = dashboardVersionReader; _client = client; _functionsStore = ConcurrentTextStore.CreateBlobStore(_client, DashboardContainerNames.Dashboard, DashboardDirectoryNames.FunctionsFlat); _logsStore = ConcurrentTextStore.CreateBlobStore(_client, DashboardContainerNames.Dashboard, DashboardDirectoryNames.Logs); // From archive back to output _upgradeQueueReader = new PersistentQueueReader<PersistentQueueMessage>(client.GetContainerReference(ContainerNames.HostArchive), client.GetContainerReference(ContainerNames.HostOutput)); }
public CloudBlobManager(CloudBlobClient blobClient, string containerName, BlobContainerPublicAccessType containerAccess = BlobContainerPublicAccessType.Off) { BlobClient = blobClient; var container = blobClient.GetContainerReference(containerName); container.CreateIfNotExists(); Container = container; SetPublicAccess(containerAccess); }
public EventsService() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["pocketDDDCloudStorage"].ConnectionString); blobClient = storageAccount.CreateCloudBlobClient(); eventsContainer = blobClient.GetContainerReference("events"); tableClient = storageAccount.CreateCloudTableClient(); eventsTable = tableClient.GetTableReference("events"); }
public SKSEventProcessor() { var storageAccount = CloudStorageAccount.Parse(StorageConnectionString); blobClient = storageAccount.CreateCloudBlobClient(); blobContainer = blobClient.GetContainerReference("d2ctutorial"); blobContainer.CreateIfNotExists(); queueClient = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, ConfigurationManager.AppSettings["serviceBusQueueName"]); }
static void Main(string[] args) { var accountName = args[0]; var accountKey = args[1]; var GifsDir = args[2]; storageAccount = CloudStorageAccount.Parse(String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",accountName,accountKey)); // Create the blob client. CloudBlobClient blobClient = new CloudBlobClient (storageAccount.BlobEndpoint, storageAccount.Credentials); // Create blob container if it doesn't exist. CloudBlobContainer blobContainer = blobClient.GetContainerReference("memes"); blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Container); // Create the table client. CloudTableClient tableClient = new Microsoft.WindowsAzure.Storage.Table.CloudTableClient(storageAccount.TableEndpoint, storageAccount.Credentials); // Create the table if it doesn't exist. CloudTable table = tableClient.GetTableReference("MemeMetadata"); var statusTable = table.CreateIfNotExists(); var list = new List<ClipMemeEntity> { new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200312-horse-cannon.gif", BlobName = "20140401-200312-horse-cannon.gif", Description = "Deploy", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200344-updated-visual-studio-theme.gif", BlobName = "20140401-200344-updated-visual-studio-theme.gif", Description = "News vs Theme", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200447-oops.gif", BlobName = "20140401-200447-oops.gif", Description = "First Iteration", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200534-just-learned-about-git-rebase.gif", BlobName = "20140401-200534-just-learned-about-git-rebase.gif", Description = "Tests Pass on First Try", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200606-when-i-unstash-something.gif", BlobName = "20140401-200606-when-i-unstash-something.gif", Description = "Scale up", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200750-dog-race.gif", BlobName = "20140401-200750-dog-race.gif", Description = "Sprint", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200800-cookies.gif", BlobName = "20140401-200800-cookies.gif", Description = "Scottgu Promoted", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200849-when-i-merge-my-own-pull-requests.gif", BlobName = "20140401-200849-when-i-merge-my-own-pull-requests.gif", Description = "to the cloud", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-200924-disco-girl.gif", BlobName = "20140401-200924-disco-girl.gif", Description = "Hanseldance", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-201030-when-someone-merges-your-pull-request-before-its-ready.gif", BlobName = "20140401-201030-when-someone-merges-your-pull-request-before-its-ready.gif", Description = "accidental git push", Username = "******" }, new ClipMemeEntity { BlobUri = "https://clipmeme2014.blob.core.windows.net/memes/20140401-201102-Fat-Dance-Suit-Men-Rave-On-At-Home.gif", BlobName = "20140401-201102-Fat-Dance-Suit-Men-Rave-On-At-Home.gif", Description = "msft at $40", Username = "******" } }; foreach (var item in list) { // Retrieve reference to a blob CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(item.BlobName); using (var fileStream = System.IO.File.OpenRead(String.Format("{0}\\{1}",GifsDir,item.BlobName))) { blockBlob.UploadFromStream(fileStream); } var requestOptions = new Microsoft.WindowsAzure.Storage.Table.TableRequestOptions() { RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromMilliseconds(500), 5) }; table.Execute(Microsoft.WindowsAzure.Storage.Table.TableOperation.Insert(item), requestOptions); } return; }
public AuthHelpers(IAppConfig appConfig) { _appConfig = appConfig; storageAccount = CloudStorageAccount.Parse(appConfig.StorageConnectionString); blobClient = storageAccount.CreateCloudBlobClient(); container = blobClient.GetContainerReference("apipersistenace"); container.CreateIfNotExists(); Blob = container.GetBlockBlobReference("tenantId"); }
protected void Page_Load(object sender, EventArgs e) { CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("arailproject", "zSU2JysKO4g0NmCmVSu3vsFUGnvcm8d4WsDhkNgQVVtPCyXfQprTQBWfzh72zu89Hq8vKT6v6XUZpotPTL39CQ=="), true); string projectattachments = ConfigurationManager.AppSettings["StorageConnectionString"]; Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("projectattachments"); container.CreateIfNotExists(); }
public Blob(string containerName) { _storageAccount = Account.Get(); _blobClient = _storageAccount.CreateCloudBlobClient(); _blobContainer = _blobClient.GetContainerReference(containerName); _blobContainer.CreateIfNotExists(); }
public AzureBlobVirtualPathProvider(CloudStorageAccount storageAccount, string containerName, IAppHost appHost) : base(appHost) { this.StorageAccount = storageAccount; this.client = storageAccount.CreateCloudBlobClient(); this.Container = client.GetContainerReference(containerName); this.Container.CreateIfNotExists(); this.rootDirectory = new AzureBlobVirtualDirectory(this, null); }
public string DownloadPublicBlob(string UserId, string BlobName, bool PublicAccess = true) { //Retrieve a reference to a container. //Retrieve storage account from connection string. Microsoft.WindowsAzure.Storage.CloudStorageAccount StorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Convert.ToString(ConfigurationManager.AppSettings["StorageConnectionString"])); // Create the blob client. Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference(UserId); // Create the container if it doesn't exist. container.CreateIfNotExists(); //Set permission to public if (PublicAccess) { container.SetPermissions( new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions { PublicAccess = Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob }); } else { container.SetPermissions( new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions { PublicAccess = Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Off }); } // Retrieve reference to a blob named Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blockBlob = container.GetBlockBlobReference(BlobName); //var sasToken = blockBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy() //{ // Permissions = SharedAccessBlobPermissions.Read, // SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),//assuming the blob can be downloaded in 10 miinutes //}, new SharedAccessBlobHeaders() //{ // ContentDisposition = "attachment; filename=file-name" //}); //return string.Format("{0}{1}", blockBlob.Uri, sasToken); return(blockBlob.Uri.ToString()); }
private void LogError(Exception ex, string message) { //ConfigurationManager.ConnectionStrings["CineStorageConStr"].ConnectionString Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr")); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data"); Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob logBlob = container.GetBlockBlobReference(String.Format(this.LogFile, DateTime.UtcNow.ToString("dd MMM yyyy"))); try { using (StreamReader sr = new StreamReader(logBlob.OpenRead())) { using (StreamWriter sw = new StreamWriter(logBlob.OpenWrite())) { sw.Write(sr.ReadToEnd()); if (ex != null) { sw.Write(System.Environment.NewLine); sw.WriteLine(ex.Message); sw.WriteLine(ex.StackTrace); sw.Write(System.Environment.NewLine); if (ex.InnerException != null) { sw.Write(System.Environment.NewLine); sw.WriteLine(ex.InnerException.Message); sw.WriteLine(ex.InnerException.StackTrace); sw.Write(System.Environment.NewLine); } } if (message != null) { sw.Write(System.Environment.NewLine); sw.WriteLine(message); sw.Write(System.Environment.NewLine); } } } } catch { } }
private CloudBlobContainer GetContainer() { var client = new Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient( new Uri(ConfigurationManager.AppSettings[@"blobUrl"]), new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials( ConfigurationManager.AppSettings[@"storageAccount"], ConfigurationManager.AppSettings[@"storageKey"])); var c = client.GetContainerReference(@"images"); c.CreateIfNotExists(BlobContainerPublicAccessType.Blob); return(c); }
private DateTime GetLastModified() { Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr")); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data"); // Retrieve reference to a blob. Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemasUKBlob = container.GetBlockBlobReference(CinemasUKFileName); if (cinemasUKBlob.Exists()) { DateTimeOffset?dto = cinemasUKBlob.Properties.LastModified; if (dto.HasValue) { return(dto.Value.DateTime); } } return(DateTime.MinValue); }
//Retrieve Blob Container public Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer GetCloudBlobContainer(string ContainerName, Boolean PublicAccess = false) { // Retrieve storage account from connection string. Microsoft.WindowsAzure.Storage.CloudStorageAccount StorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Convert.ToString(ConfigurationManager.AppSettings["StorageConnectionString"])); // Create the blob client. Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); // Create the container if it doesn't exist. container.CreateIfNotExists(); //Set permission to public if (PublicAccess) { container.SetPermissions( new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions { PublicAccess = Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob }); } else { container.SetPermissions( new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions { PublicAccess = Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Off }); } return(container); }
public string DownloadSharedBlob(string UserId, string BlobName) { //Retrieve storage account from connection string. Microsoft.WindowsAzure.Storage.CloudStorageAccount StorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Convert.ToString(ConfigurationManager.AppSettings["StorageConnectionString"])); // Create the blob client. Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference(UserId); var blob = container.GetBlockBlobReference(BlobName); var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(15), }, new SharedAccessBlobHeaders() { ContentDisposition = "attachment; filename=\"somefile.pdf\"", }); var downloadUrl = string.Format("{0}{1}", blob.Uri.AbsoluteUri, sasToken); return(downloadUrl); }
public static Tuple <bool, List <string> > listHubs(string account, string accountKey, string orgID, string studyID) { try { CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(account, accountKey), true); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer storageContainer = blobClient.GetContainerReference(AzureConfigContainerName); List <String> hubList = lsDirectory(storageContainer.ListBlobs(), "/" + orgID + "/" + studyID + "/"); return(new Tuple <bool, List <string> >(true, hubList)); } catch (Exception e) { return(new Tuple <bool, List <string> >(false, new List <string>() { e.Message })); } }
public void CloudBlobClientListBlobsSegmentedWithPrefixAPM() { string name = "bb" + GetRandomContainerName(); CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer rootContainer = blobClient.GetRootContainerReference(); CloudBlobContainer container = blobClient.GetContainerReference(name); try { rootContainer.CreateIfNotExists(); container.Create(); List <string> blobNames = CreateBlobs(container, 3, BlobType.BlockBlob); List <string> rootBlobNames = CreateBlobs(rootContainer, 2, BlobType.BlockBlob); using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { IAsyncResult result; BlobResultSegment results; BlobContinuationToken token = null; do { result = blobClient.BeginListBlobsSegmented("bb", token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); results = blobClient.EndListBlobsSegmented(result); token = results.ContinuationToken; foreach (CloudBlockBlob blob in results.Results) { blob.Delete(); rootBlobNames.Remove(blob.Name); } }while (token != null); Assert.AreEqual(0, rootBlobNames.Count); result = blobClient.BeginListBlobsSegmented("bb", token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); results = blobClient.EndListBlobsSegmented(result); Assert.AreEqual(0, results.Results.Count()); Assert.IsNull(results.ContinuationToken); result = blobClient.BeginListBlobsSegmented(name, token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); results = blobClient.EndListBlobsSegmented(result); Assert.AreEqual(0, results.Results.Count()); Assert.IsNull(results.ContinuationToken); token = null; do { result = blobClient.BeginListBlobsSegmented(name + "/", token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); results = blobClient.EndListBlobsSegmented(result); token = results.ContinuationToken; foreach (CloudBlockBlob blob in results.Results) { Assert.IsTrue(blobNames.Remove(blob.Name)); } }while (token != null); Assert.AreEqual(0, blobNames.Count); } } finally { container.DeleteIfExists(); } }
private async Task <(bool, string)> UploadToBlob(string filename, byte[] imageBuffer = null, Stream stream = null) { Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = null; Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer cloudBlobContainer = null; string storageConnectionString = _configuration["storageconnectionstring"]; // Check whether the connection string can be parsed. if (Microsoft.WindowsAzure.Storage.CloudStorageAccount.TryParse(storageConnectionString, out storageAccount)) { try { // Create the CloudBlobClient that represents the Blob storage endpoint for the storage account. Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); // Create a container called 'uploadblob' and append a GUID value to it to make the name unique. cloudBlobContainer = cloudBlobClient.GetContainerReference("womeninworkforce");// ("uploadblob" + Guid.NewGuid().ToString()); await cloudBlobContainer.CreateIfNotExistsAsync(); // Set the permissions so the blobs are public. BlobContainerPermissions permissions = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }; await cloudBlobContainer.SetPermissionsAsync(permissions); // Get a reference to the blob address, then upload the file to the blob. CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(filename); List <Task> tasks = new List <Task>(); int count = 0; if (imageBuffer != null) { // OPTION A: use imageBuffer (converted from memory stream) await cloudBlockBlob.UploadFromByteArrayAsync(imageBuffer, 0, imageBuffer.Length); //tasks.Add(cloudBlockBlob.UploadFromByteArrayAsync(imageBuffer, 0, options, null).ContinueWith((t) => //{ // sem.Release(); // Interlocked.Increment(ref completed_count); //})); //count++; } else if (stream != null) { // OPTION B: pass in memory stream directly await cloudBlockBlob.UploadFromStreamAsync(stream); } else { return(false, null); } return(true, cloudBlockBlob.SnapshotQualifiedStorageUri.PrimaryUri.ToString()); } catch (Microsoft.WindowsAzure.Storage.StorageException ex) { return(false, null); } finally { // OPTIONAL: Clean up resources, e.g. blob container //if (cloudBlobContainer != null) //{ // await cloudBlobContainer.DeleteIfExistsAsync(); //} } } else { return(false, null); } }
public static void SerializeDeserializeObjectUsingReflectionStream() { string blobName = "aaa/avrotest/test008"; CloudBlobClient client = new Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient( new Uri("http://hanzstorage.blob.core.windows.net"), new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials( "hanzstorage", "w9TEpvGTusvFlGAdCoWdDrwqLzy6er0Zm5YKdDD0YTkQdOj3WufeVrgd2c8q8amLR0o6xD0tBChcIIA+DCgxXA==" )); CloudBlobContainer container = client.GetContainerReference("hanzhdi"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName); foreach (var md in blockBlob.Metadata) { Console.WriteLine("{0} {1}", md.Key, md.Value); } Console.WriteLine("Serializing Sample Data Set USING REFLECTION\n"); AvroBlobAppender.AvroBlobAppenderWriter <MyDataType> writer = new AvroBlobAppender.AvroBlobAppenderWriter <MyDataType>(blockBlob, false, AvroSerializer.Create <MyDataType>(), Codec.Null); Microsoft.Hadoop.Avro.Container.SequentialWriter <MyDataType> sequentialWriter = new SequentialWriter <MyDataType>(writer, 10000); List <MyDataType> myDataList = MyDataType.GenerateData(555, 10); foreach (var myData in myDataList) { sequentialWriter.Write(myData); } sequentialWriter.Flush(); sequentialWriter.Dispose(); #region commented code //blockBlob.DownloadToFile(blobName, FileMode.Create); //using (Stream stream = File.OpenRead(blobName)) //{ // Microsoft.Hadoop.Avro.Container.SequentialReader<MyDataType> reader = // new Microsoft.Hadoop.Avro.Container.SequentialReader<MyDataType>(AvroContainer.CreateReader<MyDataType>(stream)); // List<MyDataType> actuals = reader.Objects.ToList(); // Console.WriteLine("Number of objects: {0}", actuals.Count); // for (int i = 0; i < actuals.Count; i++) // { // var actual = actuals[i]; // MyDataType exp = null; // switch (i) // { // case 0: // exp = expected; // break; // case 1: // exp = expected2; // break; // default: // Console.WriteLine("No expected for object {0}", i); // continue; // } // Console.WriteLine("Result of Data Set Identity Comparison is {0}", Program.Equal(exp, actual)); // } //} #endregion }
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var message = await result as Activity; if (message.Attachments != null) { var attachment = message.Attachments[0]; using (HttpClient httpClient = new HttpClient()) { // Skype & MS Teams attachment URLs are secured by a JwtToken, so we need to pass the token from our bot. var responseMessage = await httpClient.GetAsync(attachment.ContentUrl); var contentLenghtBytes = responseMessage.Content.Headers.ContentLength; string filename = attachment.Name; string dir = AppDomain.CurrentDomain.BaseDirectory; // System.IO.Directory.GetCurrentDirectory(); string file = dir + "Uploads"; if (!Directory.Exists(file)) { DirectoryInfo di = Directory.CreateDirectory(file); //return; } // Try to create the directory. string file1 = dir + "Uploads" + "\\" + filename; FileStream fs = new FileStream(file1, FileMode.Create, FileAccess.Write, FileShare.None); // FileStream fs = new FileStream(file1, FileMode.Open); // SaveAttchments(fs, filename); await responseMessage.Content.CopyToAsync(fs).ContinueWith( (copyTask) => { fs.Close(); }); string StorageConnectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString; //string SourceFolder = ConfigurationManager.AppSettings["SourceFolder"]; string destContainer = ConfigurationManager.AppSettings["destContainer"]; CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(StorageConnectionString); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference(destContainer); blobContainer.CreateIfNotExists(); string key = Path.GetFileName(file1); CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(key); using (var fis = System.IO.File.Open(file1, FileMode.Open, FileAccess.Read, FileShare.None)) { blockBlob.UploadFromStream(fis); } await context.PostAsync($"Attachment of {attachment.ContentType} type and size of {contentLenghtBytes} bytes received."); await context.PostAsync($"Attachment of {attachment.ContentType} type and size of bytes received."); } } else { await context.PostAsync("Hi there! I'm a bot created to show you how I can receive message attachments, but no attachment was sent to me. Please, try again sending a new message including an attachment."); } context.Wait(this.MessageReceivedAsync); }
public async Task CloudBlobClientMaximumExecutionTimeoutAsync() { CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(Guid.NewGuid().ToString("N")); byte[] buffer = BlobTestBase.GetRandomBuffer(80 * 1024 * 1024); try { await container.CreateAsync(); blobClient.DefaultRequestOptions.MaximumExecutionTime = TimeSpan.FromSeconds(5); blobClient.DefaultRequestOptions.SingleBlobUploadThresholdInBytes = 2 * 1024 * 1024; CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); blockBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await blockBlob.UploadFromStreamAsync(ms); Assert.Fail(); } catch (AggregateException ex) { #if !FACADE_NETCORE Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).ExceptionInfo.Message); #else Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).Exception.Message); #endif } catch (TaskCanceledException) { } } CloudPageBlob pageBlob = container.GetPageBlobReference("blob2"); pageBlob.StreamWriteSizeInBytes = 1 * 1024 * 1024; using (MemoryStream ms = new MemoryStream(buffer)) { try { await pageBlob.UploadFromStreamAsync(ms); Assert.Fail(); } catch (AggregateException ex) { #if !FACADE_NETCORE Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).ExceptionInfo.Message); #else Assert.AreEqual("The client could not finish the operation within specified timeout.", RequestResult.TranslateFromExceptionMessage(ex.InnerException.Message).Exception.Message); #endif } catch (TaskCanceledException) { } } } finally { blobClient.DefaultRequestOptions.MaximumExecutionTime = null; container.DeleteIfExistsAsync().Wait(); } }
public async Task CloudBlobClientListBlobsSegmentedWithPrefixAsync() { string name = "bb" + GetRandomContainerName(); CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer rootContainer = blobClient.GetRootContainerReference(); CloudBlobContainer container = blobClient.GetContainerReference(name); try { await rootContainer.CreateIfNotExistsAsync(); await container.CreateAsync(); List <string> blobNames = await CreateBlobsAsync(container, 3, BlobType.BlockBlob); List <string> rootBlobNames = await CreateBlobsAsync(rootContainer, 2, BlobType.BlockBlob); BlobResultSegment results; BlobContinuationToken token = null; do { results = await blobClient.ListBlobsSegmentedAsync("bb", token); token = results.ContinuationToken; foreach (CloudBlockBlob blob in results.Results) { await blob.DeleteAsync(); rootBlobNames.Remove(blob.Name); } }while (token != null); Assert.AreEqual(0, rootBlobNames.Count); results = await blobClient.ListBlobsSegmentedAsync("bb", token); Assert.AreEqual(0, results.Results.Count()); Assert.IsNull(results.ContinuationToken); results = await blobClient.ListBlobsSegmentedAsync(name, token); Assert.AreEqual(0, results.Results.Count()); Assert.IsNull(results.ContinuationToken); token = null; do { results = await blobClient.ListBlobsSegmentedAsync(name + "/", token); token = results.ContinuationToken; foreach (CloudBlockBlob blob in results.Results) { Assert.IsTrue(blobNames.Remove(blob.Name)); } }while (token != null); Assert.AreEqual(0, blobNames.Count); } finally { container.DeleteIfExistsAsync().Wait(); } }
private void ProcessData() { //return; Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr")); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data"); // Retrieve reference to a blob. Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemasUKBlob = container.GetBlockBlobReference(CinemasUKFileName); using (Stream s = cinemasUKBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(CinemasUK)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmsUKBlob = container.GetBlockBlobReference(FilmsUKFileName); using (Stream s = filmsUKBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(FilmsUK)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmCinemasUKBlob = container.GetBlockBlobReference(FilmCinemasUKFileName); using (Stream s = filmCinemasUKBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(filmCinemasUK)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemaFilmsUKBlob = container.GetBlockBlobReference(CinemaFilmsUKFileName); using (Stream s = cinemaFilmsUKBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(cinemaFilmsUK)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemasIEBlob = container.GetBlockBlobReference(CinemasIEFileName); using (Stream s = cinemasIEBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(CinemasIE)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmsIEBlob = container.GetBlockBlobReference(FilmsIEFileName); using (Stream s = filmsIEBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(FilmsIE)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmCinemasIEBlob = container.GetBlockBlobReference(FilmCinemasIEFileName); using (Stream s = filmCinemasIEBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(filmCinemasIE)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemaFilmsIEBlob = container.GetBlockBlobReference(CinemaFilmsIEFileName); using (Stream s = cinemaFilmsIEBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(cinemaFilmsIE)); } } } Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob filmsPostersBlob = container.GetBlockBlobReference(MovieFilmPostersFileName); using (Stream s = filmsPostersBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { sw.Write(JsonConvert.SerializeObject(MoviePosters)); } } } //Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob mediumfilmsPostersBlob = container.GetBlockBlobReference(MediumFilmPostersFileName); //using (Stream s = mediumfilmsPostersBlob.OpenWrite()) //{ // using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) // { // using (StreamWriter sw = new StreamWriter(gzipStream)) // { // sw.Write(JsonConvert.SerializeObject(mediumposters)); // } // } //} }
public async Task CloudBlobClientMaximumExecutionTimeoutShouldNotBeHonoredForStreamsAsync() { CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(Guid.NewGuid().ToString("N")); byte[] buffer = BlobTestBase.GetRandomBuffer(1024 * 1024); try { await container.CreateAsync(); blobClient.DefaultRequestOptions.MaximumExecutionTime = TimeSpan.FromSeconds(30); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); CloudPageBlob pageBlob = container.GetPageBlobReference("blob2"); blockBlob.StreamWriteSizeInBytes = 1024 * 1024; blockBlob.StreamMinimumReadSizeInBytes = 1024 * 1024; pageBlob.StreamWriteSizeInBytes = 1024 * 1024; pageBlob.StreamMinimumReadSizeInBytes = 1024 * 1024; using (var bos = await blockBlob.OpenWriteAsync()) { DateTime start = DateTime.Now; for (int i = 0; i < 7; i++) { await bos.WriteAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last write int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } await bos.WriteAsync(buffer, 0, buffer.Length); await bos.CommitAsync(); } using (Stream bis = (await blockBlob.OpenReadAsync())) { DateTime start = DateTime.Now; int total = 0; while (total < 7 * 1024 * 1024) { total += await bis.ReadAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last read int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } while (true) { int count = await bis.ReadAsync(buffer, 0, buffer.Length); total += count; if (count == 0) { break; } } } using (var bos = await pageBlob.OpenWriteAsync(8 * 1024 * 1024)) { DateTime start = DateTime.Now; for (int i = 0; i < 7; i++) { await bos.WriteAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last write int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } await bos.WriteAsync(buffer, 0, buffer.Length); await bos.CommitAsync(); } using (Stream bis = (await pageBlob.OpenReadAsync())) { DateTime start = DateTime.Now; int total = 0; while (total < 7 * 1024 * 1024) { total += await bis.ReadAsync(buffer, 0, buffer.Length); } // Sleep to ensure we are over the Max execution time when we do the last read int msRemaining = (int)(blobClient.DefaultRequestOptions.MaximumExecutionTime.Value - (DateTime.Now - start)).TotalMilliseconds; if (msRemaining > 0) { await Task.Delay(msRemaining); } while (true) { int count = await bis.ReadAsync(buffer, 0, buffer.Length); total += count; if (count == 0) { break; } } } } finally { blobClient.DefaultRequestOptions.MaximumExecutionTime = null; container.DeleteIfExistsAsync().Wait(); } }
public async Task ProcessCinemaPerformances(RegionDef region, int cinemaID, List <FilmInfo> films) { CineworldService cws = new CineworldService(); List <FilmHeader> filmsForCinema = new List <FilmHeader>(); foreach (var film in films) { Task <Dates> td = cws.GetDates(region, cinemaID, film.EDI); td.Wait(); HashSet <DateTime> perfDates = new HashSet <DateTime>(); if (!td.IsFaulted && td.Result != null && td.Result.dates != null) { FilmHeader fh = new FilmHeader() { EDI = film.EDI }; filmsForCinema.Add(fh); fh.Performances = new List <PerformanceInfo>(); foreach (var date in td.Result.dates) { DateTime performanceDate = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture); Task <Performances> tp = cws.GetPerformances(region, cinemaID, film.EDI, date); tp.Wait(); if (!tp.IsFaulted && tp.Result != null && tp.Result.performances != null) { foreach (var p in tp.Result.performances) { PerformanceInfo pi = new PerformanceInfo(); pi.PerformanceTS = performanceDate.Add(DateTime.ParseExact(p.time, "HH:mm", CultureInfo.InvariantCulture).TimeOfDay); pi.Available = p.available; pi.Type = p.Type; pi.BookUrl = new Uri(p.booking_url); fh.Performances.Add(pi); } } } } } //return; Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("CineStorageConStr")); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference("data"); Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob cinemaFilmsBlob = container.GetBlockBlobReference(String.Format(FilmsPerCinemaFileName, cinemaID)); using (Stream s = cinemaFilmsBlob.OpenWrite()) { using (var gzipStream = new GZipStream(s, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzipStream)) { await sw.WriteAsync(JsonConvert.SerializeObject(filmsForCinema)); } } } }
public async Task CloudBlobDirectoryFlatListingAsync() { foreach (String delimiter in Delimiters) { CloudBlobClient client = GenerateCloudBlobClient(); client.DefaultDelimiter = delimiter; string name = GetRandomContainerName(); CloudBlobContainer container = client.GetContainerReference(name); try { await container.CreateAsync(); if (await CloudBlobDirectorySetupWithDelimiterAsync(container, delimiter)) { BlobResultSegment segment = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter, false, BlobListingDetails.None, null, null, null, null); List <IListBlobItem> simpleList1 = new List <IListBlobItem>(); simpleList1.AddRange(segment.Results); while (segment.ContinuationToken != null) { segment = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter, false, BlobListingDetails.None, null, segment.ContinuationToken, null, null); simpleList1.AddRange(segment.Results); } Assert.IsTrue(simpleList1.Count == 3); IListBlobItem item11 = simpleList1.ElementAt(0); Assert.IsTrue(item11.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "Blob1")); IListBlobItem item12 = simpleList1.ElementAt(1); Assert.IsTrue(item12.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter)); IListBlobItem item13 = simpleList1.ElementAt(2); Assert.IsTrue(item13.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter)); CloudBlobDirectory midDir2 = (CloudBlobDirectory)item13; BlobResultSegment segment2 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1", true, BlobListingDetails.None, null, null, null, null); List <IListBlobItem> simpleList2 = new List <IListBlobItem>(); simpleList2.AddRange(segment2.Results); while (segment2.ContinuationToken != null) { segment2 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1", true, BlobListingDetails.None, null, segment2.ContinuationToken, null, null); simpleList2.AddRange(segment2.Results); } Assert.IsTrue(simpleList2.Count == 2); IListBlobItem item21 = simpleList2.ElementAt(0); Assert.IsTrue(item21.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter + "EndBlob1")); IListBlobItem item22 = simpleList2.ElementAt(1); Assert.IsTrue(item22.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir2" + delimiter + "EndBlob2")); BlobResultSegment segment3 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1" + delimiter, false, BlobListingDetails.None, null, null, null, null); List <IListBlobItem> simpleList3 = new List <IListBlobItem>(); simpleList3.AddRange(segment3.Results); while (segment3.ContinuationToken != null) { segment3 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1" + delimiter, false, BlobListingDetails.None, null, segment3.ContinuationToken, null, null); simpleList3.AddRange(segment3.Results); } Assert.IsTrue(simpleList3.Count == 2); IListBlobItem item31 = simpleList3.ElementAt(0); Assert.IsTrue(item31.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter)); IListBlobItem item32 = simpleList3.ElementAt(1); Assert.IsTrue(item32.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir2" + delimiter)); BlobResultSegment segment4 = await midDir2.ListBlobsSegmentedAsync(true, BlobListingDetails.None, null, null, null, null); List <IListBlobItem> simpleList4 = new List <IListBlobItem>(); simpleList4.AddRange(segment4.Results); while (segment4.ContinuationToken != null) { segment4 = await midDir2.ListBlobsSegmentedAsync(true, BlobListingDetails.None, null, segment4.ContinuationToken, null, null); simpleList4.AddRange(segment4.Results); } Assert.IsTrue(simpleList4.Count == 2); IListBlobItem item41 = simpleList4.ElementAt(0); Assert.IsTrue(item41.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter + "EndDir1" + delimiter + "EndBlob1")); IListBlobItem item42 = simpleList4.ElementAt(1); Assert.IsTrue(item42.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter + "EndDir2" + delimiter + "EndBlob2")); } } finally { container.DeleteIfExistsAsync().AsTask().Wait(); } } }
public void CloudBlobClientListBlobsSegmentedWithEmptyPrefix() { string name = "bb" + GetRandomContainerName(); CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer rootContainer = blobClient.GetRootContainerReference(); CloudBlobContainer container = blobClient.GetContainerReference(name); try { rootContainer.CreateIfNotExists(); container.Create(); List <Uri> preExistingBlobs = rootContainer.ListBlobs().Select(b => b.Uri).ToList(); List <string> blobNames = CreateBlobs(container, 3, BlobType.BlockBlob); List <string> rootBlobNames = CreateBlobs(rootContainer, 2, BlobType.BlockBlob); BlobResultSegment results; BlobContinuationToken token = null; List <Uri> listedBlobs = new List <Uri>(); do { results = blobClient.ListBlobsSegmented("", token); token = results.ContinuationToken; foreach (IListBlobItem blob in results.Results) { if (preExistingBlobs.Contains(blob.Uri)) { continue; } else { if (blob is CloudPageBlob) { ((CloudPageBlob)blob).Delete(); } else { ((CloudBlockBlob)blob).Delete(); } listedBlobs.Add(blob.Uri); } } }while (token != null); Assert.AreEqual(2, listedBlobs.Count); do { results = container.ListBlobsSegmented("", false, BlobListingDetails.None, null, token, null, null); token = results.ContinuationToken; foreach (IListBlobItem blob in results.Results) { if (preExistingBlobs.Contains(blob.Uri)) { continue; } else { if (blob is CloudPageBlob) { ((CloudPageBlob)blob).Delete(); } else { ((CloudBlockBlob)blob).Delete(); } listedBlobs.Add(blob.Uri); } } }while (token != null); Assert.AreEqual(5, listedBlobs.Count); } finally { container.DeleteIfExists(); } }
public Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer GetContainerReference(string containerName) { return(_blobClient.GetContainerReference(containerName)); }
// Create a CSV file and save to Blob storage with the Headers required for our Azure Function processing // A new request telemetry is created // The request is part of the parent request (since) public void CreateBlob(string fileName) { /////////////////////////////////////////////////// // Grab existing /////////////////////////////////////////////////// Microsoft.ApplicationInsights.TelemetryClient telemetryClient = new Microsoft.ApplicationInsights.TelemetryClient(); telemetryClient.Context.User.AuthenticatedUserId = "*****@*****.**"; string traceoperation = null; string traceparent = null; System.Console.WriteLine("telemetryClient.Context.Operation.Id: " + telemetryClient.Context.Operation.Id); System.Console.WriteLine("telemetryClient.Context.Session.Id: " + telemetryClient.Context.Session.Id); System.Console.WriteLine("telemetryClient.Context.Operation.ParentId: " + telemetryClient.Context.Operation.ParentId); Microsoft.ApplicationInsights.DataContracts.RequestTelemetry requestTelemetry = new Microsoft.ApplicationInsights.DataContracts.RequestTelemetry(); requestTelemetry.Name = "Create Blob: " + fileName; //requestTelemetry.Source = requestContext.Replace("appId=",string.Empty); requestTelemetry.Timestamp = System.DateTimeOffset.Now; requestTelemetry.Context.Operation.Id = traceoperation; requestTelemetry.Context.Operation.ParentId = traceparent; requestTelemetry.Context.User.AuthenticatedUserId = "*****@*****.**"; using (var requestBlock = telemetryClient.StartOperation<Microsoft.ApplicationInsights.DataContracts.RequestTelemetry>(requestTelemetry)) { /////////////////////////////////////////////////// // Request Telemetry /////////////////////////////////////////////////// requestBlock.Telemetry.Context.User.AuthenticatedUserId = "*****@*****.**"; if (!string.IsNullOrWhiteSpace(traceoperation)) { // Use the existing common operation id requestBlock.Telemetry.Context.Operation.Id = traceoperation; System.Console.WriteLine("[Use existing] traceoperation: " + traceoperation); } else { // Set the traceoperation (we did not know it until now) traceoperation = requestBlock.Telemetry.Context.Operation.Id; System.Console.WriteLine("[Set the] traceoperation = requestBlock.Telemetry.Context.Operation.Id: " + traceoperation); } if (!string.IsNullOrWhiteSpace(traceparent)) { // Use the existing traceparent requestBlock.Telemetry.Context.Operation.ParentId = traceparent; System.Console.WriteLine("[Use existing] traceparent: " + traceparent); } else { traceparent = requestBlock.Telemetry.Id; System.Console.WriteLine("[Set the] traceparent = requestBlock.Telemetry.Id: " + traceparent); } // Store future parent id traceparent = requestBlock.Telemetry.Id; System.Console.WriteLine("traceparent = requestBlock.Telemetry.Id: " + traceparent); /////////////////////////////////////////////////// // Create Dependency for future Azure Function processing // NOTE: I trick it by giving a Start Time Offset of Now.AddSeconds(1), so it sorts correctly in the Azure Portal UI /////////////////////////////////////////////////// string operationName = "Dependency: Blob Event"; // Set the target so it points to the "dependent" app insights account app id // string target = "03-disttrace-func-blob | cid-v1:676560d0-81fb-4e5b-bfdd-7da1ad11c866" string target = "03-disttrace-func-blob | cid-v1:" + System.Environment.GetEnvironmentVariable("ai_03_disttrace_web_app_appkey"); string dependencyName = "Dependency Name: Azure Function Blob Trigger"; Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry dependencyTelemetry = new Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry( operationName, target, dependencyName, "02-disttrace-web-app", System.DateTimeOffset.Now.AddSeconds(1), System.TimeSpan.FromSeconds(2), "200", true); dependencyTelemetry.Context.Operation.Id = traceoperation; dependencyTelemetry.Context.Operation.ParentId = requestBlock.Telemetry.Id; // Store future parent id traceparent = dependencyTelemetry.Id; System.Console.WriteLine("traceparent = dependencyTelemetry.Id: " + traceparent); telemetryClient.TrackDependency(dependencyTelemetry); /////////////////////////////////////////////////// // Blob code /////////////////////////////////////////////////// string containerName = "appinsightstest"; string storageConnectionString = System.Environment.GetEnvironmentVariable("ai_storage_key"); CloudStorageAccount storageAccount = null; System.Console.WriteLine("storageConnectionString: " + storageConnectionString); CloudStorageAccount.TryParse(storageConnectionString, out storageAccount); System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(); list.Add("id,date"); for (int i = 1; i <= 50000; i++) { list.Add(i.ToString() + "," + string.Format("{0:MM/dd/yyyy}", System.DateTime.Now)); } var text = string.Join("\n", list.ToArray()); Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient(); blobStorage.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(System.TimeSpan.FromSeconds(1), 10); Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobStorage.GetContainerReference(containerName); container.CreateIfNotExistsAsync().Wait(); Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = container.GetBlockBlobReference(fileName); /////////////////////////////////////////////////// // Set the blob's meta data // We need the values from the dependency /////////////////////////////////////////////////// // Request-Context: appId=cid-v1:{The App Id of the current App Insights Account} string requestContext = "appId=cid-v1:" + System.Environment.GetEnvironmentVariable("ai_02_disttrace_web_app_appkey"); System.Console.WriteLine("Blob Metadata -> requestContext: " + requestContext); blob.Metadata.Add("RequestContext", requestContext); // Request-Id / traceparent: {parent request/operation id} (e.g. the Track Dependency) System.Console.WriteLine("Blob Metadata -> RequestId: " + traceparent); blob.Metadata.Add("RequestId", traceparent); System.Console.WriteLine("Blob Metadata -> traceparent: " + traceparent); blob.Metadata.Add("traceparent", traceparent); // Traceoperation {common operation id} (e.g. same operation id for all requests in this telemetry pipeline) System.Console.WriteLine("Blob Metadata -> traceoperation: " + traceoperation); blob.Metadata.Add("traceoperation", traceoperation); using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(text))) { blob.UploadFromStreamAsync(memoryStream).Wait(); } requestTelemetry.ResponseCode = "200"; requestTelemetry.Success = true; telemetryClient.StopOperation(requestBlock); } // using /////////////////////////////////////////////////// // For Debugging /////////////////////////////////////////////////// telemetryClient.Flush(); } // Create Blob