Exemplo n.º 1
0
        /// <summary>
        /// Runs the wizard.
        /// </summary>
        public void Run()
        {
            if (!(configuration.Security is InternalServerSecurity))
            {
                if (MessageBox.Show("Importing users is only valid for internal security, do you want to change to internal security now?",
                                    "Invalid security manager",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }
                else
                {
                    changeManager = true;
                }
            }
            var steps = new List <IStep>();

            controller = new WizardController(steps);

            // Welcome text
            steps.Add(new TextDisplayStep("This wizard will guide you through the steps of importing users from a CSV file for this configuration", "Welcome"));

            // Display users step
            var users    = new UserDisplay();
            var userStep = new TemplateStep(users, 0, "Select Users to Import");

            userStep.NextHandler += () =>
            {
                settings.Clear();
                settings.Add(users.GenerateConfirmation());
                return(true);
            };

            // File selection step
            var fileStep = new FileSelectionStep("Select Import File", "What CSV file to you want to import:");

            fileStep.NextHandler += () =>
            {
                if (!File.Exists(fileStep.SelectedFullPath))
                {
                    MessageBox.Show("Unable to find the file '" + fileStep.SelectedFullPath + "'",
                                    "Invalid import file",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return(false);
                }
                else
                {
                    try
                    {
                        users.LoadCsv(fileStep.SelectedFullPath);
                        return(true);
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Unable to load the file '" + fileStep.SelectedFullPath + "'" + Environment.NewLine + error.Message,
                                        "Invalid import file",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return(false);
                    }
                }
            };
            steps.Add(fileStep);
            steps.Add(userStep);

            // Configuration mode step
            var confirmation = GenerateConfirmation();

            confirmation.NextHandler += () =>
            {
                if (changeManager)
                {
                    configuration.Security = new InternalServerSecurity();
                }
                users.ApplyConfiguration(configuration);
                configuration.Security = configuration.Security;    // Force a refresh
                return(true);
            };
            steps.Add(confirmation);
            steps.Add(new TextDisplayStep("Users have been imported", "Finished"));

            var result = controller.StartWizard("Security Configuration Wizard");
        }
Exemplo n.º 2
0
        public static User RunNewUserWizard()
        {
            //Create a list of steps
            List <IStep> steps   = new List <IStep>();
            User         newUser = new User();

            //Step 1. Welcome message
            TextBox t = new TextBox();

            t.Multiline  = true;
            t.ScrollBars = ScrollBars.Vertical;
            t.ReadOnly   = true;
            t.Text       = Resources.WelcomeMessage;
            t.Select(0, 0);
            steps.Add(new TemplateStep(t, 10, "Welcome"));

            //Step 2. Role selection
            var roleStep = new SelectionStep("Role Selection", "Please select the user's role:",
                                             Enum.GetNames(typeof(User.UserRole)));

            roleStep.NextHandler = () =>
            {
                newUser.Role = (User.UserRole)Enum.Parse(typeof(User.UserRole), roleStep.Selected as string);
                return(true);
            };
            steps.Add(roleStep);

            //Step 3. User Details
            var userFormStep = new TextFormStep("User Details");

            userFormStep.Subtitle = "This step allows you to specify the user's personal information.";
            userFormStep.Prompt   = "Please provide the following user information:";
            var userIdQuestion   = userFormStep.AddQuestion("User &ID:", Validation.NonEmpty);
            var fullNameQuestion = userFormStep.AddQuestion("Full &Name:", Validation.NonEmpty);
            var passwordQuestion = userFormStep.AddQuestion("&Password (6 or more characters):",
                                                            Validation.MinLength(6), '*');
            var passwordQuestionRetype = userFormStep.AddQuestion("&Retype Password:"******"&E-Mail address:", Validation.NonEmpty);

            steps.Add(userFormStep);
            userFormStep.NextHandler = () =>
            {
                if (!passwordQuestion.Answer.Equals(passwordQuestionRetype.Answer))
                {
                    MessageBox.Show("The password does not match the retyped password.",
                                    Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
                newUser.FullName = fullNameQuestion.Answer;
                newUser.Email    = emailAddressQuestion.Answer;
                newUser.Password = passwordQuestion.Answer;
                newUser.UserId   = userIdQuestion.Answer;
                return(true);
            };

            //Step 4. Picture Selection step. This step features the selection of a file.
            var pictureSelectionStep = new FileSelectionStep("User picture selection", "Please provide a picture for this user.");

            pictureSelectionStep.Filter           = "Images|*.bmp;*.jpg;*.gif;*.tif;*.png|All Files (*.*)|*.*";
            pictureSelectionStep.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            pictureSelectionStep.NextHandler      = () =>
            {
                if (File.Exists(pictureSelectionStep.SelectedFullPath))
                {
                    newUser.Picture = Image.FromFile(pictureSelectionStep.SelectedFullPath);
                    return(true);
                }
                else
                {
                    MessageBox.Show("Selected image does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            };
            pictureSelectionStep.AllowNextStrategy =
                () => !string.IsNullOrEmpty(pictureSelectionStep.SelectedFullPath);
            steps.Add(pictureSelectionStep);

            //Step 5. Preview step. This step features a custom UI implemented separately.
            steps.Add(new CustomSteps.PreviewStep(newUser));

            //Run the wizard with the steps defined above
            WizardController wizardController = new WizardController(steps);

            wizardController.LogoImage = Resources.NerlimWizardHeader;
            var wizardResult = wizardController.StartWizard("New User");

            //If the user clicked "Cancel", don't add the user
            if (wizardResult == WizardController.WizardResult.Cancel)
            {
                newUser = null;
            }

            return(newUser);
        }