public IHttpActionResult CloseOrder(RentoRequest <OrderClose> request) { var response = new RentoResponse(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { if ((!request.Data.Approve && !ValidateRequirdField(request.Data.Comment)) || !ValidateRequirdField(request.Data.Star) ) { response.ErrorCode = ErrorCode.RequirdField; return; } ; var userToken = await CarManager.CloseOrder(UserSession.Id, request.Data); if (userToken != null) { var bodyAr = request.Data.Approve ? "لقد تم الموافقة على طلبكم من قبل المكتب" : "لقد تم رفض طلبكم من قبل المكتب وذلك بسبب: " + request.Data.Comment; var bodyEn = request.Data.Approve ? "Your request has been processed successfully" : "Your request has been rejected from office and the reason is: " + request.Data.Comment; await Database.MessageManager.Create(userToken.CustomerId, string.Format("{0} {1}", request.Language == (int)Language.Arabic ? bodyAr + " ذو الرقم " : bodyEn + " with number ", request.Data.Id )); if (!string.IsNullOrEmpty(userToken.NotificationToken)) { FirebaseNotification.SendPushNotification("طلب استئجار السيارة", bodyAr, userToken.NotificationToken, userToken.IsAndroid); } } }))); }
public AN_FirebaseNotification(FirebaseNotification notification) { m_badge = notification.Badge; m_body = notification.Body; m_bodyLocalizationKey = notification.BodyLocalizationKey; m_clickAction = notification.ClickAction; m_color = notification.Color; m_icon = notification.Icon; m_sound = notification.Sound; m_tag = notification.Tag; m_title = notification.Title; m_titleLocalizationKey = notification.TitleLocalizationKey; BodyLocalizationArgs = notification.BodyLocalizationArgs; TitleLocalizationArgs = notification.TitleLocalizationArgs; }
public PushNotificationSender(FirebaseNotification firebaseNotification) { _firebaseNotification = firebaseNotification; }
private async Task SendNotificationsForDevices(List <Device> devices, string message, string type, Dictionary <string, string> payload) { if (devices.Count == 0) { return; } var iosPayload = new AppleNotification { Aps = new ApsPayload { Alert = message, }, Type = type, Params = payload, }; var androidPayload = new FirebaseNotification { Android = new FirebaseAndroidPayload { Notification = new FirebaseAndroidNotification { Body = message, ChannelId = "GENERAL" }, Priority = 10, Data = new FirebasePayload { Type = type, Params = payload } }, Notification = new FirebaseNotificationInfo { Body = message } }; var iOSDevices = devices.Where(d => d.Platform == 1).ToList(); using var apn = new ApnSender( settings.Connection.ApplePushKey, settings.Connection.ApplePushKeyId, settings.Connection.ApplePushTeamId, settings.Connection.ApplePushBundleId, ApnServerType.Production ); await Task.WhenAll(iOSDevices.Select(device => Policy .HandleResult <ApnsResponse>(r => !r.IsSuccess) .WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(8) }, (exception, timeSpan) => { var time = timeSpan.ToString("h'h 'm'm 's's'", CultureInfo.CurrentCulture); Logger.LogWarning($"Failed to send iOS notification to device id {device.Token} in {time}: {exception?.Result?.Error?.Reason}"); }) .ExecuteAsync(() => apn.SendAsync(iosPayload, device.Token)) ).ToArray()) .ConfigureAwait(false); var androidDevices = devices.Where(d => d.Platform == 2).ToList(); using var fcm = new FcmSender(settings.Connection.FirebaseServerKey, settings.Connection.FirebaseSenderId); await Task.WhenAll(androidDevices.Select(device => Policy .HandleResult <FcmResponse>(r => r.Failure > 0) .WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(8) }, (_, timeSpan) => { var time = timeSpan.ToString("h'h 'm'm 's's'", CultureInfo.CurrentCulture); Logger.LogWarning($"Failed to send Android notification to device id {device.Token} in {time}"); }) .ExecuteAsync(() => fcm.SendAsync(device.Token, androidPayload)) ).ToArray()) .ConfigureAwait(false); }