Ejemplo n.º 1
0
        //TODO: Bad name: GetJsonObject is a method for odata serializing
        internal static object GetJsonObject(Field field, string selfUrl)
        {
            object data;

            if (field is ReferenceField)
            {
                return(ODataReference.Create(String.Concat(selfUrl, "/", field.Name)));
            }
            else if (field is BinaryField)
            {
                var binaryField = (BinaryField)field;
                var binaryData  = (BinaryData)binaryField.GetData();

                return(ODataBinary.Create(ContentTools.GetBinaryUrl(field.Content.Id, field.Name, binaryData.Timestamp), null, binaryData.ContentType, null));
            }
            else if (ODataHandler.DeferredFieldNames.Contains(field.Name))
            {
                return(ODataReference.Create(String.Concat(selfUrl, "/", field.Name)));
            }
            data = field.GetData();
            var nodeType = data as NodeType;

            if (nodeType != null)
            {
                return(nodeType.Name);
            }
            return(data);
        }
Ejemplo n.º 2
0
        private Dictionary <string, object> Project(Content content, List <Property> expandTree, List <Property> selectTree)
        {
            Field field;

            var outfields = new Dictionary <string, object>();
            var selfurl   = GetSelfUrl(content);

            if (this.Request.EntityMetadata != MetadataFormat.None)
            {
                outfields.Add("__metadata", GetMetadata(content, selfurl, this.Request.EntityMetadata));
            }

            var hasJoker = false;

            foreach (var property in selectTree)
            {
                var propertyName = property.Name;
                if (propertyName == "*")
                {
                    hasJoker = true;
                    continue;
                }
                if (!content.Fields.TryGetValue(propertyName, out field))
                {
                    switch (propertyName)
                    {
                    case ACTIONSPROPERTY:
                        var actionExpansion = GetPropertyFromList(ACTIONSPROPERTY, expandTree);
                        if (actionExpansion == null)
                        {
                            outfields.Add(ACTIONSPROPERTY, ODataReference.Create(String.Concat(selfurl, "/", ODataHandler.PROPERTY_ACTIONS)));
                        }
                        else
                        {
                            outfields.Add(ACTIONSPROPERTY, GetActions(content));
                        }
                        break;

                    case ICONPROPERTY:
                        outfields.Add(ICONPROPERTY, content.Icon ?? content.ContentType.Icon);
                        break;

                    case ISFILEPROPERTY:
                        outfields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataHandler.PROPERTY_BINARY));
                        break;

                    default:
                        outfields.Add(propertyName, null);
                        break;
                    }
                }
                else
                {
                    if (ODataHandler.DisabledFieldNames.Contains(field.Name))
                    {
                        outfields.Add(propertyName, null);
                    }
                    else
                    {
                        var expansion = GetPropertyFromList(propertyName, expandTree);
                        if (expansion != null)
                        {
                            outfields.Add(propertyName, Project(field, expansion.Children, property.Children ?? Property.JokerList));
                        }
                        else
                        {
                            if (base.IsAllowedField(content, field.Name))
                            {
                                outfields.Add(propertyName, ODataFormatter.GetJsonObject(field, selfurl));
                            }
                            else
                            {
                                outfields.Add(propertyName, null);
                            }
                        }
                    }
                }
            }

            if (hasJoker)
            {
                foreach (var contentField in content.Fields.Values)
                {
                    if (outfields.ContainsKey(contentField.Name))
                    {
                        continue;
                    }
                    var propertyName = contentField.Name;
                    var expansion    = GetPropertyFromList(propertyName, expandTree);
                    if (expansion != null)
                    {
                        outfields.Add(propertyName, Project(contentField, expansion.Children, Property.JokerList));
                    }
                    else
                    {
                        outfields.Add(propertyName, ODataFormatter.GetJsonObject(contentField, selfurl));
                    }
                }
            }

            //var actionSelection = GetPropertyFromList(ACTIONSPROPERTY, selectTree);
            //if (!outfields.ContainsKey(ACTIONSPROPERTY) && actionSelection != null)
            //{
            //    var actionExpansion = GetPropertyFromList(ACTIONSPROPERTY, expandTree);
            //    if (actionExpansion == null)
            //        outfields.Add(ACTIONSPROPERTY, JsonDeferred.Create(String.Concat(selfurl, "/", ODataHandler.PROPERTY_ACTIONS)));
            //    else
            //        outfields.Add(ACTIONSPROPERTY, GetActions(content));
            //}
            //if (!outfields.ContainsKey(ICONPROPERTY) && null != GetPropertyFromList(ICONPROPERTY, selectTree))
            //    outfields.Add(ICONPROPERTY, content.Icon ?? content.ContentType.Icon);
            //if (null != GetPropertyFromList(ISFILEPROPERTY, selectTree))
            //    outfields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataHandler.PROPERTY_BINARY));
            //if (null != GetPropertyFromList(ISCONTAINERPROPERTY, selectTree))
            //    outfields.Add(ISCONTAINERPROPERTY, content.ContentHandler is IFolder);

            return(outfields);
        }
Ejemplo n.º 3
0
        internal override Dictionary <string, object> Project(Content content)
        {
            var fields  = new Dictionary <string, object>();
            var selfurl = GetSelfUrl(content);

            if (this.Request.EntityMetadata != MetadataFormat.None)
            {
                fields.Add("__metadata", GetMetadata(content, selfurl, this.Request.EntityMetadata));
            }

            IEnumerable <string> fieldNames = null;

            if (Request.HasSelect)
            {
                fieldNames = Request.Select;
            }
            else
            {
                if (IsCollectionItem)
                {
                    if (_fieldNamesForPaths.ContainsKey(content.ContentHandler.ParentPath))
                    {
                        fieldNames = _fieldNamesForPaths[content.ContentHandler.ParentPath];
                    }
                    else
                    {
                        _fieldNamesForPaths[content.ContentHandler.ParentPath] = fieldNames = content.GetFieldNamesInParentTable();
                    }

                    if (content.AspectFields != null && content.AspectFields.Count > 0)
                    {
                        fieldNames = fieldNames.Concat(content.AspectFields.Keys);
                    }
                }
                else
                {
                    fieldNames = content.Fields.Keys;
                }
            }

            if (Request.HasSelect)
            {
                foreach (var selectItem in Request.Select)
                {
                    if (selectItem.Contains("/"))
                    {
                        throw new ODataException("Bad item in $select: " + selectItem, ODataExceptionCode.InvalidSelectParameter);
                    }
                }
            }

            if (!Request.HasSelect)
            {
                fieldNames = fieldNames.Concat(new[] { ACTIONSPROPERTY, ISFILEPROPERTY });
            }

            foreach (var fieldName in fieldNames)
            {
                if (fields.ContainsKey(fieldName))
                {
                    continue;
                }

                if (ODataHandler.DisabledFieldNames.Contains(fieldName))
                {
                    fields.Add(fieldName, null);
                    continue;
                }

                if (base.IsAllowedField(content, fieldName))
                {
                    Field field;
                    if (content.Fields.TryGetValue(fieldName, out field))
                    {
                        fields.Add(fieldName, ODataFormatter.GetJsonObject(field, selfurl));
                    }
                    else if (fieldName == ACTIONSPROPERTY)
                    {
                        fields.Add(ACTIONSPROPERTY, ODataReference.Create(String.Concat(selfurl, "/", ODataHandler.PROPERTY_ACTIONS)));
                    }
                    else if (fieldName == ISFILEPROPERTY)
                    {
                        fields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataHandler.PROPERTY_BINARY));
                    }
                    else if (fieldName == ICONPROPERTY)
                    {
                        fields.Add(fieldName, content.Icon ?? content.ContentType.Icon);
                    }
                    else
                    {
                        fields.Add(fieldName, null);
                    }
                }
                else
                {
                    fields.Add(fieldName, null);
                }
            }
            return(fields);
        }
Ejemplo n.º 4
0
        private Dictionary <string, object> Project(Content content, List <Property> expandTree)
        {
            Property expansion;

            var outfields = new Dictionary <string, object>();
            var selfurl   = GetSelfUrl(content);

            if (this.Request.EntityMetadata != MetadataFormat.None)
            {
                outfields.Add("__metadata", GetMetadata(content, selfurl, this.Request.EntityMetadata));
            }
            var fields = content.Fields.Values;

            var expansionEnabled = !content.ContentHandler.IsHeadOnly;

            foreach (var field in fields)
            {
                if (ODataHandler.DisabledFieldNames.Contains(field.Name))
                {
                    continue;
                }

                var propertyName = field.Name;

                expansion = expansionEnabled ? GetExpansion(propertyName, expandTree) : null;

                if (expansion != null)
                {
                    outfields.Add(propertyName, Project(field, expansion.Children));
                }
                else
                {
                    if (base.IsAllowedField(content, field.Name))
                    {
                        outfields.Add(propertyName, ODataFormatter.GetJsonObject(field, selfurl));
                    }
                    else
                    {
                        outfields.Add(propertyName, null);
                    }
                }
            }

            var actionExpansion = GetExpansion(ACTIONSPROPERTY, expandTree);

            if (actionExpansion == null)
            {
                outfields.Add(ACTIONSPROPERTY, ODataReference.Create(String.Concat(selfurl, "/", ODataHandler.PROPERTY_ACTIONS)));
            }
            else
            {
                outfields.Add(ACTIONSPROPERTY, GetActions(content));
            }

            if (!outfields.ContainsKey(ICONPROPERTY))
            {
                outfields.Add(ICONPROPERTY, content.Icon ?? content.ContentType.Icon);
            }

            outfields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataHandler.PROPERTY_BINARY));

            return(outfields);
        }