static Schedule() { deadlines = new DeadlineFile("deadlineData"); cards = new CardFile("cardData"); deadlinesArchive = new DeadlineFile("deadlineArchiveData"); cardsArchive = new CardFile("cardsArchiveData"); timeslots = new TimeSlotFile("timerangeData"); timeslotsArchive = new TimeSlotFile("timerangeArchiveData"); }
public static bool CleanCards(string[] com) { if (com.Length < 2) { return(false); } if (com[0] != "clean") { return(false); } if (com[1] != "cards") { return(false); } Conzole.PrintLine("Deleting all cards that are past."); bool ok = Conzole.AreYouSure(); if (!ok) { Conzole.PrintLine("Did not delete anything.", ConsoleColor.Magenta); return(true); } DateTime limit = DateTime.Now.AddSeconds(-1); CardFile cf = Schedule.cards; List <Card> dls = new List <Card>(); for (int i = 0; i < cf.Size(); i++) { Card c = cf.Get(i); if (c.end <= limit) { dls.Add(c); } } for (int i = 0; i < dls.Count; i++) { Schedule.cardsArchive.Add(dls[i]); cf.Delete(dls[i]); } Schedule.cardsArchive.Write(); cf.Write(); Conzole.PrintLine("Succes!", ConsoleColor.Magenta); return(false); }
public static bool ListCards(string[] com) { if (com.Length < 2) { return(false); } if (com[0] != "list") { return(false); } if (com[1] != "cards") { return(false); } CardFile cf = Schedule.cards; DateTime limit = DateTime.MaxValue; int argIndex = 2; if (com.Length >= 3) { if (com[2] == "archive") { cf = Schedule.cardsArchive; argIndex = 3; } else if (com[2] == "past") { limit = DateTime.Now.AddSeconds(-1); argIndex = 3; } else { limit = Logic.Limit(com[2]); } } uint count; if (com.Length == argIndex + 1 && limit == DateTime.MaxValue) { bool ok = uint.TryParse(com[argIndex], out count); if (!ok) { Conzole.PrintLine("Could not convert \"" + com[argIndex] + "\" to a uint.", ConsoleColor.Red); return(false); } } else { count = 0; } List <Card> cards = new List <Card>(); for (int i = 0; i < cf.Size(); i++) { Card c = cf.Get(i); if (c.start <= limit) { cards.Add(c); } } cards.Sort((p, q) => p.start.CompareTo(q.end)); int max = cards.Count; if (count == 0) { count = (uint)max; } if (count > max) { count = (uint)max; } Conzole.PrintLine("Found " + count + " cards.", ConsoleColor.Magenta); for (int i = 0; i < count; i++) { Card c = cards[i]; Conzole.Print(Schedule.StrDateTime(c.start) + " >> ", ConsoleColor.Yellow); Conzole.Print(Schedule.StrDateTime(c.end) + " - ", ConsoleColor.Yellow); string msg; bool notPast = Logic.GetDayMessage(c.start, out msg); ConsoleColor col = notPast ? ConsoleColor.White : ConsoleColor.Red; Conzole.Print(msg + " - ", col); Conzole.Print(Conzole.PadAfter(c.title, 30) + " - "); Conzole.Print(Conzole.PadAfter(c.category, 20)); Conzole.Print("\n"); } return(true); }