Пример #1
0
        public void WriteMessages()
        {
            foreach (var item in newMessages.AsEnumerable().Reverse())
            {
                messages.Insert(0, item);
            }
            using (StreamWriter sw = new StreamWriter(path))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, messages);
                }
            using (FileStream fstream = new FileStream(Environment.CurrentDirectory + PathContract.pathNew, FileMode.OpenOrCreate)) {
                string incoming = "";
                foreach (var item in newMessages)
                {
                    incoming += "Отправитель: " + item.sender + "   Получатель: " + item.reciver + "    Cообщение: " + item.message + Environment.NewLine;
                }
                fstream.SetLength(0);
                byte[] array = System.Text.Encoding.Unicode.GetBytes(incoming);
                fstream.Write(array, 0, array.Length);
            }
            IDbHelper db = new DbHelperSQLite();

            db.writeMessages(newMessages);
            messages.Clear();
            newMessages.Clear();
        }