Exemplo n.º 1
0
        public async Task <NotificationCreateResultModel> CreateAsync([NotNull] NotificationCreateModel model,
                                                                      [NotNull] ElectOneSignalAppOption appInfo)
        {
            model.AppId = appInfo.AppId;

            try
            {
                var result =
                    await ElectOneSignalConstants.DefaultApiUrl
                    .ConfigureRequest(config =>
                {
                    config.JsonSerializer = ElectOneSignalConstants.NewtonsoftJsonSerializer;
                })
                    .AppendPathSegment("notifications")
                    .WithHeader("Authorization", $"Basic {appInfo.ApiKey}")
                    .PostJsonAsync(model)
                    .ReceiveJson <NotificationCreateResultModel>()
                    .ConfigureAwait(true);

                return(result);
            }
            catch (FlurlHttpException e)
            {
                var response = await e.GetResponseStringAsync().ConfigureAwait(true);

                throw new HttpRequestException(response);
            }
        }
Exemplo n.º 2
0
        public async Task <NotificationCreateResultModel> CreateAsync([NotNull] NotificationCreateModel model,
                                                                      [NotNull] string appId, [NotNull] string appKey)
        {
            var appInfo = new ElectOneSignalAppOption(appId, appKey);

            return(await CreateAsync(model, appInfo));
        }
Exemplo n.º 3
0
        public async Task <NotificationCreateResultModel> CreateAsync([NotNull] NotificationCreateModel model,
                                                                      [NotNull] string appId)
        {
            var appInfo = Options.Apps.Single(x => x.AppId == appId);

            return(await CreateAsync(model, appInfo));
        }
Exemplo n.º 4
0
        public async Task CancelNotification()
        {
            var notifyCreateOptions = new NotificationCreateModel
            {
                Url  = "https://www.google.com",       // url to redirect when user click on it,
                Data = new Dictionary <string, string> // additional data as dictionary
                {
                    { "Key1", "Data1" }
                },
                IncludedSegments = new List <string> {
                    "All"
                },                                  // send to all player
                SendAfter = DateTime.Now.AddDays(1) // [IMPORTANT] Only can cancel the Schedule Notification
            };

            // Title + Message
            // English is mandatory, If you want to have localization still need English version
            notifyCreateOptions.Contents.Add(LanguageCodes.English, $"Sample Message: {DateTime.Now:hh:mm:ss t z}");

            var client = GetClient();

            var notificationResult = await client.Notifications.CreateAsync(notifyCreateOptions, AppId);

            Assert.AreNotEqual(notificationResult.Recipients, 0);

            var cancelResult = await client.Notifications.CancelAsync(notificationResult.Id, AppId);

            Assert.AreEqual(cancelResult.Success, "success");
        }
Exemplo n.º 5
0
        private async Task SendNotification(ImportJob importJob, string message, CancellationToken cancellationToken)
        {
            var createModel = new NotificationCreateModel
            {
                Created   = DateTimeOffset.UtcNow,
                CreatedBy = importJob.CreatedBy,
                Updated   = DateTimeOffset.UtcNow,
                UpdatedBy = importJob.CreatedBy,
                TenantId  = importJob.TenantId,
                UserName  = importJob.CreatedBy,
                Type      = importJob.Type,
                Message   = message
            };

            var command = new EntityCreateCommand <NotificationCreateModel, NotificationReadModel>(null, createModel);
            var result  = await _mediator.Send(command, cancellationToken);
        }