public void Simple()
    {
        var service = new PushService
            {
                RequestBuilder = RequestBuilderHelper.Build()
            };
        var request = new PushNotificationRequest
            {
                DeviceTokens = new List<string>
                    {
                        "BadToken"
                    },
                Payload = new PushPayload
                    {
                        Alert = "Alert"
                    },
            };

        Exception exception = null;
        try
        {

            var asyncTestHelper = new AsyncTestHelper();
            service.Execute(request, respone => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
            asyncTestHelper.Wait();
        }
        catch (Exception e)
        {
            exception = e;
        }

        var remoteException = exception as RemoteException;
        Assert.IsNotNull(remoteException);
        Assert.AreEqual("{\"error_code\": 40001, \"details\": {\"device_tokens.0.device_token\": [\"device_token contains an invalid device token: BADTOKEN\"]}, \"error\": \"Data validation error\"}", remoteException.Message);
    }
        public void Simple()
        {
            var service = new PushService
                {
                    RequestBuilder = RequestBuilderHelper.Build()
                };
            var pushNotification = new PushNotificationRequest
                {
                    DeviceTokens = new List<string>
                        {
                            RemoteSettings.AppleDeviceId
                        },
                    Payload = new PushPayload
                        {
                            Alert = "Alert"
                        },
                    CustomData = new Dictionary<string, string>
                        {
                         {"Key", "Value"}
                        }
                };

            var asyncTestHelper = new AsyncTestHelper();
            service.Execute(pushNotification, response => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
            asyncTestHelper.Wait();
        }
        public void ToTag()
        {
            var service = new PushService
                {
                    RequestBuilder = RequestBuilderHelper.Build()
                };
            var pushNotification = new PushNotificationRequest
                {
                    Tags = new List<string> { "africa" },
                    Payload = new PushPayload
                        {
                            Alert = "Alert 2"
                        }
                };

            var asyncTestHelper = new AsyncTestHelper();
            service.Execute(pushNotification, response => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
            asyncTestHelper.Wait();
        }
 public void Simple()
 {
     var service = new PushService
                       {
                           RequestBuilder = ServerRequestBuilder.Instance
                       };
     var notification = new PushNotificationRequest
                            {
                                Tags = new List<string> {"MyTag"},
                                ExcludeTokens = new List<string> {"TokenToExclude"},
                                DeviceTokens = new List<string> {"AppleDeviceId"},
                                Aliases = new List<string> {"MyAlias"},
                                Payload = new PushPayload
                                              {
                                                  Alert = "Alert 2",
                                                  Badge = Badge.SetTo(2),
                                                  Sound = "Sound1"
                                              }
                            };
     service.Execute(notification, response => Debug.WriteLine("Success"),ExceptionHandler.Handle);
 }
        public void ToAlias()
        {
            var service = new PushService
            {
                RequestBuilder = RequestBuilderHelper.Build()
            };

            var random = new Random();
            var pushNotification = new PushNotificationRequest
            {
                Aliases = new List<string>(new string[] { "1gzod" }),                
                Payload = new PushPayload
                {
                    Badge = random.Next(100),
                    Alert = "What's up iPhone",
                }
            };

            var asyncTestHelper = new AsyncTestHelper();
            service.Execute(pushNotification, response => asyncTestHelper.Callback(null), asyncTestHelper.HandleException);
            asyncTestHelper.Wait();
        }
        private void PushToCustomer(long CustomerID, string Text, long ChallengeID=0)
        {
            IPushServiceTokenRepository tokenRepo = RepoFactory.GetPushServiceTokenRepo();

            AddRegistrationService reg = new AddRegistrationService { RequestBuilder = GetIOSUAProductionCredentials() };
            PushService service = new PushService { RequestBuilder = GetIOSUAProductionCredentials() };

            List<string> pushTokens = new List<string>();

            foreach (PushServiceToken t in tokenRepo.TokensForCustomer(CustomerID))
            {
                reg.Execute(t.Token, new Registration());
                pushTokens.Add(t.Token);
                Trace.WriteLine("PUSH: Registering device token "+t.Token+" for customer "+CustomerID);
            }

            if (pushTokens.Count == 0)
                return;

            PushPayload payload = new PushPayload();
            payload.Alert = Text;
            payload.Badge = "0";

            Trace.WriteLine("PUSH: Pushing \"" + Text + "\" to " + pushTokens.Count.ToString()+" clients - "+pushTokens.ToString());

            Dictionary<string, string> customData=null;

            if (ChallengeID > 0)
            {
                customData = new Dictionary<string, string>();
                customData.Add("dareid", ChallengeID.ToString());
            }
            try
            {
                PushNotification notification = new PushNotification { DeviceTokens = pushTokens, Payload = payload, CustomData=customData };
                service.Execute(notification);
            }
            catch (Exception e)
            {
                Trace.WriteLine("PUSH: Exception encountered, " + e.ToString());
            }
        }