private void ConfigureOptions(IServiceCollection services) { services.AddOptions(); bool isLocal = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")); var configBuilder = new ConfigurationBuilder(); if (isLocal) { configBuilder.SetBasePath(System.Environment.CurrentDirectory); configBuilder.AddJsonFile(@"local.settings.json", optional: true, reloadOnChange: false); } Configuration = configBuilder.AddEnvironmentVariables().Build(); var blobStorageSettings = new BlobStorageSettings(); Configuration.Bind("BlobStorageSettings", blobStorageSettings); services.Configure <BlobStorageSettings>(env => { env.StorageConnectionString = blobStorageSettings.StorageConnectionString; env.ContainerName = blobStorageSettings.ContainerName; }); var serviceBusSettings = new ServiceBusSettings(); Configuration.Bind("ServiceBusSettings", serviceBusSettings); services.Configure <ServiceBusSettings>(env => { env.ServiceBusConnectionString = serviceBusSettings.ServiceBusConnectionString; env.QueueName = serviceBusSettings.QueueName; }); }
static void Main(string[] args) { try { Console.Title = ServiceName; _config = Config.Build(); var serviceBusSettings = new ServiceBusSettings(); var serviceBusQueuesSettings = new ServiceBusQueuesSettings(); var connectionStringSettings = new ConnectionStringSettings(); var blobSettings = new BlobStorageSettings(); _config.GetSection("ServiceBus").Bind(serviceBusSettings); _config.GetSection("ServiceBusQueues").Bind(serviceBusQueuesSettings); _config.GetSection("ConnectionStrings").Bind(connectionStringSettings); _config.GetSection("BlobStorage").Bind(blobSettings); _infrastructureSettings = InfrastructureSettings.Create(connectionStringSettings, serviceBusQueuesSettings, serviceBusSettings, blobSettings); DisplayConfiguration(); ProductServiceBus.Instance.GetProductServiceBus(); Console.ReadLine(); ProductServiceBus.Instance.StopProductServiceBus(); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
public async Task Consume(ConsumeContext <IDeleteProductCommand> context) { try { var connectionStringSettings = new ConnectionStringSettings(); var blobStorageSettings = new BlobStorageSettings(); _configurationRoot.GetSection("ConnectionStrings").Bind(connectionStringSettings); _configurationRoot.GetSection("BlobStorage").Bind(blobStorageSettings); var dbContext = ProductDbContext.GetProductDbContext(connectionStringSettings.DefaultConnection); var repository = new RepositoryWrapper(dbContext); var product = repository.Product.GetProductById(Guid.Parse(context.Message.ProductId)); if (product != null) { var deleteblob = new PhotoBlob(blobStorageSettings); await deleteblob.DeleteBlob(product.BlobName); } var productService = new ProductCatalogService(repository); var result = await productService.DeleteProduct(context.Message.ProductId); var deletedEvent = new ProductDeletedEvent(result); await context.RespondAsync(deletedEvent); } catch (Exception e) { Console.WriteLine(e); throw; } }
public PhotoBlob(BlobStorageSettings blobStorageSettings) { var storageAccount = CloudStorageAccount.Parse(blobStorageSettings.ConnectionString); _blobClient = storageAccount.CreateCloudBlobClient(); _blobStorageSettings = blobStorageSettings; }
public async Task Consume(ConsumeContext <ICreateProductCommand> context) { try { var connectionStringSettings = new ConnectionStringSettings(); var blobStorageSettings = new BlobStorageSettings(); _configurationRoot.GetSection("ConnectionStrings").Bind(connectionStringSettings); _configurationRoot.GetSection("BlobStorage").Bind(blobStorageSettings); var dbContext = ProductDbContext.GetProductDbContext(connectionStringSettings.DefaultConnection); var repository = new RepositoryWrapper(dbContext); var productService = new ProductCatalogService(repository); var product = repository.Product.GetByCondition(x => x.Code.Equals(context.Message.Code) || x.Name.Equals(context.Message.Name)); if (product?.Count() == 0) { //upload photo to blob var repo = BlobConfigurator.GetMessageDataRepository(blobStorageSettings); var bytesArray = Convert.FromBase64String(context.Message.Photo); var payload = repo.PutBytes(bytesArray).Result; context.Message.BlobName = payload.Address.AbsolutePath; } //create product var result = await productService.CreateProduct(context.Message); var createdEvent = new ProductCreatedEvent(result); await context.RespondAsync(createdEvent); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task Consume(ConsumeContext <IGetProductCommand> context) { try { var connectionStringSettings = new ConnectionStringSettings(); var blobStorageSettings = new BlobStorageSettings(); _configurationRoot.GetSection("ConnectionStrings").Bind(connectionStringSettings); _configurationRoot.GetSection("BlobStorage").Bind(blobStorageSettings); var dbContext = ProductDbContext.GetProductDbContext(connectionStringSettings.DefaultConnection); var repository = new RepositoryWrapper(dbContext); var productService = new ProductCatalogService(repository); var result = await productService.GetProduct(context.Message.ProductId); var getProductEvent = new ProductRetrievedEvent(result); if (getProductEvent.ProductDto != null) { var phtoBlob = new PhotoBlob(blobStorageSettings); var byteArray = await phtoBlob.DownloadBlob(getProductEvent.ProductDto.BlobName); getProductEvent.ProductDto.Photo = byteArray; } await context.RespondAsync(getProductEvent); } catch (Exception e) { Console.WriteLine(e); throw; } }
private InfrastructureSettings() { ConnectionStringSettings = new ConnectionStringSettings(); ServiceBusQueuesSettings = new ServiceBusQueuesSettings(); ServiceBusSettings = new ServiceBusSettings(); BlobStorageSettings = new BlobStorageSettings(); }
// CONSTRUCTORS public PhotoBlobStorage(BlobStorageSettings settings) { CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(settings.ConnectionString); CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); ConfigureCors(cloudBlobClient); _cloudBlobContainerPhotos = CreateContainer(settings, cloudBlobClient); }
public void TestInit() { appSettings = new NameValueCollection(); connectionStrings = new ConnectionStringSettingsCollection(); settings = new AppSettings(appSettings, connectionStrings); blobStorageSettings = new BlobStorageSettings(settings); iBlobStorageSettings = new Mock <IBlobStorageSettings>(); service = new FileStorageService(settings, iBlobStorageSettings.Object); iService = new Mock <IFileStorageService>(); }
public MyBlobManager(BlobStorageSettings settings) { try { var storageAccount = CloudStorageAccount.Parse(settings.ConnectionString); //Storage Account var cloudBlobClient = storageAccount.CreateCloudBlobClient(); //Cliente blob sobre la storageaccount _blobContainer = cloudBlobClient.GetContainerReference(settings.ContainerName); //Contenedor blob } catch (Exception ex) { throw ex; } }
public AzureBlobRepository(IOptions <BlobStorageSettings> options) { settings = options.Value; if (!CloudStorageAccount.TryParse(settings.ConnectionString, out var account)) { throw new Exception("No valid connection string"); } client = account.CreateCloudBlobClient(); container = client.GetContainerReference(settings.ContainerName); }
public static IServiceCollection AddThirdPartyServices(this IServiceCollection services, IConfiguration configuration) { var blobStorageSettings = new BlobStorageSettings(); configuration.GetSection(BlobStorageSettings.SettingName).Bind(blobStorageSettings); services.AddSingleton(x => new BlobServiceClient(blobStorageSettings.ConnectionString)); services.AddScoped <IFileStorageService, BlobStorageService>(); return(services); }
public static void AddBlobStorage(this IServiceCollection services, IConfiguration configuration) { services.AddScoped <IImageService, ImageService>(); services.Configure <BlobStorageSettings>(configuration.GetSection("BlobStorage")); services.AddScoped <IPhotoBlobStorage>(servicesProvider => { BlobStorageSettings settings = servicesProvider.GetRequiredService <IOptions <BlobStorageSettings> >().Value; return(new PhotoBlobStorage(settings)); }); }
private CloudBlobContainer CreateContainer(BlobStorageSettings settings, CloudBlobClient cloudBlobClient) { CloudBlobContainer cloudBlobContainerPhotos = cloudBlobClient.GetContainerReference(settings.ImageContainerName); cloudBlobContainerPhotos.CreateIfNotExists(); BlobContainerPermissions permissions = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob, }; cloudBlobContainerPhotos.SetPermissionsAsync(permissions); return(cloudBlobContainerPhotos); }
public static InfrastructureSettings Create(ConnectionStringSettings connectionStringSettings, ServiceBusQueuesSettings serviceBusQueuesSettings, ServiceBusSettings serviceBusSettings, BlobStorageSettings blobStorageSettings) { var infrastructureSettings = new InfrastructureSettings { ConnectionStringSettings = connectionStringSettings, ServiceBusQueuesSettings = serviceBusQueuesSettings, ServiceBusSettings = serviceBusSettings, BlobStorageSettings = blobStorageSettings }; return(infrastructureSettings); }
public static EnchiladaMessageDataRepository GetMessageDataRepository(BlobStorageSettings settings) { var adapter = new BlobStorageAdapterConfiguration { AdapterName = settings.AdapterName, CreateContainer = true, ConnectionString = settings.ConnectionString, ContainerReference = settings.PhotoContainerReference }; var factory = new EnchiladaMessageDataRepositoryFactory(); var messageDataRepository = factory.Create(adapter); return(messageDataRepository); }
public static void ConfigureAppSettings(this IServiceCollection services, IConfiguration configuration) { var sectionName = "BlobStorageSettings"; var section = configuration.GetSection(sectionName); if (section.Exists() is false) { throw new ArgumentException($"Section {sectionName} does not exist"); } var blobStorageSettings = new BlobStorageSettings() { ContainerName = configuration["BlobStorageSettings:ContainerName"], BlobStorageUrl = configuration["BlobStorageSettings:BlobStorageUrl"] }; services.AddSingleton(blobStorageSettings); }
public BlobStorageService(IOptionsMonitor <BlobStorageSettings> blobStorageSettings, ICacheService cacheService, IMapper mapper) { BlobStorageSettings blobStorageSettings1 = blobStorageSettings.CurrentValue; _cacheService = cacheService; _mapper = mapper; CloudBlobClient blobClient = CloudStorageAccount.Parse(blobStorageSettings1.ConnectionString) .CreateCloudBlobClient(); _postsContainer = blobClient.GetContainerReference(blobStorageSettings1.PostsContainerName); _filesContainer = blobClient.GetContainerReference(blobStorageSettings1.FilesContainerName); InitializeAsync() .GetAwaiter() .GetResult(); }
public void Configure(IWebJobsBuilder builder) { builder.AddDependencyInjection(); var configuration = new ConfigurationBuilder() .SetBasePath(Environment.CurrentDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); BuildCosmosDbSettings(builder.Services, configuration); var blobStorageSettings = new BlobStorageSettings(); configuration.Bind("BlobStorageSettings", blobStorageSettings); builder.Services.AddSingleton <IBlobStorageSettings>(blobStorageSettings); var ifaocSearchSettings = new FaocSearchServiceSettings(); configuration.Bind("FaocSearchServiceSettings", ifaocSearchSettings); builder.Services.AddSingleton <IFaocSearchServiceSettings>(ifaocSearchSettings); builder.Services.AddSingleton <IConfiguration>(configuration); //builder.Services.Configure<CosmosDbCollectionSettings>(configuration.GetSection(nameof(CosmosDbCollectionSettings))); builder.Services.Configure <SearchServiceSettings>(configuration.GetSection(nameof(SearchServiceSettings))); builder.Services.Configure <VenueServiceSettings>(configuration.GetSection(nameof(VenueServiceSettings))); builder.Services.Configure <ProviderServiceSettings>(configuration.GetSection(nameof(ProviderServiceSettings))); builder.Services.AddScoped <ICosmosDbHelper, CosmosDbHelper>(); builder.Services.AddTransient <ICourseAuditService, CourseAuditService>(); builder.Services.AddTransient <ICourseArchiveService, CourseArchiveService>(); builder.Services.AddTransient <ISearchServiceWrapper, SearchServiceWrapper>(); builder.Services.AddTransient <IFaocSearchServiceWrapper, FaocSearchServiceWrapper>(); builder.Services.AddTransient <IVenueServiceWrapper, VenueServiceWrapper>(); builder.Services.AddTransient <IProviderServiceWrapper, ProviderServiceWrapper>(); builder.Services.AddTransient <IBlobStorageHelper, BlobStorageHelper>(); builder.Services.AddTransient((provider) => new HttpClient()); ReportGenerationResolver(builder.Services); var serviceProvider = builder.Services.BuildServiceProvider(); }
public async Task Consume(ConsumeContext <IUpdateProductCommand> context) { try { var connectionStringSettings = new ConnectionStringSettings(); var blobStorageSettings = new BlobStorageSettings(); _configurationRoot.GetSection("ConnectionStrings").Bind(connectionStringSettings); _configurationRoot.GetSection("BlobStorage").Bind(blobStorageSettings); var dbContext = ProductDbContext.GetProductDbContext(connectionStringSettings.DefaultConnection); var repository = new RepositoryWrapper(dbContext); var product = repository.Product.GetProductById(context.Message.Id); if (product != null) { //delete existing blob var deleteblob = new PhotoBlob(blobStorageSettings); await deleteblob.DeleteBlob(product.BlobName); //upload photo to blob var repo = BlobConfigurator.GetMessageDataRepository(blobStorageSettings); var bytesArray = Convert.FromBase64String(context.Message.Photo); var payload = repo.PutBytes(bytesArray).Result; context.Message.BlobName = payload.Address.AbsolutePath; } var productService = new ProductCatalogService(repository); var result = await productService.UpdateProduct(context.Message); var updatedEvent = new ProductUpdatedEvent(result); await context.RespondAsync(updatedEvent); } catch (Exception e) { Console.WriteLine(e); throw; } }
private static void CheckConfigurations() { BlobStorageSettings = ServiceProvider.GetRequiredService <BlobStorageSettings>(); if (!BlobStorageSettings.ValidateConfiguration().Success) { Console.WriteLine("Blob storage settings is not configured properly"); } DatabaseCsvSettings = ServiceProvider.GetRequiredService <DatabaseCsvSettings>(); if (!BlobStorageSettings.ValidateConfiguration().Success) { Console.WriteLine("Databasecsv settings is not configured properly"); } FileImporterSettings = ServiceProvider.GetRequiredService <FileImporterSettings>(); if (!FileImporterSettings.ValidateConfiguration().Success) { Console.WriteLine("FileImporter settings is not configured properly"); } }
public PersistGameCommand(BlobStorageSettings blobStorageSettings) { _blobStorageSettings = blobStorageSettings ?? throw new ArgumentNullException(nameof(blobStorageSettings)); }
public FileController(BlobServiceClient blobServiceClient, BlobStorageSettings blobStorageSettings) { _blobServiceClient = blobServiceClient; _blobStorageSettings = blobStorageSettings; }
public BlobStorageDownloadProcessor(BlobStorageSettings blobStorageSettings, GenericHttpClient genericHttpClient) { this.blobStorageSettings = blobStorageSettings; this.genericHttpClient = genericHttpClient; }
public BlobStorageService(IOptions <BlobStorageSettings> settings) { _settings = settings.Value; }