private Dictionary <string, object> Project(Content content, List <Property> expandTree)
        {
            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;

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

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

            AddField(content, expandTree, outfields, ACTIONSPROPERTY, GetActions);
            AddField(content, expandTree, outfields, ODataHandler.ChildrenPropertyName, c =>
            {
                // disable autofilters by default the same way as in ODataFormatter.WriteChildrenCollection
                c.ChildrenDefinition.EnableAutofilters =
                    Request.AutofiltersEnabled != FilterStatus.Default
                        ? Request.AutofiltersEnabled
                        : FilterStatus.Disabled;

                var expansion = GetExpansion(ODataHandler.ChildrenPropertyName, expandTree);

                return(ProjectMultiRefContents(
                           c.Children.AsEnumerable().Select(cnt => cnt.ContentHandler),
                           new List <Property>(new[] { expansion })));
            });

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

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

            return(outfields);
        }
Example #2
0
        private Dictionary <string, object> Project(Content content, List <Property> expandTree)
        {
            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;

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

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

            var actionExpansion = GetExpansion(ACTIONSPROPERTY, expandTree);

            if (actionExpansion == null)
            {
                outfields.Add(ACTIONSPROPERTY, ODataReference.Create(String.Concat(selfurl, "/", ODataHandler.ActionsPropertyName)));
            }
            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.BinaryPropertyName));

            return(outfields);
        }
Example #3
0
        private Dictionary <string, object> Project(Content content, List <Property> expandTree, List <Property> selectTree)
        {
            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 var field))
                {
                    switch (propertyName)
                    {
                    case ACTIONSPROPERTY:
                        AddField(content, expandTree, outfields, ACTIONSPROPERTY, GetActions);
                        break;

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

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

                    case ODataHandler.ChildrenPropertyName:
                        var expansion = GetPropertyFromList(ODataHandler.ChildrenPropertyName, expandTree);
                        AddField(content, expansion, outfields, ODataHandler.ChildrenPropertyName,
                                 c =>
                        {
                            // disable autofilters by default the same way as in ODataFormatter.WriteChildrenCollection
                            c.ChildrenDefinition.EnableAutofilters =
                                Request.AutofiltersEnabled != FilterStatus.Default
                                            ? Request.AutofiltersEnabled
                                            : FilterStatus.Disabled;

                            return(ProjectMultiRefContents(
                                       c.Children.AsEnumerable().Select(cnt => cnt.ContentHandler),
                                       new List <Property>(new[] { expansion }),
                                       property.Children));
                        });
                        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
                        {
                            outfields.Add(propertyName,
                                          IsAllowedField(content, field.Name)
                                    ? ODataFormatter.GetJsonObject(field, selfurl)
                                    : 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);
                    outfields.Add(propertyName,
                                  expansion != null
                            ? Project(contentField, expansion.Children, Property.JokerList)
                            : ODataFormatter.GetJsonObject(contentField, selfurl));
                }
            }

            return(outfields);
        }
Example #4
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);
        }
Example #5
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);
        }