Esempio n. 1
0
        public async Task OnPostAsync(string firstname, string lastname, IFormFile file)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            var sbc = storageAccount.CreateCloudBlobClient();

            //Blob Containers
            var writeContainer = sbc.GetContainerReference("samples-images");
            var readContainer  = sbc.GetContainerReference("sample-images-sm");
            await writeContainer.CreateIfNotExistsAsync();

            await readContainer.CreateIfNotExistsAsync();

            // Queue
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("bjornosqueue");

            await PublishToQueueAsync(queue, new Person(firstname, lastname));

            PublishToBlobStorage(writeContainer, $"{firstname}_{lastname}.png", file);

            // De person die net is gepost zit nog in de queue deze moet nog door de azure function
            // naar table gestorage gezet worden Oftewel wij lopen hier in principe 1 post achter En
            // dat is prima voor test doeleinden
            var selectAllQuery = new TableQuery <Person>();

            var account = CosmosCloudStorageAccount.Parse(connectionString);
            var client  = account.CreateCloudTableClient();
            var table   = client.GetTableReference("persons");

            Persons = table.ExecuteQuery(selectAllQuery).ToList();
        }
Esempio n. 2
0
        public CommandAuditWriter(ICommandAuditOptions options = null)
        {
            auditContainer = new Lazy <CloudBlobContainer>(() => BlobCloudStorageAccount
                                                           .Parse((options ?? CommandAuditOptions.Default).ConnectionString)
                                                           .CreateCloudBlobClient().GetContainerReference(GetAuditContainerName(options)));

            auditTable = new Lazy <CloudTable>(() => TableCloudStorageAccount
                                               .Parse((options ?? CommandAuditOptions.Default).ConnectionString)
                                               .CreateCloudTableClient().GetTableReference(GetAuditTableName(options)));
        }
Esempio n. 3
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var services = builder.Services;

            services.AddTransient <ISverigesRadioApiClient>(s => SverigesRadioApiClient.CreateClient());

            services.AddTransient(x =>
            {
                var configuration  = x.GetRequiredService <IConfiguration>();
                var storageAccount = CloudStorageAccount.Parse(configuration["AzureStorage:BlobsConnectionString"]);
                return(storageAccount.CreateCloudBlobClient());
            });

            services.AddTransient(x =>
            {
                var configuration  = x.GetRequiredService <IConfiguration>();
                var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(configuration["AzureStorage:TablesConnectionString"]);
                return(storageAccount.CreateCloudTableClient(new TableClientConfiguration()));
            });

            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                return(SpeechConfig.FromSubscription(configuration["AzureSpeech:Key"], configuration["AzureSpeech:Region"]));
            });
            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                return(SpeechBatchClient.CreateApiV2Client(configuration["AzureSpeech:Key"], configuration["AzureSpeech:Hostname"], 443));
            });

            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                var credentials   = new ApiKeyServiceClientCredentials(configuration["AzureTextAnalytics:Key"]);
                return(new TextAnalyticsClient(credentials)
                {
                    Endpoint = configuration["AzureTextAnalytics:Endpoint"]
                });
            });

            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                return(TranslatorClient.CreateClient(configuration["AzureTranslator:Key"], configuration["AzureTranslator:Endpoint"]));
            });

            services.AddTransient <IStorageTransfer, AzureStorageTransfer>();
            services.AddTransient <IStorage, AzureTableStorage>(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new AzureTableStorage(
                           s.GetRequiredService <CloudTableClient>(),
                           configuration["AzureStorage:EpisodeStatusesTableName"],
                           configuration["AzureStorage:EpisodesTableName"],
                           configuration["AzureStorage:EpisodeTranscriptionsTableName"],
                           configuration["AzureStorage:EpisodeTextAnalyticsTableName"],
                           configuration["AzureStorage:EpisodeSpeechTableName"]
                           ));
            });

            services.AddTransient <ISummaryStorage, SummaryAzureTableStorage>(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SummaryAzureTableStorage(
                           s.GetRequiredService <CloudTableClient>(),
                           configuration["AzureStorage:EpisodeSummaryTableName"]
                           ));
            });

            services.AddTransient <SrEpisodesLister>();
            services.AddTransient(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SrEpisodeCollector(
                           configuration["AzureStorage:AudioContainerName"],
                           s.GetRequiredService <IStorageTransfer>(),
                           s.GetRequiredService <ISverigesRadioApiClient>(),
                           s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                           s.GetRequiredService <IStorage>()
                           ));
            });

            services.AddTransient(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SrEpisodeTranscriber(
                           configuration["AzureStorage:EpisodeTranscriptionsContainerName"],
                           s.GetRequiredService <ISpeechBatchClientFactory>(),
                           s.GetRequiredService <IStorageTransfer>(),
                           s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                           s.GetRequiredService <IStorage>(),
                           s.GetRequiredService <CloudBlobClient>()
                           ));
            });

            services.AddTransient <SrEpisodeTextEnricher>();
            services.AddTransient <SrEpisodeSummarizer>();
            services.AddTransient(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SrEpisodeSpeaker(
                           configuration["AzureStorage:EpisodeSpeechContainerName"],
                           s.GetRequiredService <ISpeechConfigFactory>(),
                           s.GetRequiredService <IStorage>(),
                           s.GetRequiredService <ILogger <SrEpisodeSpeaker> >(),
                           s.GetRequiredService <CloudBlobClient>()
                           ));
            });

            services.AddTransient <SrWorker>();
        }
Esempio n. 4
0
        public async Task InitializeAsync()
        {
            string nowString = DateTime.UtcNow.ToString("yyMMdd-HHmmss");

            string GetDestPath(int counter)
            {
                return(Path.Combine(Path.GetTempPath(), "FunctionsE2E", $"{nowString}_{counter}"));
            }

            // Prevent collisions.
            int i = 0;

            _copiedRootPath = GetDestPath(i++);
            while (Directory.Exists(_copiedRootPath))
            {
                _copiedRootPath = GetDestPath(i++);
            }

            FileUtility.CopyDirectory(_rootPath, _copiedRootPath);

            var extensionsToInstall = GetExtensionsToInstall();

            if (extensionsToInstall != null && extensionsToInstall.Length > 0)
            {
                TestFunctionHost.WriteNugetPackageSources(_copiedRootPath, "http://www.myget.org/F/azure-appservice/api/v2", "https://www.myget.org/F/azure-appservice-staging/api/v2", "https://api.nuget.org/v3/index.json");
                var options = new OptionsWrapper <ScriptJobHostOptions>(new ScriptJobHostOptions
                {
                    RootScriptPath = _copiedRootPath
                });

                var manager = new ExtensionsManager(options, NullLogger <ExtensionsManager> .Instance, new TestExtensionBundleManager());
                await manager.AddExtensions(extensionsToInstall);
            }

            string logPath = Path.Combine(Path.GetTempPath(), @"Functions");

            if (!string.IsNullOrEmpty(_functionsWorkerRuntime))
            {
                Environment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, _functionsWorkerRuntime);
                Environment.SetEnvironmentVariable(RpcWorkerConstants.FunctionsWorkerProcessCountSettingName, _workerProcessCount.ToString());
            }
            if (!string.IsNullOrEmpty(_functionsWorkerRuntimeVersion))
            {
                Environment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, _functionsWorkerRuntimeVersion);
            }

            FunctionsSyncManagerMock = new Mock <IFunctionsSyncManager>(MockBehavior.Strict);
            FunctionsSyncManagerMock.Setup(p => p.TrySyncTriggersAsync(It.IsAny <bool>())).ReturnsAsync(new SyncTriggersResult {
                Success = true
            });

            Host = new TestFunctionHost(_copiedRootPath, logPath,
                                        configureScriptHostWebJobsBuilder: webJobsBuilder =>
            {
                ConfigureScriptHost(webJobsBuilder);
            },
                                        configureScriptHostServices: s =>
            {
                s.AddSingleton <IFunctionsSyncManager>(_ => FunctionsSyncManagerMock.Object);
                s.AddSingleton <IMetricsLogger>(_ => MetricsLogger);
            },
                                        configureWebHostServices: s =>
            {
                s.AddSingleton <IEventGenerator>(_ => EventGenerator);
                ConfigureWebHost(s);
            });

            string connectionString            = Host.JobHostServices.GetService <IConfiguration>().GetWebJobsConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            QueueClient = storageAccount.CreateCloudQueueClient();
            BlobClient  = storageAccount.CreateCloudBlobClient();

            TableStorageAccount tableStorageAccount = TableStorageAccount.Parse(connectionString);

            TableClient = tableStorageAccount.CreateCloudTableClient();

            await CreateTestStorageEntities();

            MasterKey = await Host.GetMasterKeyAsync();
        }
Esempio n. 5
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            ServicePointManager.DefaultConnectionLimit = 100;

            services.AddSingleton <ISverigesRadioApiClient>(s => SverigesRadioApiClient.CreateClient());

            services.AddTransient(x =>
            {
                var storageAccount = CloudStorageAccount.Parse(hostContext.Configuration["AzureStorage:BlobsConnectionString"]);
                return(storageAccount.CreateCloudBlobClient());
            });

            services.AddTransient(x =>
            {
                var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(hostContext.Configuration["AzureStorage:TablesConnectionString"]);
                return(storageAccount.CreateCloudTableClient(new TableClientConfiguration()));
            });


            var azureSpeechClients = new List <SpeechBatchClientOptions>();
            hostContext.Configuration.GetSection("AzureSpeech:Clients").Bind(azureSpeechClients);
            services.AddSingleton <ISpeechConfigFactory>(x => new RoundRobinSpeechConfigFactory(azureSpeechClients));
            services.AddSingleton <ISpeechBatchClientFactory>(x => new RoundRobinSpeechBatchClientFactory(azureSpeechClients));

            services.AddTransient(x =>
            {
                var credentials = new ApiKeyServiceClientCredentials(hostContext.Configuration["AzureTextAnalytics:Key"]);
                return(new TextAnalyticsClient(credentials)
                {
                    Endpoint = hostContext.Configuration["AzureTextAnalytics:Endpoint"]
                });
            });

            services.AddTransient(x => TranslatorClient.CreateClient(hostContext.Configuration["AzureTranslator:Key"], hostContext.Configuration["AzureTranslator:Endpoint"]));

            services.AddTransient <IStorageTransfer, AzureStorageTransfer>();
            services.AddTransient <IStorage, AzureTableStorage>(s => new AzureTableStorage(
                                                                    s.GetRequiredService <CloudTableClient>(),
                                                                    hostContext.Configuration["AzureStorage:EpisodeStatusesTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodesTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodeTranscriptionsTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodeTextAnalyticsTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodeSpeechTableName"]
                                                                    ));

            services.AddTransient <ISummaryStorage, SummaryAzureTableStorage>(s => new SummaryAzureTableStorage(
                                                                                  s.GetRequiredService <CloudTableClient>(),
                                                                                  hostContext.Configuration["AzureStorage:EpisodeSummaryTableName"]
                                                                                  ));


            services.AddTransient <IWordCountStorage, WordCounterAzureTableStorage>(s =>
            {
                var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(hostContext.Configuration["AzureStorage:BlobsConnectionString"]);
                var tableClient    = storageAccount.CreateCloudTableClient(new TableClientConfiguration());

                return(new WordCounterAzureTableStorage(
                           tableClient,
                           hostContext.Configuration["AzureStorage:EpisodeWordCountTableName"]
                           ));
            });

            services.AddTransient <SrEpisodesLister>();
            services.AddTransient(s => new SrEpisodeCollector(
                                      hostContext.Configuration["AzureStorage:AudioContainerName"],
                                      s.GetRequiredService <IStorageTransfer>(),
                                      s.GetRequiredService <ISverigesRadioApiClient>(),
                                      s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                                      s.GetRequiredService <IStorage>(),
                                      hostContext.Configuration["FFMpeg:Location"]
                                      ));

            services.AddTransient(s => new SrEpisodeTranscriber(
                                      hostContext.Configuration["AzureStorage:EpisodeTranscriptionsContainerName"],
                                      s.GetRequiredService <ISpeechBatchClientFactory>(),
                                      s.GetRequiredService <IStorageTransfer>(),
                                      s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                                      s.GetRequiredService <IStorage>(),
                                      s.GetRequiredService <CloudBlobClient>()
                                      ));

            services.AddTransient <SrEpisodeTextEnricher>();
            services.AddTransient <SrEpisodeSummarizer>();
            services.AddTransient(s => new SrEpisodeSpeaker(
                                      hostContext.Configuration["AzureStorage:EpisodeSpeechContainerName"],
                                      s.GetRequiredService <ISpeechConfigFactory>(),
                                      s.GetRequiredService <IStorage>(),
                                      s.GetRequiredService <ILogger <SrEpisodeSpeaker> >(),
                                      s.GetRequiredService <CloudBlobClient>()
                                      ));

            services.AddTransient <SrEpisodeWordCounter>();

            services.AddTransient <SrWorker>();

            services.AddHostedService <Worker>();
        });