Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetContainerReference(string)

Here are the examples of the csharp api Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetContainerReference(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

89 Examples 7

19 Source : StorageService.cs
with MIT License
from Azure

public async Task<string> LoadBlobToContainer(string blobname, string contents)
        {
            var clientRequestId = Guid.NewGuid().ToString();
            try
            {
                var timeTakenStopWatch = new Stopwatch();
                timeTakenStopWatch.Start();
                var containerReference = cloudBlobClient.GetContainerReference(container);
                var cloudBlob = containerReference.GetBlockBlobReference(blobname);
                BlobRequestOptions blobRequestOptions = new BlobRequestOptions();
                blobRequestOptions.LocationMode = LocationMode.PrimaryOnly;
                blobRequestOptions.MaximumExecutionTime = TimeSpan.FromSeconds(60);
                OperationContext oc = new OperationContext();
                oc.ClientRequestID = clientRequestId;
                DiagnosticsETWProvider.Instance.LogAzureStorageMessage(nameof(StorageService), $"Loading {blobname} with ClientRequestId {clientRequestId}");
                using (var uploadStream = new MemoryStream(Convert.FromBase64String(contents)))
                {
                    await cloudBlob.UploadFromStreamAsync(uploadStream, null, blobRequestOptions, oc);
                }
                await cloudBlob.FetchAttributesAsync();
                timeTakenStopWatch.Stop();
                var uploadResult = cloudBlob.Properties;
                DiagnosticsETWProvider.Instance.LogAzureStorageMessage(nameof(StorageService), $"Loaded {blobname}, etag {uploadResult.ETag}, time taken {timeTakenStopWatch.ElapsedMilliseconds} ClientRequestId {clientRequestId}");
                return uploadResult.ETag;
            }
            catch (Exception ex)
            {
                DiagnosticsETWProvider.Instance.LogAzureStorageException(nameof(StorageService), $" ClientRequestId {clientRequestId} {ex.Message}", ex.GetType().ToString(), ex.ToString());
                return null;
            }
        }

19 Source : StorageService.cs
with MIT License
from Azure

public async Task<byte[]> GetBlobByName(string name)
        {
            int retryThreshold = 2;
            int attempt = 0;
            do
            {
                var clientRequestId = Guid.NewGuid().ToString();
                try
                {

                    BlobRequestOptions options = new BlobRequestOptions();
                    options.LocationMode = LocationMode.PrimaryThenSecondary;
                    options.MaximumExecutionTime = TimeSpan.FromSeconds(30);
                    if (attempt == retryThreshold)
                    {
                        options.LocationMode = LocationMode.SecondaryOnly;
                        DiagnosticsETWProvider.Instance.LogAzureStorageMessage(nameof(StorageService), $"Retrying blob against secondary account after {attempt} attempts");
                    }
                    var timeTakenStopWatch = new Stopwatch();
                    timeTakenStopWatch.Start();
                    OperationContext oc = new OperationContext();
                    oc.ClientRequestID = clientRequestId;
                    DiagnosticsETWProvider.Instance.LogAzureStorageMessage(nameof(StorageService), $"Fetching blob {name} with ClientRequestid {clientRequestId}");
                    var containerReference = cloudBlobClient.GetContainerReference(container);
                    var cloudBlob = containerReference.GetBlockBlobReference(name);
                    using (MemoryStream ms = new MemoryStream())
                    {
                        await cloudBlob.DownloadToStreamAsync(ms, null, options, oc);
                        timeTakenStopWatch.Stop();
                        DiagnosticsETWProvider.Instance.LogAzureStorageMessage(nameof(StorageService), $"Downloaded {name} to memory stream, time taken {timeTakenStopWatch.ElapsedMilliseconds} ClientRequestid {clientRequestId}");
                        return ms.ToArray();
                    }
                                      
                }
                catch (Exception ex)
                {
                    DiagnosticsETWProvider.Instance.LogAzureStorageException(nameof(StorageService), $"ClientRequestId {clientRequestId} {ex.Message}", ex.GetType().ToString(), ex.ToString());
                }
                finally
                {
                    attempt++;
                }
            } while (attempt <= retryThreshold);
            return null;
        }

19 Source : StorageService.cs
with MIT License
from Azure

public async Task<int> ListBlobsInContainer()
        {
            var clientRequestId = Guid.NewGuid().ToString();
            try
            {
                var timeTakenStopWatch = new Stopwatch();
                timeTakenStopWatch.Start();
                BlobRequestOptions options = new BlobRequestOptions();
                options.LocationMode = LocationMode.PrimaryThenSecondary;
                options.MaximumExecutionTime = TimeSpan.FromSeconds(60);
                OperationContext oc = new OperationContext();
                oc.ClientRequestID = clientRequestId;
                var containerReference = cloudBlobClient.GetContainerReference(container);
                var blobsResult = await containerReference.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, 1000, null, options, oc);
                timeTakenStopWatch.Stop();
                DiagnosticsETWProvider.Instance.LogAzureStorageMessage(nameof(StorageService), $"Number of blobs stored in container {container} is {blobsResult.Results.Count()}, time taken {timeTakenStopWatch.ElapsedMilliseconds} milliseconds, ClientRequestId {clientRequestId}");
                return blobsResult.Results != null ? blobsResult.Results.Count() : 0;
            }
            catch (Exception ex)
            {
                DiagnosticsETWProvider.Instance.LogAzureStorageException(nameof(StorageService), $"ClientRequestId {clientRequestId} {ex.Message}", ex.GetType().ToString(), ex.ToString());
                throw ex;
            }
        }

19 Source : DurableOptionsConfigurationTests.cs
with MIT License
from Azure

private static async Task replacedertTestUsedAzureStorageAsync(string testName)
        {
            // Ensure blobs touched in the last 30 seconds
            string defaultConnectionString = TestHelpers.GetStorageConnectionString();
            string blobLeaseContainerName = $"{testName}{PlatformSpecificHelpers.VersionSuffix.ToLower()}-leases";
            CloudStorageAccount account = CloudStorageAccount.Parse(defaultConnectionString);
            CloudBlobClient blobClient = account.CreateCloudBlobClient();
            CloudBlobContainer blobContainer = blobClient.GetContainerReference(blobLeaseContainerName);
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference($"default/{testName}{PlatformSpecificHelpers.VersionSuffix.ToLower()}-control-00");
            await blob.FetchAttributesAsync();
            DateTimeOffset lastModified = blob.Properties.LastModified.Value;
            DateTimeOffset expectedLastModifiedTimeThreshold = DateTimeOffset.UtcNow.AddSeconds(-30);
            replacedert.True(lastModified > expectedLastModifiedTimeThreshold);
        }

19 Source : EntityDependencyInjectionTests.cs
with MIT License
from Azure

[Theory]
        [Trait("Category", PlatformSpecificHelpers.TestCategory)]
        [InlineData(true)]
        [InlineData(false)]
        public async Task DurableEnreplacedy_DependencyInjectionAndBindings(bool extendedSessions)
        {
            string[] orchestratorFunctionNames =
            {
                nameof(TestEnreplacedyWithDependencyInjectionHelpers.BlobEnvironmentOrchestration),
            };

            string storageConnectionString = TestHelpers.GetStorageConnectionString();
            CloudStorageAccount.TryParse(storageConnectionString, out CloudStorageAccount storageAccount);

            CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(TestEnreplacedyWithDependencyInjectionHelpers.BlobContainerPath);
            await cloudBlobContainer.CreateIfNotExistsAsync();

            using (var host = TestHelpers.GetJobHost(
                this.loggerProvider,
                nameof(this.DurableEnreplacedy_DependencyInjectionAndBindings),
                extendedSessions,
                nameResolver: new TestEnreplacedyWithDependencyInjectionHelpers.DummyEnvironmentVariableResolver()))
            {
                await host.StartAsync();

                var environment = new EnreplacedyId(nameof(TestEnreplacedyWithDependencyInjectionHelpers.BlobBackedEnvironment), Guid.NewGuid().ToString());

                var client = await host.StartOrchestratorAsync(orchestratorFunctionNames[0], environment, this.output);

                var status = await client.WaitForCompletionAsync(this.output);

                replacedert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus);
                List<string> outputValues = status?.Output?.ToObject<List<string>>();
                replacedert.NotNull(outputValues);
                replacedert.Equal(TestEnreplacedyWithDependencyInjectionHelpers.DummyEnvironmentVariableValue, outputValues[0]);
                replacedert.Equal(TestEnreplacedyWithDependencyInjectionHelpers.BlobStoredEnvironmentVariableValue, outputValues[1]);
                await host.StopAsync();
            }
        }

19 Source : BindingTests.cs
with MIT License
from Azure

[Theory]
        [Trait("Category", PlatformSpecificHelpers.TestCategory)]
        [MemberData(nameof(TestDataGenerator.GetFullFeaturedStorageProviderOptions), MemberType = typeof(TestDataGenerator))]
        public async Task BindToBlobViaParameterName(string storageProviderType)
        {
            using (ITestHost host = TestHelpers.GetJobHost(this.loggerProvider, nameof(this.BindToBlobViaParameterName), false, storageProviderType))
            {
                await host.StartAsync();

                string connectionString = TestHelpers.GetStorageConnectionString();
                CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);
                this.output.WriteLine($"Using storage account: {account.Credentials.AccountName}");

                // Blob and container names need to be kept in sync with the activity code.
                const string OriginalBlobName = "MyBlob";
                const string UpdatedBlobName = OriginalBlobName + "-archive";
                const string ContainerName = "test";

                CloudBlobClient blobClient = account.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);
                if (await container.CreateIfNotExistsAsync())
                {
                    this.output.WriteLine($"Created container '{container.Name}'.");
                }

                string randomData = Guid.NewGuid().ToString("N");

                CloudBlockBlob blob = container.GetBlockBlobReference(OriginalBlobName);
                await blob.UploadTextAsync(randomData);
                this.output.WriteLine($"Uploaded text '{randomData}' to {blob.Name}.");

                // Using StartOrchestrationArgs to start an activity function because it's easier than creating a new type.
                var startArgs = new StartOrchestrationArgs();
                startArgs.FunctionName = nameof(TestActivities.BindToBlobViaParameterName);
                startArgs.Input = OriginalBlobName;

                var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.CallActivity), startArgs, this.output);
                var status = await client.WaitForCompletionAsync(this.output);

                replacedert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus);

                CloudBlockBlob newBlob = container.GetBlockBlobReference(UpdatedBlobName);
                string copiedData = await newBlob.DownloadTextAsync();
                this.output.WriteLine($"Downloaded text '{copiedData}' from {newBlob.Name}.");

                replacedert.Equal(randomData, copiedData);

                await host.StopAsync();
            }
        }

19 Source : BindingTests.cs
with MIT License
from Azure

[Theory]
        [Trait("Category", PlatformSpecificHelpers.TestCategory)]
        [MemberData(nameof(TestDataGenerator.GetFullFeaturedStorageProviderOptions), MemberType = typeof(TestDataGenerator))]
        public async Task BindToBlobViaPOCO(string storageProviderType)
        {
            using (ITestHost host = TestHelpers.GetJobHost(this.loggerProvider, nameof(this.BindToBlobViaPOCO), false, storageProviderType))
            {
                await host.StartAsync();

                string connectionString = TestHelpers.GetStorageConnectionString();
                CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);
                this.output.WriteLine($"Using storage account: {account.Credentials.AccountName}");

                // Blob and container names need to be kept in sync with the activity code.
                var data = new
                {
                    InputPrefix = "Input",
                    OutputPrefix = "Output",
                    Suffix = 42,
                };

                const string ContainerName = "test";
                string inputBlobName = $"{data.InputPrefix}-{data.Suffix}";
                string outputBlobName = $"{data.OutputPrefix}-{data.Suffix}";

                CloudBlobClient blobClient = account.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);
                if (await container.CreateIfNotExistsAsync())
                {
                    this.output.WriteLine($"Created container '{container.Name}'.");
                }

                string randomData = Guid.NewGuid().ToString("N");

                this.output.WriteLine($"Creating blob named {outputBlobName}...");
                CloudBlockBlob blob = container.GetBlockBlobReference(inputBlobName);
                await blob.UploadTextAsync(randomData);
                this.output.WriteLine($"Uploaded text '{randomData}' to {blob.Name}.");

                // Using StartOrchestrationArgs to start an activity function because it's easier than creating a new type.
                var startArgs = new StartOrchestrationArgs();
                startArgs.FunctionName = nameof(TestActivities.BindToBlobViaJsonPayload);
                startArgs.Input = data;

                var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.CallActivity), startArgs, this.output);
                var status = await client.WaitForCompletionAsync(this.output);

                replacedert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus);

                this.output.WriteLine($"Searching for blob named {outputBlobName}...");
                CloudBlockBlob newBlob = container.GetBlockBlobReference(outputBlobName);
                string copiedData = await newBlob.DownloadTextAsync();
                this.output.WriteLine($"Downloaded text '{copiedData}' from {newBlob.Name}.");

                replacedert.Equal(randomData, copiedData);

                await host.StopAsync();
            }
        }

19 Source : Devices.cs
with MIT License
from Azure

private async Task<CloudBlockBlob> CreateImportExportBlobAsync()
        {
            // Container for the files managed by Azure IoT SDK.
            // Note: use a new container to speed up the operation and avoid old files left over
            string containerName = ("iothub-" + DateTimeOffset.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss-") + Guid.NewGuid().ToString("N")).ToLowerInvariant();
            string blobName = "devices.txt";

            this.log.Info("Creating import blob", () => new { containerName, blobName });

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(this.config.IoTHubImportStorageAccount);
            CloudBlobClient client = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference(containerName);
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

            await container.CreateIfNotExistsAsync();
            await blob.DeleteIfExistsAsync();

            return blob;
        }

19 Source : QueryMetricsAndActivityLogs.cs
with MIT License
from Azure

private static void AddBlobTransactions(string storageConnectionString)
        {

            // Upload the script file as block blob
            //
            var account = CloudStorageAccount.Parse(storageConnectionString);
            var cloudBlobClient = account.CreateCloudBlobClient();
            var container = cloudBlobClient.GetContainerReference("scripts");
            container.CreateIfNotExistsAsync().GetAwaiter().GetResult();

            var serviceProps = cloudBlobClient.GetServicePropertiesAsync().GetAwaiter().GetResult();

            // configure Storage logging and metrics
            serviceProps.Logging = new LoggingProperties
                                    {
                                        LoggingOperations = LoggingOperations.All,
                                        RetentionDays = 2,
                                        Version = "1.0"
                                    };

            var metricProps = new MetricsProperties
                                {
                                    MetricsLevel = MetricsLevel.ServiceAndApi,
                                    RetentionDays = 2,
                                    Version = "1.0"
                                };

            serviceProps.HourMetrics = metricProps;
            serviceProps.MinuteMetrics = metricProps;

            // Set the default service version to be used for anonymous requests.
            serviceProps.DefaultServiceVersion = "2015-04-05";

            // Set the service properties.
            cloudBlobClient.SetServicePropertiesAsync(serviceProps).GetAwaiter().GetResult();
            var containerPermissions = new BlobContainerPermissions();
            // Include public access in the permissions object
            containerPermissions.PublicAccess = BlobContainerPublicAccessType.Container;
            // Set the permissions on the container
            container.SetPermissionsAsync(containerPermissions).GetAwaiter().GetResult();

            var blob = container.GetBlockBlobReference("install_apache.sh");
            blob.UploadFromFileAsync(Path.Combine(Utilities.ProjectPath, "replacedet", "install_apache.sh")).GetAwaiter().GetResult();

            // give sometime for the infrastructure to process the records and fit into time grain.
            SdkContext.DelayProvider.Delay(6 * 60000);
        }

19 Source : SqlDatabaseExportRequestImpl.cs
with MIT License
from Azure

public async Task<Microsoft.Azure.Management.Sql.Fluent.ISqlDatabaseImportExportResponse> ExecuteWorkAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.storageAccountCreatable != null)
            {
                this.storageAccount = await storageAccountCreatable.CreateAsync(cancellationToken) ?? throw new Exception("Failed to create Storage Account");
            }
            if (this.storageAccount != null)
            {
                var storageKeys = (await storageAccount.GetKeysAsync(cancellationToken));
                if (storageKeys == null || storageKeys.Count == 0)
                {
                    throw new Exception("Failed to retrieve Storage Account Keys");
                }
                var storageAccountKey = storageKeys[0].Value;
                this.Inner.StorageUri = $"{this.storageAccount.EndPoints.Primary.Blob}{this.containerName}/{this.fileName}";
                this.Inner.StorageKeyType = StorageKeyType.StorageAccessKey;
                this.Inner.StorageKey = storageAccountKey;
                
                // Create the storage account container if one does not exist
                var sas = $"DefaultEndpointsProtocol=https;AccountName={storageAccount.Name};AccountKey={storageAccountKey};EndpointSuffix=core.Windows.Net";
                var cloudBlobClient = CloudStorageAccount.Parse(sas).CreateCloudBlobClient();
                await cloudBlobClient.GetContainerReference(containerName).CreateIfNotExistsAsync();
            }

            var importExportResponseInner = await this.sqlServerManager.Inner.Databases
                .ExportAsync(this.sqlDatabase.ResourceGroupName(), this.sqlDatabase.SqlServerName(), this.sqlDatabase.Name(), this.Inner, cancellationToken);
            return new SqlDatabaseImportExportResponseImpl(importExportResponseInner);
        }

19 Source : VirtualMachineExtensionTests.cs
with MIT License
from Azure

private string prepareCustomScriptStorageUri(string storageAccountName, string storageAccountKey, string containerName)
        {
            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                return "http://nonexisting.blob.core.windows.net/scripts2/install_apache.sh";
            }
            var storageConnectionString = $"DefaultEndpointsProtocol=http;AccountName={storageAccountName};AccountKey={storageAccountKey}";
            CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
            CloudBlobClient cloudBlobClient = account.CreateCloudBlobClient();
            CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerName);
            bool createdNew = container.CreateIfNotExistsAsync().Result;
            CloudBlockBlob blob = container.GetBlockBlobReference("install_apache.sh");
            using (HttpClient client = new HttpClient())
            {
                blob.UploadFromStreamAsync(client.GetStreamAsync("https://raw.githubusercontent.com/Azure/azure-libraries-for-net/master/Tests/Fluent.Tests/replacedets/install_apache.sh").Result).Wait();
            }
            return blob.Uri.ToString();
        }

19 Source : Startup.cs
with MIT License
from Azure

public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.None;
            });

            services.AddOptions();

            // Token acquisition service based on MSAL.NET
            // and chosen token cache implementation
            services.AddAzureAdV2Authentication(Configuration)
                    .AddMsal(new string[] { "https://graph.microsoft.com/.default" })
                    .AddInMemoryTokenCaches();

            services.AddSession(options =>
            {
                options.Cookie.Name = "RenderHub.Session";
                options.IdleTimeout = TimeSpan.FromMinutes(10);
            });

            services.AddTransient<IGraphProvider, GraphProvider>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.Configure<FormOptions>(x =>
            {
                x.ValueLengthLimit = int.MaxValue;
                x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart
            });

            // Add Application Insights integration:
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddLogging(builder =>
            {
                builder.AddApplicationInsights();

                // Adding the filter below to ensure logs of all severity from Program.cs
                // is sent to ApplicationInsights.
                builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>(
                    typeof(Program).FullName, Microsoft.Extensions.Logging.LogLevel.Trace);

                // Adding the filter below to ensure logs of all severity from Startup.cs
                // is sent to ApplicationInsights.
                builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>(
                    typeof(Startup).FullName, Microsoft.Extensions.Logging.LogLevel.Trace);

                builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>(
                    "WebApp", Microsoft.Extensions.Logging.LogLevel.Trace);

                builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>(
                    "", Microsoft.Extensions.Logging.LogLevel.Error);
            });

            services.AddSingleton(
                p =>
                {
                    var config = p.GetRequiredService<IConfiguration>();
                    var secretName = config["KeyVault:StorageConnectionStringSecretName"];
                    var connectionString = config[secretName];
                    return CloudStorageAccount.Parse(connectionString);
                });

            services.AddSingleton(p => p.GetRequiredService<CloudStorageAccount>().CreateCloudBlobClient());
            services.AddSingleton(p => p.GetRequiredService<CloudStorageAccount>().CreateCloudQueueClient());
            services.AddSingleton(p => p.GetRequiredService<CloudStorageAccount>().CreateCloudTableClient());
            services.AddSingleton<IKeyVaultMsiClient, KeyVaultMsiClient>();

            services.AddSingleton<BatchClientMsiProvider>();
            services.AddSingleton(Environment);

            services.AddHttpClient();
            services.AddMemoryCache();

            // Add HttpClient with retry policy for contacting Cost Management
            services.AddHttpClient<CostManagementClientAccessor>();
                // -- This is to be restored when CostManagement returns a non-500 for invalid subs.
                ////.AddTransientHttpErrorPolicy(b =>
                ////    b.WaitAndRetryAsync(
                ////        new[] { TimeSpan.Zero, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5) }));


            // These are scoped as they use the credentials of the user:
            services.AddScoped<ILogProvider, LogProvider>();
            services.AddScoped<IAzureResourceProvider, AzureResourceProvider>();
            services.AddScoped<IDeploymentCoordinator, DeploymentCoordinator>();
            services.AddScoped<AuthorizationManager>();
            services.AddScoped<ICostCoordinator>(p =>
            {
                var client = p.GetRequiredService<CostManagementClientAccessor>();
                var memoryCache = p.GetRequiredService<IMemoryCache>();
                return new CachingCostCoordinator(new CostCoordinator(client), memoryCache);
            });

            services.AddSingleton<IIdenreplacedyProvider, IdenreplacedyProvider>();
            services.AddSingleton<ManagementClientMsiProvider>();
            services.AddSingleton<StartTaskProvider>();

            services.AddSingleton<IEnvironmentCoordinator>(p =>
            {
                var cbc = p.GetRequiredService<CloudBlobClient>();
                var kvClient = p.GetRequiredService<IKeyVaultMsiClient>();
                var cache = p.GetRequiredService<IMemoryCache>();
                var logger = p.GetRequiredService<ILogger<EnvironmentSecretsRepository>>();

                // note that cache is around the secrets so they don't have to be re-fetched
                return
                    new EnvironmentCoordinator(
                        new CachingConfigRepository<RenderingEnvironment>(
                            new EnvironmentSecretsRepository(
                                new GenericConfigRepository<RenderingEnvironment>(
                                    cbc.GetContainerReference("environments")),
                                    kvClient,
                                    logger),
                            cache));
            });

            // the default IreplacedetRepoCoordinator implementation uses the user auth
            services.AddScoped<IManagementClientProvider, ManagementClientHttpContextProvider>();
            services.AddScoped(p =>
                CreatereplacedetRepoCoordinator(
                    p,
                    p.GetRequiredService<IManagementClientProvider>(),
                    p.GetRequiredService<IAzureResourceProvider>())); 

            services.AddSingleton<IPackageCoordinator>(p =>
            {
                var cbc = p.GetRequiredService<CloudBlobClient>();
                var cache = p.GetRequiredService<IMemoryCache>();
                return new PackageCoordinator(
                    new CachingConfigRepository<InstallationPackage>(
                        new GenericConfigRepository<InstallationPackage>(cbc.GetContainerReference("packages")),
                        cache));
            });

            services.AddScoped<IPoolCoordinator, PoolCoordinator>();
            services.AddSingleton<IScaleUpRequestStore, ScaleUpRequestStore>();

            services.AddScoped<IVMSizes, VMSizes>();
            services.AddScoped<IPoolUsageProvider, PoolUsageProvider>();

            // Deployment background server
            services.AddSingleton<ITemplateProvider, TemplateProvider>();
            services.AddSingleton<ILeaseMaintainer, LeaseMaintainer>();
            services.AddSingleton<IDeploymentQueue, DeploymentQueue>();
            services.AddSingleton<IHostedService>(p => new BackgroundDeploymentHost(
                // use MSI auth for background services, do not provide an IAzureResourceProvider implementation
                CreatereplacedetRepoCoordinator(p, p.GetRequiredService<ManagementClientMsiProvider>(), null),
                p.GetRequiredService<IDeploymentQueue>(),
                p.GetRequiredService<ILeaseMaintainer>(),
                p.GetRequiredService<ILogger<BackgroundDeploymentHost>>()));
            services.AddSingleton<IHostedService, AutoScaleHost>();
            services.AddSingleton<IAppInsightsQueryProvider, AppInsightsQueryProvider>();
            services.AddSingleton<IActiveNodeProvider, ActiveNodeProvider>();

            // Add scale up background service

            // Note that there is one AutoResetEvent that is used to communicate between the
            // ScaleController and the ScaleUpProcessorHost. If we want to use this type between
            // more instances then we will need to add some named-lookup system...
            services.AddSingleton<AsyncAutoResetEvent>();
            services.AddSingleton<IHostedService, ScaleUpProcessorHost>();
        }

19 Source : StartTaskProvider.cs
with MIT License
from Azure

private async Task<List<ResourceFile>> GetResourceFilesFromContainer(string containerName)
        {
            var container = _blobClient.GetContainerReference(containerName);
            var resourceFiles = new List<ResourceFile>();

            var policy = new SharedAccessBlobPolicy
            {
                SharedAccessStartTime = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15)),
                SharedAccessExpiryTime = DateTime.UtcNow.AddYears(1),
                Permissions = SharedAccessBlobPermissions.Read,
            };

            BlobContinuationToken blobContinuationToken = null;
            do
            {
                var results = await container.ListBlobsSegmentedAsync(null, blobContinuationToken);
                foreach (var blob in results.Results.OfType<CloudBlockBlob>())
                {
                    var sasBlobToken = blob.GetSharedAccessSignature(policy);
                    resourceFiles.Add(new ResourceFile(httpUrl: blob.Uri + sasBlobToken, filePath: blob.Name));
                }

                blobContinuationToken = results.ContinuationToken;
            } while (blobContinuationToken != null);

            return resourceFiles;
        }

19 Source : StartTaskProvider.cs
with MIT License
from Azure

private ResourceFile GetContainerResourceFile(string containerName, string filePath)
        {
            var container = _blobClient.GetContainerReference(containerName);
            var policy = new SharedAccessBlobPolicy
            {
                SharedAccessStartTime = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15)),
                SharedAccessExpiryTime = DateTime.UtcNow.AddYears(1),
                Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List,
            };

            var containerSas = container.GetSharedAccessSignature(policy);
            return new ResourceFile(storageContainerUrl: container.Uri + containerSas, filePath: filePath);
        }

19 Source : Startup.cs
with MIT License
from Azure

private static IreplacedetRepoCoordinator CreatereplacedetRepoCoordinator(
            IServiceProvider p,
            IManagementClientProvider clientProvider,
            IAzureResourceProvider resourceProvider)
        {
            var cbc = p.GetRequiredService<CloudBlobClient>();
            var cache = p.GetRequiredService<IMemoryCache>();
            return new replacedetRepoCoordinator(
                new CachingConfigRepository<replacedetRepository>(
                    new GenericConfigRepository<replacedetRepository>(cbc.GetContainerReference("storage")),
                    cache),
                p.GetRequiredService<ITemplateProvider>(),
                p.GetRequiredService<IIdenreplacedyProvider>(),
                p.GetRequiredService<IDeploymentQueue>(),
                clientProvider,
                resourceProvider,
                p.GetRequiredService<ILogger<replacedetRepoCoordinator>>());
        }

19 Source : PackagesController.cs
with MIT License
from Azure

[HttpDelete]
        [Route("RenderManagerPackages/{pkgId}/Delete")]
        public async Task<ActionResult> Delete(string pkgId)
        {
            var package = await _packageCoordinator.GetPackage(pkgId);
            if (package == null)
            {
                return NotFound("Package not found");
            }

            var container = _blobClient.GetContainerReference(package.Container);
            await container.DeleteIfExistsAsync();
            if (await _packageCoordinator.RemovePackage(package))
            {
                return Ok();
            }

            return StatusCode(500, "Unable to remove package");
        }

19 Source : PackagesController.cs
with MIT License
from Azure

private async Task CreatePackage(
            string packageId,
            InstallationPackageType type,
            IEnumerable<IFormFile> files,
            string commandLine = null)
        {
            var package = await _packageCoordinator.GetPackage(packageId)
                ?? new InstallationPackage(packageId, type);

            try
            {
                var container = _blobClient.GetContainerReference(package.Container);
                if (container != null)
                {
                    await container.CreateIfNotExistsAsync();
                }

                // Sanitise files as it can contain nulls
                files = files.Where(f => f != null);

                foreach (var file in files)
                {
                    await UploadFileToBlob(file, container);
                }

                package.Files.Clear();
                package.Files.AddRange(files.Select(f => f.FileName));
                package.PackageInstallCommand = commandLine;

                await _packageCoordinator.UpdatePackage(package);
            }
            catch (AggregateException aex)
            {
                throw aex.InnerExceptions.First();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

19 Source : CloudStorageWrapper.cs
with MIT License
from Azure

public CloudBlobContainer GetContainerReference(CloudBlobClient client, string containerName)
        {
            return client.GetContainerReference(containerName);
        }

19 Source : BlobStorageHelper.cs
with MIT License
from Azure-Samples

public SasUrlForBlobAccess GetSasUrlForBlobAccess(string container, string name)
        {
            this.InitializeBlobStorage();
            CloudBlobContainer blobContainer = this.cloudBlobClient.GetContainerReference(container);
            //Set the expiry time for the container.
            //In this case no start time is specified, so the shared access signature becomes valid immediately.
            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
            sasConstraints.SharedAccessExpiryTime = 
                DateTimeOffset.UtcNow.AddMinutes(blobStorageConfig.BlobStorageWebUiDirectAccessExpiryMinutes);
            //The sasConstraints.Permissions property must NOT be set or it will cause problems with the container's access policy

            string sas = blobContainer.GetSharedAccessSignature(sasConstraints, blobStorageConfig.BlobStorageWebUiDirectAccessPolicy);
            string result = blobContainer.StorageUri.PrimaryUri.ToString() + "/" + name + sas;

            return new SasUrlForBlobAccess(result);
        }

19 Source : BlobStorageHelper.cs
with MIT License
from Azure-Samples

private void Initialize()
        {
            if (!this.isInitialized)
            {
                this.storageAccount = CloudStorageAccount.Parse(this.connectionString);
                this.cloudBlobClient = storageAccount.CreateCloudBlobClient();
                this.cloudBlobContainer = cloudBlobClient.GetContainerReference(ContainerName);
                this.isInitialized = true;
            }
        }

19 Source : ReleaseNotesWebHook.cs
with MIT License
from Azure-Samples

[FunctionName("ReleaseNotesWebHook")]
        public static async void RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, ILogger log)
        {
            //Extract data from request body
            string requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            string releaseName = data?.resource?.release?.name;
            string releaseBody = data?.resource?.release?.description;

            VssBasicCredential credentials = new VssBasicCredential(Environment.GetEnvironmentVariable("DevOps.Username"), Environment.GetEnvironmentVariable("DevOps.AccessToken"));
            VssConnection connection = new VssConnection(new Uri(Environment.GetEnvironmentVariable("DevOps.OrganizationURL")), credentials);

            //Time span of 14 days from today
            var dateSinceLastRelease = DateTime.Today.Subtract(new TimeSpan(14, 0, 0, 0));

            //Acreplacedulate closed work items from the past 14 days in text format
            var workItems = GetClosedItems(connection, dateSinceLastRelease);
            var pulls = GetMergedPRs(connection, dateSinceLastRelease);
            
            //Create a new blob markdown file
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StorageAccountConnectionString"));
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("releases");
            var blob = container.GetBlockBlobReference(releaseName + ".md");

            //Format text content of blob
            var text = String.Format("# {0} \n {1} \n\n" + "# Work Items Resolved:" + workItems + "\n\n# Changes Merged:" + pulls, releaseName, releaseBody);

            //Add text to blob
            await blob.UploadTextAsync(text);
        }

19 Source : Program.cs
with MIT License
from Azure-Samples

private static async Task CreateContainerIfNotExistAsync(CloudBlobClient blobClient, string containerName)
        {
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            await container.CreateIfNotExistsAsync();
            Console.WriteLine("Creating container [{0}].", containerName);
        }

19 Source : Program.cs
with MIT License
from Azure-Samples

private static async Task<ResourceFile> UploadResourceFileToContainerAsync(CloudBlobClient blobClient, string containerName, string filePath)
        {
            Console.WriteLine("Uploading file {0} to container [{1}]...", filePath, containerName);

            string blobName = Path.GetFileName(filePath);
            var fileStream = System.IO.File.OpenRead(filePath);

            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlockBlob blobData = container.GetBlockBlobReference(blobName);
            await blobData.UploadFromFileAsync(filePath);

            // Set the expiry time and permissions for the blob shared access signature. In this case, no start time is specified,
            // so the shared access signature becomes valid immediately
            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy
            {
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(2),
                Permissions = SharedAccessBlobPermissions.Read
            };

            // Construct the SAS URL for blob
            string sasBlobToken = blobData.GetSharedAccessSignature(sasConstraints);
            string blobSasUri = String.Format("{0}{1}", blobData.Uri, sasBlobToken);

            return new ResourceFile(blobSasUri, blobName);
        }

19 Source : Program.cs
with MIT License
from Azure-Samples

private static string GetContainerSasUrl(CloudBlobClient blobClient, string containerName, SharedAccessBlobPermissions permissions)
        {
            // Set the expiry time and permissions for the container access signature. In this case, no start time is specified,
            // so the shared access signature becomes valid immediately. Expiration is in 2 hours.
            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy
            {
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(2),
                Permissions = permissions
            };

            // Generate the shared access signature on the container, setting the constraints directly on the signature
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);

            // Return the URL string for the container, including the SAS token
            return String.Format("{0}{1}", container.Uri, sasContainerToken);
        }

19 Source : Program.cs
with MIT License
from Azure-Samples

private static async Task MainAsync()
        {
            Console.WriteLine("Sample start: {0}", DateTime.Now);
            Console.WriteLine();
            Stopwatch timer = new Stopwatch();
            timer.Start();

            // Construct the Storage account connection string
            string storageConnectionString = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                                StorageAccountName, StorageAccountKey);

            // Retrieve the storage account
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

            // Create the blob client, for use in obtaining references to blob storage containers
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

             
            // Use the blob client to create the containers in blob storage
            const string inputContainerName = "input";
            const string outputContainerName = "output";

            await CreateContainerIfNotExistAsync(blobClient, inputContainerName);
            await CreateContainerIfNotExistAsync(blobClient, outputContainerName);

            // RESOURCE FILE SETUP
            // Input files: Specify the location of the data files that the tasks process, and
            // put them in a List collection. Make sure you have copied the data files to:
            // \<solutiondir>\InputFiles.

            string inputPath = Path.Combine(Environment.CurrentDirectory, "InputFiles");

            List<string> inputFilePaths = new List<string>(Directory.GetFileSystemEntries(inputPath, "*.mp4",
                                         SearchOption.TopDirectoryOnly));
               
            // Upload data files.
            // Upload the data files using UploadResourceFilesToContainer(). This data will be
            // processed by each of the tasks that are executed on the compute nodes within the pool.
            List<ResourceFile> inputFiles = await UploadFilesToContainerAsync(blobClient, inputContainerName, inputFilePaths);

            // Obtain a shared access signature that provides write access to the output container to which
            // the tasks will upload their output.
            string outputContainerSasUrl = GetContainerSasUrl(blobClient, outputContainerName, SharedAccessBlobPermissions.Write);


            // CREATE BATCH CLIENT / CREATE POOL / CREATE JOB / ADD TASKS

            // Create a Batch client and authenticate with shared key credentials.
            // The Batch client allows the app to interact with the Batch service.
            BatchSharedKeyCredentials sharedKeyCredentials = new BatchSharedKeyCredentials(BatchAccountUrl, BatchAccountName, BatchAccountKey);

            using (BatchClient batchClient = BatchClient.Open(sharedKeyCredentials))
            {
                // Create the Batch pool, which contains the compute nodes that execute the tasks.
                await CreatePoolIfNotExistAsync(batchClient, PoolId);

                // Create the job that runs the tasks.
                await CreateJobAsync(batchClient, JobId, PoolId);

                // Create a collection of tasks and add them to the Batch job. 
                // Provide a shared access signature for the tasks so that they can upload their output
                // to the Storage container.
                await AddTasksAsync(batchClient, JobId, inputFiles, outputContainerSasUrl);

                // Monitor task success or failure, specifying a maximum amount of time to wait for
                // the tasks to complete.
                await MonitorTasks(batchClient, JobId, TimeSpan.FromMinutes(30));

                // Delete input container in storage
                Console.WriteLine("Deleting container [{0}]...", inputContainerName);
                CloudBlobContainer container = blobClient.GetContainerReference(inputContainerName);
                await container.DeleteIfExistsAsync();
                   
                // Print out timing info
                timer.Stop();
                Console.WriteLine();
                Console.WriteLine("Sample end: {0}", DateTime.Now);
                Console.WriteLine("Elapsed time: {0}", timer.Elapsed);

                // Clean up Batch resources (if the user so chooses)
                Console.WriteLine();
                Console.Write("Delete job? [yes] no: ");
                string response = Console.ReadLine().ToLower();
                if (response != "n" && response != "no")
                {
                   await batchClient.JobOperations.DeleteJobAsync(JobId);
                }

                Console.Write("Delete pool? [yes] no: ");
                response = Console.ReadLine().ToLower();
                if (response != "n" && response != "no")
                {
                    await batchClient.PoolOperations.DeletePoolAsync(PoolId);
                }
            }
        }

19 Source : Program.cs
with MIT License
from Azure-Samples

static IEnumerable<IListBlobItem> GetBlobsList()
        {
            // Get a reference to the Container within the Storage Account
            // that has the files (blobs) for moderation
            CloudBlobClient CloudBlobClient = _StorageAccount.CreateCloudBlobClient();
            CloudBlobContainer MediaBlobContainer = CloudBlobClient.GetContainerReference(STORAGE_CONTAINER_NAME);

            // Get the reference to the list of Blobs 
            var blobList = MediaBlobContainer.ListBlobs();
            return blobList;
        }

19 Source : Sample.cs
with MIT License
from Azure-Samples

[FunctionName(nameof(WriteToBlob))]
        public static async Task WriteToBlob(
            [ActivityTrigger] string content)
        {
            var storageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
            var storageAccount = CloudStorageAccount.Parse(storageConnectionString);

            // Create the CloudBlobClient that represents the Blob storage endpoint for the storage account.
            var cloudBlobClient = storageAccount.CreateCloudBlobClient();

            // Create a container called 'quickstartblobs' and append a GUID value to it to make the name unique. 
            var cloudBlobContainer = cloudBlobClient.GetContainerReference("result");
            await cloudBlobContainer.CreateAsync();

            var fileName = string.Format("mapreduce_sample_result_{0}.txt", DateTime.Now.ToString("yyyy_dd_M_HH_mm_ss"));
            var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
            await cloudBlockBlob.UploadTextAsync(content);
        }

19 Source : NewRelease.cs
with MIT License
from Azure-Samples

[FunctionName("NewRelease")]
        public static async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, Route = null, WebHookType="github")]HttpRequest req, TraceWriter log)
        {        
            // Get request body
            string requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data = JsonConvert.DeserializeObject(requestBody);

            // Extract github release from request body
            string releaseBody = data?.release?.body;
            string releaseName = data?.release?.name;
            string repositoryName = data?.repository?.full_name;

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StorageAccountConnectionString"));
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("releases");
            var blob = container.GetBlockBlobReference(releaseName + ".md" );

            string txtIssues = await GetReleaseDetails(IssueTypeQualifier.Issue, repositoryName);
            string txtPulls = await GetReleaseDetails(IssueTypeQualifier.PullRequest, repositoryName);
            
            var text = String.Format("# {0} \n {1} \n\n" + "# Issues Closed:" + txtIssues + "\n\n# Changes Merged:" + txtPulls, releaseName, releaseBody);

            await blob.UploadTextAsync(text);    
        }

19 Source : BlobStorageHelper.cs
with MIT License
from Azure-Samples

static public CloudBlobContainer GetCloudBlobContainer(string storageAccountName, string storageAccountKey, string containerName)
        {
            CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(storageAccountName, storageAccountKey), true);
            CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
            return cloudBlobClient.GetContainerReference(containerName);
        }

19 Source : copyBlobHelpers.cs
with MIT License
from Azure-Samples

static public CloudBlobContainer GetCloudBlobContainer(string storageAccountName, string storageAccountKey, string containerName)
        {

            CloudStorageAccount sourceStorageAccount = new CloudStorageAccount(new StorageCredentials(storageAccountName, storageAccountKey), true);

            CloudBlobClient sourceCloudBlobClient = sourceStorageAccount.CreateCloudBlobClient();

            return sourceCloudBlobClient.GetContainerReference(containerName);

        }

19 Source : StorageService.cs
with MIT License
from Azure-Samples

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;
        }

19 Source : BlobHelpers.cs
with MIT License
from Azure-Samples

static public CloudBlobContainer GetCloudBlobContainer(string storageAccountName, string storageAccountKey, string containerName)
        {
            CloudStorageAccount sourceStorageAccount = new CloudStorageAccount(new StorageCredentials(storageAccountName, storageAccountKey), true);

            CloudBlobClient sourceCloudBlobClient = sourceStorageAccount.CreateCloudBlobClient();

            return sourceCloudBlobClient.GetContainerReference(containerName);
        }

19 Source : BlobHelpers.cs
with MIT License
from Azure-Samples

public static async Task<Ireplacedet> CreatereplacedetFromBlobAsync(CloudBlockBlob blob, string replacedetName, string storageAccountName, 
            string storageAccountKey, CloudStorageAccount destinationStorageAccount, CloudMediaContext context, TraceWriter log)
        {
            //Get a reference to the storage account that is replacedociated with the Media Services account. 
            StorageCredentials mediaServicesStorageCredentials =
                new StorageCredentials(storageAccountName, storageAccountKey);

            destinationStorageAccount = new CloudStorageAccount(mediaServicesStorageCredentials, false);

            // Create a new replacedet. 
            var replacedet = context.replacedets.Create(blob.Name, replacedetCreationOptions.None);

            log.Info($"Created new replacedet {replacedet.Name}");

            IAccessPolicy writePolicy = context.AccessPolicies.Create("writePolicy",
                TimeSpan.FromHours(4), AccessPermissions.Write);

            ILocator destinationLocator = context.Locators.CreateLocator(LocatorType.Sas, replacedet, writePolicy);

            CloudBlobClient destBlobStorage = destinationStorageAccount.CreateCloudBlobClient();

            // Get the destination replacedet container reference
            string destinationContainerName = (new Uri(destinationLocator.Path)).Segments[1];

            CloudBlobContainer replacedetContainer = destBlobStorage.GetContainerReference(destinationContainerName);

            try
            {
                replacedetContainer.CreateIfNotExists();
            }
            catch (Exception ex)
            {
                log.Error("ERROR:" + ex.Message);
            }

            log.Info("Created replacedet.");

            // Get hold of the destination blob
            CloudBlockBlob destinationBlob = replacedetContainer.GetBlockBlobReference(blob.Name);

            // Copy Blob
            try
            {
                using (var stream = await blob.OpenReadAsync())
                {
                    await destinationBlob.UploadFromStreamAsync(stream);
                }

                log.Info("Copy Complete.");

                var replacedetFile = replacedet.replacedetFiles.Create(blob.Name);
                replacedetFile.ContentFileSize = blob.Properties.Length;

                //replacedetFile.MimeType = "video/mp4";

                replacedetFile.IsPrimary = true;
                replacedetFile.Update();
                replacedet.Update();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                log.Info(ex.StackTrace);
                log.Info("Copy Failed.");

                throw;
            }

            destinationLocator.Delete();
            writePolicy.Delete();

            return replacedet;
        }

19 Source : AMSIngest.cs
with MIT License
from Azure-Samples

public static async Task<Ireplacedet> CreatereplacedetFromBlobAsync(CloudBlockBlob blob, string replacedetName, TraceWriter log)
        {
            //Get a reference to the storage account that is replacedociated with the Media Services account. 
            StorageCredentials mediaServicesStorageCredentials =
                new StorageCredentials(storageAccountName, storageAccountKey);

            destinationStorageAccount = new CloudStorageAccount(mediaServicesStorageCredentials, false);

            // Create a new replacedet. 
            var replacedet = context.replacedets.Create(blob.Name, replacedetCreationOptions.None);

            log.Info($"Created new replacedet {replacedet.Name}");

            IAccessPolicy writePolicy = context.AccessPolicies.Create("writePolicy",
                TimeSpan.FromHours(4), AccessPermissions.Write);

            ILocator destinationLocator = context.Locators.CreateLocator(LocatorType.Sas, replacedet, writePolicy);

            CloudBlobClient destBlobStorage = destinationStorageAccount.CreateCloudBlobClient();

            // Get the destination replacedet container reference
            string destinationContainerName = (new Uri(destinationLocator.Path)).Segments[1];

            log.Info($"Destination container name: {destinationContainerName}");

            CloudBlobContainer replacedetContainer = destBlobStorage.GetContainerReference(destinationContainerName);

            try
            {
                replacedetContainer.CreateIfNotExists();
            }
            catch (Exception ex)
            {
                log.Error("ERROR:" + ex.Message);
            }

            log.Info("Created replacedet.");

            // Get hold of the destination blob
            CloudBlockBlob destinationBlob = replacedetContainer.GetBlockBlobReference(blob.Name);

            // Copy Blob
            try
            {
                using (var stream = await blob.OpenReadAsync())
                {
                    await destinationBlob.UploadFromStreamAsync(stream);
                }

                log.Info("Copy Complete.");

                var replacedetFile = replacedet.replacedetFiles.Create(blob.Name);
                replacedetFile.ContentFileSize = blob.Properties.Length;

                replacedetFile.IsPrimary = true;
                replacedetFile.Update();
                replacedet.Update();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                log.Info(ex.StackTrace);
                log.Info("Copy Failed.");

                throw;
            }

            destinationLocator.Delete();
            writePolicy.Delete();

            return replacedet;
        }

19 Source : AzureStorageService .cs
with Apache License 2.0
from DICOMcloud

protected override IStorageContainer GetContainer(string containerKey)
        {
            containerKey = GetValidContainerKey ( containerKey );

            CloudBlobContainer cloudContainer = __CloudClient.GetContainerReference ( containerKey );

            cloudContainer.CreateIfNotExists ( );

            return new AzureContainer ( cloudContainer );
        }

19 Source : AzureStorageService .cs
with Apache License 2.0
from DICOMcloud

protected override bool ContainerExists ( string containerKey )
        {
            containerKey = GetValidContainerKey ( containerKey );

            CloudBlobContainer cloudContainer = __CloudClient.GetContainerReference ( containerKey ) ;

            return cloudContainer.Exists ( ) ;
        }

19 Source : DataDownloaderActivity.cs
with MIT License
from gbrueckl

private void GatherDataForOneHour(string sliceStartTime, string urlFormat)
        {
            Uri storageAccountUri = new Uri("http://" + _dataStorageAccountName + ".blob.core.windows.net/");
            string year = sliceStartTime.Substring(0, 4);
            string month = sliceStartTime.Substring(4, 2);
            string day = sliceStartTime.Substring(6, 2);
            string hour = sliceStartTime.Substring(8, 2);
            string minute = sliceStartTime.Substring(10, 2);
            DateTime dataSlotGathered = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(minute), 0);

            _logger.Write("Current data slot gathered : {0}.......", dataSlotGathered);

            // Temporary staging folder
            string dataStagingFolder = string.Format(@"{0}\{1}\{1}-{2}", Path.GetDirectoryName(replacedembly.GetExecutingreplacedembly().Location), year, month);
            Directory.CreateDirectory(dataStagingFolder);

            // Temporary staging file
            string hourlyFileName = string.Format("data-{0}{1}{2}-{3}0000.txt", year, month, day, hour);
            string decompressedFile = Path.Combine(dataStagingFolder, hourlyFileName);

            try
            {
                _logger.Write("Gathering hourly data: ..");
                TriggerRequest(urlFormat, year, month, day, hour, decompressedFile);

                _logger.Write("Uploading to Blob: ..");
                CloudBlobClient blobClient = new CloudBlobClient(storageAccountUri, new StorageCredentials(_dataStorageAccountName, _dataStorageAccountKey));
                string blobPath = string.Format(CultureInfo.InvariantCulture, "httpdownloaddatain/{0}-{1}-{2}-{3}/{4}",
                    year, month, day, hour, hourlyFileName);

                CloudBlobContainer container = blobClient.GetContainerReference(_dataStorageContainer);
                container.CreateIfNotExists();

                var blob = container.GetBlockBlobReference(blobPath);
                blob.UploadFromFile(decompressedFile);
            }
            catch (Exception ex)
            {
                _logger.Write("Error occurred : {0}", ex);
                throw;
            }
            finally
            {
                if (File.Exists(decompressedFile))
                {
                    File.Delete(decompressedFile);
                }
            }
        }

19 Source : Transcriber.cs
with MIT License
from Haishi2016

private async Task deleteFiles(string url)
        {
            string connectionString = "[Storage Account Connection String]";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("clips");
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(url);
            if (blockBlob.Exists())
                await blockBlob.DeleteAsync();
            container = blobClient.GetContainerReference("transcripts");
            blockBlob = container.GetBlockBlobReference(url + "transcript.txt");
            if (blockBlob.Exists())
                await blockBlob.DeleteAsync();
        }

19 Source : Transcriber.cs
with MIT License
from Haishi2016

private async Task uploadTranscript(string fileName, string text, string user)
        {
            string connectionString = "[Storage Account Connection String]";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("transcripts");
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName + "transcript.txt");
            
            using (var stream = new MemoryStream(Encoding.Default.GetBytes(text), false))
            {
                await blockBlob.UploadFromStreamAsync(stream);
            }

            Binding binding = WcfUtility.CreateTcpClientBinding();
            IServiceParreplacedionResolver parreplacedionResolver = ServiceParreplacedionResolver.GetDefault();
            var wcfClientFactory = new WcfCommunicationClientFactory<IStateAggregator>(
                clientBinding: binding,
                serviceParreplacedionResolver: parreplacedionResolver
                );
            var jobClient = new ServiceParreplacedionClient<WcfCommunicationClient<IStateAggregator>>(
                wcfClientFactory,
                new Uri("fabric:/AudioTranscriptionApp/StateAggregator"));
            await jobClient.InvokeWithRetryAsync(client => client.Channel.ReportCompletion(fileName, blockBlob.Uri.AbsoluteUri, user));
        }

19 Source : JobController.cs
with MIT License
from Haishi2016

[HttpPost("[action]"), DisableRequestSizeLimit]
        public async Task<IActionResult> SubmitFileJob()
        {
            //var configPackage = this.Context.CodePackageActivationContext.GetConfigurationPackageObject("Config");
            //string connectionString = configPackage.Settings.Sections["JobManagerConfig"].Parameters["StorageConnectionString"].Value;
            string connectionString = "[Storage Account Connection String]";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("clips");
            foreach (var file in Request.Form.Files)
            {
                CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.Name);
                await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
                ITranscriber proxy = ActorProxy.Create<ITranscriber>(ActorId.CreateRandom(), new Uri("fabric:/AudioTranscriptionApp/TranscriberActorService"));
                proxy.SubmitJob(file.Name, GetUserName().Result);
            }        
            return Ok();
        }

19 Source : Transcriber.cs
with MIT License
from Haishi2016

private async Task<string> getAudioFileFromBlob(string tempFolder, string url, CancellationToken token)
        {
            string connectionString = "[Storage Account Connection String]";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("clips");
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(url);
            string fileName = Path.Combine(tempFolder, url);
            token.ThrowIfCancellationRequested();
            await blockBlob.DownloadToFileAsync(fileName, FileMode.Create);
            return fileName;
        }

19 Source : Program.cs
with MIT License
from Knowzy

static int Main(string[] args)
        {
            Console.WriteLine("Custom Vision Image Trainer V1.0");
            if (args.Length < 4 || args.Contains("-?"))
            {
                Console.WriteLine("Usage: customvisiontrainer.exe {custom vision account key} {custom vision project} {source image uri} {image tag(s)}");
                return 1;
            }
            // Create the Api, preplaceding in a credentials object that contains the training key
            TrainingApiCredentials trainingCredentials = new TrainingApiCredentials(args[0]);
            TrainingApi trainingApi = new TrainingApi(trainingCredentials);
            
            // Get a reference to the project and create a tag
            var project = trainingApi.GetProjects().First(proj => String.Equals(proj.Name, args[1], StringComparison.OrdinalIgnoreCase));

            // Create the specified tag(s), if it doesn't already exist
            var tags = args[3].Split(';')
                .Select(tag =>
                {
                    var tagObject = trainingApi.GetTags(project.Id).Tags.FirstOrDefault(projTag => String.Equals(projTag.Name, tag, StringComparison.OrdinalIgnoreCase));
                    if (tagObject == null)
                    {
                        tagObject = trainingApi.CreateTag(project.Id, tag);
                    }
                    return tagObject;
                })
                .ToList();

            // Enumerate the list of images from the specified root uri
            var storageUri = new UriBuilder(args[2]);
            var path = storageUri.Path;
            storageUri.Path = "";
            var blobClient = new CloudBlobClient(storageUri.Uri);
            var pathSegments = path.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
            var container = blobClient.GetContainerReference(pathSegments[0]);
            var blobUris = container.ListBlobs(String.Join("/", pathSegments.Skip(1)))
                .Select(blobItem => blobItem.Uri)
                .ToList();

            // Upload the images directly to the custom vision project
            var images = new ImageUrlCreateBatch(tags.Select(tag => tag.Id).ToList(),
                blobUris.Select(blobUri => blobUri.ToString()).ToList());
            trainingApi.CreateImagesFromUrlsAsync(project.Id, images, new CancellationTokenSource(60000).Token).Wait();
            return 0;
        }

19 Source : BlobStore.cs
with MIT License
from loekd

internal async Task InitializeAsync()
        {
            if (_isInitialized) return;

            if (_blobClient == null)
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_blobStorageConnectionString);
                _blobClient = storageAccount.CreateCloudBlobClient();
                _blobClient.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.ExponentialRetry(TimeSpan.FromSeconds(1), 10);
                _blobClient.DefaultRequestOptions.AbsorbConditionalErrorsOnRetry = true;
            }

            _blobContainer = _blobClient.GetContainerReference(_blobContainerName);
            await _blobContainer.CreateIfNotExistsAsync();            
            _isInitialized = true;
        }

19 Source : ImagesController.cs
with MIT License
from matvelloso

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;
        }

19 Source : Program.cs
with MIT License
from microsoft

private static async Task<bool> CreateBlobContainerForImageStore()
        {
            Console.WriteLine("Creating Blob Container for Image Store Skill...");
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["BlobStorageAccountConnectionString"]);
                CloudBlobClient client = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = client.GetContainerReference(BlobContainerNameForImageStore);
                await container.CreateIfNotExistsAsync();
                // Note that setting this permission means that the container will be publically accessible.  This is necessary for
                // the website to work properly.  Remove these next 3 lines if you start using this code to process any private or
                // confidential data, but note that the website will stop working properly if you do.
                BlobContainerPermissions permissions = container.GetPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                await container.SetPermissionsAsync(permissions);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating blob container: {0}", ex.Message);
                return false;
            }
            return true;
        }

19 Source : ObjectDetectionAppService.cs
with MIT License
from microsoft

public async Task SaveResults(byte[] file, string container, string fileName)
        {
            CloudBlobContainer theContainer = null;

            if (_cloudBlobClient == null) throw new InvalidOperationException("blobClient is null");

            var segments = container.Split(@"/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var rootContainerPath = segments.First();

            var relativePath = String.Join(@"/", segments.Except(new string[] { rootContainerPath }));

            theContainer = _cloudBlobClient.GetContainerReference($"{rootContainerPath}");

            await theContainer.CreateIfNotExistsAsync();
            var permission = new BlobContainerPermissions();
            permission.PublicAccess = BlobContainerPublicAccessType.Blob;
            await theContainer.SetPermissionsAsync(permission);
            if (relativePath != rootContainerPath)
            {
                fileName = Path.Combine(relativePath, fileName);
            }
            var blob = theContainer.GetBlockBlobReference(fileName);
            await blob.UploadFromByteArrayAsync(file, 0, file.Length);
        }

19 Source : ObjectDetectionAppService.cs
with MIT License
from microsoft

public async Task SaveHtmlResults(string html, string container, string fileName)
        {
            CloudBlobContainer theContainer = null;

            if (_cloudBlobClient == null) throw new InvalidOperationException("blobClient is null");

            var segments = container.Split(@"/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var rootContainerPath = segments.First();

            var relativePath = String.Join(@"/", segments.Except(new string[] { rootContainerPath }));

            theContainer = _cloudBlobClient.GetContainerReference($"{rootContainerPath}");

            await theContainer.CreateIfNotExistsAsync();
            var permission = new BlobContainerPermissions();
            permission.PublicAccess = BlobContainerPublicAccessType.Blob;
            await theContainer.SetPermissionsAsync(permission);
            if (relativePath != rootContainerPath)
            {
                fileName = Path.Combine(relativePath, fileName);
            }
            var blob = theContainer.GetBlockBlobReference(fileName);
            await blob.UploadTextAsync(html);
        }

19 Source : ObjectDetectionAppService.cs
with MIT License
from microsoft

public async Task<PredictionDetail> GetPredictionAsync(string folderId)
        {
            if (String.IsNullOrWhiteSpace(folderId))
                throw new ArgumentNullException("folderId");

            var blobContainer = _cloudBlobClient.GetContainerReference(folderId);
            bool exists = await blobContainer.ExistsAsync();
            if (!exists)
                throw new DirectoryNotFoundException($"Container {folderId} does not exist");

            var groupsBlob = blobContainer.GetBlockBlobReference("groups.json");

            var detail = new PredictionDetail();

            detail.OriginalImage = await this.GetFile(folderId, "original.png");
            detail.PredictionImage = await this.GetFile(folderId, "predicted.png");
            detail.PredictedObjects = await this.GetFile<IList<PredictedObject>>(folderId, "results.json");
            var groupBox = await this.GetFile<GroupBox>(folderId, "groups.json");
            detail.GroupBox = new List<GroupBox> { groupBox };

            return detail;
        }

19 Source : ObjectDetectionAppService.cs
with MIT License
from microsoft

public async Task<byte[]> GetFile(string container, string file)
        {
            var blobcontainer = _cloudBlobClient.GetContainerReference(container);
            if (!await blobcontainer.ExistsAsync())
            {
                throw new ApplicationException($"container {container} does not exist");
            }
            var blob = blobcontainer.GetBlobReference(file);
            if (!await blob.ExistsAsync())
            {
                throw new ApplicationException($"file {file} does not exist in container {container}");
            }
            using (var ms = new MemoryStream())
            {
                await blob.DownloadToStreamAsync(ms);
                return ms.ToArray();
            }
        }

19 Source : Program.cs
with MIT License
from microsoft

static string GetUriForPromoImage(string imageName)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_storageConnectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("promo");

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(imageName);

            return GetBlobSasUri(blockBlob);
        }

See More Examples