public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { switch (previous) { case null: return(this); case ParseDeleteOperation _: return(new ParseSetOperation(_objects.ToList())); case ParseSetOperation _: { var setOp = (ParseSetOperation)previous; var oldList = Conversion.To <IList <object> >(setOp.Value); var result = Apply(oldList, null); return(new ParseSetOperation(result)); } case ParseAddUniqueOperation _: { var oldList = ((ParseAddUniqueOperation)previous).Objects; return(new ParseAddUniqueOperation((IList <object>)Apply(oldList, null))); } } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return(this); } if (previous is ParseDeleteOperation) { throw new InvalidOperationException("You can't modify a relation after deleting it."); } var other = previous as ParseRelationOperation; if (other != null) { if (other.TargetClassName != TargetClassName) { throw new InvalidOperationException( string.Format("Related object must be of class {0}, but {1} was passed in.", other.TargetClassName, TargetClassName)); } var newAdd = adds.Union(other.adds.Except(removes)).ToList(); var newRemove = removes.Union(other.removes.Except(adds)).ToList(); return(new ParseRelationOperation(newAdd, newRemove, TargetClassName)); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return(this); } if (previous is ParseDeleteOperation) { return(new ParseSetOperation(amount)); } if (previous is ParseSetOperation) { var otherAmount = ((ParseSetOperation)previous).Value; if (otherAmount is string) { throw new InvalidOperationException("Cannot increment a non-number type."); } var myAmount = amount; return(new ParseSetOperation(Add(otherAmount, myAmount))); } if (previous is ParseIncrementOperation) { object otherAmount = ((ParseIncrementOperation)previous).Amount; object myAmount = amount; return(new ParseIncrementOperation(Add(otherAmount, myAmount))); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { switch (previous) { case null: return(this); case ParseDeleteOperation _: return(new ParseSetOperation(_amount)); case ParseSetOperation _: { var otherAmount = ((ParseSetOperation)previous).Value; if (otherAmount is string) { throw new InvalidOperationException("Cannot increment a non-number type."); } var myAmount = _amount; return(new ParseSetOperation(Add(otherAmount, myAmount))); } case ParseIncrementOperation _: { var otherAmount = ((ParseIncrementOperation)previous).Amount; var myAmount = _amount; return(new ParseIncrementOperation(Add(otherAmount, myAmount))); } } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IDictionary <string, object> Encode <T>(T state, IDictionary <string, IParseFieldOperation> operations, ParseEncoder encoder) where T : IObjectState { Dictionary <string, object> result = new Dictionary <string, object>(); foreach (KeyValuePair <string, IParseFieldOperation> pair in operations) { // Serialize the data IParseFieldOperation operation = pair.Value; result[pair.Key] = encoder.Encode(operation); } return(result); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return this; } if (previous is ParseDeleteOperation) { return new ParseSetOperation(objects.ToList()); } if (previous is ParseSetOperation) { var setOp = (ParseSetOperation)previous; var oldList = (IList<object>)ParseClient.ConvertTo<IList<object>>(setOp.Value); return new ParseSetOperation(oldList.Concat(objects).ToList()); } if (previous is ParseAddOperation) { return new ParseAddOperation(((ParseAddOperation)previous).Objects.Concat(objects)); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return this; } if (previous is ParseDeleteOperation) { return previous; } if (previous is ParseSetOperation) { var setOp = (ParseSetOperation)previous; var oldList = Conversion.As<IList<object>>(setOp.Value); return new ParseSetOperation(this.Apply(oldList, null)); } if (previous is ParseRemoveOperation) { var oldOp = (ParseRemoveOperation)previous; return new ParseRemoveOperation(oldOp.Objects.Concat(objects)); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return this; } if (previous is ParseDeleteOperation) { return new ParseSetOperation(objects.ToList()); } if (previous is ParseSetOperation) { var setOp = (ParseSetOperation)previous; var oldList = (IList<object>)Conversion.ConvertTo<IList<object>>(setOp.Value); var result = this.Apply(oldList, null); return new ParseSetOperation(result); } if (previous is ParseAddUniqueOperation) { var oldList = ((ParseAddUniqueOperation)previous).Objects; return new ParseAddUniqueOperation((IList<object>)this.Apply(oldList, null)); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { switch (previous) { case null: return(this); case ParseDeleteOperation _: return(new ParseSetOperation(_objects.ToList())); case ParseSetOperation _: var setOp = (ParseSetOperation)previous; var oldList = Conversion.To <IList <object> >(setOp.Value); return(new ParseSetOperation(oldList.Concat(_objects).ToList())); case ParseAddOperation _: return(new ParseAddOperation(((ParseAddOperation)previous).Objects.Concat(_objects))); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return this; } if (previous is ParseDeleteOperation) { throw new InvalidOperationException("You can't modify a relation after deleting it."); } var other = previous as ParseRelationOperation; if (other != null) { if (other.TargetClassName != TargetClassName) { throw new InvalidOperationException( string.Format("Related object must be of class {0}, but {1} was passed in.", other.TargetClassName, TargetClassName)); } var newAdd = adds.Union(other.adds.Except(removes)).ToList(); var newRemove = removes.Union(other.removes.Except(adds)).ToList(); return new ParseRelationOperation(newAdd, newRemove, TargetClassName); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { switch (previous) { case null: return(this); case ParseDeleteOperation _: throw new InvalidOperationException("You can't modify a relation after deleting it."); case ParseRelationOperation other: if (other.TargetClassName != TargetClassName) { throw new InvalidOperationException(String.Format("Related object must be of class {0}, but {1} was passed in.", other.TargetClassName, TargetClassName)); } return(new ParseRelationOperation(AdditionQueue.Union(other.AdditionQueue.Except(RemovalQueue)).ToList(), RemovalQueue.Union(other.RemovalQueue.Except(AdditionQueue)).ToList(), TargetClassName)); default: throw new InvalidOperationException("Operation is invalid after previous operation."); } }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return(this); } if (previous is ParseDeleteOperation) { return(new ParseSetOperation(objects.ToList())); } if (previous is ParseSetOperation) { var setOp = (ParseSetOperation)previous; var oldList = (IList <object>)ParseClient.ConvertTo <IList <object> >(setOp.Value); return(new ParseSetOperation(oldList.Concat(objects).ToList())); } if (previous is ParseAddOperation) { return(new ParseAddOperation(((ParseAddOperation)previous).Objects.Concat(objects))); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return(this); } if (previous is ParseDeleteOperation) { return(previous); } if (previous is ParseSetOperation) { var setOp = (ParseSetOperation)previous; var oldList = Conversion.As <IList <object> >(setOp.Value); return(new ParseSetOperation(this.Apply(oldList, null))); } if (previous is ParseRemoveOperation) { var oldOp = (ParseRemoveOperation)previous; return(new ParseRemoveOperation(oldOp.Objects.Concat(objects))); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return(this); } if (previous is ParseDeleteOperation) { return(new ParseSetOperation(objects.ToList())); } if (previous is ParseSetOperation) { var setOp = (ParseSetOperation)previous; var oldList = Conversion.To <IList <object> >(setOp.Value); var result = this.Apply(oldList, null); return(new ParseSetOperation(result)); } if (previous is ParseAddUniqueOperation) { var oldList = ((ParseAddUniqueOperation)previous).Objects; return(new ParseAddUniqueOperation((IList <object>) this.Apply(oldList, null))); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { return this; }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { if (previous == null) { return this; } if (previous is ParseDeleteOperation) { return new ParseSetOperation(amount); } if (previous is ParseSetOperation) { var otherAmount = ((ParseSetOperation)previous).Value; if (otherAmount is string) { throw new InvalidOperationException("Cannot increment a non-number type."); } var myAmount = amount; return new ParseSetOperation(Add(otherAmount, myAmount)); } if (previous is ParseIncrementOperation) { object otherAmount = ((ParseIncrementOperation)previous).Amount; object myAmount = amount; return new ParseIncrementOperation(Add(otherAmount, myAmount)); } throw new InvalidOperationException("Operation is invalid after previous operation."); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) { return(this); }
public IParseFieldOperation MergeWithPrevious(IParseFieldOperation previous) => this;