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
        /// <summary>
        /// Creates an image manager along with storage dependencies, if needed
        /// </summary>
        /// <param name="tableStorageAccount">
        /// The storage account used to save original and optimized images
        /// </param>
        /// <param name="imageTableName">
        /// The name of the table storing the relationship between original
        /// and optimized images
        /// </param>
        /// <param name="optimizer">
        /// The image optimizer used to optimize images
        /// </param>
        /// <returns></returns>
        public static async Task <ImageManager> CreateAsync(CloudStorageAccount tableStorageAccount, Microsoft.Azure.Storage.CloudStorageAccount blobStorageAccount, string imageTableName, IImageOptimizer optimizer)
        {
            var tableClient = tableStorageAccount.CreateCloudTableClient();
            var table       = tableClient.GetTableReference(imageTableName);
            await table.CreateIfNotExistsAsync().ConfigureAwait(false);

            return(new ImageManager(table, blobStorageAccount.CreateCloudBlobClient(), optimizer));
        }
        public AzureJobStorage(AzureStorageOptions options)
        {
            _options = options;

            _cosmosAccount = CloudStorageAccount.Parse(options.ConnectionString);
            _account       = Microsoft.Azure.Storage.CloudStorageAccount.Parse(options.ConnectionString);

            _tableClient = _cosmosAccount.CreateCloudTableClient();
            _blobClient  = _account.CreateCloudBlobClient();
            _queueClient = _account.CreateCloudQueueClient();

            // ensure the required tables / containers exists
            GetTable(SERVER_TABLE).CreateIfNotExists();
            GetTable(SETS_TABLE).CreateIfNotExists();
            GetTable(LISTS_TABLE).CreateIfNotExists();
            GetTable(JOBS_TABLE).CreateIfNotExists();
            GetTable(HASHS_TABLE).CreateIfNotExists();
            GetTable(COUNTERS_TABLE).CreateIfNotExists();

            GetContainer(JOB_CONTAINER).CreateIfNotExists();
        }
Esempio n. 4
0
        /// <inheritdoc />
        public virtual async Task <IEnumerable <string> > ListBlobContainersAsync()
        {
            List <string>          containers = new List <string>();
            BlobContinuationToken  token      = new BlobContinuationToken();
            CloudBlobClient        client     = _account.CreateCloudBlobClient();
            ContainerResultSegment result;

            do
            {
                result = await client.ListContainersSegmentedAsync(token).ConfigureAwait(false);

                if (result.Results?.Any() == false)
                {
                    break;
                }

                containers.AddRange(result.Results.Select(c => c.Name));
                token = result.ContinuationToken;
            }while (token != null);

            return(containers);
        }
Esempio n. 5
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. 6
0
 public BlobStorageService()
 {
     _cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
     _blobClient          = _cloudStorageAccount.CreateCloudBlobClient();
 }