private Task ProcessMessage(JObject msgJObject) { OccuredEventType eventType = msgJObject.Value <OccuredEventType>("EventType"); JObject eventoObject = msgJObject.Value <JObject>("Data"); var eventId = eventoObject.Value <Guid>("EventId"); switch (eventType) { case OccuredEventType.EventoDeleted: locationManager.ClearEventAndUserLocations(eventId); break; case OccuredEventType.EventoEnded: locationManager.ClearEventAndUserLocations(eventId); break; case OccuredEventType.ParticipantLeft: locationManager.ClearUserLocations(eventoObject.Value <Guid>("UserId"), eventId); break; case OccuredEventType.ParticipantStateUpdated: locationManager.ClearUserLocations(eventoObject.Value <Guid>("UserId"), eventId); break; default: break; } return(Task.CompletedTask); }
public async Task HandleEvent(JObject eventNotificationJObj) { NotificationData notficationData; var eventObject = eventNotificationJObj.Value <JObject>("Event"); var userIds = GetEventParticipants(eventObject); OccuredEventType eventType = ParseMyEnum <OccuredEventType>(eventNotificationJObj.Value <string>("NotificationType")); switch (eventType) { case OccuredEventType.EventoCreated: notficationData = CreateMessage(eventObject, PushMessageType.EventInvite); userIds.ToList().Remove(eventObject.Value <Guid>("InitiatorId")); await NotifyEvent(notficationData, userIds); break; case OccuredEventType.EventoUpdated: await NotifyEventAndParticipantListUpdated(eventObject, userIds); userIds.ToList().Remove(eventObject.Value <Guid>("InitiatorId")); break; case OccuredEventType.EventoDeleted: notficationData = CreateMessage(eventObject, PushMessageType.EventDeleted); userIds.ToList().Remove(eventObject.Value <Guid>("InitiatorId")); await NotifyEvent(notficationData, userIds); break; case OccuredEventType.EventoEnded: notficationData = CreateMessage(eventObject, PushMessageType.EventEnd); userIds.ToList().Remove(eventObject.Value <Guid>("InitiatorId")); await NotifyEvent(notficationData, userIds); break; case OccuredEventType.EventoExtended: notficationData = CreateMessage(eventObject, PushMessageType.EventExtend); userIds.ToList().Remove(eventObject.Value <Guid>("InitiatorId")); notficationData.ExtendDuration = eventObject.Value <int>("ExtendDuration"); await NotifyEvent(notficationData, userIds); break; case OccuredEventType.ParticipantLeft: notficationData = CreateMessage(eventObject, PushMessageType.EventLeave); notficationData.ResponderId = eventObject.Value <Guid>("RequesterId"); notficationData.ResponderName = eventObject.Value <string>("RequesterName"); userIds.ToList().Remove(notficationData.ResponderId.Value); await NotifyEvent(notficationData, userIds); break; case OccuredEventType.DestinationUpdated: notficationData = CreateMessage(eventObject, PushMessageType.EventUpdateLocation); notficationData.DestinationName = eventObject.Value <string>("DestinationName"); userIds.ToList().Remove(notficationData.InitiatorId); await NotifyEvent(notficationData, userIds); break; case OccuredEventType.ParticipantsListUpdated: await NotifyEventAndParticipantListUpdated(eventObject, userIds); break; case OccuredEventType.ParticipantStateUpdated: notficationData = CreateMessage(eventObject, PushMessageType.EventResponse); notficationData.ResponderId = eventObject.Value <Guid>("RequesterId"); notficationData.ResponderName = eventObject.Value <string>("RequesterName"); notficationData.EventAcceptanceState = ParseMyEnum <EventAcceptanceStatus>(eventObject.Value <string>("CurrentParticipant.acceptanceStatus")); userIds.ToList().Remove(notficationData.ResponderId.Value); await NotifyEvent(notficationData, userIds); break; } }
public async System.Threading.Tasks.Task NotifyParticipantsAsync(Notification.EventWithUserIds @event, OccuredEventType eventType) { var notificationUrl = configuration["PushNotificationSettings:NotificationUrl"]; var notification = new Notification() { NotificationType = eventType, Event = @event }; using (var client = new HttpClient()) { MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); string requestBody = JsonConvert.SerializeObject(notification); var httpContent = new StringContent(requestBody, Encoding.UTF8, "application/json"); try { var response = await client.PostAsync(notificationUrl, httpContent); if (response.IsSuccessStatusCode) { var stringData = await response.Content.ReadAsStringAsync(); } else { throw new Exception("Notification failed."); } } catch (Exception ex) { throw new Exception("Notification failed." + ex); } finally { httpContent.Dispose(); } } }