Exemplo n.º 1
0
 protected virtual void ExecuteCore(
     string actionName,
     RequestValues values,
     Action <ActionResult> callBack)
 {
     if (this.RequestContext == null)
     {
         this.RequestContext = new RequestContext();
     }
     this.RequestContext.ActionName = actionName;
     try
     {
         this.GetActionResult <ActionResult>(actionName, values, (Action <ActionResult>)(result =>
         {
             if (result.Handled)
             {
                 return;
             }
             if (callBack == null)
             {
                 callBack = Engine.ValidateActionResult;
             }
             Action <ActionResult> action = callBack;
             if (action != null)
             {
                 action(result);
             }
         }));
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
 }
Exemplo n.º 2
0
        protected virtual void ExecuteCore(string actionName, RequestValues values, Action <ActionResult> callBack)
        {
            if (RequestContext == null)
            {
                RequestContext = new RequestContext();
            }
            RequestContext.ActionName = actionName;

            try
            {
                GetActionResult <ActionResult>(actionName, values, result => {
                    if (result != null && result.Handled == false)
                    {
                        if (callBack == null)
                        {
                            callBack = Engine.ValidateActionResult;
                        }

                        callBack?.Invoke(result);
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 3
0
        void timer_Tick(object sender, object e)
        {
#if (DEVEL)
            RequestValues.FromLocal(Constants.METER_TYPE.HOME);
#else
            RequestValues.FromOSC(Constants.METER_TYPE.HOME);
#endif
        }
Exemplo n.º 4
0
        private void GetChannelValues(Constants.FADER_GROUP group)
        {
#if DEVEL
            RequestValues.FromLocal(group);
#else
            //ignore warning, it doesn't matter how long this takes
            RequestValues.FromOSC(group);
#endif
        }
Exemplo n.º 5
0
 public AddCommentTask(IDocumentStore documentStore, BlogConfig config, string postId,
                       PostComments.CommentInput commentInput, RequestValues requestValues)
 {
     _config = config;
     this.commentInput = commentInput;
     this.requestValues = requestValues;
     this.postId = postId;
     this.RavenDocumentStore = documentStore;
 }
Exemplo n.º 6
0
        protected virtual T GetActionResult <T>(string actionName, RequestValues values, Action <T> execute)
        {
            var param  = values.ToArray();
            var method = GetMethod(actionName, param);

            if (method == null)
            {
                return(default(T));
            }

            this.RequestContext.ActionName = method.Name;

            var result = (T)method.Invoke(this, param);

            execute?.Invoke(result);
            return(result);
        }
Exemplo n.º 7
0
        protected virtual T GetActionResult <T>(
            string actionName,
            RequestValues values,
            Action <T> execute)
        {
            object[]   array  = values.ToArray();
            MethodInfo method = this.GetMethod(actionName, array);

            if (method == (MethodInfo)null)
            {
                return(default(T));
            }
            this.RequestContext.ActionName = method.Name;
            T obj = (T)method.Invoke((object)this, array);

            if (execute != null)
            {
                execute(obj);
            }
            return(obj);
        }
Exemplo n.º 8
0
        public static ModelValues Values(this HttpRequestBase request, RequestValues source = RequestValues.All)
        {
            var result = new ModelValues();

            if (source == RequestValues.All || source == RequestValues.Querystring)
            {
                foreach (string qs in request.QueryString)
                {
                    result.Add(qs, request.QueryString[qs]);
                }
            }

            if (source == RequestValues.All || source == RequestValues.Form)
            {
                foreach (string qs in request.Form)
                {
                    result.Add(qs, request.Form[qs]);
                }
            }

            return(result);
        }
Exemplo n.º 9
0
 public AddCommentCommand(CommentInput commentInput, RequestValues requestValues, int postId)
 {
     _commentInput  = commentInput;
     _requestValues = requestValues;
     _postId        = postId;
 }
Exemplo n.º 10
0
 public AddCommentTask(CommentInput commentInput, RequestValues requestValues, int postId)
 {
     this.commentInput  = commentInput;
     this.requestValues = requestValues;
     this.postId        = postId;
 }
Exemplo n.º 11
0
 public AddCommentTask(string postId, PostComments.CommentInput commentInput, RequestValues requestValues)
 {
     this.commentInput  = commentInput;
     this.requestValues = requestValues;
     this.postId        = postId;
 }
Exemplo n.º 12
0
        private async Task InitRequestValues()
        {
            _stopwatch = Stopwatch.StartNew();
            Properties["Stopwatch"] = _stopwatch;
            RouteData       = ControllerContext.RouteData;
            Request         = ControllerContext.Request;
            Url             = Request.RequestUri;
            ActionName      = RouteData.Values["action"] as string;
            ActionVersion   = RouteData.Values["action_version"] as string;
            RealHostAddress = HostAddress = GetClientIpAddress();

            IEnumerable <string> ips;

            if (Request.Headers.TryGetValues("X-Forwarded-For", out ips))
            {
                HostAddress = string.Join(",", ips);
            }
            UrlReferrer = Request.Headers.Referrer;
            UserAgent   = Request.Headers.UserAgent.ToString();
            Method      = Request.Method.Method.ToUpperInvariant();
            if (ActionName == "???")
            {
                if (Request.Method == HttpMethod.Post)
                {
                    ActionName = "Get";
                }
                else
                {
                    ActionName = Request.Method.Method;
                }
            }

            var contentType = Request.Content?.Headers?.ContentType?.MediaType ?? "";
            var isJson      = contentType.Equals("application/json", StringComparison.OrdinalIgnoreCase);

            IRequestValues values;
            var            ctx = Request.Properties["MS_HttpContext"] as HttpContextWrapper;

            if (ctx != null)
            {
                values = new RequestValues(ctx.Request.Unvalidated);
                ctx.Request.InputStream.Position = 0;
                var bytes = ctx.Request.BinaryRead(ctx.Request.ContentLength);
                values.FormBody = bytes;
            }
            else
            {
                values = new RequestValues();
                if (isJson == false)
                {
                    await ReadBody(values);
                }
                ReadQueryStrings(values);
                ReadCookies(values);
                ReadHeaders(values);
                ReadOther(values);
            }

            if (isJson)
            {
                var charset  = Request.Content?.Headers?.ContentType?.CharSet;
                var encoding = charset == null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
                var json     = encoding.GetString(values.FormBody);
                values.Form = new JsonFormBody(json);
            }

            values.ContentType = contentType;
            ReadRouteData(values);
            //values.ReadOnly();
            RequestValues = (RequestValues)values;
            WirteLog();
        }
Exemplo n.º 13
0
 public AddCommentTask(CommentInput commentInput, RequestValues requestValues, int postId)
 {
     this.commentInput = commentInput;
     this.requestValues = requestValues;
     this.postId = postId;
 }
Exemplo n.º 14
0
        public static ModelValues Values(this HttpRequest request, RequestValues source = RequestValues.All)
        {
            var requestBase = new HttpRequestWrapper(request);

            return(Values(requestBase, source));
        }