Пример #1
0
    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);
    }
Пример #2
0
    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);
    }
Пример #3
0
 static string FormatTell(TellEntry entry)
 {
     return(string.Format("Sent by {0}, {1} ago: {2}",
                          entry.From, Format.DurationWithDays(entry.ElapsedTime),
                          entry.Message));
 }