Exemple #1
0
        internal void Exec(JObject cronJob)
        {
            try
            {
                IActionExecuter actionExecuter = new ActionExecuter(_logger);
                ParamContainer  pamamContainer = CreateParamContainer(_logger, actionExecuter);
                pamamContainer.AddKey(CommonConst.CommonValue.PARAM_CRON_JOB_OBJ, () => { return(cronJob); });
                IDBService dbProxy = pamamContainer.GetKey(CommonConst.CommonValue.PARAM_DBPROXY);

                var filter = new JObject();
                filter[CommonConst.CommonField.DISPLAY_ID]      = cronJob[CommonConst.CommonField.DISPLAY_ID];
                cronJob[CommonConst.CommonField.STATUS]         = CommonConst.CommonValue.INPROGRESS;
                cronJob[CommonConst.CommonField.TRANSACTION_ID] = _logger.TransactionId;
                var startDatetime = DateTime.Now;
                cronJob[CommonConst.CommonField.LAST_EXEC_ON] = startDatetime.ToString();
                cronJob[CommonConst.CommonField.ERR_MESSAGE]  = string.Empty;
                if (cronJob[CommonConst.CommonField.HISTORY] == null)
                {
                    cronJob[CommonConst.CommonField.HISTORY] = new JArray();
                }
                else
                {
                    while ((cronJob[CommonConst.CommonField.HISTORY] as JArray).Count >= 10)
                    {
                        (cronJob[CommonConst.CommonField.HISTORY] as JArray).Remove((cronJob[CommonConst.CommonField.HISTORY] as JArray)[0]);
                    }
                }
                dbProxy.Update(CommonConst.Collection.CRON_JOB, filter.ToString(), cronJob, false, MergeArrayHandling.Replace);
                try
                {
                    object resonse = actionExecuter.Exec(cronJob[CommonConst.CommonField.EXECULT_ASSEMBLY].ToString(), cronJob[CommonConst.CommonField.EXECUTE_TYPE].ToString(), cronJob[CommonConst.CommonField.EXECUTE_METHOD].ToString(), pamamContainer);
                    cronJob[CommonConst.CommonField.STATUS] = CommonConst.CommonValue.FINISH;
                }
                catch (Exception ex)
                {
                    cronJob[CommonConst.CommonField.ERR_MESSAGE] = ex.Message;
                    cronJob[CommonConst.CommonField.STATUS]      = CommonConst.CommonValue.FINISH_WITH_ERROR;
                }
                finally
                {
                    cronJob[CommonConst.CommonField.DURATION] = (DateTime.Now - startDatetime).TotalMilliseconds;
                    JObject history = new JObject();
                    history[CommonConst.CommonField.START_ON] = startDatetime.ToString();
                    history[CommonConst.CommonField.DURATION] = cronJob[CommonConst.CommonField.DURATION];
                    history[CommonConst.CommonField.STATUS]   = cronJob[CommonConst.CommonField.STATUS];
                    if (cronJob[CommonConst.CommonField.ERR_MESSAGE] != null)
                    {
                        history[CommonConst.CommonField.ERR_MESSAGE] = cronJob[CommonConst.CommonField.ERR_MESSAGE];
                    }
                    history[CommonConst.CommonField.TRANSACTION_ID] = _logger.TransactionId;
                    (cronJob[CommonConst.CommonField.HISTORY] as JArray).Add(history);
                }

                dbProxy.Update(CommonConst.Collection.CRON_JOB, filter.ToString(), cronJob, false, MergeArrayHandling.Replace);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
            }
        }
Exemple #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);
            }
        }