public bool Apply(IJSONDocument document) { var attribute = _targetField as Attribute; if (attribute != null) { switch (Type) { case UpdateType.Single: IJsonValue value; if (_evaluators[0].Value.Evaluate(out value, document)) { return(Attributor.TryUpdate(document, value, attribute, true)); } return(false); case UpdateType.Array: Array array; if (Attributor.TryGetArray(document, out array, attribute)) { var values = new ClusteredArrayList(array.Length + _evaluators.Length); values.AddRange(array); bool isChangeApplicable = false; foreach (var keyValuePair in _evaluators) { IJsonValue oldValue, newValue; if (keyValuePair.Key.Evaluate(out oldValue, document) && keyValuePair.Value.Evaluate(out newValue, document)) { int index = -1; while ((index = values.IndexOf(oldValue.Value)) >= 0) { //bugfix: infinite loop for replace 1=1 //New and old values are same and values contain old value if (oldValue.CompareTo(newValue) == 0) { isChangeApplicable = true; break; } values[index] = newValue.Value; isChangeApplicable = true; } } } return(isChangeApplicable && Attributor.TrySetArray(document, values.ToArray(), attribute)); } return(false); } return(false); } return(false); }
public bool Apply(IJSONDocument document) { var attribute = _targetField as Attribute; if (attribute != null) { switch (Type) { case UpdateType.Single: IJsonValue newValue; if (_evaluator[0].Evaluate(out newValue, document)) { return(Attributor.TryUpdate(document, newValue.Value, attribute, true)); } return(false); case UpdateType.Array: Array array; if (Attributor.TryGetArray(document, out array, attribute)) { var values = new ClusteredArrayList(array.Length + _evaluator.Length); values.AddRange(array); bool insertionDone = false; foreach (var evaluable in _evaluator) { if (evaluable.Evaluate(out newValue, document)) { if (!values.Contains(newValue.Value)) { values.Add(newValue.Value); insertionDone = true; } } } return(insertionDone && Attributor.TrySetArray(document, values.ToArray(), attribute)); } return(false); } return(false); } return(false); }
public bool Apply(IJSONDocument document) { var attribute = _targetField as Attribute; if (attribute != null) { switch (Type) { case UpdateType.Single: return(Attributor.TryDelete(document, attribute)); case UpdateType.Array: Array array; if (Attributor.TryGetArray(document, out array, attribute)) { var values = new ClusteredArrayList(array.Length + _evaluator.Length); values.AddRange(array); bool isChangeApplicable = false; foreach (var evaluable in _evaluator) { IJsonValue newValue; if (evaluable.Evaluate(out newValue, document)) { while (values.Contains(newValue.Value)) { values.Remove(newValue.Value); isChangeApplicable = true; } } } return(isChangeApplicable && Attributor.TrySetArray(document, values.ToArray(), attribute)); } return(false); } return(false); } return(false); }