public void Save(TellsInbox inbox) { string filename = Prefix + inbox.Username.ToLowerInvariant() + ".xml"; var path = Path.Combine(storagePath, filename); // Normal save. if (inbox.MessagesCount > 0) { using (var stream = File.Open(path, FileMode.Create)) { var settings = new XmlWriterSettings() { Indent = true, // Because tell messages can contain control codes that make the XmlWriter barf, // disable checking. Not ideal, but it seems to serialize and deserialize fine. CheckCharacters = false }; using (var writer = XmlWriter.Create(stream, settings)) dcs.WriteObject(writer, inbox); } } // Remove empty inbox from dict and clean up remnants of the inbox on disk. else { nickToInbox.Remove(inbox.Username); File.Delete(path); } }
public TellsInbox GetOrNew(string nick) { TellsInbox inbox; if (!nickToInbox.TryGetValue(nick, out inbox)) { inbox = new TellsInbox(nick); nickToInbox[nick] = inbox; } return(inbox); }