public void ICardClearAllMediaTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    ICard  card      = writeLM.Cards.AddNew();
                    string testImage = TestInfrastructure.GetTestImage();
                    IMedia media     = card.CreateMedia(EMedia.Image, testImage, true, true, true);

                    for (int i = 0; i < 5; i++)
                    {
                        card.AddMedia(media, Side.Question);
                        card.AddMedia(media, Side.Answer);
                    }
                    card.ClearAllMedia();
                    Assert.AreEqual(0, card.AnswerMedia.Count, "Media couldn't be cleared from ICard");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "Media couldn't be cleared from ICard");
                    try { File.Delete(testImage); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemple #2
0
        public void ICardAddImagePerformanceTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            IMedia media;

            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    Tools.TestStopWatch.Start(TestContext);
                    ICard  card      = writeLM.Cards.AddNew();
                    string testImage = TestInfrastructure.GetLargeTestImage();
                    media = card.CreateMedia(EMedia.Image, testImage, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (image) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (image) to an AnswerMedia");
                    card.ClearAllMedia();
                    Tools.TestStopWatch.Stop(TestContext);
                    try { File.Delete(testImage); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
        public void ICardAddMediaTest()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            IMedia media;

            if (TestInfrastructure.IsActive(TestContext))
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    ICard  card      = writeLM.Cards.AddNew();
                    string testImage = TestInfrastructure.GetTestImage();
                    media = card.CreateMedia(EMedia.Image, testImage, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (image) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (image) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (image) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (image) to an QuestionMedia");
                    card.ClearAllMedia();

                    string testAudio = TestInfrastructure.GetTestAudio();
                    //With the following parameters, the audiofile is saved 2 times
                    media = card.CreateMedia(EMedia.Audio, testAudio, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    media = card.CreateMedia(EMedia.Audio, testAudio, true, false, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    media = card.CreateMedia(EMedia.Audio, testAudio, true, true, false);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    media = card.CreateMedia(EMedia.Audio, testAudio, true, false, false);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (audio) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (audio) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (audio) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (audio) to an QuestionMedia");
                    card.ClearAllMedia();

                    string testVideo = TestInfrastructure.GetTestVideo();
                    media = card.CreateMedia(EMedia.Video, testVideo, true, true, true);
                    card.AddMedia(media, Side.Question);
                    Assert.AreEqual(1, card.QuestionMedia.Count, "ICard doesn't save a QuestionMedia (video) with the method 'card.AddMedia(Media, Side.Question)'");
                    Assert.AreEqual(0, card.AnswerMedia.Count, "ICard saves a QuestionMedia (video) to an AnswerMedia");
                    card.ClearAllMedia();
                    card.AddMedia(media, Side.Answer);
                    Assert.AreEqual(1, card.AnswerMedia.Count, "ICard doesn't save an AnswerMedia (video) with the method 'card.AddMedia(Media, Side.Answer)'");
                    Assert.AreEqual(0, card.QuestionMedia.Count, "ICard saves a AnswerMedia (video) to an QuestionMedia");
                    card.ClearAllMedia();

                    try { File.Delete(testImage); }
                    catch { }
                    try { File.Delete(testAudio); }
                    catch { }
                    try { File.Delete(testVideo); }
                    catch { }
                }
            }

            TestInfrastructure.DebugLineEnd(TestContext);
        }
Exemple #4
0
        /// <summary>
        /// Sets the card values.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <remarks>Documented by Dev05, 2007-10-12</remarks>
        private void SetCardValues(ICard card)
        {
            card.Answer.ClearWords();
            card.Question.ClearWords();
            card.Answer.AddWords(GetWord(Side.Answer).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
            card.Question.AddWords(GetWord(Side.Question).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
            card.AnswerDistractors.ClearWords();
            card.QuestionDistractors.ClearWords();
            card.AnswerDistractors.AddWords(GetDistractors(Side.Answer).ToArray());
            card.QuestionDistractors.AddWords(GetDistractors(Side.Question).ToArray());

            card.AnswerExample.ClearWords();
            card.AnswerExample.AddWord(card.AnswerExample.CreateWord(textBoxAnswerExample.Text, WordType.Sentence, false));
            card.QuestionExample.ClearWords();
            card.QuestionExample.AddWord(card.QuestionExample.CreateWord(textBoxQuestionExample.Text, WordType.Sentence, false));

            if (comboBoxChapter.SelectedItem != null && comboBoxChapter.SelectedItem is IChapter)
                card.Chapter = ((IChapter)comboBoxChapter.SelectedItem).Id;
            card.Active = checkBoxActive.Checked;

            card.ClearAllMedia(false);

            try
            {
                this.Parent.Enabled = false;        //ML-2413, maintain doesn't block user inputs while loading stuff into db
                //currently only the DB can show a progress bar
                card.CreateMediaProgressChanged += new StatusMessageEventHandler(card_CreateMediaProgressChanged);
                statusDialog = new LoadStatusMessage(Resources.CARDEDIT_LOADING_MEDIA_TO_DB, 100, dictionary.IsDB);
                if (!(card is DAL.Preview.PreviewCard)) statusDialog.Show();
                statusDialog.SetProgress(0);

                //Image
                if (pictureBoxAnswer.Tag as IImage != null)
                {
                    if (checkBoxResizeAnswer.Checked)
                        ResizePicture(pictureBoxAnswer);
                    card.AddMedia(pictureBoxAnswer.Tag as IMedia, Side.Answer);
                }
                if (pictureBoxQuestion.Tag as IImage != null)
                {
                    if (checkBoxResizeQuestion.Checked)
                        ResizePicture(pictureBoxQuestion);

                    IMedia media = pictureBoxQuestion.Tag as IMedia;
                    media = card.AddMedia(media, Side.Question);

                    if (checkBoxSamePicture.Checked)
                        card.AddMedia(media, Side.Answer);
                }

                //Audio
                if (buttonAnswerAudio.Tag as IAudio != null)
                    card.AddMedia(buttonAnswerAudio.Tag as IMedia, Side.Answer);
                if (buttonAnswerExampleAudio.Tag as IAudio != null)
                    card.AddMedia(buttonAnswerExampleAudio.Tag as IMedia, Side.Answer);
                if (buttonQuestionAudio.Tag as IAudio != null)
                    card.AddMedia(buttonQuestionAudio.Tag as IMedia, Side.Question);
                if (buttonQuestionExampleAudio.Tag as IAudio != null)
                    card.AddMedia(buttonQuestionExampleAudio.Tag as IMedia, Side.Question);

                //video
                if (buttonAnswerVideo.Tag as IVideo != null)
                    card.AddMedia(buttonAnswerVideo.Tag as IMedia, Side.Answer);
                if (buttonQuestionVideo.Tag as IVideo != null)
                    card.AddMedia(buttonQuestionVideo.Tag as IMedia, Side.Question);

                if (card.Active)
                {
                    int oldBox = card.Box;
                    card.Box = comboBoxCardBox.SelectedIndex;
                    int newBox = card.Box;

                    if (oldBox != newBox)
                    {
                        LearnLogStruct lls = new LearnLogStruct();
                        lls.CardsID = card.Id;
                        lls.SessionID = Log.LastSessionID;
                        lls.MoveType = MoveType.Manual;
                        lls.OldBox = oldBox;
                        lls.NewBox = newBox;
                        //Dummy values:
                        lls.TimeStamp = DateTime.Now;
                        lls.Duration = 0;
                        lls.CaseSensitive = false;
                        lls.CorrectOnTheFly = false;
                        lls.Direction = EQueryDirection.Question2Answer;
                        lls.LearnMode = EQueryType.Word;

                        Log.CreateLearnLogEntry(lls, dictionary.DictionaryDAL.Parent);
                    }
                }

                CardID = card.Id;
                Modified = false;
            }
            catch
            {
                throw;
            }
            finally
            {
                this.Parent.Enabled = true;
                card.CreateMediaProgressChanged -= new StatusMessageEventHandler(card_CreateMediaProgressChanged);
                if (statusDialog != null)
                {
                    statusDialog.Close();
                    statusDialog = null;
                }
            }
        }
        /// <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;
        }