示例#1
0
        //private static Dictionary<AppType, int> WeChatAppMapping
        //{
        //    get
        //    {
        //        var config = CommonService.GetSysConfig(Consts.AppIdMappingConfigName, "");
        //        var settingList = JsonConvert.DeserializeObject<List<KeyValuePair<int, int>>>(config);
        //        return settingList.ToDictionary(o => (AppType)o.Key, o => o.Value);
        //    }
        //}
        //public SysWechatConfig GetWechatConfigByAppType(AppType type)
        //{
        //    var appid = WeChatAppMapping[type];
        //    return WeChatCommonService.GetWeChatConfigByID(appid);
        //}
        public virtual ActionResult ActionCommand <TParam>(Func <TParam> func)
        {
            var parameters = Request.QueryString.ToString();

            if (string.IsNullOrEmpty(parameters) && !Request.HttpMethod.Equals(HttpMethod.Get.ToString()))
            {
                var bytes = new byte[Request.InputStream.Length];
                Request.InputStream.Read(bytes, 0, bytes.Length);
                parameters = Encoding.UTF8.GetString(bytes);
            }
            StackTrace trace  = new StackTrace();
            var        caller = trace.GetFrame(1).GetMethod();

            Logger.Info("api interface {0} params:{1}", caller.Name, parameters);
            var result = new ApiResult <TParam>();

            try
            {
                result.Data = func();
            }
            catch (ApiException apiException)
            {
                if (apiException.Error.ErrorCode == ErrorCode.Unauthorised)
                {
                    return(Redirect(apiException.Error.ErrorMessage));
                }
                Logger.Error("Get {0} info error:code:{1},detail:{2}", caller.Name, apiException.Error.ErrorCode, apiException.ToString());
                result.Result    = false;
                result.ErrorInfo = apiException.Error;
            }
            catch (Exception e)
            {
                Logger.Error(e, "Get {0} info error:{1}", caller.Name, e.ToString());
                result.Result    = false;
                result.ErrorInfo = ErrorConfig.GetErrorInfo(ErrorCode.ServerException);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public void ColumnItselfIsNotThere()
        {
            Employee master = new Employee();

            master.Name = "Ganesh";

            ErrorConfig errorConfig = new ErrorConfig();

            errorConfig.ErrorMessageWhenColumnNotPresentKey   = "Column {0} is not present ";
            errorConfig.ErrorMessageWhenColumnNotPresentValue = "Header Row";
            List <AbstractProcessorConfig> configs = new List <AbstractProcessorConfig>();
            var config = DataTableProcessorConfiguration.CreateConfig("Old Name1").AddValidatorWithParams((input1, input2) => {
                return(master.Name == "Hari");
            }, master)
                         .GetConfiguration();

            configs.Add(config);
            var dataTableProcessorResult = configs.ProcessConfigs(dt, errorConfig);

            Assert.Equal(dataTableProcessorResult.Error.Rows.Count, 1);
            Assert.Equal("Column Old Name1 is not present ", dataTableProcessorResult.Error.Rows[0].ItemArray[0]);
            Assert.Equal("Header Row", dataTableProcessorResult.Error.Rows[0].ItemArray[1]);
        }
示例#3
0
        public void ValueOfAdditionalColumnShouldBePassedAndErrorShouldBeThrownWhenValidationCriteriaFails()
        {
            Employee master = new Employee();

            master.Name = "Ganesh";

            ErrorConfig errorConfig = new ErrorConfig();

            errorConfig.ErrorMessageWhenColumnNotPresentKey   = "Column {0} is not present ";
            errorConfig.ErrorMessageWhenColumnNotPresentValue = "Header Row";
            List <AbstractProcessorConfig> configs = new List <AbstractProcessorConfig>();
            var config = DataTableProcessorConfiguration.CreateConfig("Old Name").AddValidatorWithParams((input1, input2, input3) => {
                return(input3 == "Hari");
            }, master, "additional Name")
                         .GetConfiguration();

            configs.Add(config);
            var dataTableProcessorResult = configs.ProcessConfigs(dt, 2);

            Assert.Equal(dataTableProcessorResult.Error.Rows.Count, 1);
            Assert.Equal("Old Name is invalid", dataTableProcessorResult.Error.Rows[0].ItemArray[0]);
            Assert.Equal("2,3", dataTableProcessorResult.Error.Rows[0].ItemArray[1]);
        }
示例#4
0
        public void ValidatorWithParamsFailureCheckWithStartRowSetThroughErrorConfig()
        {
            Employee master = new Employee();

            master.Name = "Ganesh";

            ErrorConfig errorConfig = new ErrorConfig();

            errorConfig.ErrorMessageWhenColumnNotPresentKey   = "Column {0} is not present ";
            errorConfig.ErrorMessageWhenColumnNotPresentValue = "Header Row";
            errorConfig.StartRowNumberForValidationError      = 3;

            List <AbstractProcessorConfig> configs = new List <AbstractProcessorConfig>();
            var config = DataTableProcessorConfiguration.CreateConfig("Old Name").AddValidatorWithParams((input1, input2) => {
                return(master.Name == "Hari");
            }, master)
                         .GetConfiguration();

            configs.Add(config);
            var dataTableProcessorResult = configs.ProcessConfigs(dt, errorConfig);

            Assert.Equal(dataTableProcessorResult.Error.Rows.Count, 1);
            Assert.Equal("3,4", dataTableProcessorResult.Error.Rows[0].ItemArray[1]);
        }
示例#5
0
        public DataTableProcessorResult Process(List <AbstractProcessorConfig> configurations, DataTable dt, ErrorConfig errorConfig)
        {
            DataTableProcessorResult result = new DataTableProcessorResult();

            DataTable errors = CreateErrorDataTable();

            foreach (var config in configurations)
            {
                if (dt.Columns.Contains(config.ExcelColumnName))
                {
                    dt = ProcessConfig(config, dt, errors, errorConfig.StartRowNumberForValidationError);
                }
                else
                {
                    errors = AddErrorRow(errors, errorConfig.ErrorMessageWhenColumnNotPresentKey == null ? config.ExcelColumnName : string.Format(errorConfig.ErrorMessageWhenColumnNotPresentKey, config.ExcelColumnName), errorConfig.ErrorMessageWhenColumnNotPresentValue);
                }
            }
            result.Result = dt;
            result.Error  = errors;
            return(result);
        }
示例#6
0
        protected void Application_Error(object s, EventArgs e)
        {
            var ex = Server.GetLastError();

            ErrorConfig.CatchAllErrors(ex, this.Context);
        }