Beispiel #1
0
        static void Main(string[] args)
        {
            DateTime christmasThisYear = new DateTime(2014, 12, 25);
            string adultArchivePath = @"C:\Users\cgehrer\Documents\Visual Studio 2013\Projects\ChristmasPick\Archive\Adult\Archive.xml";
            IXMasArchivePersister adultPersister = new FileArchivePersister(adultArchivePath);
            string kidArchivePath = @"C:\Users\cgehrer\Documents\Visual Studio 2013\Projects\ChristmasPick\Archive\Kids\Archive.xml";
            IXMasArchivePersister kidPersister = new FileArchivePersister(kidArchivePath);

            IFamilyProvider familyProvider = new FileFamilyProvider(@"C:\Users\cgehrer\Documents\Visual Studio 2013\Projects\ChristmasPick\Archive\Gehred\GehredFamily.xml");
            FamilyTree gehredFamily = familyProvider.GetFamilies();

            XMasArchive kidArchive = kidPersister.LoadArchive();
            PersonCollection kids = gehredFamily.CreateChristmasKidList(christmasThisYear);
            XMasPickList kidPickList = kidArchive.GetPickListForYear(christmasThisYear);

            XMasArchive adultArchive = adultPersister.LoadArchive();
            PersonCollection adults = gehredFamily.CreateChristmasAdultList(christmasThisYear);
            XMasPickList adultPickList = adultArchive.GetPickListForYear(christmasThisYear);

            XMasPickListValidator validator = new XMasPickListValidator();

            var kidCheckList = validator.PickListToValidateWithPeopleList(kids, kidPickList);
            var adultCheckList = validator.PickListToValidateWithPeopleList(adults, adultPickList);

            OutputDiagnosticInfo(kidCheckList, "Kid Pick List");
            OutputDiagnosticInfo(adultCheckList, "Adult Pick List");

             /*           IDictionary<Person, ExchangeCheckSum> checkList = new Dictionary<Person, ExchangeCheckSum>();
            // For each adult create an entry, in that entry store two ints number of people buying a present for, and a number of presents being recieved.
            foreach (Person person in adults) {
                checkList.Add(person, new ExchangeCheckSum());
            }

            foreach (XMasPick pick in adultPickList)
            {
                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));
                }
            }
            */
        }
        static void Main(string[] args)
        {
            DateTime christmasThisYear = new DateTime(2016, 12, 25);
                  string adultArchivePath = @"C:\Users\gehredbo\Source\Hobby\ChristmasPick\Archive\Adult\Archive.xml";
                  string kidArchivePath = @"C:\Users\gehredbo\Source\Hobby\ChristmasPick\Archive\Kids\Archive.xml";
                  IXMasArchivePersister adultPersister = new FileArchivePersister(adultArchivePath);
                  IXMasArchivePersister kidPersister = new FileArchivePersister(kidArchivePath);
                  IFamilyProvider familyProvider = new FileFamilyProvider(@"C:\Users\gehredbo\Source\Hobby\ChristmasPick\Archive\Gehred\GehredFamily.xml");
                  // Go ahead and get family
                  FamilyTree gehredFamily = familyProvider.GetFamilies();
                  XMasArchive adultArchive = adultPersister.LoadArchive();
                  XMasArchive kidArchive = kidPersister.LoadArchive();
                  // Create two poeple collections
                  PersonCollection kidList = gehredFamily.CreateChristmasKidList(christmasThisYear);
                  PersonCollection adultList = gehredFamily.CreateChristmasAdultList(christmasThisYear);

                  IPickListRuleProvider kidRules = new KidListRuleProvider(gehredFamily, kidArchive, 5);
                  IPickListService picker = new PickListServiceAdvanced(new RandomNumberGenerator(kidList.Count), kidRules, kidList);
                  XMasPickList kidPicklist = picker.CreateChristmasPick(christmasThisYear);
                  XMasPickListValidator validation = new XMasPickListValidator();
                  try
                  {
                      var checkList = validation.PickListToValidateWithPeopleList(kidList, kidPicklist);
                      if (validation.isPickListValid(checkList))
                      {
                          kidArchive.Add(christmasThisYear.Year, kidPicklist);
                          kidPersister.SaveArchive(kidArchive);
                      }
                      else
                      {
                          Console.WriteLine("The kid pick list has errors. Nothing was saved.");
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("An exception occurred validating kids picklist: {0}", ex.ToString());
                  }

                  IPickListRuleProvider adultRules = new AdultListRuleProvider(gehredFamily, adultArchive, 5);
                  IPickListService adultPicker = new PickListServiceAdvanced(new RandomNumberGenerator(adultList.Count), adultRules, adultList);
                  XMasPickList adultPickList = adultPicker.CreateChristmasPick(christmasThisYear);

                  try
                  {
                      var checkList = validation.PickListToValidateWithPeopleList(adultList, adultPickList);
                      if (validation.isPickListValid(checkList))
                      {
                          adultArchive.Add(christmasThisYear.Year, adultPickList);
                          adultPersister.SaveArchive(adultArchive);
                      }
                      else
                      {
                          Console.WriteLine("The adult pick list has errors. Nothing was saved.");
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("An exception occurred: {0}", ex.ToString());
                  }
        }