コード例 #1
0
        public async Task CreateRegistrationAsync_PassValidWindowsTemplateRegistration_GetCreatedRegistrationBack()
        {
            LoadMockData();
            await DeleteAllRegistrationsAndInstallations();

            var registration = new WindowsTemplateRegistrationDescription(_configuration["WindowsDeviceToken"], "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">bodyText</text></binding>  </visual></toast>", new[] { "tag1" });

            registration.PushVariables = new Dictionary <string, string>()
            {
                { "var1", "value1" }
            };
            registration.Tags = new HashSet <string>()
            {
                "tag1"
            };
            registration.SecondaryTileName = "Tile name";
            registration.TemplateName      = "Template Name";

            var createdRegistration = await _hubClient.CreateRegistrationAsync(registration);

            Assert.NotNull(createdRegistration.RegistrationId);
            Assert.NotNull(createdRegistration.ETag);
            Assert.NotNull(createdRegistration.ExpirationTime);
            Assert.Contains(new KeyValuePair <string, string>("var1", "value1"), createdRegistration.PushVariables);
            Assert.Contains("tag1", createdRegistration.Tags);
            Assert.Equal(registration.ChannelUri, createdRegistration.ChannelUri);
            Assert.Equal(registration.SecondaryTileName, createdRegistration.SecondaryTileName);
            Assert.Equal(registration.BodyTemplate.Value, createdRegistration.BodyTemplate.Value);
            Assert.Equal(registration.TemplateName, createdRegistration.TemplateName);
            RecordTestResults();
        }
コード例 #2
0
        private RegistrationDescription CriaRegistration(RegistroNotificacaoViewModel model)
        {
            RegistrationDescription registration;

            switch (model.Plataforma)
            {
            case PlataformaNotificacao.WNS:
                var template = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>";
                registration = new WindowsTemplateRegistrationDescription(model.Handle, template);
                break;

            case PlataformaNotificacao.GCM:
                template     = "{\"data\":{\"message\":\"$(message)\"}}";
                registration = new GcmTemplateRegistrationDescription(model.Handle, template);
                break;

            case PlataformaNotificacao.APNS:
                template     = "{\"aps\":{\"alert\":\"$(message)\"}}";
                registration = new AppleTemplateRegistrationDescription(model.Handle, template);
                break;

            default:
                throw new InvalidOperationException();
            }
            return(registration);
        }
コード例 #3
0
        public async Task <IActionResult> Register([FromBody] ClientData data)
        {
            var hub = NotificationService.Hub;

            var payload      = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>";
            var registration = new WindowsTemplateRegistrationDescription(data.Handle, payload, new[] { $"group:{data.Group}" });

            registration.RegistrationId = await hub.CreateRegistrationIdAsync();

            var description = await hub.CreateOrUpdateRegistrationAsync(registration);

            return(Ok());
        }
コード例 #4
0
        // PUT api/register/5
        // This creates or updates a registration (with provided channelURI) at the specified id
        public async Task <HttpResponseMessage> Put(string id, DeviceRegistration deviceUpdate)
        {
            RegistrationDescription registration = null;

            switch (deviceUpdate.Platform)
            {
            case "mpns":
                var toastTemplate = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                    "<wp:Notification xmlns:wp=\"WPNotification\">" +
                                    "<wp:Toast>" +
                                    "<wp:Text1>$(message)</wp:Text1>" +
                                    "</wp:Toast> " +
                                    "</wp:Notification>";
                registration = new MpnsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate);
                break;

            case "wns":
                toastTemplate = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>";
                registration  = new WindowsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate);
                break;

            case "apns":
                var alertTemplate = "{\"aps\":{\"alert\":\"$(nameandmsg)\",\"badge\":1}}";
                registration = new AppleTemplateRegistrationDescription(deviceUpdate.Handle, alertTemplate);
                break;

            case "gcm":
                var messageTemplate = "{\"data\":{\"msg\":\"$(message)\",\"senderid\":\"$(userid)\",\"sender\":\"$(username)\",\"icon\":\"$(usericon)\"}}";
                registration = new GcmTemplateRegistrationDescription(deviceUpdate.Handle, messageTemplate);
                break;

            default:
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            registration.RegistrationId = id;
            registration.Tags           = new HashSet <string>(deviceUpdate.Tags);
            try
            {
                await _hub.CreateOrUpdateRegistrationAsync(registration);
            }
            catch (MessagingException e)
            {
                ReturnGoneIfHubResponseIsGone(e);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #5
0
        // PUT api/register/5
        // This creates or updates a registration (with provided channelURI) at the specified id
        public async Task<HttpResponseMessage> Put(string id, DeviceRegistration deviceUpdate)
        {
            RegistrationDescription registration = null;
            switch (deviceUpdate.Platform)
            {
                case "mpns":
                    var toastTemplate = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                        "<wp:Notification xmlns:wp=\"WPNotification\">" +
                           "<wp:Toast>" +
                                "<wp:Text1>$(message)</wp:Text1>" +
                           "</wp:Toast> " +
                        "</wp:Notification>";
                    registration = new MpnsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate);
                    break;
                case "wns":
                    toastTemplate = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>";
                    registration = new WindowsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate);
                    break;
                case "apns":
                    var alertTemplate = "{\"aps\":{\"alert\":\"$(message)\"}}";
                    registration = new AppleTemplateRegistrationDescription(deviceUpdate.Handle, alertTemplate);
                    break;
                case "gcm":
                    var messageTemplate = "{\"data\":{\"msg\":\"$(message)\"}}";
                    registration = new GcmTemplateRegistrationDescription(deviceUpdate.Handle, messageTemplate);
                    break;
                default:
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            registration.RegistrationId = id;
            registration.Tags = new HashSet<string>(deviceUpdate.Tags);
            try
            {
                await _hub.CreateOrUpdateRegistrationAsync(registration);
            }
            catch (MessagingException e)
            {
                ReturnGoneIfHubResponseIsGone(e);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }