Exemplo n.º 1
0
        /// <summary>
        /// Adds a card to the currently loaded dictionary.
        /// </summary>
        /// <param name="questionText">CurrentQuestion Text</param>
        /// <param name="answerText">CurrentAnswer Text</param>
        /// <param name="questionExample">CurrentQuestion example</param>
        /// <param name="answerExample">CurrentAnswer example</param>
        /// <param name="questionStyle">CurrentQuestion stylesheet</param>
        /// <param name="answerStyle">CurrentAnswer stylesheet</param>
        /// <param name="chapter">Chapter ID</param>
        /// <returns>Card ID if successfull, -1 if failure</returns>
        /// <remarks>Documented by Dev05, 2007-09-03</remarks>
        public int AddCard(string questionText, string answerText, string questionExample,
                           string answerExample, string questionStyle, string answerStyle, int chapter)
        {
            try
            {
                dictionary.Chapters.GetChapterByID(chapter);
            }
            catch (IdAccessException)
            {
                return(-1);
            }

            ICard card = cards.AddNew();

            foreach (string word in answerText.Split(new char[] { ',', ';' }))
            {
                card.Answer.AddWord(card.Answer.CreateWord(word, WordType.Word, true));
            }
            foreach (string word in questionText.Split(new char[] { ',', ';' }))
            {
                card.Question.AddWord(card.Question.CreateWord(word, WordType.Word, true));
            }
            card.QuestionExample.AddWord(card.QuestionExample.CreateWord(questionExample.Trim('"'), WordType.Sentence, true));
            card.AnswerExample.AddWord(card.AnswerExample.CreateWord(answerExample.Trim('"'), WordType.Sentence, true));
            card.Settings.QuestionStylesheet = new CompiledTransform(questionStyle, null);
            card.Settings.AnswerStylesheet   = new CompiledTransform(answerStyle, null);
            card.Chapter = chapter;

            return(card.Id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public static void Copy(ICards source, ICards target, CopyToProgress progressDelegate)
        {
            source.Parent.GetParentDictionary().Chapters.CopyTo(target.Parent.GetParentDictionary().Chapters, progressDelegate);

            CopyBase.Copy(source, target, typeof(ICards), progressDelegate);
            int counter = 0;
            int count   = source.Cards.Count - (CardIdsNotToCopy != null ? CardIdsNotToCopy.Count : 0);
            Dictionary <int, int> chapterMappings = target.Parent.GetParentDictionary().Parent.Properties[ParentProperty.ChapterMappings] as Dictionary <int, int>;

            foreach (ICard card in source.Cards)
            {
                if (CardIdsNotToCopy != null && CardIdsNotToCopy.Contains(card.Id))
                {
                    continue;
                }

                ++counter;
                if (progressDelegate != null && counter % 5 == 0)
                {
                    progressDelegate.Invoke(String.Format(Properties.Resources.CARDS_COPYTO_STATUS, counter, count), counter * 1.0 / count * 100);
                }

                ICard newCard = target.AddNew();
                card.CopyTo(newCard, progressDelegate);
                newCard.Chapter = chapterMappings[card.Chapter];
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public static void Copy(ICards source, ICards target, CopyToProgress progressDelegate)
        {
            source.Parent.GetParentDictionary().Chapters.CopyTo(target.Parent.GetParentDictionary().Chapters, progressDelegate);

            CopyBase.Copy(source, target, typeof(ICards), progressDelegate);
            int counter = 0;
            int count = source.Cards.Count - (CardIdsNotToCopy != null ? CardIdsNotToCopy.Count : 0);
            Dictionary<int, int> chapterMappings = target.Parent.GetParentDictionary().Parent.Properties[ParentProperty.ChapterMappings] as Dictionary<int, int>;
            foreach (ICard card in source.Cards)
            {
                if (CardIdsNotToCopy != null && CardIdsNotToCopy.Contains(card.Id))
                    continue;

                ++counter;
                if (progressDelegate != null && counter % 5 == 0)
                    progressDelegate.Invoke(String.Format(Properties.Resources.CARDS_COPYTO_STATUS, counter, count), counter * 1.0 / count * 100);

                ICard newCard = target.AddNew();
                card.CopyTo(newCard, progressDelegate);
                newCard.Chapter = chapterMappings[card.Chapter];
            }
        }