/// <summary> /// Concatinates two options by combining duplicated properties into comma-separated list /// </summary> /// <param name="options1">first options to merge</param> /// <param name="options2">second options to merge</param> /// <param name="keys">when define it limits only to specific keys</param> public static ConfigParams Concat(ConfigParams options1, ConfigParams options2, params string[] keys) { var options = ConfigParams.FromValue(options1); foreach (var key in options2.Keys) { var value1 = options1.GetAsString(key) != null?options1.GetAsString(key) : ""; var value2 = options2.GetAsString(key) != null?options2.GetAsString(key) : ""; if (value1 != "" && value2 != "") { if (keys == null || keys.Length == 0 || ((IList <string>)keys).Contains(key)) { options.SetAsObject(key, value1 + "," + value2); } } else if (value1 != "") { options.SetAsObject(key, value1); } else if (value2 != "") { options.SetAsObject(key, value2); } } return(options); }
public void Configure(ConfigParams config) { ClientId = config.GetAsString("credential.client_id"); ClientSecret = config.GetAsString("credential.client_secret"); SubscriptionId = config.GetAsString("credential.subscription_id"); TenantId = config.GetAsString("credential.tenant_id"); ApiVersion = config.GetAsString("credential.api_version"); }
public async Task It_Should_Return_OpenApi_Content() { var baseRoute = ServiceConfig.GetAsString("base_route"); var openApiContent = ServiceConfig.GetAsString("openapi_content"); var result = await SendRequestAsync("get", string.Format("{0}/swagger", baseRoute), new { }); Assert.Equal(openApiContent, result); }
public virtual void Configure(ConfigParams config) { _configParams = config; Enabled = config.GetAsBooleanWithDefault("parameters.enabled", true); TimerInterval = config.GetAsNullableInteger("parameters.timer_interval") ?? DefaultTimerInterval; DelayInterval = config.GetAsNullableInteger("parameters.delay_interval") ?? DefaultDelayInterval; MinimumThroughput = config.GetAsNullableInteger("parameters.minimum_throughput") ?? DefaultMinimumThroughput; MaximumThroughput = config.GetAsNullableInteger("parameters.maximum_throughput") ?? DefaultMaximumThroughput; GrowthRate = config.GetAsNullableDouble("parameters.growth_rate") ?? DefaultGrowthRate; ResourceGroup = config.GetAsString("parameters.resource_group"); ConnectionUri = config.GetAsString("parameters.connection_uri"); }
public void TestReadConfig() { var parameters = ConfigParams.FromTuples( "param1", "Test Param 1", "param2", "Test Param 2"); ConfigParams config = JsonConfigReader.ReadConfig(null, "../../../../data/config.json", parameters); Assert.Equal(9, config.Count); Assert.Equal(123, config.GetAsInteger("field1.field11")); Assert.Equal("ABC", config.GetAsString("field1.field12")); Assert.Equal(123, config.GetAsInteger("field2.0")); Assert.Equal("ABC", config.GetAsString("field2.1")); Assert.Equal(543, config.GetAsInteger("field2.2.field21")); Assert.Equal("XYZ", config.GetAsString("field2.2.field22")); Assert.Equal(true, config.GetAsBoolean("field3")); }
/// <summary> /// Configures component by passing configuration parameters. /// </summary> /// <param name="config">configuration parameters to be set.</param> public void Configure(ConfigParams config) { if (config == null || !config.ContainsKey("path")) { throw new ConfigException(null, "NO_PATH", "Data file path is not set"); } Path = config.GetAsString("path"); }
public async Task TestOpenApiAsync() { DummyCommandableHttpService service = CreateAndOpenService(RestConfig); try { var serviceUri = RestConfig.GetAsString("connection.uri"); using var httpClient = new HttpClient(); var response = await httpClient.GetAsync($"{serviceUri}/dummy/swagger"); var openApiContent = await response.Content.ReadAsStringAsync(); Assert.StartsWith("openapi:", openApiContent); } finally { await service.CloseAsync(null); } }
public virtual void Configure(ConfigParams config) { Enabled = config.GetAsBooleanWithDefault("parameters.enabled", true); TimerInterval = config.GetAsNullableInteger("parameters.timer_interval") ?? DefaultTimerInterval; DelayInterval = config.GetAsNullableInteger("parameters.delay_interval") ?? DefaultDelayInterval; MinimumThroughput = config.GetAsNullableInteger("parameters.minimum_throughput") ?? DefaultMinimumThroughput; MaximumThroughput = config.GetAsNullableInteger("parameters.maximum_throughput") ?? DefaultMaximumThroughput; GrowthRate = config.GetAsNullableDouble("parameters.growth_rate") ?? DefaultGrowthRate; ResourceGroup = config.GetAsString("parameters.resource_group"); ConnectionUri = config.GetAsString("parameters.connection_uri"); var mongoDbConnectionUrl = new MongoUrlBuilder(ConnectionUri); AccountName = mongoDbConnectionUrl.Username; AccessKey = mongoDbConnectionUrl.Password; DatabaseName = mongoDbConnectionUrl.DatabaseName; _timer = new FixedRateTimer(PerformMonitorAsync, TimerInterval, DelayInterval); }
public async Task TestCrudOperationsAsync() { // Create one section ConfigParams parameters = await this._client.SetSectionAsync(null, "test.1", ConfigParams.FromTuples( "key1", "value11", "key2", "value12" )); Assert.NotNull(parameters); Assert.Equal("value11", parameters.GetAsString("key1")); // Create another section parameters = await this._client.ModifySectionAsync(null, "test.2", ConfigParams.FromTuples("key1", "value21"), ConfigParams.FromTuples("key2", 1)); Assert.NotNull(parameters); Assert.Equal("value21", parameters.GetAsString("key1")); Assert.Equal("1", parameters.GetAsString("key2")); // Get second section parameters = await this._client.GetSectionByIdAsync(null, "test.2"); Assert.NotNull(parameters); Assert.Equal("value21", parameters.GetAsString("key1")); Assert.Equal("1", parameters.GetAsString("key2")); // Get all sections var page = await this._client.GetSectionsAsync(null, null, null); Assert.NotNull(page); Assert.Equal(2, page.Data.Count); // Get all section ids var page1 = await this._client.GetSectionIdsAsync(null, null, null); Assert.NotNull(page1); Assert.Equal(2, page1.Data.Count); }
private static async Task <T> Invoke <T>(string route, dynamic request) { using (var httpClient = new HttpClient()) { var requestValue = JsonConverter.ToJson(request); using (var content = new StringContent(requestValue, Encoding.UTF8, "application/json")) { var response = await httpClient.PostAsync($"{_httpConfig.GetAsString("connection.protocol")}://{_httpConfig.GetAsString("connection.host")}:{_httpConfig.GetAsString("connection.port")}/v1/Guides/" + route, content); var responseValue = response.Content.ReadAsStringAsync().Result; var result = JsonConverter.FromJson <T>(responseValue); return(result); } } }
/// <summary> /// Includes specified keys from the config parameters. /// </summary> /// <param name="options">configuration parameters to be processed.</param> /// <param name="keys">a list of keys to be included.</param> /// <returns>a processed config parameters.</returns> public static ConfigParams Include(ConfigParams options, params string[] keys) { if (keys == null || keys.Length == 0) { return(options); } var result = new ConfigParams(); foreach (var key in options.Keys) { if (((IList <string>)keys).Contains(key)) { result.SetAsObject(key, options.GetAsString(key)); } } return(result); }
/// <summary> /// Parses URI into config parameters. /// The URI shall be in the following form: /// `protocol://username@password@host1:port1,host2:port2,...?param1=abc¶m2=xyz&...` /// </summary> /// <param name="uri">the URI to be parsed</param> /// <param name="defaultProtocol">a default protocol</param> /// <param name="defaultPort">a default port</param> /// <returns>a configuration parameters with URI elements</returns> public static ConfigParams ParseUri(string uri, string defaultProtocol, int defaultPort) { var options = new ConfigParams(); if (uri == null || uri == "") { return(options); } uri = uri.Trim(); // Process parameters int pos = uri.IndexOf("?"); if (pos > 0) { var parameters = uri.Substring(pos + 1); uri = uri.Substring(0, pos); var paramsList = parameters.Split('&'); foreach (var param in paramsList) { pos = param.IndexOf("="); if (pos >= 0) { var key = Uri.UnescapeDataString(param.Substring(0, pos)); var value = Uri.UnescapeDataString(param.Substring(pos + 1)); options.SetAsObject(key, value); } else { options.SetAsObject(Uri.UnescapeDataString(param), null); } } } // Process protocol pos = uri.IndexOf("://"); if (pos > 0) { var protocol = uri.Substring(0, pos); uri = uri.Substring(pos + 3); options.SetAsObject("protocol", protocol); } else { options.SetAsObject("protocol", defaultProtocol); } // Process user and password pos = uri.IndexOf("@"); if (pos > 0) { var userAndPass = uri.Substring(0, pos); uri = uri.Substring(pos + 1); pos = userAndPass.IndexOf(":"); if (pos > 0) { options.SetAsObject("username", userAndPass.Substring(0, pos)); options.SetAsObject("password", userAndPass.Substring(pos + 1)); } else { options.SetAsObject("username", userAndPass); } } // Process host and ports var servers = uri.Split(','); foreach (var server in servers) { pos = server.IndexOf(":"); if (pos > 0) { options.SetAsObject("servers", ConnectionUtils.ConcatValues(options.GetAsString("servers"), server)); options.SetAsObject("host", ConnectionUtils.ConcatValues(options.GetAsString("host"), server.Substring(0, pos))); options.SetAsObject("port", ConnectionUtils.ConcatValues(options.GetAsString("port"), server.Substring(pos + 1))); } else { options.SetAsObject("servers", ConnectionUtils.ConcatValues(options.GetAsString("servers"), server + ":" + defaultPort.ToString())); options.SetAsObject("host", ConnectionUtils.ConcatValues(options.GetAsString("host"), server)); options.SetAsObject("port", ConnectionUtils.ConcatValues(options.GetAsString("port"), defaultPort.ToString())); } } return(options); }
/// <summary> /// Configures component by passing configuration parameters. /// </summary> /// <param name="config">configuration parameters to be set.</param> public override void Configure(ConfigParams config) { base.Configure(config); Path = config.GetAsString("path"); }