Beispiel #1
0
        private void SaveChangesToCard(IUserSet currentUserSet, ICard currentCard)
        {       
            Card existingCard = FindCard(currentUserSet, currentCard);
            Card modifiedCard = (Card)currentCard;

            Type typeOfExistingCard = existingCard.GetType();
            Type typeOfModifiedCard = modifiedCard.GetType();

            List<PropertyInfo> propertiesExistingCard = new List<PropertyInfo>(typeOfExistingCard.GetRuntimeProperties());
            List<PropertyInfo> propertiesModifiedCard = new List<PropertyInfo>(typeOfModifiedCard.GetRuntimeProperties());

            // check if the properties are changed in the meantime. Should not be.
            for (int i = 0; i < propertiesExistingCard.Count; i++)
            {
                if(propertiesExistingCard[i].Name == propertiesModifiedCard[i].Name)
                {
                    propertiesExistingCard[i].SetValue(existingCard, propertiesModifiedCard[i].GetValue(modifiedCard));
                }
                else
                {
                    throw new ArrayTypeMismatchException("Cannot save the modified Card information",
                                                            new Exception(
                                                                "The type of the card is changed, because the properties ofthe existing and modified cards are not the same "));
                }
            }
        }
Beispiel #2
0
        private Card FindCard(IUserSet currentUserSet, ICard currentCard)
        {
            foreach (var CardSet in currentUserSet.AllCardSets)
            {
                return CardSet.Cards.FirstOrDefault(x => x.ID == currentCard.ID);
            }

            return null;
        }
Beispiel #3
0
		public void ProcessResponse(IUserSet currentUserSet, int answerQuality)
		{
			new CardMaintainer().ModifyNextIteration(currentUserSet.CurrentCard, answerQuality);

            DateTime learnDay = Convert.ToDateTime(AppSettings.AppSettingsWrapper.GetSetting(AppSettings.AppSettingsKeyNames.ExpectedLearnDay));

			currentUserSet.CurrentCardSet = ComposeToLearnCardSet(currentUserSet.CurrentCardSet, learnDay);
			//NumberOfCardsInLearnSet(currentUserSet);

            SaveChangesToCard(currentUserSet, currentUserSet.CurrentCard);

			NextCard(currentUserSet, currentUserSet.CurrentCard);
		}
Beispiel #4
0
 private HostRoot()
 {
     _userSet     = new UserSet();
     this.UserSet = _userSet;
 }
Beispiel #5
0
		public void PreviousCard(IUserSet currentUserSet, ICard currentCard)
		{
			int index = currentUserSet.CurrentCardSet.Cards.IndexOf((Card)currentCard);
			index--;

			if (index < 0)
			{
				index = currentUserSet.CurrentCardSet.Cards.IndexOf(currentUserSet.CurrentCardSet.Cards.Last());
			}

			SetCardToShow(currentUserSet, index);
		}
Beispiel #6
0
        private int NumberOfCardsInLearnSet(IUserSet currentUserSet)
		{
			return currentUserSet.CurrentCardSet.Cards.Count;
		}
Beispiel #7
0
		public void setCurrentCardSet(IUserSet currentUserSet, string cardSetName = null)
		{
			if (cardSetName != null)
			{
				// notCovered
				currentUserSet.CurrentCardSet = currentUserSet.AllCardSets.Where(x => x.Name.Equals(cardSetName)).First();
				return;
			}

			currentUserSet.CurrentCardSet = currentUserSet.AllCardSets.First();
		}
Beispiel #8
0
		public void SetCardToShow(IUserSet currentUserSet, int index = 0)
		{
			// if there are no more cards to learn in the set, then show that to user
			if (currentUserSet.CurrentCardSet != null &&
				currentUserSet.CurrentCardSet.Cards.Count() == 0)
			{
				currentUserSet.CurrentCard = new Card() { Question = "No card to learn.", Answer = "No card to learn.", };
			}
			else
			{
				currentUserSet.CurrentCard = (Card)currentUserSet.CurrentCardSet.Cards[index];
			}
		}
Beispiel #9
0
		public void NextCard(IUserSet currentUserSet, ICard currentCard)
		{
			int index = currentUserSet.CurrentCardSet.Cards.IndexOf((Card)currentCard);
			index++;

			if (index >= currentUserSet.CurrentCardSet.Cards.Count() && index > 0)
			{
				// notCovered
				index = currentUserSet.CurrentCardSet.Cards.IndexOf(currentUserSet.CurrentCardSet.Cards.First());
			}

			SetCardToShow(currentUserSet, index);
		}
Beispiel #10
0
 public UserSetMaintainer(IUserSet userSet)
 {
     UserSet = userSet;
 }