コード例 #1
0
        internal void WriteMetadata(HttpContext context, ODataRequest req)
        {
            var content = ODataHandler.LoadContentByVersionRequest(req.RepositoryPath);

            if (content == null)
            {
                ODataHandler.ResourceNotFound();
                return;
            }

            var isRoot = content.ContentType.IsInstaceOfOrDerivedFrom("Site");

            if (isRoot)
            {
                MetaGenerator.WriteMetadata(context.Response.Output, this);
            }
            else
            {
                MetaGenerator.WriteMetadata(context.Response.Output, this, content, req.IsCollection);
            }

            var mimeType = this.MimeType;

            if (mimeType != null)
            {
                context.Response.ContentType = mimeType;
            }
        }
コード例 #2
0
        //----------------------------------------------------------------------------------------------------------------------------------- operations

        /// <summary>
        /// Handles GET operations. Parameters come from the URL or the request stream.
        /// </summary>
        /// <param name="portalContext"></param>
        /// <param name="odataReq"></param>
        internal void WriteOperationResult(PortalContext portalContext, ODataRequest odataReq)
        {
            object response = null;
            var    content  = ODataHandler.LoadContentByVersionRequest(odataReq.RepositoryPath);

            if (content == null)
            {
                throw new ContentNotFoundException(string.Format(SNSR.GetString("$Action,ErrorContentNotFound"), odataReq.RepositoryPath));
            }

            var action = ODataHandler.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null);

            if (action == null)
            {
                // check if this is a versioning action (e.g. a checkout)
                SavingAction.AssertVersioningAction(content, odataReq.PropertyName, true);

                throw new InvalidContentActionException(InvalidContentActionReason.UnknownAction, content.Path);
            }

            if (!action.IsODataOperation)
            {
                throw new ODataException("Not an OData operation.", ODataExceptionCode.IllegalInvoke);
            }
            if (action.CausesStateChange)
            {
                throw new ODataException("OData action cannot be invoked with HTTP GET.", ODataExceptionCode.IllegalInvoke);
            }

            if (action.Forbidden || (action.GetApplication() != null && !action.GetApplication().Security.HasPermission(PermissionType.RunApplication)))
            {
                throw new InvalidContentActionException("Forbidden action: " + odataReq.PropertyName);
            }

            var parameters = GetOperationParameters(action, portalContext.OwnerHttpContext.Request);

            response = action.Execute(content, parameters);

            var responseAsContent = response as Content;

            if (responseAsContent != null)
            {
                WriteSingleContent(responseAsContent, portalContext);
                return;
            }

            int count;

            response = ProcessOperationResponse(response, portalContext, odataReq, out count);
            //Write(response, portalContext);
            WriteOperationResult(response, portalContext, odataReq, count);
        }
コード例 #3
0
        private object[] GetOperationParameters(ActionBase action, Stream inputStream)
        {
            if (action.ActionParameters.Length == 0)
            {
                return(ActionParameter.EmptyValues);
            }

            var values = new object[action.ActionParameters.Length];
            //if (inputStream == null || inputStream.Length == 0)
            //    return values;

            var parameters = action.ActionParameters;

            if (parameters.Length == 1 && parameters[0].Name == null)
            {
                var parameter = parameters[0];
                if (parameter.Type == null)
                {
                    using (var reader = new StreamReader(inputStream))
                        values[0] = reader.ReadToEnd();
                    if (parameter.Required && values[0] == null)
                    {
                        throw new ArgumentNullException("[unnamed]", "Request parameter is required.");
                    }
                }
                else
                {
                    values[0] = ODataHandler.Read(inputStream, parameter.Type);
                    if (parameter.Required && values[0] == null)
                    {
                        throw new ArgumentNullException("[unnamed]", "Request parameter is required. Type: " + parameter.Type.FullName);
                    }
                }
            }
            else
            {
                var model = ODataHandler.Read(inputStream);
                var i     = 0;
                foreach (var parameter in parameters)
                {
                    var name = parameter.Name;
                    var type = parameter.Type;
                    var val  = model == null ? null : model[name];
                    if (val == null)
                    {
                        if (parameter.Required)
                        {
                            throw new ArgumentNullException(parameter.Name);
                        }
                    }
                    else
                    {
                        var valStr = val.ToString();

                        if (type == typeof(string))
                        {
                            values[i] = valStr;
                        }
                        else if (type == typeof(Boolean))
                        {
                            // we handle "True", "true" and "1" as boolean true values
                            values[i] = JsonConvert.DeserializeObject(valStr.ToLower(), type);
                        }
                        else
                        {
                            values[i] = JsonConvert.DeserializeObject(valStr, type);
                        }
                    }
                    i++;
                }
            }
            return(values);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        //----------------------------------------------------------------------------------------------------------------------------------- contents

        internal void WriteSingleContent(String path, PortalContext portalContext)
        {
            WriteSingleContent(ODataHandler.LoadContentByVersionRequest(path), portalContext);
        }
コード例 #6
0
 protected string GetSelfUrl(Content content)
 {
     //return string.Concat("/", ODataRequest.ODATA_SVC, ODataHandler.GetEntityUrl(PortalContext.GetSiteRelativePath(content.Path)));
     return(string.Concat("/", ODataRequest.ODATA_SVC, ODataHandler.GetEntityUrl(content.Path)));
 }