Ejemplo n.º 1
0
        internal PayloadComplexProperty parseComplexObject(PayloadObject parent, JSField field)
        {
            PayloadComplexProperty payloadProperty = new PayloadComplexProperty(parent);

            payloadProperty.Name = field.Name;

            JSObject fieldValue = (JSObject)field.GetValue(field);

            FieldInfo[] fieldInfo = fieldValue.GetFields(BindingFlags.Default);

            for (int j = 0; j < fieldInfo.Length; j++)
            {
                JSField currentField = (JSField)fieldInfo[j];

                if (currentField.GetValue(currentField) is JSObject)
                {
                    PayloadComplexProperty payloadComplexProperty = this.parseComplexObject(parent, (JSField)fieldInfo[j]);
                    payloadProperty.PayloadProperties.Add(payloadComplexProperty.Name, payloadComplexProperty);
                }
                else
                {
                    PayloadProperty payloadSimpleProperty = this.parseSimpleObject(parent, (JSField)fieldInfo[j]);
                    payloadProperty.PayloadProperties.Add(payloadSimpleProperty.Name, payloadSimpleProperty);
                }
            }

            return(payloadProperty);
        }
Ejemplo n.º 2
0
        private JSField GetArrayField(JSField field, int index)
        {
            JSObject fieldObject = (JSObject)field.GetValue(field);

            FieldInfo[] fields     = fieldObject.GetFields(BindingFlags.Default);
            JSField     indexField = (JSField)fields[index];

            return(indexField);
        }
Ejemplo n.º 3
0
        private string GetArrayString(JSField field, string name)
        {
            JSField jsField = this.GetArrayField(field, name);

            if (jsField != null)
            {
                return(jsField.GetValue(jsField).ToString());
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        private JSField GetArrayField(JSField field, string name)
        {
            JSObject fieldObject = (JSObject)field.GetValue(field);

            FieldInfo[] fields = fieldObject.GetFields(BindingFlags.Default);

            for (int i = 0; i < fields.Length; i++)
            {
                JSField indexField = (JSField)fields[i];
                if (indexField.Name == name)
                {
                    return(indexField);
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        internal PayloadSimpleProperty parseSimpleObject(PayloadObject parent, JSField field)
        {
            PayloadSimpleProperty payloadProperty = new PayloadSimpleProperty(parent);

            payloadProperty.Name = field.Name;

            object val = field.GetValue(field);

            if (val is System.DBNull)
            {
                payloadProperty.Value  = null;
                payloadProperty.Type   = null;
                payloadProperty.IsNull = true;
            }
            else
            {
                payloadProperty.Type   = AstoriaUnitTests.Data.TypeData.FindForType(val.GetType()).GetEdmTypeName();
                payloadProperty.Value  = ConvertJsonValue(val);
                payloadProperty.IsNull = false;
            }

            return(payloadProperty);
        }
Ejemplo n.º 6
0
        private PayloadObject parseJsonObject(JSObject jsObject)
        {
            PayloadObject payloadObject = new PayloadObject(this);

            FieldInfo[] fields = jsObject.GetFields(BindingFlags.Default);

            for (int i = 0; i < fields.Length; i++)
            {
                JSField field = (JSField)fields[i];
                var     value = field.GetValue(field);

                if (value is ArrayObject)
                {
                    PayloadObject payloadNestedParentObject = new PayloadObject(this);
                    payloadNestedParentObject.Name = field.Name;

                    ArrayObject nestedPayloadObjects = (ArrayObject)field.GetValue(field);
                    payloadNestedParentObject.PayloadObjects.AddRange(this.ParseJsonArray(nestedPayloadObjects));

                    foreach (PayloadObject po in payloadNestedParentObject.PayloadObjects)
                    {
                        po.Name = field.Name;
                    }

                    payloadObject.PayloadObjects.Add(payloadNestedParentObject);
                }
                else if (value is JSObject)
                {
                    if (field.Name == "__metadata")
                    {
                        payloadObject.Uri  = this.GetArrayString(field, "uri");
                        payloadObject.Type = this.GetArrayString(field, "type");

                        string etag = this.GetArrayString(field, "etag");
                        if (etag != null)
                        {
                            payloadObject.ETag = etag;
                        }
                    }
                    else
                    {
                        JSField firstChild = this.GetArrayField(field, 0);

                        if (firstChild != null && firstChild.Name == v2JsonResultsField)
                        {
                            PayloadObject payloadNestedParentObject = new PayloadObject(this);
                            payloadNestedParentObject.Name = field.Name;

                            ArrayObject nestedPayloadObjects = (ArrayObject)firstChild.GetValue(firstChild);
                            payloadNestedParentObject.PayloadObjects.AddRange(this.ParseJsonArray(nestedPayloadObjects));

                            foreach (PayloadObject po in payloadNestedParentObject.PayloadObjects)
                            {
                                po.Name = field.Name;
                            }

                            payloadObject.PayloadObjects.Add(payloadNestedParentObject);
                        }
                        else if (firstChild != null && firstChild.Name == "__deferred") // Deferred reference/collection
                        {
                            PayloadObject deferredObject = new PayloadObject(this);
                            deferredObject.Name     = field.Name;
                            deferredObject.Uri      = this.GetArrayString(firstChild, "uri");
                            deferredObject.Deferred = true;

                            payloadObject.PayloadObjects.Add(deferredObject);
                        }
                        else if (firstChild != null && firstChild.Name == "__mediaresource")
                        {
                            PayloadNamedStream stream = new PayloadNamedStream();
                            stream.Name        = field.Name;
                            stream.ContentType = this.GetArrayString(firstChild, "content-type");
                            stream.EditLink    = this.GetArrayString(firstChild, "edit_media");
                            stream.SelfLink    = this.GetArrayString(firstChild, "media_src");
                            stream.ETag        = this.GetArrayString(firstChild, "etag");
                            payloadObject.NamedStreams.Add(stream);
                        }
                        else
                        {
                            JSObject objectValue       = (JSObject)field.GetValue(field);
                            var      objectValueFields = objectValue.GetFields(BindingFlags.Default);
                            if (objectValueFields.Any(f => f.Name == "__metadata" && GetArrayString((JSField)f, "uri") != null))
                            {
                                PayloadObject referencePayloadObject = parseJsonObject(objectValue);
                                referencePayloadObject.Name      = field.Name;
                                referencePayloadObject.Reference = true;

                                payloadObject.PayloadObjects.Add(referencePayloadObject);
                            }
                            else
                            {
                                PayloadComplexProperty payloadProperty = this.parseComplexObject(payloadObject, field);    // Complex object
                                payloadObject.PayloadProperties.Add(payloadProperty);
                            }
                        }
                    }
                }
                else
                {
                    PayloadProperty payloadProperty = this.parseSimpleObject(payloadObject, field);
                    payloadObject.PayloadProperties.Add(payloadProperty);
                }
            }

            return(payloadObject);
        }