private IObservable <HashStructItemModel> ExecuteEdit( byte[] key, RedisTargetInfo targetInfo, HashStructItemModel hashItem) { var editedHashItem = new HashStructItemModel { Key = hashItem.Key, Value = hashItem.Value, IsChecked = hashItem.IsChecked, IsEnabled = hashItem.IsEnabled, CheckAction = hashItem.CheckAction, EditAction = hashItem.EditAction }; return(_dialogManager.Open(EditorDialogModel.UpdateHashItem( hashItem.Key, hashItem.Value, target => { return _clientAccessor.With(targetInfo, client => { var isValueEmpty = string.IsNullOrEmpty(target.Value); if (!isValueEmpty) { client.HSet(ustring.Make(key).ToString(), hashItem.Key, target.Value); editedHashItem.Value = target.Value; } return new EditorResult { ValueError = isValueEmpty ? "Value is empty" : null, Action = target.Action }; }); })) .Select(wasEdited => wasEdited ? editedHashItem : null)); }
private IObservable <bool> ExecuteAdd( byte[] key, RedisTargetInfo targetInfo) { return(_dialogManager.Open(EditorDialogModel.AddHashItem(target => { return _clientAccessor.With(targetInfo, client => { var isValueEmpty = string.IsNullOrEmpty(target.Value); var isKeyEmpty = string.IsNullOrEmpty(target.Key); var isKeyDuplicate = !isKeyEmpty && client.Exists(target.Key); // TODO: async if (!isValueEmpty && !isKeyEmpty && !isKeyDuplicate) { client.HSet(ustring.Make(key).ToString(), target.Key, target.Value); } return new EditorResult { KeyError = isKeyEmpty ? "Key is empty" : (isKeyDuplicate ? "Key already exists" : null), ValueError = isValueEmpty ? "Value is empty" : null, Action = target.Action }; }); }))); }
private IObservable <bool> ExecuteAdd( byte[] key, RedisTargetInfo targetInfo) { return(_dialogManager.Open(EditorDialogModel.AddListItem(target => { return _clientAccessor.With(targetInfo, client => { var isValueEmpty = string.IsNullOrEmpty(target.Value); if (!isValueEmpty) { switch (target.Action) { case EditorAction.Prepend: client.LPush(ustring.Make(key).ToString(), target.Value); // TODO: async break; case EditorAction.Append: client.RPush(ustring.Make(key).ToString(), target.Value); // TODO: async break; } } return new EditorResult { ValueError = isValueEmpty ? "Value is empty" : null, Action = target.Action }; }); }))); }
private IObservable <(ZSetStructItemModel, ZSetStructItemModel)> ExecuteEdit( byte[] key, RedisTargetInfo targetInfo, ZSetStructItemModel zsetItem) { var editedSetItem = new ZSetStructItemModel { Score = zsetItem.Score, Value = zsetItem.Value, IsChecked = zsetItem.IsChecked, IsEnabled = zsetItem.IsEnabled, CheckAction = zsetItem.CheckAction, EditAction = zsetItem.EditAction }; return(_dialogManager.Open(EditorDialogModel.ReplaceZSetItem( double.Parse(zsetItem.Score), zsetItem.Value, target => { return _clientAccessor.With(targetInfo, client => { var isValueEmpty = string.IsNullOrEmpty(target.Value); var alreadyExists = !isValueEmpty && zsetItem.Score != target.Score.ToString(CultureInfo.InvariantCulture) && zsetItem.Value != target.Value && client.ZScore(ustring.Make(key).ToString(), target.Value) != null; if (!isValueEmpty && !alreadyExists) { client.Multi(); client.ZRem(ustring.Make(key).ToString(), zsetItem.Value); client.ZAdd(ustring.Make(key).ToString(), Tuple.Create(target.Score, target.Value)); client.Exec(); editedSetItem.Score = target.Score.ToString(CultureInfo.InvariantCulture); editedSetItem.Value = target.Value; } return new EditorResult { ValueError = isValueEmpty ? "Value is empty" : (alreadyExists ? "Value already exists" : null), Action = target.Action }; }); })) .Select(wasEdited => wasEdited ? (zsetItem, editedSetItem) : (null, null))); }
private IObservable <(SetStructItemModel, SetStructItemModel)> ExecuteEdit( byte[] key, RedisTargetInfo targetInfo, SetStructItemModel setItem) { var editedSetItem = new SetStructItemModel { Value = setItem.Value, IsChecked = setItem.IsChecked, IsEnabled = setItem.IsEnabled, CheckAction = setItem.CheckAction, EditAction = setItem.EditAction }; return(_dialogManager.Open(EditorDialogModel.ReplaceSetItem( setItem.Value, target => { return _clientAccessor.With(targetInfo, client => { var isValueEmpty = string.IsNullOrEmpty(target.Value); var alreadyExists = !isValueEmpty && setItem.Value != target.Value && client.SIsMember(ustring.Make(key).ToString(), target.Value); if (!isValueEmpty && !alreadyExists) { client.Multi(); client.SRem(ustring.Make(key).ToString(), setItem.Value); client.SAdd(ustring.Make(key).ToString(), target.Value); client.Exec(); editedSetItem.Value = target.Value; } return new EditorResult { ValueError = isValueEmpty ? "Value is empty" : (alreadyExists ? "Value already exists" : null), Action = target.Action }; }); })) .Select(wasEdited => wasEdited ? (setItem, editedSetItem) : (null, null))); }
private IObservable <bool> ExecuteAdd(byte[] key, RedisTargetInfo targetInfo) { return(_dialogManager.Open(EditorDialogModel.AddSetItem(target => { return _clientAccessor.With(targetInfo, client => { var isValueEmpty = string.IsNullOrEmpty(target.Value); var isValueDuplicate = !isValueEmpty && client.SIsMember(ustring.Make(key).ToString(), target.Value); if (!isValueEmpty && !isValueDuplicate) { client.SAdd(ustring.Make(key).ToString(), target.Value); } return new EditorResult { ValueError = isValueEmpty ? "Value is empty" : (isValueDuplicate ? "Value already exists" : null), Action = target.Action }; }); }))); }