Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: dinners46.exe <path to roster file>");
                return;
            }

            Family[] roster;
            XmlSerializer rosterSerializer = new XmlSerializer(typeof(Family[]), new XmlRootAttribute("Roster"));
            using (FileStream fs = new FileStream(args[0], FileMode.Open))
            {
                roster = (Family[])rosterSerializer.Deserialize(fs);
            }

            History history;
            XmlSerializer historySerializer = new XmlSerializer(typeof(History));
            using (FileStream fs = new FileStream(@".\Resources\d46history.xml", FileMode.Open))
            {
                history = (History)historySerializer.Deserialize(fs);
            }

            Exclusion[] exclusions;
            XmlSerializer exclusionSerializer = new XmlSerializer(typeof(Exclusion[]), new XmlRootAttribute("Exclusions"));
            using (FileStream fs = new FileStream(@".\Resources\d46exclusions.xml", FileMode.Open))
            {
                exclusions = (Exclusion[])exclusionSerializer.Deserialize(fs);
            }

            GroupGenerator groupGenerator = new GroupGenerator(roster, exclusions, history);
            List<string> failures;
            int nTries = 0;
            do
            {
                groupGenerator.GenerateGroupsUsingRandomOrder(out failures);
                Console.WriteLine("Try: " + ++nTries);
            } while (failures.Count > 0);

            Group[] generatedGroups = groupGenerator.GeneratedGroups;
            if (failures.Count == 0)
            {
                Console.WriteLine("Success!");
                var newEntries = new List<HistoryEntry>(history.HistoryEntries);
                newEntries.Add(new HistoryEntry() { Formed = DateTime.Today, Groups = generatedGroups });
                History newHistory = new History() { HistoryEntries = newEntries.ToArray() };
                using (StreamWriter writer = new StreamWriter("d46history.out.xml"))
                {
                    historySerializer.Serialize(writer, newHistory);
                }

                XmlSerializer groupSerializer = new XmlSerializer(typeof(Group[]));
                using (StreamWriter writer = new StreamWriter("d46groups.out.xml"))
                {
                    groupSerializer.Serialize(writer, generatedGroups);
                }

            }
            else
            {
                Console.WriteLine("Failures detected: ");
                foreach (string s in failures)
                {
                    Console.WriteLine("\t" + s);
                }
            }

            Console.WriteLine("Groups:");
            int i = 1;
            foreach (Group g in generatedGroups)
            {
                Console.WriteLine("Group " + i++);
                Console.WriteLine(FormatContactInfo(roster, g));
            }

            if (failures.Count == 0)
            {
                Console.WriteLine("Send e-mail? y/n");
                if (Console.ReadLine() == "y")
                {
                    SendEmailToGroups(roster, generatedGroups);
                }
            }

            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
Ejemplo n.º 2
0
 public GroupGenerator(Family[] roster, Exclusion[] exclusions, History history)
 {
     _roster = roster;
     _exclusions = exclusions;
     _history = history;
 }