Guest User

Untitled

a guest
Jul 20th, 2019
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. private void _sendNewMessageNotification(int roomID, Message item, RoomUser authorUser, List<RoomUser> users)
  3. {
  4. var _serializationSettings = new JsonSerializerSettings()
  5. {
  6. ContractResolver = new CamelCasePropertyNamesContractResolver()
  7. };
  8.  
  9.  
  10. var json = JsonConvert.SerializeObject(new
  11. {
  12. result = true,
  13. roomID,
  14. user = authorUser,
  15. item = item
  16. }, _serializationSettings);
  17.  
  18. // вытаскиваем всех юзеров которые это могут получить из connections
  19. var s = new SignalRHub();
  20. var allConnections = s.GetConnectionsInfo();
  21. var connectionIDs = new List<string>();
  22. var context = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
  23.  
  24. var usernames = users.Select(x => x.Username).ToList();
  25. var selConnections = allConnections.Where(x => usernames.Contains(x.data.username)).ToList();
  26.  
  27. if (selConnections.Count > 0)
  28. {
  29. var ids = selConnections.Select(x => x.id).ToList();
  30. context.Clients.Clients(ids).messageReceived(json);
  31. }
  32. }
RAW Paste Data