Пример #1
0
 public Task RemoveAsync(SettingKey settingKey, SettingGroupKey settingGroupKey, CancellationToken cancellationToken)
 {
     return(_msSqlConnection.ExecuteAsync(
                cancellationToken,
                DeleteSql,
                new { Key = settingKey.Value, GroupKey = settingGroupKey.Value }));
 }
Пример #2
0
        public async Task <string> GetAsync(SettingKey settingKey, SettingGroupKey settingGroupKey, CancellationToken cancellationToken)
        {
            var values = await _msSqlConnection.QueryAsync <string>(
                cancellationToken,
                GetSql,
                new { Key = settingKey.Value, GroupKey = settingGroupKey.Value })
                         .ConfigureAwait(false);

            return(values.SingleOrDefault());
        }
Пример #3
0
        public async Task <IReadOnlyCollection <SettingGroupKey> > GetKeysAsync(SettingGroupKey settingGroupKey, CancellationToken cancellationToken)
        {
            var keys = await _msSqlConnection.QueryAsync <string>(
                cancellationToken,
                ListSql,
                new { GroupKey = settingGroupKey.Value })
                       .ConfigureAwait(false);

            return(keys
                   .Select(SettingGroupKey.With)
                   .ToList());
        }
Пример #4
0
        public async Task SetAsync(SettingKey settingKey, SettingGroupKey settingGroupKey, string value, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(nameof(value));
            }

            var affectedRows = await _msSqlConnection.ExecuteAsync(
                cancellationToken,
                SetSql,
                new { Key = settingKey.Value, Value = value, GroupKey = settingGroupKey.Value })
                               .ConfigureAwait(false);

            if (affectedRows != 1)
            {
                throw new Exception($"Updating key '{settingKey}' didn't update any rows");
            }
        }
Пример #5
0
 public static SettingGroupKey ToSettingGroupKey(this PluginId pluginId)
 {
     return SettingGroupKey.With($"plugin.{pluginId.Value}");
 }