コード例 #1
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);
                }
            }

            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);
        }
コード例 #2
0
ファイル: MetaGenerator.cs プロジェクト: vlslavik/SenseNet
 public static void WriteMetadata(TextWriter writer, ODataFormatter formatter)
 {
     if (_edmx == null)
     {
         CreateEdmx();
     }
     formatter.WriteMetadataInternal(writer);
 }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        /// Processes the OData web request. Designed for test purposes.
        /// </summary>
        /// <param name="context">An <see cref="HttpContext" /> object that provides references to the intrinsic server objects (for example, <see langword="Request" />, <see langword="Response" />, <see langword="Session" />, and <see langword="Server" />) used to service HTTP requests. </param>
        /// <param name="httpMethod">HTTP protocol method.</param>
        /// <param name="inputStream">Request stream containing the posted JSON object.</param>
        public void ProcessRequest(HttpContext context, string httpMethod, Stream inputStream)
        {
            ODataRequest   odataReq      = null;
            ODataFormatter formatter     = null;
            var            portalContext = (PortalContext)context.Items[PortalContext.CONTEXT_ITEM_KEY];

            try
            {
                Content content;

                odataReq = portalContext.ODataRequest;
                if (odataReq == null)
                {
                    formatter = ODataFormatter.Create("json", portalContext);
                    throw new ODataException("The Request is not an OData request.", ODataExceptionCode.RequestError);
                }

                this.ODataRequest = portalContext.ODataRequest;
                Exception requestError = this.ODataRequest.RequestError;

                formatter = ODataFormatter.Create(portalContext, odataReq);
                if (formatter == null)
                {
                    formatter = ODataFormatter.Create("json", portalContext);
                    throw new ODataException(ODataExceptionCode.InvalidFormatParameter);
                }

                if (requestError != null)
                {
                    var innerOdataError = requestError as ODataException;
                    var message         = "An error occured during request parsing. " + requestError.Message +
                                          " See inner exception for details.";
                    var code = innerOdataError?.ODataExceptionCode ?? ODataExceptionCode.RequestError;
                    throw new ODataException(message, code, requestError);
                }

                odataReq.Format = formatter.FormatName;
                formatter.Initialize(odataReq);

                var exists = Node.Exists(odataReq.RepositoryPath);
                if (!exists && !odataReq.IsServiceDocumentRequest && !odataReq.IsMetadataRequest && !AllowedMethodNamesWithoutContent.Contains(httpMethod))
                {
                    ContentNotFound(context, odataReq.RepositoryPath);
                    return;
                }

                JObject model;
                switch (httpMethod)
                {
                case "GET":
                    if (odataReq.IsServiceDocumentRequest)
                    {
                        formatter.WriteServiceDocument(portalContext, odataReq);
                    }
                    else if (odataReq.IsMetadataRequest)
                    {
                        formatter.WriteMetadata(context, odataReq);
                    }
                    else
                    {
                        if (!Node.Exists(odataReq.RepositoryPath))
                        {
                            ContentNotFound(context, odataReq.RepositoryPath);
                        }
                        else if (odataReq.IsCollection)
                        {
                            formatter.WriteChildrenCollection(odataReq.RepositoryPath, portalContext, odataReq);
                        }
                        else if (odataReq.IsMemberRequest)
                        {
                            formatter.WriteContentProperty(odataReq.RepositoryPath, odataReq.PropertyName,
                                                           odataReq.IsRawValueRequest, portalContext, odataReq);
                        }
                        else
                        {
                            formatter.WriteSingleContent(odataReq.RepositoryPath, portalContext);
                        }
                    }
                    break;

                case "PUT":     // update
                    if (odataReq.IsMemberRequest)
                    {
                        throw new ODataException("Cannot access a member with HTTP PUT.",
                                                 ODataExceptionCode.IllegalInvoke);
                    }
                    else
                    {
                        model   = Read(inputStream);
                        content = LoadContentOrVirtualChild(odataReq);
                        if (content == null)
                        {
                            ContentNotFound(context, odataReq.RepositoryPath);
                            return;
                        }

                        ResetContent(content);
                        UpdateContent(content, model, odataReq);
                        formatter.WriteSingleContent(content, portalContext);
                    }
                    break;

                case "MERGE":
                case "PATCH":     // update
                    if (odataReq.IsMemberRequest)
                    {
                        throw new ODataException(
                                  String.Concat("Cannot access a member with HTTP ", httpMethod, "."),
                                  ODataExceptionCode.IllegalInvoke);
                    }
                    else
                    {
                        model   = Read(inputStream);
                        content = LoadContentOrVirtualChild(odataReq);
                        if (content == null)
                        {
                            ContentNotFound(context, odataReq.RepositoryPath);
                            return;
                        }

                        UpdateContent(content, model, odataReq);
                        formatter.WriteSingleContent(content, portalContext);
                    }
                    break;

                case "POST":     // invoke an action, create content
                    if (odataReq.IsMemberRequest)
                    {
                        formatter.WriteOperationResult(inputStream, portalContext, odataReq);
                    }
                    else
                    {
                        // parent must exist
                        if (!Node.Exists(odataReq.RepositoryPath))
                        {
                            ContentNotFound(context, odataReq.RepositoryPath);
                            return;
                        }
                        model   = Read(inputStream);
                        content = CreateContent(model, odataReq);
                        formatter.WriteSingleContent(content, portalContext);
                    }
                    break;

                case "DELETE":
                    if (odataReq.IsMemberRequest)
                    {
                        throw new ODataException(
                                  String.Concat("Cannot access a member with HTTP ", httpMethod, "."),
                                  ODataExceptionCode.IllegalInvoke);
                    }
                    else
                    {
                        content = LoadContentOrVirtualChild(odataReq);
                        content?.Delete();
                    }
                    break;
                }
            }
            catch (ContentNotFoundException e)
            {
                var oe = new ODataException(ODataExceptionCode.ResourceNotFound, e);

                formatter?.WriteErrorResponse(context, oe);
            }
            catch (ODataException e)
            {
                if (e.HttpStatusCode == 500)
                {
                    SnLog.WriteException(e);
                }

                formatter?.WriteErrorResponse(context, e);
            }
            catch (SenseNetSecurityException e)
            {
                // In case of a visitor we should not expose the information that this content actually exists. We return
                // a simple 404 instead to provide exactly the same response as the regular 404, where the content
                // really does not exist. But do this only if the visitor really does not have permission for the
                // requested content (because security exception could be thrown by an action or something else too).
                if (odataReq != null && User.Current.Id == Identifiers.VisitorUserId)
                {
                    var head = NodeHead.Get(odataReq.RepositoryPath);
                    if (head != null && !SecurityHandler.HasPermission(head, PermissionType.Open))
                    {
                        ContentNotFound(context, odataReq.RepositoryPath);
                        return;
                    }
                }

                var oe = new ODataException(ODataExceptionCode.NotSpecified, e);

                SnLog.WriteException(oe);

                formatter?.WriteErrorResponse(context, oe);
            }
            catch (InvalidContentActionException ex)
            {
                var oe = new ODataException(ODataExceptionCode.NotSpecified, ex);
                if (ex.Reason != InvalidContentActionReason.NotSpecified)
                {
                    oe.ErrorCode = Enum.GetName(typeof(InvalidContentActionReason), ex.Reason);
                }

                // it is unnecessary to log this exception as this is not a real error
                formatter?.WriteErrorResponse(context, oe);
            }
            catch (ContentRepository.Storage.Data.NodeAlreadyExistsException nae)
            {
                var oe = new ODataException(ODataExceptionCode.ContentAlreadyExists, nae);

                formatter?.WriteErrorResponse(context, oe);
            }
            catch (System.Threading.ThreadAbortException tae)
            {
                if (!context.Response.IsRequestBeingRedirected)
                {
                    var oe = new ODataException(ODataExceptionCode.RequestError, tae);
                    formatter?.WriteErrorResponse(context, oe);
                }
                // specific redirect response so do nothing
            }
            catch (Exception ex)
            {
                var oe = new ODataException(ODataExceptionCode.NotSpecified, ex);

                SnLog.WriteException(oe);

                formatter?.WriteErrorResponse(context, oe);
            }
            finally
            {
                context.Response.End();
            }
        }
コード例 #5
0
ファイル: ODataHandler.cs プロジェクト: vlslavik/SenseNet
        public void ProcessRequest(HttpContext context, string httpMethod, Stream inputStream)
        {
            ODataRequest   odataReq      = null;
            ODataFormatter formatter     = null;
            var            portalContext = (PortalContext)context.Items[PortalContext.CONTEXT_ITEM_KEY];

            try
            {
                // Allows browsers to send cross-domain requests to this URL
                context.Response.AddHeader("Access-Control-Allow-Origin", "*");

                Content content;

                Exception requestError = null;
                try
                {
                    odataReq          = ODataRequest.Parse(portalContext.RequestedUri.GetComponents(UriComponents.Path, UriFormat.Unescaped), portalContext);
                    this.ODataRequest = odataReq;
                }
                catch (Exception e)
                {
                    requestError = e;
                }

                formatter = ODataFormatter.Create(portalContext, odataReq);
                if (formatter == null)
                {
                    formatter = ODataFormatter.Create("json", portalContext);
                    throw new ODataException(ODataExceptionCode.InvalidFormatParameter);
                }

                if (requestError != null)
                {
                    var innerOdataError = requestError as ODataException;
                    var message         = "An error occured during request parsing. " + requestError.Message + " See inner exception for details.";
                    var code            = innerOdataError == null ? ODataExceptionCode.RequestError : innerOdataError.ODataExceptionCode;
                    throw new ODataException(message, code, requestError);
                }

                odataReq.Format = formatter.FormatName;
                formatter.Initialize(odataReq);

                var exists = Node.Exists(odataReq.RepositoryPath);
                if (httpMethod != "POST" && !exists)
                {
                    ContentNotFound(context, odataReq.RepositoryPath);
                    return;
                }

                JObject model = null;
                switch (httpMethod)
                {
                case "GET":
                    if (odataReq.IsServiceDocumentRequest)
                    {
                        formatter.WriteServiceDocument(portalContext, odataReq);
                    }
                    else if (odataReq.IsMetadataRequest)
                    {
                        formatter.WriteMetadata(context, odataReq);
                    }
                    else
                    {
                        if (!Node.Exists(odataReq.RepositoryPath))
                        {
                            ContentNotFound(context, odataReq.RepositoryPath);
                        }
                        if (odataReq.HasContentQuery)
                        {
                            formatter.WriteQueryResult(portalContext, odataReq);
                        }
                        else if (odataReq.IsCollection)
                        {
                            formatter.WriteChildrenCollection(odataReq.RepositoryPath, portalContext, odataReq);
                        }
                        else if (odataReq.IsMemberRequest)
                        {
                            formatter.WriteContentProperty(odataReq.RepositoryPath, odataReq.PropertyName, odataReq.IsRawValueRequest, portalContext, odataReq);
                        }
                        else
                        {
                            formatter.WriteSingleContent(odataReq.RepositoryPath, portalContext);
                        }
                    }
                    break;

                case "PUT":     // update
                    if (odataReq.IsMemberRequest)
                    {
                        throw new ODataException("Cannot access a member with HTTP PUT.", ODataExceptionCode.IllegalInvoke);
                    }
                    else
                    {
                        model   = Read(inputStream);
                        content = Content.Load(odataReq.RepositoryPath);
                        ResetContent(content);
                        UpdateContent(content, model, odataReq);
                        formatter.WriteSingleContent(content, portalContext);
                    }
                    break;

                case "MERGE":
                case "PATCH":     // update
                    if (odataReq.IsMemberRequest)
                    {
                        throw new ODataException(String.Concat("Cannot access a member with HTTP ", httpMethod, "."), ODataExceptionCode.IllegalInvoke);
                    }
                    else
                    {
                        model   = Read(inputStream);
                        content = Content.Load(odataReq.RepositoryPath);
                        UpdateContent(content, model, odataReq);
                        formatter.WriteSingleContent(content, portalContext);
                    }
                    break;

                case "POST":     // invoke an action, create content
                    if (odataReq.IsMemberRequest)
                    {
                        formatter.WriteOperationResult(inputStream, portalContext, odataReq);
                    }
                    else
                    {
                        model   = Read(inputStream);
                        content = CreateContent(model, odataReq, portalContext);
                        formatter.WriteSingleContent(content, portalContext);
                    }
                    break;

                case "DELETE":
                    if (odataReq.IsMemberRequest)
                    {
                        throw new ODataException(String.Concat("Cannot access a member with HTTP ", httpMethod, "."), ODataExceptionCode.IllegalInvoke);
                    }
                    else
                    {
                        //model = Read(inputStream);
                        Content.Delete(odataReq.RepositoryPath);
                    }
                    break;
                }
            }
            catch (ContentNotFoundException e)
            {
                var oe = new ODataException(ODataExceptionCode.ResourceNotFound, e);

                formatter.WriteErrorResponse(context, oe);
            }
            catch (ODataException e)
            {
                if (e.HttpStatusCode == 500)
                {
                    Logger.WriteException(e);
                }

                formatter.WriteErrorResponse(context, e);
            }
            catch (SenseNetSecurityException e)
            {
                // In case of a visitor we should not expose the information that this content actually exists. We return
                // a simple 404 instead to provide exactly the same response as the regular 404, where the content
                // really does not exist. But do this only if the visitor really does not have permission for the
                // requested content (because security exception could be thrown by an action or something else too).
                if (odataReq != null && User.Current.Id == User.Visitor.Id)
                {
                    var head = NodeHead.Get(odataReq.RepositoryPath);
                    if (head != null && !SecurityHandler.HasPermission(head, PermissionType.Open))
                    {
                        ContentNotFound(context, odataReq.RepositoryPath);
                        return;
                    }
                }

                var oe = new ODataException(ODataExceptionCode.NotSpecified, e);

                Logger.WriteException(oe);

                formatter.WriteErrorResponse(context, oe);
            }
            catch (InvalidContentActionException ex)
            {
                var oe = new ODataException(ODataExceptionCode.NotSpecified, ex);
                if (ex.Reason != InvalidContentActionReason.NotSpecified)
                {
                    oe.ErrorCode = Enum.GetName(typeof(InvalidContentActionReason), ex.Reason);
                }

                // it is unnecessary to log this exception as this is not a real error
                //Logger.WriteException(oe);

                formatter.WriteErrorResponse(context, oe);
            }
            catch (Exception ex)
            {
                var oe = new ODataException(ODataExceptionCode.NotSpecified, ex);

                Logger.WriteException(oe);

                formatter.WriteErrorResponse(context, oe);
            }
            finally
            {
                context.Response.End();
            }
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: SimpleProjector.cs プロジェクト: sztomi/sensenet
        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);
        }
コード例 #9
0
        public static void WriteMetadata(TextWriter writer, ODataFormatter formatter, Content content, bool isCollection)
        {
            var edmx = CreateEdmx(content, isCollection);

            formatter.WriteMetadataInternal(writer, edmx);
        }
コード例 #10
0
 public static void WriteMetadata(TextWriter writer, ODataFormatter formatter)
 {
     formatter.WriteMetadataInternal(writer, CreateEdmx());
 }