Exemplo n.º 1
0
 public void LoadObject(object dest, IJSONDocument src)
 {
     if (src.RootType != JSONItemType.Object)
     {
         throw new ArgumentException("no object as root");
     }
     LoadObject(dest, src.RootAsObject);
 }
Exemplo n.º 2
0
 public static IJsonValue[] GetArray(IJSONDocument document, string attribute)
 {
     if (document.GetAttributeDataType(attribute) != ExtendedJSONDataTypes.Array)
     {
         return(null);
     }
     return(ToIJsonList((IEnumerable)document[attribute]).ToArray());
 }
Exemplo n.º 3
0
        public virtual IJSONDocument Transform(IJSONDocument document)
        {
            IJSONDocument newDocument;

            if (_criteria.GetAllFields)
            {
                newDocument = document.Clone() as IJSONDocument;
            }
            else
            {
                newDocument = JSONType.CreateNew();
            }

            //if (!_criteria.IsGrouped)
            //    newDocument.Key = document.Key;

            for (int i = 0; i < _criteria.ProjectionCount; i++)
            {
                IEvaluable field = _criteria[i];
                IJsonValue finalValue;

                if (field.Evaluate(out finalValue, document))
                {
                    //newDocument[field.ToString()] = finalValue.Value;
                    var binaryExpression = field as BinaryExpression;

                    if (binaryExpression != null)
                    {
                        if (binaryExpression.Alias != null)
                        {
                            newDocument[binaryExpression.Alias] = finalValue.Value;
                            continue;
                        }
                    }
                    newDocument[field.CaseSensitiveInString] = finalValue.Value;
                }
                else
                {
                    return(null);
                }
            }

            if (_criteria.ContainsOrder && !_criteria.IsGrouped)
            {
                _criteria.OrderByField.FillWithAttributes(document, newDocument);
            }
            else if (_criteria.IsGrouped)
            {
                _criteria.GroupByField.FillWithAttributes(document, newDocument);
            }

            if (newDocument.Count == 0)
            {
                return(null);
            }

            return(newDocument);
        }
        /// <summary>
        /// Compose data to JSON data
        /// </summary>
        /// <returns></returns>
        public IJSONItem ToJSON(IJSONDocument doc)
        {
            string          output = string.Empty;
            IJSONItemObject o      = doc.CreateItemObject();

            o.Add("handler", handler.ToString());
            o.Add("propertyName", propName);
            return(o);
        }
Exemplo n.º 5
0
        public void ApplyValue(IJSONDocument value)
        {
            IJsonValue evaluatedValue = _fieldName.Evaluate(value);

            if (first == null)
            {
                first = evaluatedValue.Value;
            }
        }
Exemplo n.º 6
0
 public virtual void Add(DocumentKey key, long rowId, IJSONDocument document, IOperationContext context, long size = 0)
 {
     lock (_keyToRowIndex)
     {
         _keyToRowIndex[key] = rowId;
         _enumerationSet.Add(rowId);
     }
     AddBucketKeyIndex(key);
     AddSize(rowId, document, size, context);
 }
Exemplo n.º 7
0
        public object Initialize(object initialValue)
        {
            if (!(initialValue is IJSONDocument))
            {
                throw new Exception("At NoAggregationDataCombiner: Document needs to be in IJSONDocument format");
            }

            _document = (IJSONDocument)initialValue;
            return(_document);
        }
Exemplo n.º 8
0
        public bool Apply(IJSONDocument document)
        {
            var attribute = _targetField as Attribute;

            if (attribute != null)
            {
                return(Attributor.TryDelete(document, attribute));
            }
            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts data into JSON for computer graphics
        /// </summary>
        public void ToJSON()
        {
            IJSONDocument  doc = JSONDocument.CreateDocument();
            IJSONItemArray arr = doc.CreateItemArray();

            foreach (Beam b in this.GetAllProperties())
            {
                IJSONItem o = b.ToJSON(doc);
                arr.Add(o);
            }
        }
Exemplo n.º 10
0
 public override bool FillWithAttributes(IJSONDocument source, IJSONDocument target)
 {
     if (source != null && target != null)
     {
         for (int i = 0; i < _individualFields.Count; i++)
         {
             _individualFields[i].FillWithAttributes(source, target);
         }
     }
     return(false);
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public ISetElement GetTopElement()
        {
            if (_dataChunk.Documents.Count <= 0)
            {
                return(null);
            }
            IJSONDocument doc        = _dataChunk.Documents.First();
            ISetElement   setElement = new SetElement(this, _dataChunk.IsLastChunk, doc);

            return(setElement);
        }
Exemplo n.º 13
0
 public bool IsTrue(IJSONDocument entry)
 {
     foreach (var predciate in _predciates)
     {
         if (!predciate.IsTrue(entry))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 14
0
 public override bool FillWithAttributes(IJSONDocument source, IJSONDocument target)
 {
     //if (target != null)
     //{
     //    foreach (var attribute in source.GetAttributes())
     //    {
     //        target[attribute] = source[attribute];
     //    }
     //}
     return(true);
 }
Exemplo n.º 15
0
 public bool Evaluate(out IJsonValue value, IJSONDocument document)
 {
     if (EvaluationType.Equals(EvaluationType.Constant))
     {
         value = new StringJsonValue((string)Constant);
     }
     else
     {
         value = this;
     }
     return(true);
 }
Exemplo n.º 16
0
        public bool Evaluate(out IJsonValue value, IJSONDocument document)
        {
            List <IJsonValue> allValues = new List <IJsonValue>();

            foreach (var attribute in document.GetAttributes())
            {
                allValues.Add(JsonWrapper.Wrap(document[attribute]));
            }

            value = new ArrayJsonValue(allValues.ToArray());
            return(true);
        }
Exemplo n.º 17
0
        public static T Deserialize <T>(IJSONDocument jsonDocument)
        {
            if (jsonDocument == null)
            {
                return(default(T));
            }
            if (typeof(T) == typeof(JSONDocument))
            {
                return((T)(object)jsonDocument);
            }

            return(JsonConvert.DeserializeObject <T>(jsonDocument.ToString()));
        }
Exemplo n.º 18
0
 public bool Contains(IJSONDocument entry, IJsonValue item)
 {
     foreach (var value in _values)
     {
         IJsonValue outValue;
         if (value.Evaluate(out outValue, entry) &&
             item.Equals(outValue))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 19
0
 public virtual bool GetAttributeValue(IJSONDocument document, out AttributeValue value)
 {
     if (GetValue(document, out value))
     {
         var attributeList = new List <AttributeValue> {
             new SingleAttributeValue(_fieldId.ToString())
         };
         attributeList.Add(value);
         value = new MultiAttributeValue(attributeList);
         return(true);
     }
     return(false);
 }
Exemplo n.º 20
0
        public static void Update(IJSONDocument document, IJSONDocument update)
        {
            if (update == null)
            {
                throw new ArgumentNullException("update", "Value cannot be null");
            }

            foreach (string attribute in update.GetAttributes())
            {
                Queue <string> attributeQueue = new Queue <string>(attribute.Split('.'));
                ExpandAttribute(document, attributeQueue, update[attribute]);
            }
        }
Exemplo n.º 21
0
 public static bool ArrayContainsAll(IJsonValue value1, IEnumerable <IEvaluable> values,
                                     IJSONDocument entry)
 {
     if (!(value1 is EmbeddedList))
     {
         if (value1 is ArrayJsonValue)
         {
             return(ContainsAll(value1 as ArrayJsonValue, values, entry));
         }
         return(false);
     }
     return(ContainsAll(new ArrayJsonValue(((EmbeddedList)value1).WrapedValue.ToArray()), values, entry));
 }
Exemplo n.º 22
0
 public void AddToIndex(long rowId, IJSONDocument document, long operationId)
 {
     foreach (IIndex index in _indexes.Values)
     {
         AttributeValue[] attribValue;
         if (index.IndexKey.TryGetValue(document, out attribValue))
         {
             foreach (var attributeValue in attribValue)
             {
                 index.Add(attributeValue, rowId, operationId);
             }
         }
     }
 }
Exemplo n.º 23
0
        public override IEnumerable <KeyValuePair <AttributeValue, long> > Enumerate(QueryCriteria value)
        {
            IQueryStore   tempCollection = value.SubstituteStore;
            IJSONDocument doc            = JSONType.CreateNew();

            doc.Add("$count(*)", _count);
            doc.Key = Guid.NewGuid().ToString();
            tempCollection.InsertDocument(doc, null);
            var rowid = tempCollection.GetRowId(new DocumentKey(doc.Key));

            value.Store        = tempCollection;
            value.GroupByField = new AllField(Field.FieldType.Grouped);
            yield return(new KeyValuePair <AttributeValue, long>(NullValue.Null, rowid));
        }
Exemplo n.º 24
0
        public bool Evaluate(out IJsonValue value, IJSONDocument document)
        {
            value = null;
            IJsonValue outJsonValue;

            //int adjustedItems = _items+1; //slice (1,0) means first item

            if (!_expression.Evaluate(out outJsonValue, document))
            {
                return(false);
            }

            if (outJsonValue.DataType != FieldDataType.Array && outJsonValue.DataType != FieldDataType.Embedded)
            {
                return(false);
            }

            ArrayJsonValue arrayValue;

            if (outJsonValue.DataType == FieldDataType.Embedded)
            {
                arrayValue = new ArrayJsonValue(((EmbeddedList)outJsonValue).WrapedValue.ToArray());
            }
            else
            {
                arrayValue = (ArrayJsonValue)outJsonValue;
            }

            int sourceIndex = (_start > 0) ? _start - 1 : (arrayValue.Length + _start) - _items + 1;

            if (sourceIndex < 0)
            {
                return(false);
            }

            if (arrayValue.Length < sourceIndex + _items)
            {
                return(false);
            }


            IJsonValue[] returnArray = new IJsonValue[_items];

            Array.Copy(arrayValue.WrapedValue, sourceIndex, returnArray, 0, _items);

            value = new ArrayJsonValue(returnArray);
            return(true);
        }
Exemplo n.º 25
0
 public static void ForceSet <T>(IJSONDocument document, T value, IAttributeChain thisAttribute)
 {
     if (thisAttribute.Child == null)
     {
         if (thisAttribute.Indices != null)
         {
             var lengths = new int[thisAttribute.Indices.Length];
             for (int i = 0; i < thisAttribute.Indices.Length; i++)
             {
                 lengths[i] = thisAttribute.Indices[i] + 1;
             }
             Array array = Array.CreateInstance(typeof(object), lengths);
             array.SetValue(value, thisAttribute.Indices);
             document[thisAttribute.Name] = array;
         }
         else
         {
             document[thisAttribute.Name] = value;
         }
     }
     else
     {
         if (thisAttribute.Indices != null)
         {
             var lengths = new int[thisAttribute.Indices.Length];
             for (int i = 0; i < thisAttribute.Indices.Length; i++)
             {
                 lengths[i] = thisAttribute.Indices[i] + 1;
             }
             Array array = Array.CreateInstance(typeof(object), lengths);
             document[thisAttribute.Name] = array;
             var newDocument = JSONType.CreateNew();
             array.SetValue(newDocument, thisAttribute.Indices);
             ForceSet(newDocument, value, thisAttribute.Child);
         }
         else
         {
             if (!document.Contains(thisAttribute.Name) ||
                 document.GetAttributeDataType(thisAttribute.Name) != ExtendedJSONDataTypes.Object)
             {
                 document[thisAttribute.Name] = JSONType.CreateNew();
             }
             document = document.GetDocument(thisAttribute.Name);
             ForceSet(document, value, thisAttribute.Child);
         }
     }
 }
Exemplo n.º 26
0
        public object Initialize(object initialValue)
        {
            if (!(initialValue is IJSONDocument))
            {
                throw new Exception("At MinDataCombiner: Document needs to be in IJSONDocument format");
            }

            IJSONDocument document = (IJSONDocument)initialValue;

            foreach (var attribute in _attributes)
            {
                object value1 = document.Get <object>(_userDefinedName);
                document[_userDefinedName] = value1;
            }
            _document = document;
            return(_document);
        }
Exemplo n.º 27
0
 private static bool ContainsAll(ArrayJsonValue array, IEnumerable <IEvaluable> values,
                                 IJSONDocument entry)
 {
     foreach (var evaluable in values)
     {
         IJsonValue value;
         if (!evaluable.Evaluate(out value, entry))
         {
             return(false);
         }
         if (!array.Contains(value))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 28
0
        /*[JsonProperty(PropertyName = "AutoGenerated")]
         * public bool AutoGenerated { get; set; }*/

        /*public DocumentKey GetFormattedPartitionKey(params string[] partitionKeyValues)
         * {
         *  string key = null;
         *  if (AutoGenerated)
         *  {
         *      key = GenerateKey();
         *  }
         *  else
         *  {
         *      StringBuilder sb = new StringBuilder();
         *
         *      foreach (string partitionKeyValue in partitionKeyValues)
         *      {
         *          if (sb.Length > 0)
         *              sb.Append(":");
         *          sb.Append(partitionKeyValue);
         *      }
         *
         *      key = sb.ToString();
         *  }
         *
         *  return new DocumentKey(key);
         * }*/

        /// <summary>
        /// Get the value for each attribute in the Document. Concat them to make a key out of it.
        /// If even one of the attribute does not exists inside the document, it returns null
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public string GetStringFormattedPartitionKey(IJSONDocument document)
        {
            string key = string.Empty;

            foreach (var partitionKeyAttribute in Attributes)
            {
                if (document.Contains(partitionKeyAttribute.Name))
                {
                    key = string.Concat(key, document.GetToString(partitionKeyAttribute.Name));
                }
                else
                {
                    return(null);
                }
            }
            return(key.Equals(string.Empty) ? null : key);
        }
Exemplo n.º 29
0
 public override void Add(DocumentKey key, long rowId, IJSONDocument document, IOperationContext context, long size = 0)
 {
     lock (_keyToRowIndex)
     {
         _keyToRowIndex[key] = rowId;
         //_enumerationSet.Add(rowId);
         lock (_keysDeleted)
         {
             if (_keysDeleted.Contains(key))
             {
                 _keysDeleted.Remove(key);
             }
         }
     }
     //AddBucketKeyIndex(key);
     AddSize(rowId, document, size, context);
 }
Exemplo n.º 30
0
        public object Combine(object value)
        {
            if (!(value is IJSONDocument))
            {
                throw new Exception("At AverageDataCombiner: Document needs to be in IJSONDocument format");
            }

            bool          isUpdateApplicable = false;
            IJSONDocument document           = (IJSONDocument)value;
            IJSONDocument updateDoc          = new JSONDocument();

            foreach (var attribute in _attributes)
            {
                IJSONDocument sumAndCount = new JSONDocument();
                if (document.GetAttributeDataType(_userDefinedName) == ExtendedJSONDataTypes.Array)
                {
                    if (_document.Contains("$" + _userDefinedName) && _document.GetAttributeDataType("$" + _userDefinedName) == ExtendedJSONDataTypes.Array)
                    {
                        double[] sumAndCountDoc = document.GetArray <double>(_userDefinedName);
                        double   sum            = sumAndCountDoc[0];
                        double   count          = sumAndCountDoc[1];

                        double[] existingSumAndCount = _document.GetArray <double>("$" + _userDefinedName);
                        double   sum1   = existingSumAndCount[0];
                        double   count1 = existingSumAndCount[1];

                        double combinedSum   = sum + sum1;
                        double combinedCount = count + count1;

                        sumAndCountDoc[0] = combinedSum;
                        sumAndCountDoc[1] = combinedCount;

                        updateDoc.Add("$" + _userDefinedName, sumAndCountDoc);
                        updateDoc.Add(_userDefinedName, combinedSum / combinedCount);
                        isUpdateApplicable = true;
                    }
                }
            }

            if (isUpdateApplicable)
            {
                JsonDocumentUtil.Update(_document, updateDoc);
            }
            return(_document);
        }