Пример #1
0
        private int AddPersonToList(string personid, QDChatLine chatline, direction direction)
        {
            int personindex = INDEXNOTFOUND;

            personindex = List.FindIndex(x => personid == x.id);
            if (personindex == INDEXNOTFOUND)       //new name ID added, it was not found in the list
            {
                QDChatPerson newperson = new QDChatPerson();
                newperson.id              = personid;
                newperson.name            = personid;
                newperson.count           = 1;
                newperson.firstAppearance = chatline.timestamp;
                newperson.lastAppearance  = newperson.firstAppearance;
                newperson.numberOfLines   = chatline.NumberOfLines;
                List.Add(newperson);
            }
            else
            {
                List[personindex].count++;
                if (List[personindex].firstAppearance > chatline.timestamp)
                {
                    List[personindex].firstAppearance = chatline.timestamp;
                }
                if (List[personindex].lastAppearance < chatline.timestamp)
                {
                    List[personindex].lastAppearance = chatline.timestamp;
                }
                List[personindex].numberOfLines += chatline.NumberOfLines;
            }
            return(personindex);
        }
Пример #2
0
 public int SetSelectedPerson(int personindex)
 {
     if (personindex != INDEXNOTFOUND)
     {
         Selected      = List[personindex];
         Selected.isMe = (Selected.id == Me.id);
     }
     return(personindex);
 }
Пример #3
0
        private QDChatPerson ChangePersonName(string id, string name)
        {
            QDChatPerson foundPerson = QDPersons.ChangePersonName(id, name);

            if (foundPerson.id != "")
            {
                personSerializer.SerializeToXML();
            }
            return(foundPerson);
        }
Пример #4
0
        //
        public void WriteChatOfPerson(string filename, QDChatPerson qdperson)
        {
            string filetype = System.IO.Path.GetExtension(filename);

            if (filetype == "xlsx")
            {
                //Storage as Excel file
            }
            else
            {
                WriteTxtFile(filename, qdperson);
            }
        }
Пример #5
0
        private void WriteTxtFile(string targetfile, QDChatPerson qdperson)
        {
            string     me       = ((App)Application.Current).QDChatReaderData.MyName;
            FileStream file     = null;
            string     tempfile = Path.GetTempPath() + "qdchat.txt"; // GetTempFileName();

            try
            {
                file = new FileStream(tempfile, FileMode.Create);
                using (StreamWriter writer = new StreamWriter(file))
                {
                    foreach (QDChatLine chatline in this)
                    {
                        if (chatline.receiverid == qdperson.id || chatline.senderid == qdperson.id)
                        {
                            string workRow = "";
                            workRow += chatline.timestamp.ToString();
                            workRow += "\t" + ((chatline.chatdirection == 1) ? me: qdperson.name) + ":";
                            workRow += "\t" + chatline.chattext;
                            writer.WriteLine(workRow);
                        }
                    }
                }
            }
            finally
            {
                if (file != null)
                {
                    file.Dispose();
                }
            }
            try
            {
                if (File.Exists(tempfile))
                {
                    File.Copy(tempfile, targetfile, true);
                    if (File.Exists(targetfile))
                    {
                        File.Delete(tempfile);
                        System.Diagnostics.Process.Start(targetfile);
                    }
                }
            }
            catch
            {
                //no success
            }
        }
Пример #6
0
        public QDChatPerson ChangePersonName(string id, string name)
        {
            QDChatPerson foundPerson = new QDChatPerson();
            int          personindex = GetPersonIndexFromId(id);

            if (personindex != QDChatPersons.INDEXNOTFOUND)
            {
                List[personindex].name = name;
                if (Selected.id == id)
                {
                    Selected.name = name;
                }
                if (Me.id == id)
                {
                    Me.name = name;
                }
                //personSerializer.SerializeToXML();
                foundPerson = List[personindex];
            }
            return(foundPerson);
        }
Пример #7
0
 public int ReadFromChatList(QDChatList qdchatlist)
 {
     if (qdchatlist.Count > 0)
     {
         ResetCounter();
         foreach (QDChatLine chatline in qdchatlist)
         {
             AddPersonToList(chatline.senderid, chatline, direction.sender);
             AddPersonToList(chatline.receiverid, chatline, direction.receiver);
         }
         List.Sort(new QDPersonsCountComparer());
         List[0].isMe = true;
         Me           = List[0];
         if ((Selected.id == "") && (List.Count > 0))
         {
             Selected = List[1];
         }
         return(0);
     }
     else
     {
         return(-1);
     }
 }
Пример #8
0
 public bool isMe(QDChatPerson person)
 {
     return(person.id == Me.id);
 }