public void ProcessOfflineContact(ContactIsOffline contactIsOffline) { ContactSectionViewModel.ProcessOfflineContact(contactIsOffline); }
private static void StartReceiving(Socket clientSocket) { MemoryStream stream = new MemoryStream(); const int BufferSize = 8192; byte[] buffer = new byte[BufferSize]; bool newPacket = true; int receivedBytes = 0; int unreceivedBytes = 0; PacketType PacketType = PacketType.None; try { while (true) { if (newPacket) { receivedBytes = clientSocket.Receive(buffer, BufferSize, SocketFlags.None); PacketType = (PacketType)BitConverter.ToInt32(buffer, 0); unreceivedBytes = BitConverter.ToInt32(buffer, 4); receivedBytes -= 8; unreceivedBytes -= receivedBytes; stream.Position = 0; stream.Write(buffer, 8, receivedBytes); newPacket = false; } else { receivedBytes = clientSocket.Receive(buffer, BufferSize, SocketFlags.None); unreceivedBytes -= receivedBytes; stream.Write(buffer, 0, receivedBytes); } if (unreceivedBytes == 0) // all fragments received { Task.Factory.StartNew(() => { ProcessPacket(clientSocket, PacketType, new MemoryStream(stream.ToArray())); }); newPacket = true; } } } catch (Exception e) { int clientID = _clientSocketDictionary[clientSocket]; List<int> contactIdList = UserDAO.GetContacIDListByUserID(clientID); lock (_clientSocketDictionary){_clientSocketDictionary.Remove(clientSocket);} Socket recipientSocket = null; ContactIsOffline contactIsOffline = new ContactIsOffline() { ContactID = clientID }; byte[] data = null; contactIdList.ForEach((id)=> { if(_clientSocketDictionary.ContainsValue(id)) { lock (_clientSocketDictionary) { recipientSocket = _clientSocketDictionary.FirstOrDefault(s => s.Value == id).Key; } if (recipientSocket != null) { data = contactIsOffline.CreateTransferablePacket(); Task.Factory.StartNew(() => { Send(recipientSocket, data); }); } } }); stream.Close(); Console.WriteLine(e.ToString()); } }
public void ProcessOfflineContact(ContactIsOffline contactIsOffline) { _contactsLoaded.WaitOne(); lock (_lock) { Contact senderContact = Contacts.FirstOrDefault((contact) => { return contact.Id == contactIsOffline.ContactID; }); if (senderContact != null) { senderContact.StatusLogoBytes = App.GetStatusLogo(false); } } }