コード例 #1
0
        //public async Task<HttpResponseMessage> Post(string pns, [FromBody]string message, string to_tag)
        public async Task <HttpResponseMessage> Post()
        {
            string value = await Request.Content.ReadAsStringAsync();

            var    entidad = System.Web.Helpers.Json.Decode(value);
            string pns     = Convert.ToString(entidad.platform);
            var    message = entidad.mensaje;
            var    to_tag  = entidad.to_tag;

            var user = HttpContext.Current.User.Identity.Name;

            string[] userTag = new string[2];
            userTag[0] = "username:"******"from:" + user;

            Microsoft.ServiceBus.Notifications.NotificationOutcome outcome = null;
            HttpStatusCode ret = HttpStatusCode.InternalServerError;


            switch (pns.ToLower())
            {
            case "wns":
                // Windows 8.1 / Windows Phone 8.1
                var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" +
                            "From " + user + ": " + message + "</text></binding></visual></toast>";
                outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag);

                break;

            case "apns":
                // iOS
                var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}";
                outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag);

                break;

            case "gcm":
                // Android
                var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}";
                outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, userTag);

                //outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif);
                break;
            }

            if (outcome != null)
            {
                if (!((outcome.State == Microsoft.ServiceBus.Notifications.NotificationOutcomeState.Abandoned) ||
                      (outcome.State == Microsoft.ServiceBus.Notifications.NotificationOutcomeState.Unknown)))
                {
                    ret = HttpStatusCode.OK;
                }
            }

            return(Request.CreateResponse(ret));
        }
コード例 #2
0
        public async Task <ApiResult> Sent(SentPushDto sentPushDto)
        {
            var userId = User.Identity.GetUserId();

            string[] userTag = new string[2];
            userTag[0] = "username:"******"from:" + userId;

            Microsoft.ServiceBus.Notifications.NotificationOutcome outcome = null;
            HttpStatusCode ret = HttpStatusCode.InternalServerError;

            switch (sentPushDto.Pns.ToLower())
            {
            case "wns":
                // Windows 8.1 / Windows Phone 8.1
                var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" +
                            "From " + userId + ": " + sentPushDto.Message + "</text></binding></visual></toast>";
                outcome = await _hub.SendWindowsNativeNotificationAsync(toast);

                break;

            case "apns":
                // iOS
                var alert = "{\"aps\":{\"alert\":\"" + "From " + userId + ": " + sentPushDto.Message + "\"}}";
                outcome = await _hub.SendAppleNativeNotificationAsync(alert, userTag);

                break;

            case "gcm":
                // Android
                var notif = "{ \"data\" : {\"message\":\"" + "From " + userId + ": " + sentPushDto.Message + "\"}}";
                outcome = await _hub.SendGcmNativeNotificationAsync(notif, userTag);

                break;
            }

            if (outcome != null)
            {
                if (!((outcome.State == Microsoft.ServiceBus.Notifications.NotificationOutcomeState.Abandoned) ||
                      (outcome.State == Microsoft.ServiceBus.Notifications.NotificationOutcomeState.Unknown)))
                {
                    ret = HttpStatusCode.OK;
                }
            }

            return(SuccessApiResult(ret));
        }
コード例 #3
0
        private static async Task <HttpStatusCode> enviarPush(string pns, dynamic message, string user, string[] userTag)
        {
            Microsoft.ServiceBus.Notifications.NotificationOutcome outcome = null;
            HttpStatusCode ret = HttpStatusCode.InternalServerError;


            switch (pns.ToLower())
            {
            case "wns":
                // Windows 8.1 / Windows Phone 8.1
                var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" +
                            "From " + user + ": " + message + "</text></binding></visual></toast>";
                outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag);

                break;

            case "apns":
                // iOS
                var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}";
                outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag);

                break;

            case "gcm":
                // Android
                var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}";
                outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, userTag);

                break;
            }

            if (outcome != null)
            {
                if (!((outcome.State == Microsoft.ServiceBus.Notifications.NotificationOutcomeState.Abandoned) ||
                      (outcome.State == Microsoft.ServiceBus.Notifications.NotificationOutcomeState.Unknown)))
                {
                    ret = HttpStatusCode.OK;
                }
            }
            return(ret);
        }
コード例 #4
0
 protected override void ProcessResponse()
 {
     try
     {
         if (!this.testSend)
         {
             NotificationOutcome notificationOutcome = new NotificationOutcome()
             {
                 State      = NotificationOutcomeState.Enqueued,
                 TrackingId = base.TrackingContext.TrackingId
             };
             this.Result = notificationOutcome;
         }
         else
         {
             Stream            responseStream   = base.Response.GetResponseStream();
             XmlReaderSettings xmlReaderSetting = new XmlReaderSettings()
             {
                 CloseInput = true
             };
             using (XmlReader xmlReader = XmlReader.Create(responseStream, xmlReaderSetting))
             {
                 DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(NotificationOutcome));
                 this.Result            = (NotificationOutcome)dataContractSerializer.ReadObject(xmlReader);
                 this.Result.State      = NotificationOutcomeState.DetailedStateAvailable;
                 this.Result.TrackingId = base.TrackingContext.TrackingId;
             }
         }
     }
     catch (XmlException xmlException)
     {
         throw new MessagingException(SRClient.InvalidXmlFormat, xmlException);
     }
     catch (WebException webException1)
     {
         WebException webException = webException1;
         throw ServiceBusResourceOperations.ConvertWebException(base.TrackingContext, webException, base.Request.Timeout, false);
     }
 }
コード例 #5
0
        internal static NotificationOutcome GetUnknownOutCome()
        {
            RegistrationResult registrationResult = new RegistrationResult()
            {
                ApplicationPlatform = "Unknown",
                PnsHandle           = "Unknown",
                RegistrationId      = "Unknown",
                Outcome             = "UnknownError"
            };
            RegistrationResult  registrationResult1 = registrationResult;
            NotificationOutcome notificationOutcome = new NotificationOutcome()
            {
                Failure = (long)1,
                Success = (long)0,
                Results = new List <RegistrationResult>()
                {
                    registrationResult1
                }
            };

            return(notificationOutcome);
        }