Esempio n. 1
0
        internal void WriteContentProperty(String path, string propertyName, bool rawValue, PortalContext portalContext, ODataRequest req)
        {
            var content = ODataHandler.LoadContentByVersionRequest(path);

            if (content == null)
            {
                ODataHandler.ContentNotFound(portalContext.OwnerHttpContext, path);
                return;
            }

            if (propertyName == ODataHandler.ActionsPropertyName)
            {
                WriteActionsProperty(portalContext, ODataTools.GetActionItems(content, req).ToArray(), rawValue);
                return;
            }
            if (propertyName == ODataHandler.ChildrenPropertyName)
            {
                WriteChildrenCollection(path, portalContext, req);
                return;
            }

            if (content.Fields.TryGetValue(propertyName, out var field))
            {
                if (field is ReferenceField refField)
                {
                    var refFieldSetting = refField.FieldSetting as ReferenceFieldSetting;
                    var isMultiRef      = true;
                    if (refFieldSetting != null)
                    {
                        isMultiRef = refFieldSetting.AllowMultiple == true;
                    }
                    if (isMultiRef)
                    {
                        WriteMultiRefContents(refField.GetData(), portalContext, req);
                    }
                    else
                    {
                        WriteSingleRefContent(refField.GetData(), portalContext);
                    }
                }
                else if (field is AllowedChildTypesField actField)
                {
                    WriteMultiRefContents(actField.GetData(), portalContext, req);
                }
                else if (!rawValue)
                {
                    WriteSingleContent(portalContext, new Dictionary <string, object> {
                        { propertyName, field.GetData() }
                    });
                }
                else
                {
                    WriteRaw(field.GetData(), portalContext);
                }
            }
            else
            {
                WriteOperationResult(portalContext, req);
            }
        }
Esempio n. 2
0
        internal void WriteContentProperty(String path, string propertyName, bool rawValue, PortalContext portalContext, ODataRequest req)
        {
            var content = ODataHandler.LoadContentByVersionRequest(path);

            if (content == null)
            {
                ODataHandler.ContentNotFound(portalContext.OwnerHttpContext, path);
                return;
            }

            if (propertyName == ODataHandler.PROPERTY_ACTIONS)
            {
                var backUrl = portalContext.BackUrl;

                //Get actions without back url: let the client append the back parameter,
                //as we are in a service here that does not know about the redirect url.
                var snActions = ODataHandler.ActionResolver.GetActions(content, req.Scenario, string.IsNullOrEmpty(backUrl) ? null : backUrl);

                var actions = snActions.Where(a => a.IsHtmlOperation).Select(a => new ODataActionItem
                {
                    Name           = a.Name,
                    DisplayName    = SNSR.GetString(a.Text),
                    Icon           = a.Icon,
                    Index          = a.Index,
                    Url            = a.Uri,
                    IncludeBackUrl = a.GetApplication() == null ? 0 : (int)a.GetApplication().IncludeBackUrl,
                    ClientAction   = a is ClientAction && !string.IsNullOrEmpty(((ClientAction)a).Callback),
                    Forbidden      = a.Forbidden
                });
                WriteActionsProperty(portalContext, actions.ToArray(), rawValue);
                return;
            }

            Field field;

            if (content.Fields.TryGetValue(propertyName, out field))
            {
                var refField = field as ReferenceField;
                if (refField != null)
                {
                    var refFieldSetting = refField.FieldSetting as ReferenceFieldSetting;
                    var isMultiRef      = true;
                    if (refFieldSetting != null)
                    {
                        isMultiRef = refFieldSetting.AllowMultiple == true;
                    }
                    if (isMultiRef)
                    {
                        WriteMultiRefContents(refField.GetData(), portalContext, req);
                    }
                    else
                    {
                        WriteSingleRefContent(refField.GetData(), portalContext);
                    }
                }
                else if (!rawValue)
                {
                    WriteSingleContent(portalContext, new Dictionary <string, object> {
                        { propertyName, field.GetData() }
                    });
                }
                else
                {
                    WriteRaw(field.GetData(), portalContext);
                }
            }
            else
            {
                //ResourceNotFound(content, propertyName);
                WriteOperationResult(portalContext, req);
            }
        }