public NotificationType GetByKey(NotificationKey key) { return this.notificationTypeRepos .All() .Where(nt => nt.Key == key) .FirstOrDefault(); }
private void dispatchNotifications(int dispatchIntervalMS) { var dispatchInterval = new TimeSpan(0, 0, 0, 0, dispatchIntervalMS); var now = DateTime.Now; if ((now - lastSendTime) >= dispatchInterval) { var key = new NotificationKey(); PlayerRewardNotification notification = null; var removeNotification = false; foreach (var kvp in accumulatingNotifications) { key = kvp.Key; notification = kvp.Value; if ((now - notification.TimeStamp) >= accumulateDuration) { lastSendTime = now; getCombatTextOffsets(out var xOffset, out var yOffset); notification.Send(xOffset, yOffset); removeNotification = true; break; } } //remove if (removeNotification) { accumulatingNotifications.Remove(key); } } }
//accumulate/concatenate incoming entries into a dictionary, keyed by entry( player + global + currency ). //These will then get dispatched in a later step. private void accumulateNotifications() { const int maxIterations = 64; //keep the looping bounded int counter = 0; var now = DateTime.Now; var volleySpan = TimeSpan.FromMilliseconds(1000); //if another matching notification is accumulated within this time frame, //we "extend" the life of the accumulated notification, in case more // matching notifications are coming. This volley effect in essence, // keeps the accumulation rolling. while (incomingNotificationsQueue.Count > 0 && counter++ < maxIterations) { if (incomingNotificationsQueue.TryDequeue(out var notification)) { var notificationKey = new NotificationKey(notification); if (!accumulatingNotifications.TryGetValue(notificationKey, out var accumulatingNotification)) { accumulatingNotifications.Add(notificationKey, notification); notification.TimeStamp = DateTime.Now; } else { //should we extend the lifetime of this notification? if (now - accumulatingNotification.TimeStamp > volleySpan) { accumulatingNotification.TimeStamp = now + volleySpan; } accumulatingNotification.Accumulate(notification); } } } }
public HttpResponseMessage PostNotificationKey(NotificationKey notificationKey) { using (var client = createClient(_accessToken)) { var response = client.PostAsJsonAsync(_appPath + "/api/Settings/NotificationKey", notificationKey).Result; return(response); } }
public NotificationAvailableActionModel GetAvailableActionModel(NotificationKey key, bool actionHasBeenTaken, int tripId, string userId) { var result = new NotificationAvailableActionModel { CanApprove = false, CanDisapprove = false }; if (!actionHasBeenTaken) { switch (key) { case NotificationKey.JoinTripRequest: bool tripRequestIsRejected = this.tripServices.CheckIfUserHasPendingRequest(tripId, userId); if (tripRequestIsRejected) { result.CanApprove = true; result.CanDisapprove = true; } break; case NotificationKey.JoinTripApproved: break; case NotificationKey.JoinTripDisApproved: break; case NotificationKey.FinishTripDriverRequest: result.CanApprove = true; break; case NotificationKey.TripFinished: result.Url = string.Format("/Trip/Rate/{0}", tripId); break; case NotificationKey.TripChanged: break; case NotificationKey.DriverRemovePassenger: break; case NotificationKey.PassengerLeftTrip: break; default: break; } } return result; }
public TripNotification Create( int tripId, string fromUserId, string forUserId, string title, string message, NotificationKey keyType, DateTime dueTo, DateTime availableAfter) { NotificationType type = this.notificationTypeRepos .All() .Where(t => t.Key == keyType) .FirstOrDefault(); if (type == null) { throw new Exception("No such type, given key type " + keyType); } TripNotification tripNotification = new TripNotification() { TripId = tripId, FromUserId = fromUserId, ForUserId = forUserId, Title = title, Message = message, Seen = false, AvailableAfter = availableAfter, DueTo = dueTo, Type = type }; this.tripNotificationRepos.Add(tripNotification); this.tripNotificationRepos.Save(); return tripNotification; }
public IServiceResults<bool> SendNotificationToUser(Guid userId, NotificationType notificationType, string message) { try { var user = _userService.FindUser(userId); if (user.Result == null) return new ServiceResults<bool> { IsSuccessfull = false, Message = BusinessMessage.Error, Result = false }; var notification = _notificationSettingService.GetNotificationType(notificationType); var sms = new List<string>(); var telegram = new List<int>(); var email = new List<string>(); var type = new NotificationKey(); if (notification.Email) { type.Email = true; email.Add(user.Result.Email); } if (notification.Sms) { type.Sms = true; sms.Add(user.Result.Mobile); } if (notification.Telegram && user.Result.Telegram != 0) { type.Telegram = true; telegram.Add(user.Result.Telegram); } _messagingGateway.GivenMessages(new NotificationPackage { Message = new List<string> { message }, Type = new List<NotificationKey> { type }, Sms = sms, Telegram = telegram, Email = email }); return new ServiceResults<bool> { IsSuccessfull = true, Message = string.Empty, Result = true }; } catch (Exception) { return new ServiceResults<bool> { IsSuccessfull = false, Message = BusinessMessage.NotificationNotSend, Result = false }; } }