public IDictionary<Person, ExchangeCheckSum> PickListToValidateWithPeopleList(PersonCollection personList, XMasPickList pickList)
        {
            IDictionary<Person, ExchangeCheckSum> checkList = new Dictionary<Person, ExchangeCheckSum>();

            foreach (Person person in personList)
            {
                checkList.Add(person, new ExchangeCheckSum());
            }

            foreach (XMasPick pick in pickList)
            {
                if (checkList.ContainsKey(pick.Recipient))
                {
                    checkList[pick.Recipient].updatePresentsIn();
                }
                else
                {
                    throw new Exception(string.Format("The recipient {0} is not found in adult list", pick.Recipient));
                }

                if (checkList.ContainsKey(pick.Subject))
                {
                    checkList[pick.Subject].updatePresentsOut();
                }
                else
                {
                    throw new Exception(string.Format("The subject {0} is not found in adult list", pick.Subject));
                }
            }

            return checkList;
        }
Exemplo n.º 2
0
        public XMasPickList CreateChristmasPick(DateTime evaluationDate)
        {
            int MaxAttemptsBeforeGivingUp = 10;
            PersonCollection alreadyPicked = new PersonCollection();
            XMasPickList thisYearPickList = new XMasPickList(evaluationDate);
            SortPickList(this.familyList, evaluationDate);

            for (int attempts = 1; attempts <= MaxAttemptsBeforeGivingUp; attempts++)
            {
                foreach (var subject in familyList)
                {
                    PersonCollection availableToBePicked = CreatePossiblePickList(subject, alreadyPicked);

                    if (availableToBePicked.Count == 0)
                    {
                        // Reset pick list creation info and try again.
                        alreadyPicked = new PersonCollection();
                        thisYearPickList = new XMasPickList(evaluationDate);
                        // throw new NotImplementedException("I have no idea how to handle this yet.");
                        Console.WriteLine("{0} had no available people to pick, attempt: {1} Reset lists and try again.", subject, attempts);
                        break;
                    }

                    if (availableToBePicked.Count > 1)
                    {
                        SortPickList(availableToBePicked, evaluationDate);
                        int tmpIndex = indexGenerator.GenerateNumberBetweenZeroAnd(availableToBePicked.Count);
                        Person toBuyPresentFor = availableToBePicked.GetAt((tmpIndex == 0) ? tmpIndex : (tmpIndex - 1));
                        alreadyPicked.Add(toBuyPresentFor);
                        thisYearPickList.Add(new XMasPick(subject, toBuyPresentFor));

                    }
                    else
                    {
                        Person toBuyPresentFor = availableToBePicked.GetAt(0);
                        alreadyPicked.Add(toBuyPresentFor);
                        thisYearPickList.Add(new XMasPick(subject, toBuyPresentFor));
                    }
                }

                Console.WriteLine("Verifing attempt: {0} ...", attempts);

                try
                {
                    // Throws exceptions if a person is not recieving a present.
                    foreach (Person person in familyList)
                    {
                        Person recipient = thisYearPickList.GetRecipientFor(person);
                    }
                    Console.WriteLine("Successfully created pick list in {0} attempts.", attempts);
                    break;
                }
                catch (Exception err)
                {
                    Console.WriteLine("Attempt {0} failed because {1}", attempts, err.ToString());
                }
            }

            return thisYearPickList;
        }
        protected XMasPickList CreateTestPickList()
        {
            XMasPickList testYear = new XMasPickList(2001);
              Person Dad = new Person("Tom", "Gehred", new DateTime(1936,3,5), "11111111-6666-3333-4444-555555555555");
              Person Mike = new Person("Mike", "Gehred", new DateTime(1954, 3, 18), "11111111-7777-3333-4444-555555555555");
              Person Jim = new Person("Jim", "Gehred", new DateTime(1963, 2, 13), "11111111-8888-3333-4444-555555555555");
              Person TonyI = new Person("Tony", "Ingrassia", new DateTime(1901, 3, 3), "11111111-9999-3333-4444-555555555555");

              testYear.Add(new XMasPick(Dad, Mike));
              testYear.Add(new XMasPick(Mike, Jim));
              testYear.Add(new XMasPick(Jim, TonyI));
              testYear.Add(new XMasPick(TonyI, Dad));

              return testYear;
        }
Exemplo n.º 4
0
 public void Add(int year, XMasPickList pickList)
 {
     DateTime key = new DateTime(year, 12, 25);
       if (!pickList.IsPickListForYear(key))
       {
     throw new ArgumentException(string.Format("Year of {0} does not match pickList date", year), "year/pickList");
       }
       else
       {
     if (mArchive.ContainsKey(key))
     {
       mArchive.Remove(key);
     }
     mArchive.Add(key, pickList);
       }
 }
Exemplo n.º 5
0
 public void ReadXml(XmlReader reader)
 {
     while (reader.IsStartElement())
       {
     XMasPickList tmp = new XMasPickList();
     tmp.ReadXml(reader);
     mArchive.Add(tmp.PickListDate, tmp);
       }
       reader.ReadEndElement();
 }
        protected XMasPickList CreateTestPickList(int year, string[] firstName)
        {
            XMasPickList testYear = new XMasPickList(year);

              for (int i = 0; i < firstName.GetLength(0); i++)
              {
            int index = i + 1;
            if (index >= firstName.GetLength(0))
              index = 0;

            Person subject = new Person(firstName[i], "Gehred", new DateTime(1972, 7, 27), string.Format("{0}5111111-2222-3333-4444-555555555555", i));
            Person recipient = new Person(firstName[index], "Gehred", new DateTime(1972, 7, 27), string.Format("5{0}111111-2222-3333-4444-555555555555", index));
            testYear.Add(new XMasPick(subject, recipient));
              }

              return testYear;
        }