Exemplo n.º 1
0
        /// <summary>
        /// Modifies the multiple cards.
        /// </summary>
        /// <remarks>Documented by Dev05, 2007-10-12</remarks>
        private void ModifyMultipleCards()
        {
            if (!Multiselect)
                return;

            Cursor = Cursors.WaitCursor;
            LoadStatusMessage statusMessage = new LoadStatusMessage(string.Format(Properties.Resources.CARDEDIT_STATUS_SAVING, cards.Length), cards.Length, true);
            statusMessage.Show();

            string[] question = GetWord(Side.Question).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            string[] answer = GetWord(Side.Answer).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            string questionExample = textBoxQuestionExample.Text;
            string answerExample = textBoxAnswerExample.Text;

            foreach (int id in cards)
            {
                Dictionary.Cards.ChangeCardOnDifference(id, question, answer, questionExample, answerExample,
                    (comboBoxChapter.SelectedItem is IChapter ? ((IChapter)comboBoxChapter.SelectedItem).Id : -1), Resources.MAINTAIN_UNCHANGED);

                ICard card = Dictionary.Cards.GetCardByID(id).BaseCard;
                if (checkBoxActive.CheckState != CheckState.Indeterminate)
                    if (card.Active != checkBoxActive.Checked)
                        card.Active = checkBoxActive.Checked;

                if (comboBoxCardBox.SelectedIndex != -1 && card.Active)
                {
                    card.Box = comboBoxCardBox.SelectedIndex;
                }

                //Save old Media objects
                Dictionary<string, IMedia> oldMedia = new Dictionary<string, IMedia>();
                IMedia media = null;
                if ((media = Dictionary.Cards.GetImageObject(card, Side.Answer, true)) != null)
                    oldMedia.Add("answerImage", media);
                if ((media = Dictionary.Cards.GetImageObject(card, Side.Question, true)) != null)
                    oldMedia.Add("questionImage", media);
                if ((media = Dictionary.Cards.GetAudioObject(card, Side.Answer, true, false, true)) != null)
                    oldMedia.Add("answerAudio", media);
                if ((media = Dictionary.Cards.GetAudioObject(card, Side.Question, true, false, true)) != null)
                    oldMedia.Add("questionAudio", media);
                if ((media = Dictionary.Cards.GetAudioObject(card, Side.Answer, false, true, true)) != null)
                    oldMedia.Add("answerExample", media);
                if ((media = Dictionary.Cards.GetAudioObject(card, Side.Question, false, true, true)) != null)
                    oldMedia.Add("questionExample", media);
                if ((media = Dictionary.Cards.GetVideoObject(card, Side.Answer, true)) != null)
                    oldMedia.Add("answerVideo", media);
                if ((media = Dictionary.Cards.GetVideoObject(card, Side.Question, true)) != null)
                    oldMedia.Add("questionVideo", media);

                card.ClearAllMedia(false);

                //Image
                if (pictureBoxAnswer.Tag as IImage != null && checkBoxSamePicture.CheckState != CheckState.Unchecked)
                    card.AddMedia(pictureBoxAnswer.Tag as IMedia, Side.Answer);
                else if (pictureBoxAnswer.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerImage") && checkBoxSamePicture.CheckState != CheckState.Unchecked)
                    card.AddMedia(oldMedia["answerImage"], Side.Answer);
                if (pictureBoxQuestion.Tag as IImage != null)
                {
                    IMedia image = pictureBoxQuestion.Tag as IMedia;
                    card.AddMedia(image, Side.Question);
                    if (checkBoxSamePicture.CheckState == CheckState.Checked)
                        card.AddMedia(image, Side.Answer);
                }
                else if (pictureBoxQuestion.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionImage"))
                {
                    IMedia image = oldMedia["questionImage"];
                    card.AddMedia(image, Side.Question);
                    if (checkBoxSamePicture.CheckState == CheckState.Checked)
                        card.AddMedia(image, Side.Answer);
                }

                //Audio
                if (buttonAnswerAudio.Tag as IAudio != null)
                    card.AddMedia(buttonAnswerAudio.Tag as IMedia, Side.Answer);
                else if (buttonAnswerAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerAudio"))
                    card.AddMedia(oldMedia["answerAudio"], Side.Answer);
                if (buttonAnswerExampleAudio.Tag as IAudio != null)
                    card.AddMedia(buttonAnswerExampleAudio.Tag as IMedia, Side.Answer);
                else if (buttonAnswerExampleAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerExample"))
                    card.AddMedia(oldMedia["answerExample"], Side.Answer);
                if (buttonQuestionAudio.Tag as IAudio != null)
                    card.AddMedia(buttonQuestionAudio.Tag as IMedia, Side.Question);
                else if (buttonQuestionAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionAudio"))
                    card.AddMedia(oldMedia["questionAudio"], Side.Question);
                if (buttonQuestionExampleAudio.Tag as IAudio != null)
                    card.AddMedia(buttonQuestionExampleAudio.Tag as IMedia, Side.Question);
                else if (buttonQuestionExampleAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionExample"))
                    card.AddMedia(oldMedia["questionExample"], Side.Question);

                //Video
                if (buttonAnswerVideo.Tag as IVideo != null)
                    card.AddMedia(buttonAnswerVideo.Tag as IMedia, Side.Answer);
                else if (buttonAnswerVideo.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerVideo"))
                    card.AddMedia(oldMedia["answerVideo"], Side.Answer);
                if (buttonQuestionVideo.Tag as IVideo != null)
                    card.AddMedia(buttonQuestionVideo.Tag as IMedia, Side.Question);
                else if (buttonQuestionVideo.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionVideo"))
                    card.AddMedia(oldMedia["questionVideo"], Side.Question);

                statusMessage.ProgressStep();
            }

            statusMessage.Close();

            Modified = false;
            OnMultiEdit(EventArgs.Empty);
            Cursor = Cursors.Default;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks the commentary sounds.
        /// </summary>
        /// <param name="one">The one.</param>
        /// <param name="two">The two.</param>
        /// <remarks>Documented by Dev10, 2008-29-09</remarks>
        private void checkCommentarySounds(Dictionary<CommentarySoundIdentifier, IMedia> one, Dictionary<CommentarySoundIdentifier, IMedia> two)
        {
            Assert.AreEqual<int>(one.Count, two.Count, "Number of commentary Sounds do not match");
            foreach (KeyValuePair<CommentarySoundIdentifier, IMedia> kvp in one)
            {
                if (two.ContainsKey(kvp.Key))
                {
                    Assert.IsTrue(checkMedia(two[kvp.Key], kvp.Value), "Media do not match");
                }
                else
                    Assert.Fail("Key is missing in one directory, in commentary Sounds");

            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the control with the specified connection (name).
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="connection">The connection.</param>
        /// <remarks>Documented by Dev05, 2009-03-03</remarks>
        public UserStruct? Initialize(ConnectionStringStruct connection, UserStruct lastUser)
        {
            ConnectionString = LearningModulesIndex.ConnectionsHandler.GetConnectionFromConnectionStringStruct(connection);
            if (ConnectionString == null)
            {
                LearningModulesIndexEntry entry = RecentLearningModules.GetRecentModules().Find(m => m.ConnectionString.ConnectionString == connection.ConnectionString);
                if (entry != null)
                    ConnectionString = entry.Connection;
            }

            ConnectionName = connection.Typ != DatabaseType.MsSqlCe ? (ConnectionString != null ? ConnectionString.Name : Resources.NO_CONNECTION_NAME) : Path.GetFileName(connection.ConnectionString);
            Connection = connection;

            if (connection.Typ == DatabaseType.MsSqlCe)
                comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDownList;
            else
                comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDown;

            #region error handling
            switch (lastUser.LastLoginError)
            {
                case LoginError.AlreadyLoggedIn:
                    EmulatedTaskDialog taskDialog = new EmulatedTaskDialog();
                    taskDialog.Title = Resources.TASKDIALOG_KICK_TITLE;
                    taskDialog.MainInstruction = string.Format(Resources.TASKDIALOG_KICK_MAIN, lastUser.UserName);
                    taskDialog.Content = string.Format(Resources.TASKDIALOG_KICK_CONTENT, ConnectionName);
                    taskDialog.CommandButtons = Resources.TASKDIALOG_KICK_BUTTONS;

                    taskDialog.VerificationText = string.Empty;
                    taskDialog.VerificationCheckBoxChecked = false;
                    taskDialog.Buttons = TaskDialogButtons.None;
                    taskDialog.MainIcon = TaskDialogIcons.Warning;
                    taskDialog.FooterIcon = TaskDialogIcons.Warning;
                    taskDialog.MainImages = new Image[] { Resources.system_log_out, Resources.processStopBig };
                    taskDialog.HoverImages = new Image[] { Resources.system_log_out, Resources.processStopBig };
                    taskDialog.CenterImages = true;
                    taskDialog.BuildForm();
                    DialogResult dialogResult = taskDialog.ShowDialog();

                    if (dialogResult != DialogResult.Cancel && taskDialog.CommandButtonClickedIndex == 0)
                    {
                        lastUser.CloseOpenSessions = true;
                        return lastUser;
                    }
                    else
                        AllowAutoLogin = false;
                    break;
                case LoginError.InvalidUsername:
                    TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_USER_TITLE, Resources.TASKDIALOG_WRONG_USER_MAIN, Resources.TASKDIALOG_WRONG_USER_CONTENT,
                        TaskDialogButtons.OK, TaskDialogIcons.Error);
                    break;
                case LoginError.InvalidPassword:
                    TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_PASSWORD_TITLE, Resources.TASKDIALOG_WRONG_PASSWORD_MAIN, Resources.TASKDIALOG_WRONG_PASSWORD_CONTENT,
                        TaskDialogButtons.OK, TaskDialogIcons.Error);
                    break;
                case LoginError.WrongAuthentication:
                case LoginError.ForbiddenAuthentication:
                    TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_TITLE, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_MAIN, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_CONTENT,
                        TaskDialogButtons.OK, TaskDialogIcons.Error);
                    break;
                case LoginError.NoError:
                default:
                    break;
            }
            #endregion

            labelHeader.Text = string.Format(Resources.LOGIN_HEADER_TEXT, ConnectionName);

            buttonCancel.Enabled = connection.Typ != DatabaseType.MsSqlCe;

            try
            {
                SetListItems();
                UpdateSelection(false);

                #region persitancy
                Stream outputStream = null;
                try
                {
                    BinaryFormatter binary = new BinaryFormatter();
                    IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly();
                    outputStream = new IsolatedStorageFileStream(Settings.Default.AuthDataFile, FileMode.Open, storageFile);
                    outputStream = new CryptoStream(outputStream, Rijndael.Create().CreateDecryptor(Encoding.Unicode.GetBytes("mlifter"), Encoding.Unicode.GetBytes("omicron")), CryptoStreamMode.Read);
                    persitancyData = binary.Deserialize(outputStream) as Dictionary<string, SavedUserData>;
                    outputStream.Close();
                }
                catch { persitancyData = new Dictionary<string, SavedUserData>(); }
                finally
                {
                    if (outputStream != null)
                        outputStream.Close();
                }

                if (ConnectionString != null && persitancyData.ContainsKey(ConnectionString.ConnectionString))
                {
                    SavedUserData data = persitancyData[ConnectionString.ConnectionString];
                    if (data.SaveUsername)
                    {
                        checkBoxSaveUsername.Checked = true;
                        ShowOptions = true;
                        comboBoxUserSelection.Text = data.Username;
                        if (data.SavePassword)
                        {
                            checkBoxSavePassword.Checked = true;
                            textBoxPassword.Text = data.Password;
                            textBoxPassword.Tag = PasswordType.Hashed;
                            if (data.AutoLogin)
                            {
                                checkBoxAutoLogin.Checked = true;
                                if (AllowAutoLogin && !MLifter.BusinessLayer.User.PreventAutoLogin)
                                {
                                    Login();
                                    return GetActualUser();
                                }
                            }
                            else
                                checkBoxAutoLogin.Checked = false;
                        }
                        else
                            checkBoxSavePassword.Checked = false;
                    }
                    else
                    {
                        checkBoxSaveUsername.Checked = false;
                        ShowOptions = false;
                    }
                }
                #endregion

                comboBoxUserSelection.Focus();

                if (lastUser.LastLoginError != LoginError.NoError)
                {
                    comboBoxUserSelection.Text = lastUser.UserName;
                    textBoxPassword.Text = string.Empty;
                    textBoxPassword.Tag = PasswordType.ClearText;
                }

                LoginError = lastUser.LastLoginError;
            }
            catch (ConnectionNotSetException ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return null;
        }