예제 #1
0
        private string UploadProfilePicture(IFormFile profilePicture)
        {
            var reader = profilePicture.OpenReadStream();
            var cloudStorageAccount = CloudStorageAccount.Parse(@"DefaultEndpointsProtocol=https;AccountName=atazure;AccountKey=KfLMRh/w+nHjvUmPdhnBQtgYamgn418nqxMqOrk0T4Kxt14PnUXBpJuH+dEgvIHWBoeXq4H+Fi6NKZK84yNUIw==;EndpointSuffix=core.windows.net");
            var blobClient          = cloudStorageAccount.CreateCloudBlobClient();
            var container           = blobClient.GetContainerReference("fotoperfil");

            container.CreateIfNotExists();
            var blob = container.GetBlockBlobReference(Guid.NewGuid().ToString());

            blob.UploadFromStream(reader);
            var destinyOfThePictureInTheCloud = blob.Uri.ToString();

            return(destinyOfThePictureInTheCloud);
        }
예제 #2
0
        public async Task InitializeAsync()
        {
            if (!string.IsNullOrEmpty(_functionsWorkerLanguage))
            {
                Environment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, _functionsWorkerLanguage);
            }
            IConfiguration      configuration    = TestHelpers.GetTestConfiguration();
            string              connectionString = configuration.GetWebJobsConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount   = CloudStorageAccount.Parse(connectionString);

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

            TableStorageAccount tableStorageAccount = TableStorageAccount.Parse(connectionString);

            TableClient = tableStorageAccount.CreateCloudTableClient();

            await CreateTestStorageEntities();

            // ApiHubTestHelper.SetDefaultConnectionFactory();

            //ILoggerProviderFactory loggerProviderFactory = new TestLoggerProviderFactory(LoggerProvider);

            // Reset the timer logs first, since one of the tests will
            // be checking them
            TestHelpers.ClearFunctionLogs("TimerTrigger");
            TestHelpers.ClearFunctionLogs("ListenerStartupException");

            Host = new HostBuilder()
                   .ConfigureDefaultTestWebScriptHost(webjobsBuilder =>
            {
                webjobsBuilder.AddAzureStorage();

                // This needs to added manually at the ScriptHost level, as although FunctionMetadataManager is available through WebHost,
                // it needs to change the services during its lifetime.
                webjobsBuilder.Services.AddSingleton <IFunctionMetadataManager, FunctionMetadataManager>();
            },
                                                      o =>
            {
                o.ScriptPath = _rootPath;
                o.LogPath    = TestHelpers.GetHostLogFileDirectory().Parent.FullName;
            },
                                                      runStartupHostedServices: true)
                   .ConfigureServices(services =>
            {
                services.Configure <ScriptJobHostOptions>(o =>
                {
                    o.FileLoggingMode = FileLoggingMode.Always;

                    if (_functions != null)
                    {
                        o.Functions = _functions;
                    }
                });

                if (_proxyClient != null)
                {
                    services.AddSingleton <ProxyClientExecutor>(_proxyClient);
                }

                // Shared memory data transfer
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    services.AddSingleton <IMemoryMappedFileAccessor, MemoryMappedFileAccessorWindows>();
                }
                else
                {
                    services.AddSingleton <IMemoryMappedFileAccessor, MemoryMappedFileAccessorUnix>();
                }
                services.AddSingleton <ISharedMemoryManager, SharedMemoryManager>();

                ConfigureServices(services);
            })
                   .ConfigureLogging(b =>
            {
                b.AddProvider(LoggerProvider);
            })
                   .Build();

            JobHost = Host.GetScriptHost();

            if (_startHost)
            {
                JobHost.HostStarted += (s, e) => _hostStartedEvent.Set();
                await Host.StartAsync();

                _hostStartedEvent.Wait(TimeSpan.FromSeconds(30));
            }
        }
예제 #3
0
        public async Task InitializeAsync()
        {
            _copiedRootPath = Path.Combine(Path.GetTempPath(), "FunctionsE2E", DateTime.UtcNow.ToString("yyMMdd-HHmmss"));
            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);
            });

            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();
        }
예제 #4
0
        public async Task InitializeAsync()
        {
            if (!string.IsNullOrEmpty(_functionsWorkerLanguage))
            {
                Environment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, _functionsWorkerLanguage);
            }
            IConfiguration      configuration    = TestHelpers.GetTestConfiguration();
            string              connectionString = configuration.GetWebJobsConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount   = CloudStorageAccount.Parse(connectionString);

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

            TableStorageAccount tableStorageAccount = TableStorageAccount.Parse(connectionString);

            TableClient = tableStorageAccount.CreateCloudTableClient();

            await CreateTestStorageEntities();

            // ApiHubTestHelper.SetDefaultConnectionFactory();

            //ILoggerProviderFactory loggerProviderFactory = new TestLoggerProviderFactory(LoggerProvider);

            // Reset the timer logs first, since one of the tests will
            // be checking them
            TestHelpers.ClearFunctionLogs("TimerTrigger");
            TestHelpers.ClearFunctionLogs("ListenerStartupException");

            Host = new HostBuilder()
                   .ConfigureDefaultTestWebScriptHost(webjobsBuilder =>
            {
                webjobsBuilder.AddAzureStorage();
            },
                                                      o =>
            {
                o.ScriptPath = _rootPath;
                o.LogPath    = TestHelpers.GetHostLogFileDirectory().Parent.FullName;
            },
                                                      runStartupHostedServices: true)
                   .ConfigureServices(services =>
            {
                services.Configure <ScriptJobHostOptions>(o =>
                {
                    o.FileLoggingMode = FileLoggingMode.Always;

                    if (_functions != null)
                    {
                        o.Functions = _functions;
                    }
                });

                if (_proxyClient != null)
                {
                    services.AddSingleton <ProxyClientExecutor>(_proxyClient);
                }

                ConfigureServices(services);
            })
                   .ConfigureLogging(b =>
            {
                b.AddProvider(LoggerProvider);
            })
                   .Build();

            JobHost = Host.GetScriptHost();

            if (_startHost)
            {
                JobHost.HostStarted += (s, e) => _hostStartedEvent.Set();
                await Host.StartAsync();

                _hostStartedEvent.Wait(TimeSpan.FromSeconds(30));
            }
        }