Beispiel #1
0
        public ActionResult <string> UpdateApplicationKeyValue([FromRoute] string appName, [FromRoute] string key, [FromRoute] string value)
        {
            string tenantId = this.GetTenantIdFromRouteData();

            MemoryConfigurationStoreRepository repo = new MemoryConfigurationStoreRepository(tenantId);

            var keyValue = new StoreKeyValue()
            {
                TenantId = tenantId,
                AppName  = appName,
                Key      = key,
                Value    = value
            };

            var res = repo.UpdateForApplication(appName, keyValue);

            if (res)
            {
                this.HttpContext.Response.StatusCode = 200;
            }
            else
            {
                this.HttpContext.Response.StatusCode = 404;
            }

            return(string.Empty);
        }
        public bool AddForApplication(string appName, StoreKeyValue keyValue)
        {
            var existingApp = ServicesRuntime.AllApplications.Applications.SingleOrDefault(a => a.TenantId.CompareTo(repoTenantId) == 0 && a.Name.CompareTo(appName) == 0);

            if (existingApp == null)
            {
                return(false);
            }

            var existingKey = Memory.ConfigurationStore.AllKeyValues.SingleOrDefault(g => g.TenantId.CompareTo(repoTenantId) == 0 && g.AppName.CompareTo(appName) == 0 && g.Key.CompareTo(keyValue.Key) == 0);

            if (existingKey != null)
            {
                Update(keyValue);
            }
            else
            {
                keyValue.TenantId = repoTenantId;
                keyValue.AppName  = appName;
                Memory.ConfigurationStore.AllKeyValues.Add(keyValue);

                existingApp.Configuration.Add(keyValue);
            }

            IncreaseVersionForServicesRuntime();

            return(true);
        }
        public bool UpdateForApplication(string appName, StoreKeyValue keyValue)
        {
            var existingApp = ServicesRuntime.AllApplications.Applications.SingleOrDefault(a => a.TenantId.CompareTo(repoTenantId) == 0 && a.Name.CompareTo(appName) == 0);

            if (existingApp == null)
            {
                return(false);
            }

            var existingKey = Memory.ConfigurationStore.AllKeyValues.SingleOrDefault(g => g.TenantId.CompareTo(repoTenantId) == 0 && g.AppName.CompareTo(appName) == 0 && g.Key.CompareTo(keyValue.Key) == 0);

            if (existingKey != null)
            {
                var idx = Memory.ConfigurationStore.AllKeyValues.IndexOf(existingKey);
                Memory.ConfigurationStore.AllKeyValues[idx].Value = keyValue.Value;

                var existingConf = existingApp.Configuration.SingleOrDefault(c => c.Key.CompareTo(keyValue.Key) == 0);
                var idx2         = existingApp.Configuration.IndexOf(existingConf);
                existingApp.Configuration[idx2].Value = keyValue.Value;
            }

            IncreaseVersionForServicesRuntime();

            return(true);
        }
        public ActionResult <string> UpdateGeneralKeyValue([FromRoute] string key, [FromRoute] string value, [FromServices] IMemoryGeneralConfigurationClientRepository clientRepo, [FromServices] IPublishClientsService clientPublishService)
        {
            var tenantId       = this.GetTenantIdFromRouteData();
            var clientHostname = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            clientRepo.Add(new DiscoveryClient(clientHostname));
            clientPublishService.PublishClientConfigurationActivity(tenantId, clientHostname);

            MemoryConfigurationStoreRepository repo = new MemoryConfigurationStoreRepository(tenantId);

            var keyValue = new StoreKeyValue()
            {
                TenantId = tenantId,
                Key      = key,
                Value    = value
            };

            var res = repo.Update(keyValue);

            if (res)
            {
                this.HttpContext.Response.StatusCode = 200;
            }
            else
            {
                this.HttpContext.Response.StatusCode = 404;
            }

            return(string.Empty);
        }
        public bool Update(StoreKeyValue keyValue)
        {
            var existingKey = Memory.ConfigurationStore.AllKeyValues.SingleOrDefault(g => g.TenantId.CompareTo(repoTenantId) == 0 && g.AppName.CompareTo(string.Empty) == 0 && g.Key.CompareTo(keyValue.Key) == 0);

            if (existingKey != null)
            {
                var idx = Memory.ConfigurationStore.AllKeyValues.IndexOf(existingKey);
                Memory.ConfigurationStore.AllKeyValues[idx].Value = keyValue.Value;
            }

            IncreaseVersionForGeneralStore();

            return(true);
        }
        public bool Add(StoreKeyValue keyValue)
        {
            var existingKey = Memory.ConfigurationStore.AllKeyValues.SingleOrDefault(g => g.TenantId.CompareTo(repoTenantId) == 0 && g.AppName.CompareTo(string.Empty) == 0 && g.Key.CompareTo(keyValue.Key) == 0);

            if (existingKey != null)
            {
                Update(keyValue);
            }
            else
            {
                keyValue.TenantId = repoTenantId;
                Memory.ConfigurationStore.AllKeyValues.Add(keyValue);
            }

            IncreaseVersionForGeneralStore();

            return(true);
        }