public AzureAppleNotification(BaseNotification baseNotification)
 {
     notification = baseNotification;
     aps = new Dictionary<string, string>();
     //alert = new Dictionary<string, string>();
     // Put everything in place, order is important here.
     //alert.Add("title", notification.Content);
     //alert.Add("body", notification.Content);
     aps.Add("alert", notification.Content);//JsonConvert.SerializeObject(alert));
     Content = notification.Content;
     Data = notification.Data;
     zendesk_sdk_request_id = notification.ZendeskTicketId;
 }
        public void SendNotificationToUser(Credential user, BaseNotification notification)
        {
            if (user == null || notification == null)
                throw new Exception("Missing parameters.");

            if (user.Devices == null || user.Devices.Count == 0)
                return; // no devices to send notification to.


            /* Example notification.
                notification.Data = string.Format("stylescvngr://ss/{0}", 1);
                notification.Content = "Welcome Fashionista! We Can't Wait to See Your Inspirations!";
             */
            foreach (UserDevice device in user.Devices)
            {
                if (!device.OptIn)
                    continue;
                //string tag = "id:" + device.Udid;
                string tag = "id:" + device.DeviceId;
                // Actually we should tag it with device ID as
                // tagging it by member ID will tag all devices
                // and they can be on different OS...
                if (device.Platform.Equals("gcm"))
                {
                    //Notification n = new GcmNotification("");
                    
                    var notif = //"{ \"data\" : {\"msg\":\"See your app.\"}}"; 
                        
                        "{\"data\" : {\"msg\":\"" +
                        notification.Content +
                        "\", \"url\":\"" +
                        notification.Data +
                        "\"}}";
                          
                    Hub.SendGcmNativeNotificationAsync(notif, tag);
                }
                else if (device.Platform.Equals("apns"))
                {
                    AzureAppleNotification notificationA = new AzureAppleNotification(notification);
                    string notificationJson = //"{\"aps\":{\"alert\":\"Tell dev you sa this.\"}}";
                                            JsonConvert.SerializeObject(notificationA);//notificationA.GetJson();
                    Task<NotificationOutcome> result = Hub.SendAppleNativeNotificationAsync(notificationJson, tag);
                    Console.WriteLine("Send complete.");
                    /*
                    var alert =
                        "{{\"url\":\"" + notification.Data +
                        "\"}, \"aps\":{\"alert\":\"" +
                        notification.Content + "\"}}";
                    Hub.SendAppleNativeNotificationAsync(alert, tag);
                     * */
                }
                else
                {
                    // we dont support any other platform. Should we throw an exception?
                }

            }
        }
예제 #3
0
        public HttpResponseMessage GetUserAppointments(long id)
        {
            try
            {
                // well all we want is to send this data to the device of user registered against
                // the user with the ticket id?
                /*
                if (data == null)
                    throw new ParamMissingException("Please send some data.");

                if(data.notification == null)
                    throw new ParamMissingException("Notification is empty, beats the purpose.");
                */

                /*
                if (string.IsNullOrWhiteSpace(tid))
                    throw new AlreadyExistsException("tid is empty.");
                long temp = 0;
                if (long.TryParse(tid, out temp) == false)
                    throw new InvalidValueException("Value is invalid.");
                 */
                Data.Entities.User user = _userManager.GetUserByTicketId(id, "new placeholder.");
                if (user == null)
                    throw new UserNotFoundException(string.Format("Unknown user. [{0}]", id));

                if (user.Credential.Devices != null && user.Credential.Devices.Count > 0)
                {
                        BaseNotification notification = new BaseNotification();
                        notification.Content = "New message from REOP.";
                        notification.Data = "New message from REOP.";
                        notification.ZendeskTicketId = id;
                        _serviceManager.PushNotification.SendNotificationToUser(user.Credential, notification);

                }
                else
                { return Request.CreateResponse(HttpStatusCode.OK, string.Format("Finised but [{0}]", id)); }

                return Request.CreateResponse(HttpStatusCode.OK, string.Format("Finised [{0}]", id));
            }
            catch (ParamMissingException e)
            {
                return Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse { Message = e.Message });
            }
            catch (AlreadyExistsException e)
            {
                return Request.CreateResponse(HttpStatusCode.Conflict, new ErrorResponse { Message = e.Message });
            }
            catch (InvalidValueException e)
            {
                return Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse { Message = e.Message });
            }
            catch (UserNotFoundException e)
            {
                // We have a special case here. If there is no user against the ticket... we can find the user who is
                // against the ticket and set this ticket ID against him?
                return Request.CreateResponse(HttpStatusCode.OK, new ErrorResponse { Message = e.Message });
            }
            catch (Exception e)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Message = "Oops, server encountered an issue... " + e.Message });
            }
        }