Beispiel #1
0
        private void SaveValidateStyle()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay();

            string actiontype = _Request.Get("actiontype", Method.Get, string.Empty);

            string validateCodeStyle = _Request.Get("validateCodeStyle", Method.Post, string.Empty);

            bool isInvalidActionType = true;

            foreach (ValidateCodeAction action in ValidateCodeManager.GetAllValidateCodeActions())
            {
                if (string.Compare(action.Type, actiontype, true) == 0)
                {
                    isInvalidActionType = false;
                    break;
                }
            }

            if (isInvalidActionType == true)
            {
                msgDisplay.AddError(new InvalidParamError("actiontype").Message);
            }


            ValidateCodeCollection tempValidateCodes = new ValidateCodeCollection();

            bool hasAdd = false;

            foreach (ValidateCode validateCode in AllSettings.Current.ValidateCodeSettings.ValidateCodes)
            {
                if (string.Compare(validateCode.ActionType, actiontype, true) == 0)
                {
                    ValidateCode tempValidateCode = (ValidateCode)validateCode.Clone();

                    tempValidateCode.ValidateCodeType = validateCodeStyle;

                    tempValidateCodes.Add(tempValidateCode);

                    hasAdd = true;
                }
                else
                {
                    tempValidateCodes.Add(validateCode);
                }
            }

            if (hasAdd == false)
            {
                ValidateCode validateCode = new ValidateCode();

                validateCode.ValidateCodeType = validateCodeStyle;
                validateCode.ActionType       = actiontype;

                tempValidateCodes.Add(validateCode);
            }


            try
            {
                using (new ErrorScope())
                {
                    ValidateCodeSettings setting = (ValidateCodeSettings)AllSettings.Current.ValidateCodeSettings.Clone();

                    setting.ValidateCodes = tempValidateCodes;

                    Success = SettingManager.SaveSettings(setting);

                    if (!Success)
                    {
                        CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        Return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
Beispiel #2
0
        private void SaveValidateCode()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("Limited");

            ValidateCodeCollection tempValidateCodes = new ValidateCodeCollection();

            int i = 0;

            foreach (ValidateCodeAction action in ValidateCodeActionList)
            {
                ValidateCode validateCode = new ValidateCode();
                validateCode.Enable     = _Request.Get <bool>("enable." + action.Type, Method.Post, false);
                validateCode.ActionType = action.Type;

                string valueString = _Request.Get("LimitedTime." + action.Type, Method.Post, string.Empty);

                int limitedTime = 0;

                string error = string.Empty;

                if (valueString.Trim() != string.Empty)
                {
                    if (!int.TryParse(valueString, out limitedTime))
                    {
                        error = Lang_Error.ValidateCode_LimitedTimeError;
                    }
                    else if (limitedTime < 0)
                    {
                        error = Lang_Error.ValidateCode_LimitedTimeError;
                    }
                }

                int timeType = _Request.Get <int>("limitedTimeType." + action.Type, Method.Post, 0);

                TimeUnit timeUnit = (TimeUnit)timeType;

                validateCode.LimitedTime = (int)DateTimeUtil.GetSeconds(limitedTime, timeUnit);


                valueString = _Request.Get("LimitedCount." + action.Type, Method.Post, string.Empty);

                int limitedCount = 0;

                if (valueString.Trim() != string.Empty)
                {
                    if (!int.TryParse(valueString, out limitedCount))
                    {
                        error = error + Lang_Error.ValidateCode_LimitedCountError;
                    }
                    else if (limitedCount < 0)
                    {
                        error = error + Lang_Error.ValidateCode_LimitedCountError;
                    }
                }
                if (error != string.Empty)
                {
                    msgDisplay.AddError("limited", i, error);
                    i++;
                    continue;
                }

                i++;

                validateCode.LimitedCount = limitedCount;


                ValidateCode tempValidateCode = AllSettings.Current.ValidateCodeSettings.ValidateCodes.GetValue(action.Type);

                if (tempValidateCode != null)
                {
                    validateCode.ExceptRoleIds    = tempValidateCode.ExceptRoleIds;
                    validateCode.ValidateCodeType = tempValidateCode.ValidateCodeType;
                }

                tempValidateCodes.Add(validateCode);
            }


            if (msgDisplay.HasAnyError())
            {
                return;
            }

            try
            {
                using (new ErrorScope())
                {
                    ValidateCodeSettings setting = (ValidateCodeSettings)AllSettings.Current.ValidateCodeSettings.Clone();

                    setting.ValidateCodes = tempValidateCodes;

                    bool success = SettingManager.SaveSettings(setting);

                    if (!success)
                    {
                        CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        //msgDisplay.ShowInfo(this);
                    }
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
        private void SaveValidateRole()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay();

            string actiontype = _Request.Get("actiontype", Method.Get, string.Empty);


            string roleIDString = _Request.Get("validateCodeRole", Method.Post, string.Empty);

            if (roleIDString.Length == 0)
            {
                return;
            }


            bool isInvalidActionType = true;

            foreach (ValidateCodeAction action in ValidateCodeManager.GetAllValidateCodeActions())
            {
                if (string.Compare(action.Type, actiontype, true) == 0)
                {
                    if (action.CanSetExceptRoleId == false)
                    {
                        msgDisplay.AddError(string.Format(Lang_Error.ValidateCode_ValidateCodeActionCannotSetExceptRoleID, action.Name));
                        return;
                    }
                    isInvalidActionType = false;
                    break;
                }
            }

            if (isInvalidActionType == true)
            {
                msgDisplay.AddError(new InvalidParamError("actiontype").Message);
            }


            StringList exceptRoleIDs = new StringList();

            foreach (string roleID in roleIDString.Split(','))
            {
                exceptRoleIDs.Add(roleID);
            }


            ValidateCodeCollection tempValidateCodes = new ValidateCodeCollection();

            bool hasAdd = false;

            foreach (ValidateCode validateCode in AllSettings.Current.ValidateCodeSettings.ValidateCodes)
            {
                if (string.Compare(validateCode.ActionType, actiontype, true) == 0)
                {
                    ValidateCode tempValidateCode = (ValidateCode)validateCode.Clone();

                    tempValidateCode.ExceptRoleIds = exceptRoleIDs;

                    tempValidateCodes.Add(tempValidateCode);

                    hasAdd = true;
                }
                else
                {
                    tempValidateCodes.Add(validateCode);
                }
            }

            if (hasAdd == false)
            {
                ValidateCode validateCode = new ValidateCode();

                validateCode.ExceptRoleIds = exceptRoleIDs;
                validateCode.ActionType    = actiontype;

                tempValidateCodes.Add(validateCode);
            }


            try
            {
                using (new ErrorScope())
                {
                    ValidateCodeSettings setting = (ValidateCodeSettings)AllSettings.Current.ValidateCodeSettings.Clone();

                    setting.ValidateCodes = tempValidateCodes;

                    bool success = SettingManager.SaveSettings(setting);

                    if (!success)
                    {
                        CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        Return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }