public async Task <ConfigurationVersion> Single(string id, int?version, string name)
        {
            await TestPermission();

            var n = name ?? "";
            ConfigurationVersion r =
                await ctx.GlowConfigurations.SingleOrDefaultAsync(
                    v => v.Id == id && v.Version == version && v.Name == n);

            return(r);
        }
Esempio n. 2
0
        public async Task <Unit> Handle(ConfigurationUpdate request, CancellationToken cancellationToken)
        {
            Meta partialConfiguration = partialConfigurations.Get().Single(v => v.Id == request.ConfigurationId);

            var builder = new DbContextOptionsBuilder <ConfigurationDataContext>();

            StartupExtensions.optionsAction?.Invoke(builder);
            using var ctx = new ConfigurationDataContext(builder.Options);

            ConfigurationVersion current = await ctx
                                           .GlowConfigurations
                                           .Where(v => v.Id == request.ConfigurationId && v.Name == request.Name)
                                           .OrderByDescending(v => v.Version)
                                           .FirstOrDefaultAsync() ?? new ConfigurationVersion
            {
                Version = 0,
                Values  = new Dictionary <string, object>()
            };

            var nextValues = new Dictionary <string, object>();

            foreach (KeyValuePair <string, object> value in request.Values)
            {
                var key =
                    $"{partialConfiguration.SectionId}{(request.Name == Options.DefaultName ? "" : $":{request.Name}")}:{value.Key}";
                nextValues[key] = value.Value;
            }

            ctx.GlowConfigurations.Add(new ConfigurationVersion
            {
                Id      = request.ConfigurationId,
                Name    = request.Name,
                Version = current.Version + 1,
                Values  = nextValues,
                Created = DateTime.UtcNow,
                Message = "",
                User    = null
            });

            await ctx.SaveChangesAsync();

            EfConfigurationProvider.SetReloadNecessary();
            return(Unit.Value);
        }