Beispiel #1
0
        public void Execute()
        {
            var configContent = _nacosConfigClient.GetConfigAsync(new GetConfigRequest
            {
                DataId = _nacosConfigurationSource.DataId,
                Group  = _nacosConfigurationSource.Group,
                Tenant = _nacosConfigurationSource.Tenant
            }).ConfigureAwait(false).GetAwaiter().GetResult();

            if (configContent == null)
            {
                var filename = "appsettings";

                if (_hostEnvironment.IsDevelopment())
                {
                    filename += $".{_hostEnvironment.EnvironmentName}";
                }

                var content = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, $"{filename}.ini"));

                _nacosConfigClient.PublishConfigAsync(new PublishConfigRequest
                {
                    DataId  = _nacosConfigurationSource.DataId,
                    Group   = _nacosConfigurationSource.Group,
                    Tenant  = _nacosConfigurationSource.Tenant,
                    Content = content,
                    Type    = "text"
                }).ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }
Beispiel #2
0
        public async Task <string> Add([FromQuery] string key, [FromQuery] string value)
        {
            var res = await _configClient.PublishConfigAsync(new PublishConfigRequest
            {
                DataId = key,
                Group  = "DEFAULT_GROUP",
                //Tenant = "tenant"
                Content = value
            });

            return(res.ToString());
        }