示例#1
0
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            if (previous == null) {
                return this;
            }

            if ((previous is NCMBDeleteOperation)) {
                return new NCMBSetOperation (this.objects);
            }

            if ((previous is NCMBSetOperation)) {
                object value = ((NCMBSetOperation)previous).getValue ();
                if ((value is IList)) {
                    ArrayList result = new ArrayList ((IList)value);
                    result.AddRange (this.objects);
                    return new NCMBSetOperation (result);
                }
                throw new  InvalidOperationException ("You can only add an item to a List.");
            }

            if ((previous is NCMBAddOperation)) {
                ArrayList result = new ArrayList (((NCMBAddOperation)previous).objects);
                result.AddRange (this.objects);
                return new NCMBAddOperation (result);
            }
            throw new  InvalidOperationException ("Operation is invalid after previous operation.");
        }
示例#2
0
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            if (previous == null)
            {
                return(this);
            }

            if ((previous is NCMBDeleteOperation))
            {
                return(new NCMBSetOperation(this.objects));
            }

            if ((previous is NCMBSetOperation))
            {
                object value = ((NCMBSetOperation)previous).getValue();
                if ((value is IList))
                {
                    ArrayList result = new ArrayList((IList)value);
                    result.AddRange(this.objects);
                    return(new NCMBSetOperation(result));
                }
                throw new  InvalidOperationException("You can only add an item to a List.");
            }

            if ((previous is NCMBAddOperation))
            {
                ArrayList result = new ArrayList(((NCMBAddOperation)previous).objects);
                result.AddRange(this.objects);
                return(new NCMBAddOperation(result));
            }
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            if (previous == null)
            {
                return(this);
            }

            if ((previous is NCMBDeleteOperation))
            {
                return(new NCMBSetOperation(this.amount));
            }

            if ((previous is NCMBSetOperation))
            {
                object value = ((NCMBSetOperation)previous).getValue();
                if (value is string || value == null)
                {
                    throw new  InvalidOperationException("You cannot increment a non-number.");
                }
                return(new NCMBSetOperation(NCMBObject._addNumbers(value, this.amount)));
            }

            if ((previous is NCMBIncrementOperation))
            {
                object oldAmount = (((NCMBIncrementOperation)previous).amount);
                return(new NCMBIncrementOperation(NCMBObject._addNumbers(oldAmount, this.amount)));
            }
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
示例#4
0
        //前回の履歴データを元に新規履歴データの作成
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            //過去のデータ操作履歴はなし
            if (previous == null)
            {
                return(this);
            }
            //前回すでに削除(Remove実行)されていれば空のリストを返す
            if (previous is NCMBDeleteOperation)
            {
                return(new NCMBSetOperation(new ArrayList()));
            }

            //前回データ操作がSetOperationだった場合はSetOPerationの値を返す
            if (previous is NCMBSetOperation)
            {
                object value = ((NCMBSetOperation)previous).getValue();
                if ((value is IList))
                {
                    return(new NCMBSetOperation(Apply(value, null, null)));
                }
                throw new  InvalidOperationException("You can only add an item to a List.");
            }

            //前回RemoveAllFromList(objectIdがある時)の場合、重複しない値の追加
            if (previous is NCMBRemoveOperation)
            {
                ArrayList result = new ArrayList(((NCMBRemoveOperation)previous).objects);
                foreach (object o in this.objects)
                {
                    result.Add(o);
                }
                //result.UnionWith (this.objects);//重複しない値の追加
                return(new NCMBRemoveOperation(result));
            }
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            if (previous == null) {
                return this;
            }

            if ((previous is NCMBDeleteOperation)) {
                return new NCMBSetOperation (this.amount);
            }

            if ((previous is NCMBSetOperation)) {
                object value = ((NCMBSetOperation)previous).getValue ();
                if (value is string || value == null) {
                    throw new  InvalidOperationException ("You cannot increment a non-number.");
                }
                return new NCMBSetOperation (NCMBObject._addNumbers (value, this.amount));
            }

            if ((previous is NCMBIncrementOperation)) {
                object oldAmount = (((NCMBIncrementOperation)previous).amount);
                return new NCMBIncrementOperation (NCMBObject._addNumbers (oldAmount, this.amount));
            }
            throw new  InvalidOperationException ("Operation is invalid after previous operation.");
        }
示例#6
0
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            if (previous == null)
            {
                return(this);
            }
            if ((previous is NCMBDeleteOperation))
            {
                throw new NCMBException(new  ArgumentException("You can't modify a relation after deleting it."));
            }
            if ((previous is NCMBRelationOperation <T>))
            {
                NCMBRelationOperation <T> previousOperation = (NCMBRelationOperation <T>)previous;

                if ((previousOperation._targetClass != null) && (!previousOperation._targetClass.Equals(this._targetClass)))
                {
                    throw new NCMBException(new  ArgumentException("Related object object must be of class " + previousOperation._targetClass + ", but " + this._targetClass + " was passed in."));
                }

                //最後にSaveしてから今までAddまたはRemoveしたオブジェクトIDをそれぞれ保持する
                HashSet <string> newRelationsToAdd    = new HashSet <string> (previousOperation._relationsToAdd);
                HashSet <string> newRelationsToRemove = new HashSet <string> (previousOperation._relationsToRemove);

                //Add時
                if (this._relationsToAdd.Count > 0)
                {
                    //Removeがまだ実行されてない時のみ、Add対象をリストに追加する
                    if (newRelationsToRemove.Count == 0)
                    {
                        foreach (string str in _relationsToAdd)
                        {
                            newRelationsToAdd.Add(str);
                        }
                    }
                    else
                    {
                        foreach (string str in _relationsToAdd)
                        {
                            newRelationsToRemove.Remove(str);
                        }
                    }
                }

                //Remove時
                if (this._relationsToRemove.Count > 0)
                {
                    //Addがまだ実行されてない時のみ、Remove対象をリストに追加する
                    if (newRelationsToAdd.Count == 0)
                    {
                        foreach (string str in _relationsToRemove)
                        {
                            newRelationsToRemove.Add(str);
                        }
                    }
                    else
                    {
                        foreach (string str in _relationsToRemove)
                        {
                            newRelationsToAdd.Remove(str);
                        }
                    }
                }

                return(new NCMBRelationOperation <T> (this._targetClass, newRelationsToAdd, newRelationsToRemove));
            }
            throw new NCMBException(new  ArgumentException("Operation is invalid after previous operation."));
        }
示例#7
0
 public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
 {
     return(this);
 }
示例#8
0
 public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
 {
     return this;
 }
示例#9
0
        //前回の履歴データを元に新規履歴データの作成
        public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            //過去のデータ操作履歴はなし
            if (previous == null) {
                return this;
            }
            //前回すでに削除(Remove実行)されていれば空のリストを返す
            if (previous is NCMBDeleteOperation) {
                return new NCMBSetOperation (new ArrayList ());
            }

            //前回データ操作がSetOperationだった場合はSetOPerationの値を返す
            if (previous is NCMBSetOperation) {
                object value = ((NCMBSetOperation)previous).getValue ();
                if ((value is IList)) {
                    return new NCMBSetOperation (Apply (value, null, null));
                }
                throw new  InvalidOperationException ("You can only add an item to a List.");
            }

            //前回RemoveAllFromList(objectIdがある時)の場合、重複しない値の追加
            if (previous is NCMBRemoveOperation) {
                ArrayList result = new ArrayList (((NCMBRemoveOperation)previous).objects);
                foreach (object o in this.objects) {
                    result.Add (o);
                }
                //result.UnionWith (this.objects);//重複しない値の追加
                return new NCMBRemoveOperation (result);
            }
            throw new  InvalidOperationException ("Operation is invalid after previous operation.");
        }