public static bool ListTimeSlots(string[] com) { if (com.Length < 2) { return(false); } if (com[0] != "list") { return(false); } if (com[1] != "timeslots") { return(false); } TimeSlotFile cf = Schedule.timeslots; if (com.Length >= 3 && com[2] == "archive") { cf = Schedule.timeslotsArchive; } Conzole.PrintLine("Found " + cf.Size() + " timeslots.", ConsoleColor.Magenta); for (int i = 0; i < cf.Size(); i++) { TimeSlot ts = cf.Get(i); Conzole.Print(Conzole.PadBefore(ts.startSec + ":" + ts.startMin + ":" + ts.startHou + " >> ", 12), ConsoleColor.Yellow); Conzole.Print(Conzole.PadBefore(ts.endSec + ":" + ts.endMin + ":" + ts.endHou, 8), ConsoleColor.Yellow); Conzole.Print(" - " + Conzole.PadAfter(ts.name, 50)); Conzole.Print("\n"); } return(true); }
public static bool ListDeadlines(string[] com) { if (com.Length < 2) { return(false); } if (com[0] != "list") { return(false); } if (com[1] != "deadlines") { return(false); } DeadlineFile df = Schedule.deadlines; DateTime limit = DateTime.MaxValue; if (com.Length >= 3 && com[2] == "archive") { df = Schedule.deadlinesArchive; } else if (com.Length >= 3 && com[2] == "past") { limit = DateTime.Now.AddSeconds(-1); } else if (com.Length >= 3) { limit = Logic.Limit(com[2]); } if (df.Size() == 0) { Conzole.PrintLine("No deadlines to show!", ConsoleColor.Magenta); return(false); } Conzole.PrintLine("Deadlines: ", ConsoleColor.Magenta); List <Deadline> dls = new List <Deadline>(); for (int i = 0; i < df.Size(); i++) { Deadline d = df.Get(i); if (d.deadline <= limit) { dls.Add(d); } } dls.Sort((p, q) => p.SecondsLeft().CompareTo(q.SecondsLeft())); for (int i = 0; i < dls.Count; i++) { Deadline l = dls[i]; Conzole.Print(Schedule.StrDateTime(l.deadline) + " - ", ConsoleColor.Yellow); string msg = ""; int left = l.SecondsLeft(); int abs = Math.Abs(left); int min = 60; int hour = min * 60; int day = hour * 24; if (abs < min * 5) { msg = Conzole.PadBefore(abs + "", 4) + " seconds - "; } else if (abs < hour) { msg = Conzole.PadBefore("" + (abs / min), 4) + " minutes - "; } else if (abs < day * 2) { msg = Conzole.PadBefore("" + (abs / hour), 4) + " hours - "; } else { msg = Conzole.PadBefore("" + (abs / day), 4) + " days - "; } if (left > 0) { msg = "Left: " + msg; } else { msg = "Past: " + msg; } ConsoleColor colour; if (left > 0) { colour = ConsoleColor.White; } else { colour = ConsoleColor.Red; } Conzole.Print(msg, colour); Conzole.Print(Conzole.PadAfter(l.title, 50) + " - ", ConsoleColor.Green); Conzole.Print(Conzole.PadAfter(l.category, 20) + "\n", ConsoleColor.Green); } return(true); }
public static bool InspectCard(string[] com) { if (com.Length < 3) { return(false); } if (com[0] != "inspect") { return(false); } if (com[1] != "card") { return(false); } DateTime dt; string firstPart; if (com[2] == "null") { firstPart = "0:0:0"; } else { firstPart = com[2]; } bool ok = Schedule.DateTimeFromString(firstPart + "-" + com[3], out dt); if (!ok) { Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red); return(false); } Card card; int index = 0; bool found = Schedule.cards.Get(dt, com[2] == "null", out card, out index); if (!found) { Conzole.PrintLine("Card not found", ConsoleColor.Red); return(false); } Conzole.Print("Title: ", ConsoleColor.Magenta); Conzole.PrintLine(Conzole.PadAfter(card.title, 100)); Conzole.Print("Category: ", ConsoleColor.Magenta); Conzole.PrintLine(Conzole.PadAfter(card.category, 97)); Conzole.Print("Start: ", ConsoleColor.Magenta); Conzole.PrintLine(Schedule.StrDateTime(card.start), ConsoleColor.Yellow); Conzole.Print("End: ", ConsoleColor.Magenta); Conzole.PrintLine(Schedule.StrDateTime(card.end), ConsoleColor.Yellow); Conzole.Print("Day: ", ConsoleColor.Magenta); Conzole.PrintLine(card.start.DayOfWeek.ToString()); Conzole.Print("Relativeness: ", ConsoleColor.Magenta); string msg; bool notPast = Logic.GetDayMessage(card.start, out msg); ConsoleColor col = notPast ? ConsoleColor.White : ConsoleColor.Red; Conzole.PrintLine(msg, col); TimeSpan res = card.end - card.start; Conzole.Print("Duration: ", ConsoleColor.Magenta); Conzole.PrintLine(res.Hours + " hours, " + res.Minutes + " minutes and " + res.Seconds + " seconds.", ConsoleColor.Yellow); Conzole.PrintLine("Content: ", ConsoleColor.Magenta); Conzole.PrintLine(card.content); return(true); }
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); }