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

        /// <summary>
        /// Handles GET operations. Parameters come from the URL or the request stream.
        /// </summary>
        internal async Task WriteGetOperationResultAsync(HttpContext httpContext, ODataRequest odataReq, IConfiguration appConfig)
        {
            var content = ODataMiddleware.LoadContentByVersionRequest(odataReq.RepositoryPath, httpContext);

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

            var action = ODataMiddleware.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null, httpContext, appConfig);

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

                SnTrace.System.WriteError($"OData: {odataReq.PropertyName} operation not found " +
                                          $"for content {content.Path} and user {User.Current.Username}.");

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

            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 response = action is ODataOperationMethodExecutor odataAction
                ? (odataAction.IsAsync ? await odataAction.ExecuteAsync(content) : action.Execute(content))
                : action.Execute(content, GetOperationParameters(action, httpContext.Request));

            if (response is Content responseAsContent)
            {
                await WriteSingleContentAsync(responseAsContent, httpContext)
                .ConfigureAwait(false);

                return;
            }

            response = ProcessOperationResponse(response, odataReq, httpContext, out var count);
            await WriteOperationResultAsync(response, httpContext, odataReq, count)
            .ConfigureAwait(false);
        }
コード例 #3
0
        /// <summary>
        /// Handles POST operations. Parameters come from request stream.
        /// </summary>
        internal async Task WritePostOperationResultAsync(HttpContext httpContext, ODataRequest odataReq, IConfiguration appConfig)
        {
            var content = ODataMiddleware.LoadContentByVersionRequest(odataReq.RepositoryPath, httpContext);

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

            var action = ODataMiddleware.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null, httpContext, appConfig);

            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, null, odataReq.PropertyName);
            }

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

            var response = action is ODataOperationMethodExecutor odataAction
            ? (odataAction.IsAsync ? await odataAction.ExecuteAsync(content) : action.Execute(content))
            : action.Execute(content, await GetOperationParametersAsync(action, httpContext, odataReq));

            if (response is Content responseAsContent)
            {
                await WriteSingleContentAsync(responseAsContent, httpContext)
                .ConfigureAwait(false);

                return;
            }

            response = ProcessOperationResponse(response, odataReq, httpContext, out var count);
            await WriteOperationResultAsync(response, httpContext, odataReq, count)
            .ConfigureAwait(false);
        }
コード例 #4
0
        /// <summary>
        /// Handles POST operations. Parameters come from request stream.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="portalContext"></param>
        /// <param name="odataReq"></param>
        internal void WriteOperationResult(Stream inputStream, PortalContext portalContext, ODataRequest odataReq)
        {
            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, null, odataReq.PropertyName);
            }

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

            var parameters = GetOperationParameters(action, inputStream);
            var response   = action.Execute(content, parameters);

            if (response is Content responseAsContent)
            {
                WriteSingleContent(responseAsContent, portalContext);
                return;
            }

            response = ProcessOperationResponse(response, odataReq, out var count);
            WriteOperationResult(response, portalContext, odataReq, count);
        }