Exemple #1
0
        private bool AddFile(string rawFile)
        {
            bool addFileResult = true;

            string rawFileName = rawFile.Substring(1, rawFile.IndexOf(" ") - 1);;

            if (!string.IsNullOrEmpty(rawFile))
            {
                if (int.TryParse(rawFile.Substring(rawFile.IndexOf(" ")), out int rawFileSize))
                {
                    OWLOSFile owlosNewFile = new OWLOSFile();
                    owlosNewFile.name = rawFileName;
                    owlosNewFile.size = rawFileSize;
                    filesList.Add(owlosNewFile);
                    OnNewFile?.Invoke(this, owlosNewFile);
                    owlosNewFile.networkStatus = NetworkStatus.Online;
                }
                else
                {
                    addFileResult = false;
                }
            }

            return(addFileResult);
        }
        public static void GetMessage(string[] splited, bool file = false)
        {
            if (splited.Length < 5)
            {
                return;
            }
            if (!int.TryParse(splited[1], out var sessionId) || !int.TryParse(splited[2], out var senderId) || !long.TryParse(splited[4], out var ticks) || !int.TryParse(splited[5], out var messageId))
            {
                return;
            }
            var     fromMe = Id == senderId;
            Message mess   = null;

            if (!file)
            {
                mess = new Message(false, messageId)
                {
                    DeliveryTime = new DateTime(ticks),
                    _rawMessage  = splited[3],
                    FromMe       = fromMe
                }
            }
            ;
            else
            {
                var dataSp = splited[3].Split(';');
                if (dataSp.Length < 2)
                {
                    return;
                }
                var fileName = dataSp[0];
                var data     = splited[3].Substring(fileName.Length + 1);
                mess = new File(fileName, messageId)
                {
                    DeliveryTime = new DateTime(ticks),
                    _rawMessage  = data,
                    FromMe       = fromMe
                };
                OnNewFile?.Invoke(mess as File);
            }
            if (fromMe)
            {
                Contacts[sessionId].Messages.Add(mess);
            }
            else
            {
                Contacts[senderId].Messages.Add(mess);
            }

            OnMessage?.Invoke(mess, sessionId, senderId);
        }
Exemple #3
0
 private void ProcessFile(FileInfo path)
 {
     OnNewFile?.Invoke(this, new FileEventArgs(path));
 }