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));
                }
            }
            */
        }
Beispiel #2
0
        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");

              XMasArchive adultArchive = adultPersister.LoadArchive();
              XMasArchive kidArchive = kidPersister.LoadArchive();
              FamilyTree gehredFamily = familyProvider.GetFamilies();

              XMasPickList adultPickList = adultArchive.GetPickListForYear(christmasThisYear);
              XMasPickList kidPickList = kidArchive.GetPickListForYear(christmasThisYear);

              // Okay loop through each family.
              // For each family member
              // Determine if adult or child
              // Using the correct archive find that pick by subject
              // Write out a line as follows
              // For the [ChristmasDate] {Subject] will buy a ${Amount] for [Recipient]
              string pickMsg = "\tFor the Christmas of {0} {1} will buy a {2} gift for {3}";
              foreach (Family family in gehredFamily)
              {
            Console.WriteLine("");
            Console.WriteLine(string.Format("Master List for {0}", family.Name));
            foreach (Person person in family)
            {
              if (person.IsConsideredAChild(christmasThisYear))
              {
            decimal giftAmount = 20.00M;
            Person recipient = kidPickList.GetRecipientFor(person);
            Console.WriteLine(string.Format(pickMsg, christmasThisYear.Year, person.ToString(), giftAmount.ToString("c"), recipient.ToString()));
              }
              else
              {
            decimal giftAmount = 5.00M;
            Person recipient = adultPickList.GetRecipientFor(person);
            Console.WriteLine(string.Format(pickMsg, christmasThisYear.Year, person.ToString(), giftAmount.ToString("c"), recipient.ToString()));
              }
            }
            Console.WriteLine(string.Format("List complete for {0}", family.Name));
            Console.WriteLine("");
              }
        }
        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());
                  }
        }