Пример #1
0
        /// <summary> Get the input tag in the form corresponding to the given name</summary>
        /// <param name="name">The name of the input tag to be retrieved
        /// </param>
        /// <returns> Tag The input tag corresponding to the name provided
        /// </returns>
        public virtual InputTag GetInputTag(System.String name)
        {
            InputTag inputTag;
            bool     found;

            System.String inputTagName;

            inputTag = null;
            found    = false;
            for (ISimpleNodeIterator e = FormInputs.Elements(); e.HasMoreNodes() && !found;)
            {
                inputTag     = (InputTag)e.NextNode();
                inputTagName = inputTag.GetAttribute("NAME");
                if (inputTagName != null && inputTagName.ToUpper().Equals(name.ToUpper()))
                {
                    found = true;
                }
            }
            if (found)
            {
                return(inputTag);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        private void btnThrowError_Click(object sender, EventArgs e)
        {
            string          message         = "";
            StringBuilder   stringBuilder   = null;
            Exception       oops            = null;
            ValidationLogic validationLogic = null;
            FormInputs      formInputs      = null;

            try
            {
                //formInputs = new FormInputs();
                formInputs.Name = txtName.Text.Trim();
                formInputs.DOB  = dateTimePicker1.Value.ToString();

                if (rbtnFemale.Checked == true)
                {
                    formInputs.Gender = "1";
                }

                if (rbtnMale.Checked == true)
                {
                    formInputs.Gender = "0";
                }

                formInputs.Age = txtAge.Text.Trim();
                ProcessFormInputs(formInputs);
            }
            catch (Exception exception)
            {
                stringBuilder = new StringBuilder();
                // walking the stack trace for all error information presented
                oops = exception;
                while (oops != null)
                {
                    message = oops.Message;
                    stringBuilder.Append("Message: " + message + ".\r\n");

                    message = oops.Source;
                    stringBuilder.Append("\tSource: " + message + ".\r\n");

                    message = oops.StackTrace;
                    stringBuilder.Append("\tStackTrace: " + message + ".\r\n");
                    stringBuilder.Append("**********\r\n");
                    oops = oops.InnerException;
                }
                message       = stringBuilder.ToString();
                lblError.Text = message;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            FormInputs formInputs = null;

            formInputs      = new FormInputs();
            formInputs.Name = txtName.Text.Trim();
            formInputs.DOB  = dateTimePicker1.Value.ToString();

            if (rbtnFemale.Checked == true)
            {
                formInputs.Gender = "1";
            }

            if (rbtnMale.Checked == true)
            {
                formInputs.Gender = "0";
            }

            formInputs.Age = txtAge.Text.Trim();
            ProcessFormInputs(formInputs);
        }
        public FormInputsValidator ValidateFormInputs(FormInputs formInputs)
        {
            FormInputsValidator formInputsValidator = null;
            DateTime            dob = DateTime.MinValue;
            Int32 age    = 0;
            Int32 gender = 0;

            if (formInputs != null)
            {
                if (string.IsNullOrEmpty(formInputs.Name) == true)
                {
                    if (formInputsValidator == null)
                    {
                        formInputsValidator = new FormInputsValidator();
                    }
                    formInputsValidator.isError         = true;
                    formInputsValidator.ErrorMessage   += "Name has an error.";
                    formInputsValidator.isNameOK        = false;
                    formInputsValidator.NameExplanation = FormInputsValidator.ErrorNameExplanation;
                }

                if (string.IsNullOrEmpty(formInputs.DOB) == false)
                {
                    if (DateTime.TryParse(formInputs.DOB.ToString(), out dob) == true)
                    {
                        if (dob == DateTime.MinValue)
                        {
                            if (formInputsValidator == null)
                            {
                                formInputsValidator = new FormInputsValidator();
                            }
                            formInputsValidator.isError        = true;
                            formInputsValidator.ErrorMessage  += "DOB has an error.";
                            formInputsValidator.isDOBOK        = false;
                            formInputsValidator.DOBExplanation = FormInputsValidator.ErrorDOBExplanation;
                        }

                        if (dob == DateTime.MaxValue)
                        {
                            if (formInputsValidator == null)
                            {
                                formInputsValidator = new FormInputsValidator();
                            }
                            formInputsValidator.isError        = true;
                            formInputsValidator.ErrorMessage  += "DOB has an error.";
                            formInputsValidator.isDOBOK        = false;
                            formInputsValidator.DOBExplanation = FormInputsValidator.ErrorDOBExplanation;
                        }
                    }
                    else
                    {
                        if (formInputsValidator == null)
                        {
                            formInputsValidator = new FormInputsValidator();
                        }
                        formInputsValidator.isError        = true;
                        formInputsValidator.ErrorMessage  += "DOB has an error.";
                        formInputsValidator.isDOBOK        = false;
                        formInputsValidator.DOBExplanation = FormInputsValidator.ErrorDOBExplanation;
                    }
                }
                else
                {
                    if (formInputsValidator == null)
                    {
                        formInputsValidator = new FormInputsValidator();
                    }
                    formInputsValidator.isError        = true;
                    formInputsValidator.ErrorMessage  += "DOB has an error (it's empty).";
                    formInputsValidator.isDOBOK        = false;
                    formInputsValidator.DOBExplanation = FormInputsValidator.ErrorDOBExplanation;
                }

                if (string.IsNullOrEmpty(formInputs.Gender) == false)
                {
                    if (Int32.TryParse(formInputs.Gender, out gender) == true)
                    {
                        switch (gender)
                        {
                        case 0:
                            // do nothing gendor = 0 = male;
                            break;

                        case 1:
                            // do nothing gendor = 1 = female;
                            break;

                        default:
                            if (formInputsValidator == null)
                            {
                                formInputsValidator = new FormInputsValidator();
                            }
                            formInputsValidator.isError           = true;
                            formInputsValidator.ErrorMessage     += "Gender has an error.";
                            formInputsValidator.isGenderOK        = false;
                            formInputsValidator.GenderExplanation = FormInputsValidator.ErrorGenderExplanation;

                            break;
                        }
                    }
                    else
                    {
                        if (formInputsValidator == null)
                        {
                            formInputsValidator = new FormInputsValidator();
                        }
                        formInputsValidator.isError           = true;
                        formInputsValidator.ErrorMessage     += "Gender has an error.";
                        formInputsValidator.isGenderOK        = false;
                        formInputsValidator.GenderExplanation = FormInputsValidator.ErrorGenderExplanation;
                    }
                }
                else
                {
                    if (formInputsValidator == null)
                    {
                        formInputsValidator = new FormInputsValidator();
                    }
                    formInputsValidator.isError           = true;
                    formInputsValidator.ErrorMessage     += "Gender has an error.";
                    formInputsValidator.isGenderOK        = false;
                    formInputsValidator.GenderExplanation = FormInputsValidator.ErrorGenderExplanation;
                }



                if (Int32.TryParse(formInputs.Age, out age) == true)
                {
                    if (age < 0)
                    {
                        if (formInputsValidator == null)
                        {
                            formInputsValidator = new FormInputsValidator();
                        }
                        formInputsValidator.isError        = true;
                        formInputsValidator.ErrorMessage  += "Age has an error.";
                        formInputsValidator.isAgeOK        = false;
                        formInputsValidator.AgeExplanation = FormInputsValidator.ErrorAgeExplanation;
                    }


                    if (age == 0)
                    {
                        if (formInputsValidator == null)
                        {
                            formInputsValidator = new FormInputsValidator();
                        }
                        formInputsValidator.isError        = true;
                        formInputsValidator.ErrorMessage  += "Age has an error (cannot be 0).";
                        formInputsValidator.isAgeOK        = false;
                        formInputsValidator.AgeExplanation = FormInputsValidator.ErrorAgeExplanation;
                    }
                }
                else
                {
                    if (formInputsValidator == null)
                    {
                        formInputsValidator = new FormInputsValidator();
                    }
                    formInputsValidator.isError        = true;
                    formInputsValidator.ErrorMessage  += "Age has an error.";
                    formInputsValidator.isAgeOK        = false;
                    formInputsValidator.AgeExplanation = FormInputsValidator.ErrorAgeExplanation;
                }
            }
            else
            {
                formInputsValidator                   = new FormInputsValidator();
                formInputsValidator.isError           = true;
                formInputsValidator.ErrorMessage     += "FormInputs is null.";
                formInputsValidator.isNameOK          = false;
                formInputsValidator.NameExplanation   = FormInputsValidator.ErrorNameExplanation;
                formInputsValidator.isDOBOK           = false;
                formInputsValidator.DOBExplanation    = FormInputsValidator.ErrorDOBExplanation;
                formInputsValidator.isGenderOK        = false;
                formInputsValidator.GenderExplanation = FormInputsValidator.ErrorGenderExplanation;
                formInputsValidator.isAgeOK           = false;
                formInputsValidator.AgeExplanation    = FormInputsValidator.ErrorAgeExplanation;
            }



            return(formInputsValidator);
        }
Пример #5
0
 SessionManager()
 {
     _formInputs = new FormInputs();
 }
        private FormInputs ProcessFormInputs(FormInputs formInputs)
        {
            string              message             = "";
            StringBuilder       stringBuilder       = null;
            Exception           oops                = null;
            ValidationLogic     validationLogic     = null;
            FormInputsValidator formInputsValidator = null;

            try
            {
                ResetErrorLabels();
                if (formInputs != null)
                {
                    validationLogic     = new ValidationLogic();
                    formInputsValidator = validationLogic.ValidateFormInputs(formInputs);
                    if (formInputsValidator != null)
                    {
                        if (formInputsValidator.isError == true)
                        {
                            if (formInputsValidator.isNameOK == false)
                            {
                                errorProvider1.SetError(txtName, formInputsValidator.NameExplanation);
                                lblNameExplanation.Text = formInputsValidator.NameExplanation;
                            }
                            if (formInputsValidator.isDOBOK == false)
                            {
                                errorProvider1.SetError(dateTimePicker1, formInputsValidator.DOBExplanation);
                                lblDOBExplanation.Text = formInputsValidator.DOBExplanation;
                            }
                            if (formInputsValidator.isGenderOK == false)
                            {
                                errorProvider1.SetError(grpGender, formInputsValidator.GenderExplanation);
                                lblGenderExplanation.Text = formInputsValidator.GenderExplanation;
                            }
                            if (formInputsValidator.isAgeOK == false)
                            {
                                errorProvider1.SetError(txtAge, formInputsValidator.AgeExplanation);
                                lblAgeExplanation.Text = formInputsValidator.AgeExplanation;
                            }
                            lblError.Text = formInputsValidator.ErrorMessage;
                        }
                        else
                        {
                            lblError.Text = "No Errors found! Great work!";
                        }
                    }
                    else
                    {
                        lblError.Text = "No Errors found! Great work!";
                    }
                }
            }
            catch (Exception exception)
            {
                stringBuilder = new StringBuilder();
                // walking the stack trace for all error information presented
                oops = exception;
                while (oops != null)
                {
                    message = oops.Message;
                    stringBuilder.Append("Message: " + message + ".\r\n");

                    message = oops.Source;
                    stringBuilder.Append("\tSource: " + message + ".\r\n");

                    message = oops.StackTrace;
                    stringBuilder.Append("\tStackTrace: " + message + ".\r\n");
                    stringBuilder.Append("**********\r\n");
                    oops = oops.InnerException;
                }
            }
            return(formInputs);
        }
Пример #7
0
        static RestResponse()
        {
            // Create the login form.
            var loginForm = new FormInputs
            {
                Type   = "LOGIN_FORM",
                Inputs = new List <FormInput>
                {
                    // AccountForm
                    new FormInput
                    {
                        Id        = "account_name",
                        Type      = "text",
                        Label     = "Battle.net email",
                        MaxLength = 320
                    },
                    // PasswordForm
                    new FormInput
                    {
                        Id        = "password",
                        Type      = "password",
                        Label     = "Password",
                        MaxLength = 100
                    },
                    // SubmitForm
                    new FormInput
                    {
                        Id    = "log_in_submit",
                        Type  = "submit",
                        Label = "Log in to Battle.net"
                    }
                }
            };

            LoginForm = HttpResponse.Create(HttpCode.Ok, Json.CreateString(loginForm));

            // Create the authenticator logon result.
            var authenticatorForm = new LogonResult
            {
                AuthenticationState = AuthenticationState.Authenticator,
                AuthenticatorForm   = new FormInputs
                {
                    Type   = "AUTHENTICATOR_FORM",
                    Prompt = "Enter the security code from your authenticator.",
                    Inputs = new List <FormInput>
                    {
                        // SecurityCodeForm
                        new FormInput
                        {
                            Id        = "authenticator_input",
                            Type      = "text",
                            Label     = "Security Code",
                            MaxLength = 20
                        },
                        // RememberForm
                        new FormInput
                        {
                            Id    = "remember_authenticator",
                            Type  = "checkbox",
                            Label = "Don't ask me again"
                        },
                        // SubmitForm
                        new FormInput
                        {
                            Id    = "authenticator_submit",
                            Type  = "submit",
                            Label = "Submit"
                        }
                    }
                }
            };

            AuthenticatorForm = HttpResponse.Create(HttpCode.Ok, Json.CreateString(authenticatorForm));

            var logonResult = new LogonResult
            {
                AuthenticationState = AuthenticationState.Login,
                ErrorCode           = "INVALID_ACCOUNT_OR_CREDENTIALS",
                ErrorMessage        = "We couldn't log you in with what you just entered. Please try again.",
            };

            InvalidAccountOrCredentials = HttpResponse.Create(HttpCode.BadRequest, Json.CreateString(logonResult), true);
        }