/// <summary>
        /// Get the service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>The service properties of the specified service type</returns>
        public XSCLProtocol.ServiceProperties GetStorageServiceProperties(StorageServiceType type, IRequestOptions options, XSCL.OperationContext operationContext)
        {
            XSCL.CloudStorageAccount account = StorageContext.StorageAccount;
            try
            {
                switch (type)
                {
                case StorageServiceType.Blob:
                    return(account.CreateCloudBlobClient().GetServicePropertiesAsync((BlobRequestOptions)options, operationContext).Result);

                case StorageServiceType.Queue:
                    return(account.CreateCloudQueueClient().GetServicePropertiesAsync((QueueRequestOptions)options, operationContext).Result);

                case StorageServiceType.File:
                    FileServiceProperties          fileServiceProperties = account.CreateCloudFileClient().GetServicePropertiesAsync((FileRequestOptions)options, operationContext).Result;
                    XSCLProtocol.ServiceProperties sp = new XSCLProtocol.ServiceProperties();
                    sp.Clean();
                    sp.Cors          = fileServiceProperties.Cors;
                    sp.HourMetrics   = fileServiceProperties.HourMetrics;
                    sp.MinuteMetrics = fileServiceProperties.MinuteMetrics;
                    return(sp);

                default:
                    throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
                }
            }
            catch (AggregateException e) when(e.InnerException is XSCL.StorageException)
            {
                throw e.InnerException;
            }
        }
Пример #2
0
        void UploadToBlob(List <string> entries)
        {
            string data = "";

            foreach (string item in entries)
            {
                data += item + "\n";
            }

            try
            {
                //Setup connection to the azure blob storage
                Microsoft.Azure.Storage.CloudStorageAccount storageAccount = Microsoft.Azure.Storage.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["TableConnectionString"].ConnectionString);
                CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container  = blobClient.GetContainerReference(blobName);
                container.CreateIfNotExistsAsync().Wait();
                CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

                //Upload the data string to storage
                blob.UploadTextAsync(data);
            }
            catch (Exception ex)
            {
                Error1.Text = "Failed to upload to blob storage. ";
            }
        }
Пример #3
0
        void RemoveFromBlob()
        {
            try
            {
                //Setup connection to the azure blob storage
                Microsoft.Azure.Storage.CloudStorageAccount storageAccount = Microsoft.Azure.Storage.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["TableConnectionString"].ConnectionString);
                CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container  = blobClient.GetContainerReference(blobName);
                CloudBlockBlob     blob       = container.GetBlockBlobReference(fileName);

                //Deletes the whole blob
                blob.DeleteAsync();

                //Update status to user
                ResultTitle.Text = "Status:";
                Results1.Text    = "";
                Results1.Text    = "Removed from Blob Storage";
            }
            catch (Exception ex)
            {
                Error1.Text = "Failed to remove from blob storage. ";
            }
        }
        /// <summary>
        /// Set service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="properties">Service properties</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        public void SetStorageServiceProperties(StorageServiceType type, XSCLProtocol.ServiceProperties properties, IRequestOptions options, XSCL.OperationContext operationContext)
        {
            XSCL.CloudStorageAccount account = StorageContext.StorageAccount;
            try
            {
                switch (type)
                {
                case StorageServiceType.Blob:
                    Task.Run(() => account.CreateCloudBlobClient().SetServicePropertiesAsync(properties, (BlobRequestOptions)options, operationContext)).Wait();
                    break;

                case StorageServiceType.Queue:
                    Task.Run(() => account.CreateCloudQueueClient().SetServicePropertiesAsync(properties, (QueueRequestOptions)options, operationContext)).Wait();
                    break;

                case StorageServiceType.File:
                    if (null != properties.Logging)
                    {
                        throw new InvalidOperationException(Resources.FileNotSupportLogging);
                    }

                    FileServiceProperties fileServiceProperties = new FileServiceProperties();
                    fileServiceProperties.Cors          = properties.Cors;
                    fileServiceProperties.HourMetrics   = properties.HourMetrics;
                    fileServiceProperties.MinuteMetrics = properties.MinuteMetrics;
                    Task.Run(() => account.CreateCloudFileClient().SetServicePropertiesAsync(fileServiceProperties, (FileRequestOptions)options, operationContext)).Wait();
                    break;

                default:
                    throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
                }
            }
            catch (AggregateException e) when(e.InnerException is XSCL.StorageException)
            {
                throw e.InnerException;
            }
        }
Пример #5
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));
            }
        }
Пример #6
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();
        }
Пример #7
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));
            }
        }