public async Task register_device_notification_Hub()
    {
        NotificationHubRepository repo = new NotificationHubRepository(notificationHubConString);

        var registration = new MobileDeviceInstallationNotificationHub()
        {
            InstallationId = "instaltestid",
            Platform       = "gcm",
            PushChannel    = "testToken",
            Tags           = new List <string> {
                "tag1", "tag2"
            },
            Templates = new System.Collections.Generic.Dictionary <string, NotificationPushTemplate>
            {
                { "key1", new NotificationPushTemplate()
                  {
                      Body = "{\"data\":{\"message\":\"Notification Hub test notification\"}}"
                  } }
            }
        };

        await repo.RegisterMobileDevice(registration);

        // await repo.SendNotification("{\"data\":{\"message\":\"Notification Hub test notification\"}}", "testtag");
    }
    public async Task send_notification_stringAsync()
    {
        NotificationHubRepository repo = new NotificationHubRepository(notificationHubConString);

        // List<string> tags = new List<string> { "Test", "Test1" };
        var response = await repo.SendNotification("{\"data\":{\"message\":\"Notification from gcm\"}}",
                                                   "Test");
    }
예제 #3
0
        public async Task <string> PostAsync([FromBody] PushRegistration registration)
        {
            #region input validation
            if (registration == null)
            {
                throw new ArgumentException("Check one or more of your arguments");
            }

            if (string.IsNullOrEmpty(registration.AppId))
            {
                throw new ArgumentException("Please provide a valid AppId");
            }

            if (string.IsNullOrEmpty(registration.DeviceToken))
            {
                throw new ArgumentException("Please provide a valid DeviceToken");
            }

            if (registration.Platform == Platform.none)
            {
                throw new ArgumentException("Platform can only be iOS, Android or Windows");
            }
            #endregion

            string registrationId = null;

            //registration.UserId = "*****@*****.**";
            //registration.UserId = RequestContext.Principal.Identity.Name.ToLower();
            if (registration.Tags == null)
            {
                registration.Tags = new List <string>();
            }
            registration.Tags.Add($"UserId:{registration.UserId}");

            AzureNotificationHub hub = await _dbRepo.GetAzureNotificationHubEndpoint(registration.AppId);

            if (string.IsNullOrEmpty(hub.Endpoint) && string.IsNullOrEmpty(hub.HubName))
            {
                throw new Exception($"Unable to find an enpoint for appId = '{registration.AppId}'");
            }

            _nhRepo = new NotificationHubRepository(hub.Endpoint, hub.HubName);

            registrationId = await _nhRepo.Upsert(registration);

            registration.RegistrationId = registrationId;

            var success = await _dbRepo.Upsert(registration);

            //await Clean(registration);

            return(registrationId);
        }
    public async Task send_notification_string_multiple_Async()
    {
        NotificationHubRepository repo = new NotificationHubRepository(notificationHubConString);

        List <string> tags = new List <string> {
            "Test", "Test1", "Test2", "Test3", "Test4", "Test5",
            "Test6", "Test7", "Test8", "Test9", "Test10", "Test11", "Test12", "Test13", "Test14", "Test15", "Test16", "Test17", "Test18", "Test19",
            "Test20", "Test21", "Test22", "Test23"
        };
        await repo.SendNotificationMultipleDevices("{\"data\":{\"message\":\"Notification from gcm\"}}",
                                                   tags);
    }
예제 #5
0
        public async Task <IEnumerable <RegistrationDescription> > GetAsync(string appId)
        {
            AzureNotificationHub hub = await _dbRepo.GetAzureNotificationHubEndpoint(appId);

            if (string.IsNullOrEmpty(hub.Endpoint) && string.IsNullOrEmpty(hub.HubName))
            {
                throw new Exception($"Unable to find an enpoint for appId = '{appId}'");
            }

            _nhRepo = new NotificationHubRepository(hub.Endpoint, hub.HubName);

            var retval = await _nhRepo.Get();

            return(retval);
        }
예제 #6
0
        public async Task <HttpResponseMessage> Post([FromBody] SendPayload sendPayload)
        {
            HttpStatusCode             ret      = HttpStatusCode.InternalServerError;
            List <NotificationOutcome> outcomes = null;
            AzureNotificationHub       hub      = await _dbRepo.GetAzureNotificationHubEndpoint(sendPayload.AppId);

            if (string.IsNullOrEmpty(hub.Endpoint) && string.IsNullOrEmpty(hub.HubName))
            {
                throw new Exception($"Unable to find an enpoint for appId = '{sendPayload.AppId}'");
            }

            var _nhRepo = new NotificationHubRepository(hub.Endpoint, hub.HubName);

            if (!string.IsNullOrEmpty(sendPayload.UserId))
            {
                var pns = await _dbRepo.GetPns(sendPayload.AppId, sendPayload.UserId);

                outcomes = await _nhRepo.Send(sendPayload, pns);
            }
            else
            {
                outcomes = await _nhRepo.Send(sendPayload);
            }

            if (outcomes != null)
            {
                ret = HttpStatusCode.OK;

                foreach (var outcome in outcomes)
                {
                    if ((outcome.State == NotificationOutcomeState.Abandoned) ||
                        (outcome.State == NotificationOutcomeState.Unknown))
                    {
                        ret = HttpStatusCode.InternalServerError;
                        break;
                    }
                }
            }

            return(Request.CreateResponse(ret, "{\"result\":\"OK\"}"));
        }
    public async Task push_message_notification_Hub()
    {
        NotificationHubRepository repo = new NotificationHubRepository(notificationHubConString);

        //var registration = new MobileDeviceInstallationNotificationHub()
        //{
        //    InstallationId = "instaltestid",
        //    Platform = "gcm",
        //    PushChannel = "testToken",
        //    Tags = new List<string> { "tag1", "tag2" },
        //    Templates = new System.Collections.Generic.Dictionary<string, NotificationPushTemplate>
        //    {
        //        { "genericTemplate", new NotificationPushTemplate(){
        //            Body="{\"data\":{\"message\":\"Notification Hub test notification\"}}"
        //        }
        //        }
        //    }
        //};

        // await repo.RegisterMobileDevice(registration);

        //"{ "genericTemplate":{ "body":"{\"data\":{\"message\":\"$(messageParam)\"}}"}"

        var pushRequest = new PushNotificationRequest()
        {
            Text   = "{\"data\":{\"message\":\"sample test template\"}",
            Action = "sample action",
            Silent = false,
            Tags   = new List <string> {
                "Test"
            }
        };

        await repo.PushNotification(pushRequest);

        //await repo.SendNotification("{\"data\":{\"message\":\"Notification Hub test notification\"}}", "testtag");
    }