Ejemplo n.º 1
0
        private void ChatScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (this.ChatGrid.RowDefinitions[0].Height != new GridLength(0))
            {
                if (this.ChatScrollViewer.VerticalOffset == 0 /*&&   this.ChatScrollViewer.ScrollableHeight != 0*/)
                {
                    if (ChatScrollViewerVerticalOffsetZeroPointerFixer)
                    {
                        DayMessageJournalSerializable s = XmlFunctions.GetDayJournal(CurrentChatID, LoadPrevLastChatFile());

                        if (s != null)
                        {
                            int index = 0;
                            foreach (var item in s.Messages)
                            {
                                var tmp_msg = new MessageUiForm(item.MessageText, item.SendDateTime, item.SenderName, item.DoesRead, item.DoesRead, item.MessageContentUrl)
                                {
                                    DoesRead          = item.DoesRead,
                                    MessageContentUrl = item.MessageContentUrl,
                                    MyTurn            = item.MyTurn,
                                    SenderName        = item.SenderName,
                                    SendDateTime      = item.SendDateTime
                                };

                                bool test_first_msg = false;
                                foreach (var i in this.MessageListBox.Items)
                                {
                                    if ((i as MessageUiForm).SendDateTime == tmp_msg.SendDateTime)
                                    {
                                        test_first_msg = true;
                                    }
                                }

                                if (!test_first_msg)
                                {
                                    MessageListBox.Items.Insert(index, tmp_msg);
                                    // MessageBox.Show($"{tmp_msg.MessageText}");
                                }
                                index++;
                            }
                            this.ChatScrollViewer.LineDown();
                            this.ChatScrollViewer.LineDown();
                            this.ChatScrollViewer.LineDown();
                            this.ChatScrollViewer.LineDown();
                            this.ChatScrollViewer.LineDown();
                            //MessageBox.Show(this.ChatScrollViewer.VerticalOffset.ToString());

                            GC.Collect();
                            ChatScrollViewerVerticalOffsetZeroPointerFixer = false;
                        }
                        //MessageBox.Show(CurrentLoadedDate.ToString());
                    }
                    else
                    {
                        ChatScrollViewerVerticalOffsetZeroPointerFixer = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static DayMessageJournalSerializable GetDayJournal(long chatID, string dateToFind)
        {
            //if (dateToFind == null)
            //    return null;

            DayMessageJournalSerializable userPreviewSerializableList = null;

            if (File.Exists(CreatePathToJournal(chatID, dateToFind)))
            {
                XmlSerializer formatter = new XmlSerializer(typeof(DayMessageJournalSerializable));

                using (FileStream fs = new FileStream(CreatePathToJournal(chatID, dateToFind), FileMode.OpenOrCreate)) {
                    userPreviewSerializableList = (DayMessageJournalSerializable)formatter.Deserialize(fs);
                    userPreviewSerializableList.Messages.Sort((x, y) => DateTime.Parse((x.SendDateTime)).CompareTo(DateTime.Parse((y.SendDateTime))));
                }
            }

            return(userPreviewSerializableList);
        }
Ejemplo n.º 3
0
        public static void UpdateDayJournal(IMessage message, long ID)
        {
            DayMessageJournalSerializable dayMessageJournalSerializable;

            if (File.Exists(CreatePathToJournal(ID, DateTime.Now.ToShortDateString())))
            {
                dayMessageJournalSerializable = GetDayJournal(ID, DateTime.Now.ToShortDateString());
                File.Delete(CreatePathToJournal(ID, DateTime.Now.ToShortDateString()));
            }
            else
            {
                dayMessageJournalSerializable = new DayMessageJournalSerializable();
            }

            dayMessageJournalSerializable.Messages.Add(new Message(message));

            XmlSerializer formatter = new XmlSerializer(typeof(DayMessageJournalSerializable));

            using (FileStream fs = new FileStream(CreatePathToJournal(ID, dayMessageJournalSerializable.CurrentDate), FileMode.OpenOrCreate)) {
                formatter.Serialize(fs, dayMessageJournalSerializable);
            }

            GC.Collect();
        }
Ejemplo n.º 4
0
        public static void WriteDayJournal(Message message, long ID, string OldMsgSendTime)
        {
            try {
                string        local_tmp_path = Properties.Resources.UserDataDirPath + "\\" + ID + "\\" + DateTime.Parse(message.SendDateTime).ToShortDateString() + Properties.Resources.SaveFormatter;
                XmlSerializer xmlSerializer  = new XmlSerializer(typeof(DayMessageJournalSerializable));

                //MessageBox.Show($"OLD SEND DATE TIME {OldMsgSendTime}\n NEW DATE TIME {message.SendDateTime}");
                string path_to_existing_file_remove = Properties.Resources.UserDataDirPath + "\\" + ID + "\\" + DateTime.Parse(OldMsgSendTime).ToShortDateString() + Properties.Resources.SaveFormatter;
                if (File.Exists(local_tmp_path))
                {
                    #region Creating and editing new journal

                    DayMessageJournalSerializable new_chat_journal = XmlFunctions.GetDayJournal(ID, DateTime.Parse(message.SendDateTime).ToShortDateString());
                    File.Delete(local_tmp_path);
                    new_chat_journal.Messages.Add(message);
                    new_chat_journal.Messages.Sort((x, y) => DateTime.Parse((x.SendDateTime)).CompareTo(DateTime.Parse((y.SendDateTime))));
                    //new_chat_journal.Messages.Reverse();

                    using (FileStream fs = new FileStream(CreatePathToJournal(ID, new_chat_journal.CurrentDate), FileMode.OpenOrCreate)) {
                        xmlSerializer.Serialize(fs, new_chat_journal);
                    }
                    //MessageBox.Show(message.MyTurn.ToString());

                    #endregion Creating and editing new journal
                }
                else
                {
                    DayMessageJournalSerializable new_chat_journal = new DayMessageJournalSerializable();
                    new_chat_journal.Messages.Add(new Message(message));
                    new_chat_journal.CurrentDate = DateTime.Parse(message.SendDateTime).ToShortDateString();

                    XmlSerializer formatter = new XmlSerializer(typeof(DayMessageJournalSerializable));

                    using (FileStream fs = new FileStream(CreatePathToJournal(ID, DateTime.Parse(message.SendDateTime).ToShortDateString()), FileMode.OpenOrCreate)) {
                        formatter.Serialize(fs, new_chat_journal);
                    }
                }

                #region Editing old journal

                if (File.Exists(path_to_existing_file_remove))
                {
                    var oldChat = GetDayJournal(ID, DateTime.Parse(OldMsgSendTime).ToShortDateString());

                    oldChat.Messages.Remove(oldChat.Messages.Find(x => x.SendDateTime == OldMsgSendTime));

                    if (File.Exists(path_to_existing_file_remove))
                    {
                        File.Delete(path_to_existing_file_remove);
                    }

                    if (oldChat.Messages.Count != 0)
                    {
                        using (FileStream fs = new FileStream(CreatePathToJournal(ID, oldChat.CurrentDate), FileMode.OpenOrCreate)) {
                            xmlSerializer.Serialize(fs, oldChat);
                        }
                    }
                }

                #endregion Editing old journal
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }

            GC.Collect();
        }