public bool Add(string from, string tellMsg) { for (int i = 0; i < entries.Length; i++) { if (entries[i] == null) { entries[i] = new TellEntry(from, tellMsg); MessagesCount++; NewMessages = true; isSorted = false; return(true); } } return(false); }
public TellEntry[] Read(int amount) { TellEntry[] messages; if (amount > MessagesCount) { messages = new TellEntry[MessagesCount]; } else { messages = new TellEntry[amount]; } // Index over internal tell entries. int inboxIdx = 0; // Index over outgoing 'read' messages. int messagesIdx = 0; if (!isSorted) { Sort(entries); } while (inboxIdx < entries.Length && messagesIdx < messages.Length) { if (entries[inboxIdx] != null) { messages[messagesIdx] = entries[inboxIdx]; entries[inboxIdx] = null; messagesIdx++; } inboxIdx++; } MessagesCount = MessagesCount - messages.Length; NewMessages = false; isSorted = true; return(messages); }
static string FormatTell(TellEntry entry) { return(string.Format("Sent by {0}, {1} ago: {2}", entry.From, Format.DurationWithDays(entry.ElapsedTime), entry.Message)); }