Exemplo n.º 1
0
        private void EditItem(ZSetStructItemModel item)
        {
            if (item.IsEditing)
            {
                return;
            }

            item.IsEditing = true;

            _model.EditCommand.Execute(item)
            .SubscribeOn(RxApp.TaskpoolScheduler)
            .ObserveOn(RxApp.MainThreadScheduler)
            .SubscribeWithLog(_ => { item.IsEditing = false; });
        }
Exemplo n.º 2
0
        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)));
        }
Exemplo n.º 3
0
 private void CheckItem(ZSetStructItemModel item)
 {
     ChangeActionsMode();
 }