Ejemplo n.º 1
0
        private void LoadChatMsgs()
        {
            var s = XmlFunctions.GetDayJournal(CurrentChatID, LoadLastChatFile().ToShortDateString());

            if (s != null)
            {
                foreach (var item in s.Messages)
                {
                    MessageListBox.Items.Add(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,
                    });
                }
                MoveChatScrollToDownEnd();
                //LastMSG = s.Messages.Last();

                //LastDateToLoad = DateTime.Parse(DateTime.Parse(s.Messages.First().SendDateTime).ToShortDateString());
            }

            GC.Collect();
        }
Ejemplo n.º 2
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.º 3
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();
        }