Esempio n. 1
0
        public void Save()
        {
            MailsData data = new MailsData
            {
                MainCurrentID = MainCurrentID,
                Mails         = MailList.Values.ToList()
            };

            data.SaveTo(FILENAME);
        }
Esempio n. 2
0
        public void Load()
        {
            try
            {
                if (!File.Exists(FILENAME))
                {
                    CommandBoardcast.ConsoleMessage(GameLanguage.GetText("creatingMailsData"));
                    MailsData mailsData = new MailsData();
                    mailsData.SaveTo(FILENAME);
                    return;
                }

                CommandBoardcast.ConsoleMessage(GameLanguage.GetText("readingMailsData"));
                string data;
                using (var reader = new StreamReader(FILENAME, Encoding.UTF8))
                {
                    data = reader.ReadToEnd();
                }

                var list = JsonConvert.DeserializeObject <MailsData>(data);
                MainCurrentID = list.MainCurrentID;
                foreach (var mail in list.Mails)
                {
                    MailList.Add(mail.MailHead.MailID, mail);
                    var player = ServerSideCharacter2.PlayerCollection.Get(mail.MailHead.Recevier);
                    player?.MailList.Add(mail);
                }
                foreach (var pair in ServerSideCharacter2.PlayerCollection)
                {
                    pair.Value.MailList.Sort();
                }
                CommandBoardcast.ConsoleMessage(GameLanguage.GetText("finishReadPlayerDoc"));
            }
            catch (Exception ex)
            {
                CommandBoardcast.ConsoleError(ex);
            }
        }