Example #1
0
        private ParamContainer CreateParamContainer(ILogger loggerController, IActionExecuter actionExecuter)
        {
            ParamContainer  paramContainer  = ActionExecuterHelper.CreateParamContainer(_logger, actionExecuter);
            IRoutings       routings        = Routings.Routings.GetRoutings();
            ILogReader      logReader       = Logger.GetLogReader();
            ResponseBuilder responseBuilder = new ResponseBuilder(loggerController, logReader, new CronJobInitData(loggerController.TransactionId));

            paramContainer.AddKey(CommonConst.CommonValue.PARAM_RESPONBUILDER, () => { return(responseBuilder); });
            paramContainer.AddKey(CommonConst.CommonValue.PARAM_ROUTING_OBJECT, () => { return(routings); });
            return(paramContainer);
        }
Example #2
0
        public void Exec(RoutingModel route, IHttpContextProxy httpProxy)
        {
            ILogger           loggerController  = Logger.GetLogger(route.ExecuteType, httpProxy.TransactionId);
            RouteEventHandler routeEventHandler = new RouteEventHandler();

            try
            {
                loggerController.Info(string.Format("{0}:: Route: [{1}]", "RouteExecuter.Exec", route.ToString()));
                IActionExecuter actionExecuter = new ActionExecuter(loggerController);
                ParamContainer  paramContainer = ActionExecuterHelper.CreateParamContainer(route, httpProxy, loggerController, actionExecuter);
                WriteStartTransaction(loggerController, httpProxy, route);
                (paramContainer.GetKey(CommonConst.CommonValue.PARAM_SESSION_PROVIDER) as ISessionProvider).SetValue(CommonConst.CommonField.UPDATED_DATE_TIME, CommonUtility.GetUnixTimestamp(DateTime.Now));
                // Execute before Events
                routeEventHandler.ExecBeforeEvent(actionExecuter, route, paramContainer);

                var objResult = actionExecuter.Exec(route, paramContainer);
                httpProxy.ContentType = route.ContentType;

                // Add response in param
                paramContainer.AddKey(CommonConst.CommonValue.PARAM_API_RESPONSE, () => { return(objResult); });

                if (objResult == null)
                {
                    httpProxy.SetResponse(CommonConst._500_SERVER_ERROR);
                }
                else if (objResult is byte[])
                {
                    WriteEndTransaction(loggerController, "*** Binary Data ***");
                    httpProxy.SetResponse(CommonConst._200_OK, (byte[])objResult);
                }
                else if (objResult is string)
                {
                    WriteEndTransaction(loggerController, (objResult as string));
                    httpProxy.SetResponse(CommonConst._200_OK, objResult as string);
                }
                else
                {
                    var responseData = (objResult as JObject).ToString();
                    WriteEndTransaction(loggerController, responseData);
                    httpProxy.SetResponse(CommonConst._200_OK, responseData);
                }

                // Execute after Events
                routeEventHandler.ExecAfterEvent(actionExecuter, route, paramContainer, objResult);

                //    List<string> userGroups = _httpProxy.GetSessionUserGroups();
                //    if (route.auth_users.Count == 0 || userGroups.Intersect(route.auth_users).Any())
                //    {
                //        var objResult = routeExecuter.Exec(route, helper);
                //        if (objResult == null)
                //        {
                //            SetInternalServerError();
                //            return null;
                //        }
                //        else if (objResult is byte[])
                //        {
                //            return (byte[])objResult;
                //        }
                //        else
                //        {
                //            return Encoding.UTF8.GetBytes((objResult as JObject).ToString());
                //        }
                //    }
                //    else
                //    {
                //        SetUnauthorized();
                //        return Encoding.UTF8.GetBytes((ZApp.Common.HttpUtility.GetFullResponse((int)ResponseCodes.Unauthorized, ResponseCodes.Unauthorized.ToString(), null)).ToString());
                //    }
            }
            catch (UnauthorizedAccessException ex)
            {
                loggerController.Error(string.Format("Error While executing Route : {0}, Error : {1}", route.ToString(), ex.Message), ex);
                httpProxy.SetResponse(CommonConst._401_UNAUTHORIZED);
            }
            catch (Exception ex)
            {
                httpProxy.SetResponse(CommonConst._500_SERVER_ERROR);
                loggerController.Error(string.Format("Error While executing Route : {0}, Error : {1}", route.ToString(), ex.Message), ex);
            }
        }