public Task<HttpResponseMessage> PostNotification (BlackberryNotification notification)
        {
            var c = new MultipartContent ("related", Configuration.Boundary);
            c.Headers.Remove("Content-Type");
            c.Headers.TryAddWithoutValidation("Content-Type", "multipart/related; boundary=" + Configuration.Boundary + "; type=application/xml");

            var xml = notification.ToPapXml ();


            c.Add (new StringContent (xml, Encoding.UTF8, "application/xml"));

            var bc = new ByteArrayContent(notification.Content.Content);
            bc.Headers.Add("Content-Type", notification.Content.ContentType);

            foreach (var header in notification.Content.Headers)
                bc.Headers.Add(header.Key, header.Value);

            c.Add(bc);

            return PostAsync (Configuration.SendUrl, c);
        }
        public Task <HttpResponseMessage> PostNotification(BlackberryNotification notification)
        {
            var c = new MultipartContent("related", Configuration.Boundary);

            c.Headers.Remove("Content-Type");
            c.Headers.TryAddWithoutValidation("Content-Type", "multipart/related; boundary=" + Configuration.Boundary + "; type=application/xml");

            var xml = notification.ToPapXml();


            c.Add(new StringContent(xml, Encoding.UTF8, "application/xml"));

            var bc = new ByteArrayContent(notification.Content.Content);

            bc.Headers.Add("Content-Type", notification.Content.ContentType);

            foreach (var header in notification.Content.Headers)
            {
                bc.Headers.Add(header.Key, header.Value);
            }

            c.Add(bc);

            return(PostAsync(Configuration.SendUrl, c));
        }
Example #3
0
		public void Blackberry_Simple_Test()
		{
			var waitCallback = new ManualResetEvent (false);

		    var settings = new BlackberryPushChannelSettings("APPID", "PWD"); 

			var c = new BlackberryPushChannel (settings);

			var n = new BlackberryNotification ();
		    n.Content = new BlackberryMessageContent("text/plain", "66");

			n.QualityOfService = QualityOfServiceLevel.Unconfirmed;
		    n.SourceReference = "3682-8s4B97Rc2388i46I8M08769D005ra6286o4";
		    n.DeliverBeforeTimestamp = DateTime.UtcNow.AddMinutes(1);
			var r = new BlackberryRecipient ("push_all");

			n.Recipients.Add (r);

			c.SendNotification (n, (sender, resp) => {

				waitCallback.Set();
			});

			waitCallback.WaitOne ();
		}
 public static BlackberryNotification ForSingleRegistrationId(BlackberryNotification msg, string registrationId)
 {
     var result = new BlackberryNotification();
     result.Platform = PlatformType.Blackberry;
     result.Tag = msg.Tag;
     result.PushPin = registrationId;
     result.Message = msg.Message;
     return result;
 }
        bool push(BlackberryNotification notification)
        {
            bool success = true;

            byte[] bytes = Encoding.ASCII.GetBytes(notification.Message);

            Stream          requestStream = null;
            HttpWebResponse HttpWRes      = null;
            HttpWebRequest  HttpWReq      = null;

            try
            {
                //http://<BESName>:<BESPort>/push?DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
                // Build the URL to define our connection to the BES.
                string httpURL = "http://" + this.blackberrySettings.BESAddress + ":" + blackberrySettings.BESWebServerListenPort.ToString()
                                 + "/push?DESTINATION=" + notification.PushPin + "&PORT=" + blackberrySettings.BESPushPort.ToString()
                                 + "&REQUESTURI=/";

                //make the connection
                HttpWReq        = (HttpWebRequest)WebRequest.Create(httpURL);
                HttpWReq.Method = ("POST");
                //add the headers nessecary for the push
                HttpWReq.ContentType   = "text/plain";
                HttpWReq.ContentLength = bytes.Length;
                // ******* Test this *******
                HttpWReq.Headers.Add("X-Rim-Push-Id", notification.PushPin + "~" + DateTime.Now);                 //"~" +pushedMessage +
                HttpWReq.Headers.Add("X-Rim-Push-Reliability", "application-preferred");
                HttpWReq.Headers.Add("X-Rim-Push-NotifyURL", (notification.WidgetNotificationUrl + notification.PushPin + "~" + notification.Message + "~" + DateTime.Now).Replace(" ", ""));

                // *************************
                HttpWReq.Credentials = new NetworkCredential(blackberrySettings.PushUsername, blackberrySettings.PushPassword);

                requestStream = HttpWReq.GetRequestStream();
                //Write the data from the source
                requestStream.Write(bytes, 0, bytes.Length);

                //get the response
                HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();

                var pushStatus = HttpWRes.Headers["X-RIM-Push-Status"];

                //if the MDS received the push parameters correctly it will either respond with okay or accepted
                if (HttpWRes.StatusCode == HttpStatusCode.OK || HttpWRes.StatusCode == HttpStatusCode.Accepted)
                {
                    success = true;
                }
                else
                {
                    success = false;
                }
                //Close the streams

                HttpWRes.Close();
                requestStream.Close();
            }
            catch (System.Exception)
            {
                success = false;
            }

            return(success);
        }
        bool push(BlackberryNotification notification)
        {
            bool success = true;
            byte[] bytes = Encoding.ASCII.GetBytes(notification.Message);

            Stream requestStream = null;
            HttpWebResponse HttpWRes = null;
            HttpWebRequest HttpWReq = null;

            try
            {
                //http://<BESName>:<BESPort>/push?DESTINATTION=<PIN/EMAIL>&PORT=<PushPort>&REQUESTURI=/
                // Build the URL to define our connection to the BES.
                string httpURL = "http://" + this.blackberrySettings.BESAddress + ":" + blackberrySettings.BESWebServerListenPort.ToString()
                    + "/push?DESTINATION=" + notification.PushPin + "&PORT=" + blackberrySettings.BESPushPort.ToString()
                    + "&REQUESTURI=/";

                //make the connection
                HttpWReq = (HttpWebRequest)WebRequest.Create(httpURL);
                HttpWReq.Method = ("POST");
                //add the headers nessecary for the push
                HttpWReq.ContentType = "text/plain";
                HttpWReq.ContentLength = bytes.Length;
                // ******* Test this *******
                HttpWReq.Headers.Add("X-Rim-Push-Id", notification.PushPin + "~" + DateTime.Now); //"~" +pushedMessage +
                HttpWReq.Headers.Add("X-Rim-Push-Reliability", "application-preferred");
                HttpWReq.Headers.Add("X-Rim-Push-NotifyURL", (notification.WidgetNotificationUrl + notification.PushPin + "~" + notification.Message + "~" + DateTime.Now).Replace(" ", ""));

                // *************************
                HttpWReq.Credentials = new NetworkCredential(blackberrySettings.PushUsername, blackberrySettings.PushPassword);

                requestStream = HttpWReq.GetRequestStream();
                //Write the data from the source
                requestStream.Write(bytes, 0, bytes.Length);

                //get the response
                HttpWRes = (HttpWebResponse)HttpWReq.GetResponse();

                var pushStatus = HttpWRes.Headers["X-RIM-Push-Status"];

                //if the MDS received the push parameters correctly it will either respond with okay or accepted
                if (HttpWRes.StatusCode == HttpStatusCode.OK || HttpWRes.StatusCode == HttpStatusCode.Accepted)
                {
                    success = true;
                }
                else
                {
                    success = false;
                }
                //Close the streams

                HttpWRes.Close();
                requestStream.Close();
            }
            catch (System.Exception)
            {
                success = false;
            }

            return success;
        }
 public BlackberryNotificationException(BlackberryMessageStatus msgStatus, string desc, BlackberryNotification notification)
     : base(desc + " - " + msgStatus, notification)
 {
     Notification  = notification;
     MessageStatus = msgStatus;
 }
        void transport_UnhandledException(BlackberryNotification notification, Exception exception)
        {
            //Raise individual failures for each registration id for the notification
            this.Events.RaiseNotificationSendFailure(BlackberryNotification.ForSingleRegistrationId(notification, notification.PushPin),
                    exception);

            this.Events.RaiseChannelException(exception, PlatformType.Blackberry, notification);

            Interlocked.Decrement(ref waitCounter);
        }
        bool push(BlackberryNotification notification)
        {
            transport.Send(notification, blackberrySettings.PPGBaseURL, blackberrySettings.PushUsername, blackberrySettings.PushPassword);

            return true;
        }
Example #10
0
 public BlackberryNotificationException (BlackberryMessageStatus msgStatus, string desc, BlackberryNotification notification) 
     :base (desc + " - " + msgStatus, notification)
 {
     Notification = notification;
     MessageStatus = msgStatus;
 }