示例#1
0
        protected override BeeDataAdapter GetRouteData(System.Web.HttpContext context)
        {
            XmlDocument document = new XmlDocument();

            document.Load(context.Request.InputStream);

            BeeDataAdapter dataAdapter = new BeeDataAdapter();

            foreach (XmlNode node in document.DocumentElement.ChildNodes)
            {
                dataAdapter.Add(node.Name, node.InnerText);
            }

            string msgType = dataAdapter.TryGetValue <string>("msgtype", string.Empty);

            if (string.Compare("event", msgType, true) == 0)
            {
                string eventName = dataAdapter.TryGetValue <string>("event", string.Empty);

                dataAdapter.Add(Constants.BeeControllerName, MainControllerName);
                dataAdapter.Add(Constants.BeeActionName, eventName);
            }
            else
            {
                dataAdapter.Add(Constants.BeeControllerName, MainControllerName);
                dataAdapter.Add(Constants.BeeActionName, msgType);
            }

            Logger.Debug(dataAdapter.ToString());

            // 实现一个调用链

            /*
             * menuid-1-2-3
             *
             *
             */

            InvokeTreeManager.Instance.Check(dataAdapter);

            return(dataAdapter);
        }
示例#2
0
        public void ProcessRequest(HttpContext context)
        {
            System.Runtime.Remoting.Messaging.CallContext.HostContext = context;
            Stopwatch stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();

                BeeDataAdapter routeData = GetRouteData(context);

                string controllerName = routeData[Constants.BeeControllerName] as string;
                string actionName     = routeData[Constants.BeeActionName] as string;


                HttpContext httpContext = context;
                //this.httpContext = context;
                BeeDataAdapter dataAdapter = new BeeDataAdapter(routeData);

                NameValueCollection formParams = httpContext.Request.Form;
                foreach (string key in formParams.Keys)
                {
                    if (!string.IsNullOrEmpty(key))
                    {
                        dataAdapter.Add(key.ToLower(), StringUtil.HtmlEncode(formParams[key]));
                    }
                }

                formParams = httpContext.Request.QueryString;
                foreach (string key in formParams.Keys)
                {
                    if (!string.IsNullOrEmpty(key))
                    {
                        dataAdapter.Add(key.ToLower(), StringUtil.HtmlEncode(formParams[key]));
                    }
                }
                // 解析inputstream
                string json = new StreamReader(httpContext.Request.InputStream).ReadToEnd();
                if (!string.IsNullOrEmpty(json) && json.StartsWith("{"))
                {
                    var jObject = Newtonsoft.Json.Linq.JObject.Parse(json);
                    foreach (var item in jObject)
                    {
                        dataAdapter.Add(item.Key, item.Value);
                    }
                }

                if (LogRequestFlag)
                {
                    BeeDataAdapter cookieData = new BeeDataAdapter();
                    foreach (string key in context.Request.Cookies.AllKeys)
                    {
                        cookieData.Add(key, context.Request.Cookies[key].Value);
                    }

                    Logger.Debug(@"
cookie:{0}
Request:{1}".FormatWith(cookieData.ToString(), dataAdapter.ToString()));
                }

                ActionExecutingArgs args = new ActionExecutingArgs(controllerName, actionName, dataAdapter);
                ActionExecuting(args); // 提供拦截通道
                if (args.Result != ActionExecutingResult.OK)
                {
                    BeeMvcResult mvcResult = new BeeMvcResult();
                    mvcResult.code = 400;
                    if (args.Code > 0)
                    {
                        mvcResult.code = args.Code;
                    }
                    mvcResult.msg = args.Message;

                    WriteMvcResult(httpContext, mvcResult);
                    return;
                }

                InnerExecuteAction(context, controllerName, actionName, dataAdapter);

                stopwatch.Stop();
                if (stopwatch.ElapsedMilliseconds > 5000)
                {
                    Logger.Debug(string.Format("{0}耗时较长, 耗时:{1}ms", context.Request.Url.ToString(), stopwatch.ElapsedMilliseconds));
                }
            }
            catch (Exception e)
            {
                string error = ResourceUtil.ReadToEndFromCache(typeof(MvcDispatcher).Assembly, "Bee.Web.Error.htm", false);

                context.Response.Write(string.Format(error, e.Message, GetFullException(e)));

                Logger.Error(e.Message, e);

                Logger.Log(LogLevel.Core, e.Message, e);
            }
        }