示例#1
0
        private ActionBase GetMethodBasedAction(string name, Content content, object state)
        {
            var httpContext = (HttpContext)state;
            //var odataRequest = (ODataRequest) httpContext.Items[ODataMiddleware.ODataRequestHttpContextKey];
            OperationCallingContext method;

            try
            {
                method = OperationCenter.GetMethodByRequest(content, name,
                                                            ODataMiddleware.ReadToJsonAsync(httpContext)
                                                            .GetAwaiter().GetResult(),
                                                            httpContext.Request.Query);
            }
            catch (OperationNotFoundException e)
            {
                throw new InvalidContentActionException(e, InvalidContentActionReason.UnknownAction, content.Path,
                                                        e.Message, name);
            }
            catch (AmbiguousMatchException e)
            {
                throw new InvalidContentActionException(e, InvalidContentActionReason.UnknownAction, content.Path,
                                                        e.Message, name);
            }

            method.HttpContext = httpContext;
            return(new ODataOperationMethodExecutor(method));
        }
示例#2
0
        private ActionBase GetMethodBasedAction(string name, Content content, object state)
        {
            var httpContext = (HttpContext)state;
            OperationCallingContext method;

            try
            {
                //TODO:~ Combine request body and querystring parameters into the 3th parameter.
                method = OperationCenter.GetMethodByRequest(content, name,
                                                            ODataMiddleware.Read(httpContext.Request.Body));
            }
            catch (OperationNotFoundException e)
            {
                throw new InvalidContentActionException(e, InvalidContentActionReason.UnknownAction, content.Path,
                                                        e.Message, name);
            }
            catch (AmbiguousMatchException e)
            {
                throw new InvalidContentActionException(e, InvalidContentActionReason.UnknownAction, content.Path,
                                                        e.Message, name);
            }

            method.HttpContext = httpContext;
            return(new ODataOperationMethodExecutor(method));
        }
        private ActionBase GetMethodBasedAction(string name, Content content, object state)
        {
            var(httpContext, config) = ((HttpContext, IConfiguration))state;

            //var odataRequest = (ODataRequest) httpContext.Items[ODataMiddleware.ODataRequestHttpContextKey];
            OperationCallingContext method;

            try
            {
                method = OperationCenter.GetMethodByRequest(content, name,
                                                            ODataMiddleware.ReadToJsonAsync(httpContext)
                                                            .GetAwaiter().GetResult(),
                                                            httpContext.Request.Query);
            }
            catch (OperationNotFoundException e)
            {
                SnTrace.System.WriteError($"Operation {name} not found. " +
                                          $"Content: {content.Path}, User: {User.Current.Username}");

                throw new InvalidContentActionException(e, InvalidContentActionReason.UnknownAction, content.Path,
                                                        e.Message, name);
            }
            catch (AmbiguousMatchException e)
            {
                SnTrace.System.WriteError($"Operation {name} is ambiguous. " +
                                          $"Content: {content.Path}, User: {User.Current.Username}");

                throw new InvalidContentActionException(e, InvalidContentActionReason.UnknownAction, content.Path,
                                                        e.Message, name);
            }
            catch (Exception ex)
            {
                SnTrace.System.WriteError($"Error during discovery of method {name}. {ex.Message} " +
                                          $"Content: {content.Path}, User: {User.Current.Username}");
                throw;
            }

            method.HttpContext = httpContext;
            method.ApplicationConfiguration = config;
            return(new ODataOperationMethodExecutor(method));
        }