コード例 #1
0
ファイル: Field.cs プロジェクト: waqashaneef/NosDB
        public virtual bool FillWithAttributes(IJSONDocument source, IJSONDocument target)
        {
            if (source != null && target != null)
            {
                IJsonValue wrapedValue;
                if (_fieldName.ToString().Equals("_key"))
                {
                    if (source.Contains("!_key"))
                    {
                        target.Key = source.GetString("!_key");
                    }
                    else
                    {
                        target.Add("!_key", source.Key);
                    }
                    return(true);
                }

                if (_fieldName.Evaluate(out wrapedValue, source))
                {
                    IAttributeChain attributor = Attributor.Create(Attributor.Delimit(_fieldName.InString, new[] { '$' }));
                    Attributor.TryUpdate(target, wrapedValue.Value, attributor, true);
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public bool Apply(Common.Server.Engine.IJSONDocument document)
        {
            var attribute = _targetField as Attribute;

            if (attribute != null)
            {
                return(Attributor.TryRename(document, _newName.ToString(), attribute));
            }
            return(false);
        }
コード例 #3
0
        public bool Apply(IJSONDocument document)
        {
            var attribute = _targetField as Attribute;

            if (attribute != null)
            {
                return(Attributor.TryDelete(document, attribute));
            }
            return(false);
        }
コード例 #4
0
ファイル: Replace.cs プロジェクト: waqashaneef/NosDB
        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);
        }
コード例 #5
0
ファイル: Insert.cs プロジェクト: waqashaneef/NosDB
        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);
        }
コード例 #6
0
        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);
        }