Exemplo n.º 1
0
        // GET: api/Person/5
        public ArrayList Get(String id)
        {
            FriendsPersistence pp = new FriendsPersistence();

            /*Friends p = pp.getFriends(id);
             * if (p == null)
             * {
             *  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
             * }*/
            return(pp.getFriends(id));
        }
Exemplo n.º 2
0
        // POST: api/friends
        public HttpResponseMessage Post([FromBody] Friends value)
        {
            FriendsPersistence pp = new FriendsPersistence();
            String             id;

            id = pp.saveFriend(value);



            value.UserFBID = id;
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);

            response.Headers.Location = new Uri(Request.RequestUri, String.Format("/friends/{0}", id));
            return(response);
        }
Exemplo n.º 3
0
        public HttpResponseMessage Delete(string userId, string friendId)
        {
            FriendsPersistence pp = new FriendsPersistence();
            bool recordExisted    = false;

            recordExisted = pp.deleteFriend(userId, friendId);

            HttpResponseMessage response;

            if (recordExisted)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
Exemplo n.º 4
0
        // PUT: api/Person/5
        public HttpResponseMessage Put(string id, [FromBody] Friends value)
        {
            FriendsPersistence pp = new FriendsPersistence();
            bool recordExisted    = false;

            recordExisted = pp.updateFriend(id, value);


            HttpResponseMessage response;

            if (recordExisted)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
        // POST: api/Victim
        public async System.Threading.Tasks.Task <HttpResponseMessage> Post(string pns, [FromBody] Victim value, string to_tag)
        {
            var user = value.FBID;


            string[] userTag = new string[2];
            userTag[0] = "username:"******"T"
            FriendsPersistence fp      = new FriendsPersistence();
            ArrayList          friends = fp.getFriends(value.FBID);


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

                    break;

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

                    break;

                case "gcm":
                    // Android
                    //value.UserName + " Need Help from you. The User ID =" + value.FBID
                    var notif = "{ \"data\" : {\"message\":\"" + "From " + value.UserName + " Need Help from you. The User ID =" + value.FBID + "\"}}";
                    outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, f.FriendFBID + "T");

                    break;
                }

                if (outcome != null)
                {
                    if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) ||
                          (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown)))
                    {
                        ret = HttpStatusCode.OK;
                    }
                }
            }
            // return Request.CreateResponse(ret);
            /////////////////////////////////////////////////////////here for every friend-End



            VictimPersistence pp = new VictimPersistence();
            String            id;

            id = pp.saveUser(value);

            /*
             * // Get the settings for the server project.
             * HttpConfiguration config = this.Configuration;
             * MobileAppSettingsDictionary settings =
             *  this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings();
             *
             * // Get the Notification Hubs credentials for the Mobile App.
             * string notificationHubName = settings.NotificationHubName;
             * string notificationHubConnection = settings
             *  .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString;
             *
             * // Create a new Notification Hub client.
             * NotificationHubClient hub = NotificationHubClient
             * .CreateClientFromConnectionString(notificationHubConnection, notificationHubName);
             *
             * // Sending the message so that all template registrations that contain "messageParam"
             * // will receive the notifications. This includes APNS, GCM, WNS, and MPNS template registrations.
             * Dictionary<string, string> templateParams = new Dictionary<string, string>();
             * templateParams["messageParam"] = value.UserName + " Need Help from you. The User ID =" + value.FBID;
             *
             * try
             * {
             *  // Send the push notification and log the results.
             *  var result = await hub.SendTemplateNotificationAsync(templateParams);
             *
             *  // Write the success result to the logs.
             *  config.Services.GetTraceWriter().Info(result.State.ToString());
             * }
             * catch (System.Exception ex)
             * {
             *  // Write the failure result to the logs.
             *  config.Services.GetTraceWriter()
             *      .Error(ex.Message, null, "Push.SendAsync Error");
             * }
             */
            value.FBID = id;
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);

            response.Headers.Location = new Uri(Request.RequestUri, String.Format("/user/{0}", id));
            return(response);
        }
Exemplo n.º 6
0
        public async System.Threading.Tasks.Task sendpushNotificationAsync()
        {
            var user = FBID;

            string to_tag = FBID + "T";

            string[] userTag = new string[2];
            userTag[0] = "username:"******"T"
            FriendsPersistence fp      = new FriendsPersistence();
            ArrayList          friends = fp.getFriends(FBID);
            string             pns     = "gcm";

            bool firsttime = true;

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

                        break;

                    case "apns":
                        // iOS
                        var alert = "{\"aps\":{\"alert\":\"" + "From " + UserName + " Need Help from you. The User ID =[" + FBID
                                    + "] [" + Latitude + "] [" + Longitude + "]\"}}";
                        outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, f.FriendFBID + "T");

                        if (firsttime)
                        {
                            var alert1 = "{\"aps\":{\"alert\":\"" + "Your alarm was successfully sent to all your friends ID =[" + FBID
                                         + "] [" + Latitude + "] [" + Longitude + "]\"}}";
                            outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert1, FBID + "T");

                            firsttime = false;
                        }
                        break;

                    case "gcm":
                        // Android
                        //{"data":{"message":"From Hussi Need Help from you. The User ID =[132569873917640] [56.6642811] [12.8778527]"}}

                        if (f.FriendFBID.Equals(FBID))
                        {
                            var notif = "{ \"data\" : {\"message\":\"" + "From yourfriend"
                                        + " Need Help from you. The User ID =[" + f.UserFBID
                                        + "] [" + Latitude + "] [" + Longitude + "]\"}}";
                            outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, f.UserFBID + "T");
                        }
                        else
                        {
                            var notif = "{ \"data\" : {\"message\":\"" + "From " + UserName
                                        + " Need Help from you. The User ID =[" + FBID
                                        + "] [" + Latitude + "] [" + Longitude + "]\"}}";
                            outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, f.FriendFBID + "T");
                        }

                        if (firsttime)
                        {
                            System.Threading.Thread.Sleep(500);
                            var notif = "{ \"data\" : {\"message\":\"" + "Your alarm was successfully sent to all your friends ID =[" + FBID
                                        + "] [" + Latitude + "] [" + Longitude + "]\"}}";
                            outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, FBID + "T");

                            firsttime = false;
                        }


                        break;
                    }

                    if (outcome != null)
                    {
                        if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) ||
                              (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown)))
                        {
                            ret = HttpStatusCode.OK;
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        // GET: api/Person
        public ArrayList Get()
        {
            FriendsPersistence pp = new FriendsPersistence();

            return(pp.getFriends());
        }