Пример #1
0
        /// <summary>
        /// Gets the categories from the database.
        /// </summary>
        private void populateCategoryComboBox()
        {
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;

                    List <Category> view = DBModel.Category.ToList();
                    view.Reverse();
                    categoryComboBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    categoryComboBox.DisplayMember = "Name";
                }
            }
            catch (Exception exp)
            {
                MPAiMessageBoxFactory.Show(dataLinkErrorText);
                Console.WriteLine(exp);
            }
        }
Пример #2
0
        /// <summary>
        /// Authenticates the user and handles user errors.
        /// Also handles informing the user if they have entered an incorrect username or password.
        /// </summary>
        /// <returns>True if the user has logged in successfully, false otherwise.</returns>
        private bool login()
        {
            MPAiUser tUser = new MPAiUser(usernameTextBox.Text, passwordTextBox.Text);

            if (UserManagement.AuthenticateUser(ref tUser))
            {
                return(true);
            }
            else
            {
                if (UserManagement.ContainsUser(tUser))
                {
                    MPAiMessageBoxFactory.Show("Password is incorrect!",
                                               "Oops", MPAiMessageBoxButtons.OK);
                    passwordTextBox.Clear();
                    watermarkPassword(true);
                }
                else
                {
                    MPAiMessageBoxFactory.Show("User does not exist!",
                                               "Oops", MPAiMessageBoxButtons.OK);
                    usernameTextBox.Clear();
                    watermarkUsername(false);
                    passwordTextBox.Clear();
                    watermarkPassword(false);
                }
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateWordComboBox()
        {
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;
                    UserManagement.CurrentUser.setSpeakerFromVoiceType();

                    List <Word> view = DBModel.Word.Where(x => (
                                                              x.Category.Name.Equals(((Category)categoryComboBox.SelectedItem).Name) &&
                                                              x.Recordings.Any(y => y.Speaker.SpeakerId == UserManagement.CurrentUser.Speaker.SpeakerId)
                                                              )).ToList();

                    view.Sort(new VowelComparer());
                    WordComboBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    WordComboBox.DisplayMember = "Name";
                }
            }
            catch (Exception exp)
            {
                MPAiMessageBoxFactory.Show(dataLinkErrorText);
                Console.WriteLine(exp);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateBoxes()
        {
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;
                    Console.WriteLine(VoiceType.getDisplayNameFromVoiceType(current.Voice));

                    List <Word> view = DBModel.Word.Where(x => (
                                                              x.Category.Name.Equals("Word") &&
                                                              x.Recordings.Any(y => y.Speaker.SpeakerId == current.Speaker.SpeakerId)
                                                              )).ToList();

                    view.Sort(new VowelComparer());
                    WordComboBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    WordComboBox.DisplayMember = "Name";
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
 /// <summary>
 /// Private method that checks whether the user directory exists, and if it does not, creates it.
 /// </summary>
 /// <param name="user"></param>
 private static void ensureUserDirectoryExists(MPAiUser user)
 {
     if (!Directory.Exists(Path.Combine(DirectoryManagement.ScoreboardReportFolder, user.getName())))
     {
         Directory.CreateDirectory(Path.Combine(DirectoryManagement.ScoreboardReportFolder, user.getName()));
     }
 }
Пример #6
0
        /// <summary>
        /// Constructor for the ChangePasswordWindow. Loads the UserManagement object in and creates the UI.
        /// </summary>
        /// <param name="users">The UserManagement object containing all the current users.</param>
        public ChangePasswordWindow()
        {
            InitializeComponent();

            currentUser = UserManagement.CurrentUser;

            InitUI();
        }
Пример #7
0
        private void checkBoxChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.CheckBox checkBox = (System.Windows.Forms.CheckBox)sender;
            MPAiUser user = userCheckBoxMap[checkBox];

            user.IsAdmin = checkBox.Checked;
            UserManagement.WriteSettings();
        }
Пример #8
0
        private void resetButtonClick(object sender, EventArgs e)
        {
            MPAiUser user = userButtonMap[(MPAiButton)sender];
            ConfirmRandomisedPassword dialog = new ConfirmRandomisedPassword();

            user.UserPswd = dialog.ConfirmPassword(user.GetCorrectlyCapitalisedName(), user.UserPswd);
            UserManagement.WriteSettings();
        }
Пример #9
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateBoxes()
        {
            // Stop playback and clear the boxes, to prevent errors.
            asyncStop();
            VowelComboBox.Items.Clear();
            soundListCurrentListBox.Items.Clear();
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;

                    List <Recording> videoView = DBModel.Recording.Where(x => (
                                                                             (x.Word.Category.Name.Equals("vowel")) &&        // If the category is vowel, and
                                                                             (current.Speaker.Name.Equals(x.Speaker.Name)) && // The speaker's gender matches the current user's gender, and
                                                                             ((x.Video != null) ||                            // There is a video of that speaker, or
                                                                              (x.VocalTract != null))                         // The recording has a vocaltract attached. (They are gender neutral, albeit with a male voice.)
                                                                             )).ToList();

                    wordsList = videoView;   // Take this action before display names are changed

                    // Lists of Recording objects, but only their name needs to be displayed to the user.
                    soundListAllListBox.DisplayMember     = "Name";
                    VowelComboBox.DisplayMember           = "Name";
                    soundListCurrentListBox.DisplayMember = "Name";

                    // Set the values in all the lists used by the program.
                    foreach (Recording rd in videoView)
                    {
                        // Adjust the display names of the recordings in the list, so they are human readable.
                        if (rd.Video != null)
                        {
                            rd.Name = DBModel.Word.SingleOrDefault(x => x.WordId == rd.WordId).Name + videoText;
                        }
                        else if (rd.VocalTract != null)
                        {
                            rd.Name = DBModel.Word.SingleOrDefault(x => x.WordId == rd.WordId).Name + vocalText;
                        }
                        soundListCurrentListBox.Items.Add(rd);
                        VowelComboBox.Items.Add(rd);
                    }

                    soundListAllListBox.DataSource = new BindingSource()
                    {
                        DataSource = videoView
                    };

                    selectItemInComboBox();
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Пример #10
0
        /// <summary>
        /// Automatically enters a username and password into the correct text boxes.
        /// </summary>
        /// <param name="Username">The username to enter, as a string.</param>
        /// <param name="Password">The password to enter, as a string.</param>
        public void VisualizeUser(MPAiUser user)
        {
            if (!(user == null))
            {
                watermarkUsername(true);
                usernameTextBox.Text = user.getName();

                watermarkPassword(true);
                passwordTextBox.Text = user.getCode();
            }
        }
Пример #11
0
        private void formantButton_Click(object sender, EventArgs e)
        {
            MPAiUser user = UserManagement.CurrentUser;

            PlotController.PlotType?plotType = PlotController.PlotType.FORMANT_PLOT;
            VoiceType voiceType = user.Voice;

            PlotController.RunPlot(plotType, voiceType);

            closeThis();
        }
Пример #12
0
        private void deleteButtonClick(object sender, EventArgs e)
        {
            MPAiUser user = userButtonMap[(MPAiButton)sender];

            if (MPAiMessageBoxFactory.Show("Are you sure you want to delete " + user.GetCorrectlyCapitalisedName() + "'s account?", MPAiMessageBoxButtons.YesNoCancel).Equals(DialogResult.Yes))
            {
                UserManagement.RemoveUser(user);
                generatedUserTable = generateUserTable();
                this.Close();
                new AdministratorConsole().ShowDialog();
                Console.WriteLine("delete " + user.GetCorrectlyCapitalisedName());
            }
            UserManagement.WriteSettings();
        }
Пример #13
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateBoxes()
        {
            // Stop playback and clear the boxes, to prevent errors.
            asyncStop();
            WordComboBox.Items.Clear();
            soundListCurrentListBox.Items.Clear();
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;

                    List <Word> view = DBModel.Word.Where(x => (
                                                              x.Category.Name.Equals("Word") &&
                                                              x.Recordings.Any(y => y.Speaker.SpeakerId == current.Speaker.SpeakerId) // Until the Menubar is finished, this won't work. Comment this line out to test.
                                                              )).ToList();

                    // Can't sort a control's Items field, so we sort a list and add values.
                    view.Sort(new VowelComparer());

                    // Lists of Word objects, but only their name needs to be displayed to the user.
                    soundListAllListBox.DisplayMember     = "Name";
                    WordComboBox.DisplayMember            = "Name";
                    soundListCurrentListBox.DisplayMember = "Name";

                    // Set the values in all the lists used by the program.
                    soundListAllListBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    foreach (Word wd in view)
                    {
                        soundListCurrentListBox.Items.Add(wd);
                        WordComboBox.Items.Add(wd);
                    }
                    wordsList = view;

                    selectItemInComboBox();
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Пример #14
0
        /// <summary>
        /// Ensures that the new user is valid, and closes the window.
        /// </summary>
        private void createUser()
        {
            if (userNameBox.Text.Trim() == "")
            {
                MPAiMessageBoxFactory.Show("Username should not be empty! ",
                                           "Oops", MPAiMessageBoxButtons.OK);
                return;
            }
            else if ((passwordBox.Text.Trim() == "") || (confirmPasswordBox.Text.Trim() == ""))
            {
                MPAiMessageBoxFactory.Show("Passwords should not be empty! ",
                                           "Oops", MPAiMessageBoxButtons.OK);
                return;
            }
            else if (passwordBox.Text != confirmPasswordBox.Text)
            {
                MPAiMessageBoxFactory.Show("Passwords do not match! ",
                                           "Oops", MPAiMessageBoxButtons.OK);
                return;
            }

            MPAiUser candidate = getCandidate();

            if (!UserManagement.CreateNewUser(candidate))
            {
                MPAiMessageBoxFactory.Show("User already exists, please use a different name! ",
                                           "Oops", MPAiMessageBoxButtons.OK);
            }
            else
            {
                MPAiMessageBoxFactory.Show("Registration successful! ",
                                           "Congratulations", MPAiMessageBoxButtons.OK);
                UserManagement.WriteSettings();
                LoginScreen loginWindow = (LoginScreen)Owner;      // Only LoginWindow can open this form.
                loginWindow.VisualizeUser(candidate);
                Close();
            }
        }
 /// <summary>
 /// Retruns the appropriate filepath string for the specified user's scoreboard file.
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static string SpeakScoreboardFileAddress(MPAiUser user)
 {
     ensureUserDirectoryExists(user);
     return(Path.Combine(DirectoryManagement.ScoreboardReportFolder, user.getName(), "MPAiSpeakScoreboard.txt"));
 }
Пример #16
0
 public MPAiSoundScoreBoard(MPAiUser user)
 {
     this.user = user;
 }
        /// <summary>
        /// This method loads the scoreboard for the specified user. It does this by reading the html-style file created by SaveScoreboard.
        /// The nested nature of the file is why this method is also deeply nested.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static MPAiSpeakScoreBoard LoadScoreboard(MPAiUser user)
        {
            MPAiSpeakScoreBoard scoreboard = new MPAiSpeakScoreBoard(user);

            if (File.Exists(SpeakScoreboardFileAddress(scoreboard.User)))
            {
                using (FileStream fs = new FileStream(SpeakScoreboardFileAddress(scoreboard.User), FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string line;
                        line = sr.ReadLine();
                        //MPAiMessageBoxFactory.Show(line + ": <Scoreboard> expected");
                        if (line.Equals("<Scoreboard>"))
                        {
                            //MPAiMessageBoxFactory.Show("Success, entered <Scoreboard>");
                            while (!line.Equals("</Scoreboard>"))
                            {
                                line = sr.ReadLine();
                                while (line.Equals("<Session>"))
                                {
                                    while (!line.Equals("</Session>"))
                                    {
                                        DateTime dateAndTime = new DateTime();;
                                        line = sr.ReadLine();
                                        if (line.Equals("<Date>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</Date>"))
                                            {
                                                dateAndTime = new DateTime();
                                                if (!DateTime.TryParse(line, out dateAndTime))
                                                {
                                                    throw new FileLoadException("Date could not be read");
                                                }
                                                line = sr.ReadLine();
                                            }
                                            line = sr.ReadLine();
                                        }

                                        List <MPAiSpeakScoreBoardItem> content = new List <MPAiSpeakScoreBoardItem>();
                                        if (line.Equals("<Content>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</Content>"))
                                            {
                                                string expected      = "";
                                                string recognised    = "";
                                                string analysis      = "";
                                                string recordingName = "";

                                                if (line.Equals("<Expected>"))
                                                {
                                                    bool firstline = true;
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</Expected>"))
                                                    {
                                                        if (firstline)
                                                        {
                                                            firstline = false;
                                                            expected += line;
                                                        }
                                                        else
                                                        {
                                                            expected += String.Format(@"{0}", Environment.NewLine) + line;
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }

                                                if (line.Equals("<Recognised>"))
                                                {
                                                    bool firstline = true;
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</Recognised>"))
                                                    {
                                                        if (firstline)
                                                        {
                                                            firstline   = false;
                                                            recognised += line;
                                                        }
                                                        else
                                                        {
                                                            recognised += String.Format(@"{0}", Environment.NewLine) + line;
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }

                                                if (line.Equals("<Analysis>"))
                                                {
                                                    bool firstline = true;
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</Analysis>"))
                                                    {
                                                        if (firstline)
                                                        {
                                                            firstline = false;
                                                            analysis += line;
                                                        }
                                                        else
                                                        {
                                                            analysis += String.Format(@"{0}", Environment.NewLine) + line;
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }

                                                if (line.Equals("<RecordingName>"))
                                                {
                                                    bool firstline = true;
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</RecordingName>"))
                                                    {
                                                        if (firstline)
                                                        {
                                                            firstline      = false;
                                                            recordingName += line;
                                                        }
                                                        else
                                                        {
                                                            recordingName += String.Format(@"{0}", Environment.NewLine) + line;
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }
                                                content.Add(new MPAiSpeakScoreBoardItem(expected, recognised, analysis, recordingName));
                                            }
                                            line = sr.ReadLine();
                                        }
                                        scoreboard.NewScoreBoardSession(dateAndTime, content);
                                    }
                                    line = sr.ReadLine();
                                }
                            }
                        }
                    }
                }
            }
            return(scoreboard);
        }
Пример #18
0
        /// <summary>
        /// This method loads the scoreboard for the specified user. It does this by reading the html-style file created by SaveScoreboard.
        /// The nested nature of the file is why this method is also deeply nested.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static MPAiSoundScoreBoard LoadScoreboard(MPAiUser user)
        {
            MPAiSoundScoreBoard scoreboard = new MPAiSoundScoreBoard(user);

            if (File.Exists(SoundScoreboardFileAddress(scoreboard.User)))
            {
                using (FileStream fs = new FileStream(SoundScoreboardFileAddress(scoreboard.User), FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string line;
                        line = sr.ReadLine();
                        //MPAiMessageBoxFactory.Show(line + ": <Scoreboard> expected");
                        if (line.Equals("<Scoreboard>"))
                        {
                            //MPAiMessageBoxFactory.Show("Success, entered <Scoreboard>");
                            while (!line.Equals("</Scoreboard>"))
                            {
                                line = sr.ReadLine();
                                while (line.Equals("<Session>"))
                                {
                                    line = sr.ReadLine();
                                    while (!line.Equals("</Session>"))
                                    {
                                        DateTime dateAndTime = new DateTime();;
                                        if (line.Equals("<Date>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</Date>"))
                                            {
                                                dateAndTime = new DateTime();
                                                if (!DateTime.TryParse(line, out dateAndTime))
                                                {
                                                    throw new FileLoadException("Date could not be read");
                                                }
                                                line = sr.ReadLine();
                                            }
                                            line = sr.ReadLine();
                                        }

                                        float overallCorrectnessPercentage = -1;
                                        if (line.Equals("<OverallCorrectnessPercentage>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</OverallCorrectnessPercentage>"))
                                            {
                                                if (!float.TryParse(line, out overallCorrectnessPercentage))
                                                {
                                                    throw new FileLoadException("Overall Correctness Percentage could not be read");
                                                }
                                                line = sr.ReadLine();
                                            }
                                            line = sr.ReadLine();
                                        }

                                        List <MPAiSoundScoreBoardItem> content = new List <MPAiSoundScoreBoardItem>();
                                        if (line.Equals("<Content>"))
                                        {
                                            line = sr.ReadLine();
                                            while (!line.Equals("</Content>"))
                                            {
                                                string vowel = "";
                                                float  correctnessPercentage = -1;

                                                if (line.Equals("<Vowel>"))
                                                {
                                                    bool firstline = true;
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</Vowel>"))
                                                    {
                                                        if (firstline)
                                                        {
                                                            firstline = false;
                                                            vowel    += line;
                                                        }
                                                        else
                                                        {
                                                            vowel += String.Format(@"{0}", Environment.NewLine) + line;
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }

                                                if (line.Equals("<CorrectnessPercentage>"))
                                                {
                                                    line = sr.ReadLine();
                                                    while (!line.Equals("</CorrectnessPercentage>"))
                                                    {
                                                        if (!float.TryParse(line, out correctnessPercentage))
                                                        {
                                                            throw new FileLoadException("Correctness Percentage could not be read");
                                                        }
                                                        line = sr.ReadLine();
                                                    }
                                                    line = sr.ReadLine();
                                                }
                                                content.Add(new MPAiSoundScoreBoardItem(vowel, correctnessPercentage));
                                            }
                                            line = sr.ReadLine();
                                        }
                                        MPAiSoundScoreBoardSession session = scoreboard.NewScoreBoardSession(dateAndTime, content);
                                        session.OverallCorrectnessPercentage = overallCorrectnessPercentage;
                                    }
                                    line = sr.ReadLine();
                                }
                            }
                        }
                    }
                }
            }
            return(scoreboard);
        }
Пример #19
0
 public MPAiSpeakScoreBoard(MPAiUser user)
 {
     this.user = user;
 }