예제 #1
0
        public static string ToErrorMessage(this NotificationSendResult result)
        {
            switch (result)
            {
            case NotificationSendResult.Sent:
                return(null);

            case NotificationSendResult.Empty:
                return(NotificationEmpty.translated);

            case NotificationSendResult.Disabled:
                return(NotificationDisabled.translated);

            case NotificationSendResult.RateLimited:
                return(NotificationRateLimit.translated);

            case NotificationSendResult.ServerError:
                return(NotificationServerError.translated);

            case NotificationSendResult.NoTargetsFound:
                return(NotificationNoTargets.translated);

            case NotificationSendResult.TooManySubscribers:
                return(NotificationTooManySubscribers.translated);

            default:
                return(NotificationUnknown.translated);
            }
        }
예제 #2
0
        public static async Task <NotificationSendResult> SendNotificationTo(ICollection <ulong> steamIds, NotificationChannel channel, string title, string body, Dictionary <string, string> data)
        {
            NotificationSendResult notificationSendResult = await SendNotificationImpl(steamIds, channel, title, body, data);

            if (notificationSendResult == NotificationSendResult.NoTargetsFound)
            {
                notificationSendResult = NotificationSendResult.Sent;
            }
            return(notificationSendResult);
        }
예제 #3
0
        public static async Task <NotificationSendResult> SendNotificationTo(ulong steamId, NotificationChannel channel, string title, string body, Dictionary <string, string> data)
        {
            HashSet <ulong> set = Facepunch.Pool.Get <HashSet <ulong> >();

            set.Clear();
            set.Add(steamId);
            NotificationSendResult result = await SendNotificationImpl(set, channel, title, body, data);

            set.Clear();
            Facepunch.Pool.Free(ref set);
            return(result);
        }
예제 #4
0
파일: App.cs 프로젝트: Ailtop/RustDocuments
        public static async void pair(Arg arg)
        {
            BasePlayer basePlayer = ArgEx.Player(arg);

            if (!(basePlayer == null))
            {
                Dictionary <string, string> playerPairingData      = Util.GetPlayerPairingData(basePlayer);
                NotificationSendResult      notificationSendResult = await Util.SendPairNotification("server", basePlayer, Server.hostname.Truncate(128), "Tap to pair with this server.", playerPairingData);

                arg.ReplyWith((notificationSendResult == NotificationSendResult.Sent) ? "Sent pairing notification." : Util.ToErrorMessage(notificationSendResult));
            }
        }
        public async Task <NotificationSendResult> SendNotificationAsync(Notification notification, string language)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var result = new NotificationSendResult();

            var message = AbstractTypeFactory <NotificationMessage> .TryCreateInstance($"{notification.Kind}Message");

            message.LanguageCode        = language;
            message.MaxSendAttemptCount = _maxRetryAttempts + 1;
            notification.ToMessage(message, _notificationTemplateRender);

            await _notificationMessageService.SaveNotificationMessagesAsync(new[] { message });

            var policy = Policy.Handle <SentNotificationException>().WaitAndRetryAsync(_maxRetryAttempts, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                                                                                       , (exception, timeSpan, retryCount, context) =>
            {
                _logger.LogError(exception, $"Retry {retryCount} of {context.PolicyKey}, due to: {exception}.");
                message.LastSendError = exception?.Message;
            });

            var policyResult = await policy.ExecuteAndCaptureAsync(() =>
            {
                message.LastSendAttemptDate = DateTime.Now;
                message.SendAttemptCount++;
                return(_notificationMessageAccessor.GetSenderForNotificationType(notification.Kind).SendNotificationAsync(message));
            });

            if (policyResult.Outcome == OutcomeType.Successful)
            {
                result.IsSuccess = true;
                message.SendDate = DateTime.Now;
            }
            else
            {
                result.ErrorMessage = policyResult.FinalException?.Message;
            }

            await _notificationMessageService.SaveNotificationMessagesAsync(new[] { message });

            return(result);
        }
예제 #6
0
        public async Task <NotificationSendResult> TrySendNotificationMessageAsync(string messageId)
        {
            var result = new NotificationSendResult();

            var message = (await _notificationMessageService.GetNotificationsMessageByIds(new[] { messageId })).FirstOrDefault();

            if (message == null)
            {
                result.ErrorMessage = $"Can't find notification message by {messageId}";
                return(result);
            }

            if (message.Status == NotificationMessageStatus.Error)
            {
                result.ErrorMessage = $"Can't send notification message by {messageId}. There are errors.";
                return(result);
            }

            var policy = Policy.Handle <SentNotificationException>().WaitAndRetryAsync(_maxRetryAttempts, retryAttempt => TimeSpan.FromSeconds(Math.Pow(3, retryAttempt)));

            var policyResult = await policy.ExecuteAndCaptureAsync(() =>
            {
                message.LastSendAttemptDate = DateTime.Now;
                message.SendAttemptCount++;
                return(_notificationMessageSenderFactory.GetSender(message).SendNotificationAsync(message));
            });

            if (policyResult.Outcome == OutcomeType.Successful)
            {
                result.IsSuccess = true;
                message.SendDate = DateTime.Now;
                message.Status   = NotificationMessageStatus.Sent;
            }
            else
            {
                result.ErrorMessage   = "Failed to send message.";
                message.LastSendError = policyResult.FinalException?.ToString();
                message.Status        = NotificationMessageStatus.Error;
            }

            await _notificationMessageService.SaveNotificationMessagesAsync(new[] { message });

            return(result);
        }
예제 #7
0
        private async Task <NotificationSendResult> SendNotificationAsync(NotificationBase notification)
        {
            NotificationSendResult result;

            try
            {
                result = await _platformNotificationApi.SendNotificationByRequestAsync(notification.ToNotificationDto());
            }
            catch (Exception exception)
            {
                result = new NotificationSendResult
                {
                    IsSuccess    = false,
                    ErrorMessage = $"Error occurred while sending notification: {exception.Message}"
                };
            }

            return(result);
        }
예제 #8
0
    public async void PairWithApp(RPCMessage msg)
    {
        BasePlayer player = msg.player;
        Dictionary <string, string> playerPairingData = CompanionServer.Util.GetPlayerPairingData(player);

        playerPairingData.Add("entityId", net.ID.ToString("G", CultureInfo.InvariantCulture));
        playerPairingData.Add("entityType", ((int)Type).ToString("G", CultureInfo.InvariantCulture));
        playerPairingData.Add("entityName", GetDisplayName());
        NotificationSendResult notificationSendResult = await CompanionServer.Util.SendPairNotification("entity", player, GetDisplayName(), "Tap to pair with this device.", playerPairingData);

        if (notificationSendResult == NotificationSendResult.Sent)
        {
            OnPairedWithPlayer(msg.player);
        }
        else
        {
            player.ClientRPCPlayer(null, player, "HandleCompanionPairingResult", (int)notificationSendResult);
        }
    }
        public ActionResult SendNotification(
            [ModelBinder(typeof(NotificationTemplateModelBinder))] INotificationContent notification,
            string channelUrl,
            NotificationPriority priority = NotificationPriority.Normal)
        {
            var options = new NotificationSendOptions()
            {
                Priority = priority
            };

            NotificationSendResult result = notification.Send(new Uri(channelUrl), this.tokenProvider, options);

            object response = new
            {
                DeviceConnectionStatus = result.DeviceConnectionStatus.ToString(),
                NotificationStatus     = result.NotificationStatus.ToString(),
                Status = result.LookupHttpStatusCode()
            };

            return(this.Json(response));
        }