public CardPreview(Card cardToDisplay, Dictionary dictionary)
        {
            card = cardToDisplay;
            dic = dictionary;

            InitializeComponent();
        }
Exemple #2
0
 /// <summary>
 /// Applies the permissions to the interface.
 /// </summary>
 /// <param name="card">The card.</param>
 /// <remarks>Documented by Dev03, 2009-01-19</remarks>
 public void ApplyPermissions(Card card)
 {
     //TODO implement CardEdit.ApplyPermissions()
 }
Exemple #3
0
        /// <summary>
        /// Handles the Click event of the buttonPreview control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>Documented by Dev05, 2008-01-04</remarks>
        private void buttonPreview_Click(object sender, EventArgs e)
        {
            Card card, styleCard = null;

            //[ML-783] Maintain card: preview only after saving changes! - allways create a new
            card = new Card(new MLifter.DAL.Preview.PreviewCard(null), dictionary);
            if (!newCard)
                styleCard = Dictionary.Cards.GetCardByID(this.CardID);  //[ML-917] Preview of maintain card doesn't work correct

            bool modified = this.Modified; //[ML-734] SetCardValues resets the Modified-value and disables the add-button
            int cardId = this.CardID;   //[ML-908] Maintain card; Add/Edit Style crashes
            SetCardValues(card.BaseCard);
            this.Modified = modified;
            this.CardID = cardId;

            //[ML-917] Preview of maintain card doesn't work correct
            if (!newCard && (styleCard != null) && (styleCard.BaseCard != null) && (styleCard.BaseCard.Settings != null) && (styleCard.BaseCard.Settings.Style != null))
                card.BaseCard.Settings.Style = styleCard.BaseCard.Settings.Style;

            CardPreview preview = new CardPreview(card, dictionary);
            preview.ShowDialog();
            //cleanup
            if ((card != null) && (card.BaseCard != null)) card.BaseCard.Dispose();
        }
Exemple #4
0
        /// <summary>
        /// Generates the card.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <param name="side">The side.</param>
        /// <param name="answer">The answer.</param>
        /// <param name="correct">if set to <c>true</c> [correct].</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2008-01-04</remarks>
        public string GenerateCard(Card card, Side side, string answer, bool correct)
        {
            XmlNode cardNode = (XmlNode)card.BaseCard.Card;
            XmlDocument cardDocument = new XmlDocument();
            cardDocument.CreateXmlDeclaration("1.0", "utf-16", "");
            cardDocument.LoadXml(cardNode.OuterXml);

            //PrepareMedia(cardDocument);

            XsltArgumentList xsltArguments = new XsltArgumentList();
            xsltArguments.AddParam("correctAnswerText", string.Empty, Properties.Resources.XSL_CORRECT);
            xsltArguments.AddParam("correctFeedbackText", string.Empty, Properties.Resources.XSL_FEEDBACK_CORRECT);
            xsltArguments.AddParam("wrongFeedbackText", string.Empty, Properties.Resources.XSL_FEEDBACK_WRONG);
            xsltArguments.AddParam("youEnteredText", string.Empty, Properties.Resources.XSL_YOUENTERED);
            xsltArguments.AddParam("clickForQuestion", string.Empty, Properties.Resources.XSL_CLICKFORQ);
            xsltArguments.AddParam("clickForExample", string.Empty, Properties.Resources.XSL_CLICKFORE);
            xsltArguments.AddParam("resizePicture", string.Empty, Properties.Resources.XSL_RESIZE_PICTURE);
            xsltArguments.AddParam("restorePicture", string.Empty, Properties.Resources.XSL_RESTORE_PICTURE);
            xsltArguments.AddParam("listeningModeText", string.Empty, Properties.Resources.XSL_LISTENING_MODE_IMAGE_BUTTON_TEXT);
            xsltArguments.AddParam("userAnswer", string.Empty, answer);
            xsltArguments.AddParam("correct", string.Empty, correct ? "true" : "false");

            // pass through what mode(s) we are in
            if (card.BaseCard is PreviewCard)
                xsltArguments.AddParam("slideshowMode", string.Empty, true.ToString().ToLower());
            else
                xsltArguments.AddParam("slideshowMode", string.Empty, this.CurrentLearnLogic.SlideShow.ToString().ToLower());
            xsltArguments.AddParam("selfAssessmentMode", string.Empty, this.Settings.SelfAssessment.ToString().ToLower());
            xsltArguments.AddParam("learningBox", string.Empty, this.LearningBox);
            xsltArguments.AddParam("cardBox", string.Empty, card.BaseCard.Box);

            // the promoted property of CardStateChangedShowResultEventArgs is passed through as bool correct
            xsltArguments.AddParam("promoted", string.Empty, correct ? "true" : "false");

            string promoteMessage;
            if (card.BaseCard.Box == 10)
            {
                promoteMessage = Properties.Resources.XSL_PROMOTE_HIGHEST_MESSAGE;
            }
            else
            {
                promoteMessage = Properties.Resources.XSL_PROMOTE_MESSAGE.Replace("{box_number}", card.BaseCard.Box.ToString());
            }

            xsltArguments.AddParam("promotedMessage", string.Empty, promoteMessage);
            xsltArguments.AddParam("demotedMessage", string.Empty, Properties.Resources.XSL_DEMOTE_MESSAGE);
            //in case we are in self assement mode
            xsltArguments.AddParam("selfassesmentDemotedMessage", string.Empty, Properties.Resources.XSL_SELFASSESMENT_DEMOTE_MESSAGE);
            xsltArguments.AddParam("selfassesmentPromotedMessage", string.Empty, Properties.Resources.XSL_SELFASSESMENT_PROMOTE_MESSAGE);

            switch (LearnMode)
            {
                case LearnModes.Sentence:
                    xsltArguments.AddParam("mode", string.Empty, "sentencemode");
                    break;
                case LearnModes.ListeningComprehension:
                    xsltArguments.AddParam("mode", string.Empty, "listeningmode");
                    break;
                case LearnModes.ImageRecognition:
                    xsltArguments.AddParam("mode", string.Empty, "imagemode");
                    break;
                case LearnModes.MultipleChoice:
                case LearnModes.Word:
                default:
                    xsltArguments.AddParam("mode", string.Empty, "wordmode");
                    break;
            }

            xsltArguments.AddParam("displayImages", string.Empty, Settings.ShowImages.Value ? "true" : "false");
            xsltArguments.AddParam("question2answer", string.Empty, Settings.QueryDirections.Question2Answer.Value ? "true" : "false");
            xsltArguments.AddParam("autoPlaySound", string.Empty, Settings.AutoplayAudio.Value ? "true" : "false");
            xsltArguments.AddParam("baseURL", string.Empty,
                Uri.UnescapeDataString(new Uri(DirectoryName.Replace(@"\", @"/")).AbsoluteUri) + "/");
            xsltArguments.AddParam("stylePath", string.Empty,
                Uri.UnescapeDataString(new Uri(StylePath).AbsoluteUri) + "/");
            xsltArguments.AddExtensionObject("urn:cardobject", card);

            XsltSettings settings = new XsltSettings(false, false);     //disable scripts and document()

            string stylesheet = string.Empty;
            CompiledTransform? ct = card.BaseCard.Settings != null ? (side == Side.Question ? card.BaseCard.Settings.QuestionStylesheet : card.BaseCard.Settings.AnswerStylesheet) : null;

            if (!xslTransformer.ContainsKey(side) || xslTransformer[side] == null)
            #if DEBUG
                xslTransformer[side] = new XslCompiledTransform(true);
            #else
                xslTransformer[side] = new XslCompiledTransform();
            #endif

            if (!CurrentlyLoadedStyleSheet.ContainsKey(side) || CurrentlyLoadedStyleSheet[side] == null)
                CurrentlyLoadedStyleSheet[side] = string.Empty;

            if (!UseDictionaryStyleSheets || !ct.HasValue || !(ct.HasValue && File.Exists(ct.Value.Filename)) || dictionary.Version <= 266)
            {
                stylesheet = (side == Side.Question ? QuestionStyleSheet : AnswerStyleSheet);

                if (CurrentlyLoadedStyleSheet[side] != stylesheet)
                {
                    CurrentlyLoadedStyleSheet[side] = stylesheet;
                    xslTransformer[side].Load(stylesheet, settings, new XmlUrlResolver());
                }
            }
            else
            {
                if (CurrentlyLoadedStyleSheet[side] != ct.Value.XslContent)
                {
                    CurrentlyLoadedStyleSheet[side] = ct.Value.XslContent;
                    xslTransformer[side].Load(XmlTextReader.Create(new StringReader(ct.Value.XslContent)), settings, new XmlUrlResolver());
                }
            }

            StringWriter htmlContent = new StringWriter();

            try
            {
                xslTransformer[side].Transform(cardDocument, xsltArguments, htmlContent);
            }
            catch (InvalidOperationException exp)   //Needed to prevent error during loading while the load-Method did not deliver any error...
            {
                Trace.WriteLine("Generate HTML Exception: " + exp.ToString());
                if (File.Exists(CurrentlyLoadedStyleSheet[side]))
                    xslTransformer[side].Load(CurrentlyLoadedStyleSheet[side], new XsltSettings(false, false), new XmlUrlResolver());
                else
                    xslTransformer[side].Load(XmlTextReader.Create(new StringReader(CurrentlyLoadedStyleSheet[side])), new XsltSettings(false, false), new XmlUrlResolver());
                xslTransformer[side].Transform(cardDocument, xsltArguments, htmlContent);
            }

            string content = htmlContent.ToString();
            #if DEBUG
            try
            {
                File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), String.Format("{0}.html", side.ToString())), content);
            }
            catch { }
            #endif
            return content;
        }
 /// <summary>
 /// Displays the priview.
 /// </summary>
 /// <param name="card">The card.</param>
 /// <remarks>Documented by Dev05, 2009-10-13</remarks>
 private void DisplayPreview(Card card)
 {
     switch (Display)
     {
         case DisplayTyp.Question:
             stylePreview.Url = MLifter.DAL.DB.DbMediaServer.DbMediaServer.PrepareQuestion(dictionary.DictionaryDAL.Parent, card.BaseCard.Id,
                 dictionary.GenerateCard(card, MLifter.DAL.Interfaces.Side.Question, String.Empty, false));
             break;
         case DisplayTyp.AnswerCorrect:
             stylePreview.Url = MLifter.DAL.DB.DbMediaServer.DbMediaServer.PrepareAnswer(dictionary.DictionaryDAL.Parent, card.BaseCard.Id,
                 dictionary.GenerateCard(card, MLifter.DAL.Interfaces.Side.Answer, Properties.Resources.XSLEDIT_USERANSWER, true));
             break;
         case DisplayTyp.AnswerWrong:
             stylePreview.Url = MLifter.DAL.DB.DbMediaServer.DbMediaServer.PrepareAnswer(dictionary.DictionaryDAL.Parent, card.BaseCard.Id,
                 dictionary.GenerateCard(card, MLifter.DAL.Interfaces.Side.Answer, Properties.Resources.XSLEDIT_USERANSWER, false));
             break;
     }
 }
Exemple #6
0
        /// <summary>
        /// Asks a new card.
        /// </summary>
        /// <remarks>Documented by Dev02, 2008-04-23</remarks>
        private void AskNextCard()
        {
            if (!UserSessionAlive)
                return;

            if (Dictionary == null || Dictionary.Settings == null)
                return;

            //check wether it's time to enable the snooze mode
            if (!SnoozeModeActive && Dictionary.Settings.SnoozeOptions != null && Dictionary.Settings.SnoozeOptions.SnoozeMode.HasValue)
            {
                if (cardStack.CheckSnooze(Dictionary.Settings.SnoozeOptions))
                {
                    if (Dictionary.Settings.SnoozeOptions.SnoozeMode == MLifter.DAL.Interfaces.ESnoozeMode.SendToTray)
                    {
                        this.SnoozeModeActive = true;
                        return;
                    }
                    if (Dictionary.Settings.SnoozeOptions.SnoozeMode == MLifter.DAL.Interfaces.ESnoozeMode.QuitProgram)
                    {
                        if (SnoozeModeQuitProgram != null)
                        {
                            SnoozeModeQuitProgram(this, EventArgs.Empty);
                            return;
                        }
                    }
                }
            }

            //get next card
            ICard cCard = SlideShow ? Dictionary.GetNextSlide() : Dictionary.GetNextCard();

            if (cCard == null)
            {
                currentCardID = -1;
                OnUserDialog(new UserNotifyDialogEventArgs(Dictionary, -1, UserNotifyDialogEventArgs.NotifyDialogKind.NoWords));
                OnLearningModuleOptionsChanged();
                return;
            }

            currentCardID = cCard.Id;

            //Use card / chapter settings
            if (!SlideShow)
            {
                hasLearnModeChangedAndNotifyUser = false;
                originalLearnMode = Dictionary.LearnMode;
                int currentChapterId = cCard.Chapter;
                CheckAndAdjustSettings(Dictionary.Chapters.GetChapterByID(currentChapterId).Settings);
                CheckAndAdjustSettings(cCard.Settings);

                //check if there are enough choices available for mutliple choice
                hasMultipleChoiceLearnModeChanged = false;
                if (Dictionary.LearnMode == LearnModes.MultipleChoice &&
                    !Dictionary.ChoicesAvailable(cCard, Dictionary.CurrentMultipleChoiceOptions.NumberOfChoices.Value))
                {
                    hasMultipleChoiceLearnModeChanged = true;
                    Dictionary.LearnMode = LearnModes.Word; //switch to fail-safe word mode
                }

                //check if image / audio is available, switch back to fail-safe word mode otherwise
                if ((Dictionary.LearnMode == LearnModes.ImageRecognition && !Dictionary.Cards.ImageAvailable(cCard, Side.Question))
                 || (Dictionary.LearnMode == LearnModes.ListeningComprehension && !Dictionary.Cards.AudioAvailable(cCard, Side.Question))
                 || (Dictionary.LearnMode == LearnModes.Sentence && !Dictionary.Cards.SentenceAvailable(cCard, Side.Answer)))
                {
                    originalLearnMode = Dictionary.LearnMode;
                    hasLearnModeChangedAndNotifyUser = true;
                    Dictionary.LearnMode = LearnModes.Word;
                }
            }
            else
            {
                //disable timer if enabled
                if (Dictionary.Settings.EnableTimer.HasValue && Dictionary.Settings.EnableTimer.Value)
                    StopCountdownTimer();
            }

            Debug.WriteLine("New card asked: " + currentCardID);

            //save timestamp
            currentCardAsked = DateTime.Now.ToUniversalTime();

            //set the current directory for the browsers
            if (!String.IsNullOrEmpty(Dictionary.DirectoryName))
                System.IO.Directory.SetCurrentDirectory(Dictionary.DirectoryName);

            //fire the event to load the new card
            if (SlideShow)
                OnCardStateChanged(new CardStateChangedShowResultEventArgs(Dictionary, currentCardID, true, AnswerResult.Correct, string.Empty, SlideShow, false));
            else
                OnCardStateChanged(new CardStateChangedNewCardEventArgs(Dictionary, currentCardID));

            //activate countdown timer
            if (Dictionary.Settings.EnableTimer.HasValue && Dictionary.Settings.EnableTimer.Value && !SlideShow)
            {
                //determine the countdown timer out of the card
                Card currentCard = new Card(cCard, Dictionary);
                int countdownseconds = 0;

                if (currentCard != null && currentCard.CurrentAnswer != null)
                    countdownseconds = currentCard.CurrentAnswer.ToQuotedString().Length + 10 * currentCard.CurrentAnswer.Words.Count;

                if (countdownseconds < CountDownTimerMinimum)
                    countdownseconds = CountDownTimerMinimum;

                CardStateChangedCountdownTimerEventArgs args = new CardStateChangedCountdownTimerEventArgs(Dictionary, currentCardID, countdownseconds);
                OnCardStateChanged(args);

                //deactivate countdown timer
                StopCountdownTimer();

                //set up new timer
                countdownTimer = new Timer();
                countdownTimer.Tag = args;
                countdownTimer.Interval = 1000;
                countdownTimer.Tick += new EventHandler(countdownTimer_Tick);
                countdownTimer.Start();
            }

            #region Show all Infobars at least

            if (hasLearnModeChangedAndNotifyUser && !SlideShow)
                OnUserDialog(new UserNotifyDialogEventArgs(Dictionary, currentCardID, UserNotifyDialogEventArgs.NotifyDialogKind.SelectedLearnModeNotAllowed, originalLearnMode));
            if (hasMultipleChoiceLearnModeChanged && !SlideShow)
                OnUserDialog(new UserNotifyDialogEventArgs(Dictionary, currentCardID, UserNotifyDialogEventArgs.NotifyDialogKind.NotEnoughMultipleChoices));

            #endregion
        }