Exemple #1
0
        public async Task <Config> GetConfig(ConfigArgumentCommand request, CancellationToken cancellationToken)
        {
            UsersEnvironments env = await _environmentService.GetEnvironment(request, cancellationToken);

            Config result = await GetConfig(env.EnvironmentId, request, cancellationToken);

            request.ThrowNotFoundExceptionWhenValueIsNull(result);

            return(result);
        }
Exemple #2
0
        public async Task <List <Config> > Handle(GetAllConfigsCommand request, CancellationToken cancellationToken)
        {
            UsersEnvironments env = await _environmentService.GetEnvironment(request, cancellationToken);

            return(await _configContext
                   .Configs.Where(w =>
                                  w.EnvironmentId.Equals(env.EnvironmentId) &&
                                  w.VersionTo == null &&
                                  w.DateTo == null)
                   .ToListAsync(cancellationToken));
        }
        public async Task <Config> Handle(CreateConfigCommand request, CancellationToken cancellationToken)
        {
            Environment env = await _environmentService.GetEnvironment(request, EnvironmentRole.Editor, cancellationToken);

            Config existConfig = await _configService.GetConfig(env.EnvironmentId, request, cancellationToken);

            if (existConfig != null && existConfig.VersionFrom == request.VersionFrom)
            {
                throw new EntityException($"{request} is exists");
            }

            Config config;

            if (existConfig != null && existConfig.VersionTo == null)
            {
                config = new Config(request.ConfigCode, env, request.VersionFrom);
                existConfig.SetVersionTo(request.From);
            }
            else if (existConfig != null && existConfig.VersionTo != null)
            {
                config = new Config(request.ConfigCode, env, request.VersionFrom, existConfig.VersionTo);
                existConfig.SetVersionTo(request.From);
            }
            else
            {
                long minVer = (await _configContext.Configs
                               .Where(w => w.EnvironmentId.Equals(env.EnvironmentId) && w.Code == request.ConfigCode)
                               .GroupBy(e => 1)
                               .Select(s => s.Min(m => m.VersionFrom)).ToListAsync(cancellationToken))[0];

                if (minVer != 0 && minVer < request.VersionFrom)
                {
                    throw new OperationException(
                              "Incorrect config latest version in storage, 'VersionTo' must be null. Contact your system administrator");
                }

                config = new Config(request.ConfigCode, env, request.VersionFrom, minVer);
            }

            ObjectConfigReader reader       = new ObjectConfigReader(config);
            ConfigElement      configElemnt = await reader.Parse(request.Data);

            _configContext.ConfigCache.Add(new ConfigCache(config, request.Data));

            await _configContext.SaveChangesAsync(cancellationToken);

            return(config);
        }
Exemple #4
0
 public EnvResult Get()
 {
     return(_environmentService.GetEnvironment());
 }
 public Task <UsersEnvironments> Handle(FindByCodeEnvironmentCommand request, CancellationToken cancellationToken)
 {
     return(_environmentMaster.GetEnvironment(request, cancellationToken));
 }