public void DeliverEventToDevice(TEvent eventObj) { eventObj.CreatedAt = DateTime.UtcNow; if (eventObj.EventId == Guid.Empty) { eventObj.EventId = Guid.NewGuid(); } if (_undeliveredEventsRepository != null) { _undeliveredEventsRepository.Add(eventObj); } ISession targetSession; if (_server.ActiveSessionsByDeviceId.TryGetValue(eventObj.ReceiverDeviceId, out targetSession)) { _pendingEvents[eventObj.EventId] = eventObj; targetSession.Send(Event, eventObj is TEventDto ? (TEventDto)(object)eventObj : _dtoMapper(eventObj)); } else if (_internalMessageBus != null && _sessionsRegistry != null) { var instanceName = _sessionsRegistry.Get(eventObj.ReceiverDeviceId); if (!string.IsNullOrEmpty(instanceName)) { //user is online but he is attached to another instance //send the event to that server by instanceName (TODO: check if instance is available) _internalMessageBus.Send(eventObj, instanceName); } else { _eventDeliveryStatusChanged(eventObj, false); } } }
public void DeliverEventToDevice(TEvent eventObj) { eventObj.CreatedAt = DateTime.UtcNow; if (eventObj.EventId == Guid.Empty) { eventObj.EventId = Guid.NewGuid(); } ISession targetSession; if (_server.ActiveSessionsByDeviceId.TryGetValue(eventObj.ReceiverDeviceId, out targetSession)) { targetSession.Send(Event, eventObj is TEventDto ? (TEventDto)(object)eventObj : _dtoMapper(eventObj)); } else if (_internalMessageBus != null && _sessionsRegistry != null) { var instanceName = _sessionsRegistry.Get(eventObj.ReceiverDeviceId); if (!string.IsNullOrEmpty(instanceName)) { _internalMessageBus.Send(eventObj, instanceName); } } }