Example #1
0
 public static void sendNotification(int peopleID, int type, int id, string title, string message)
 {
     GCMPayload notification = new GCMPayload(title, message);
     GCMData data = new GCMData(type, ACTION_REFRESH_AND_NOTIFY, id, title, message);
     GCMMessage msg = new GCMMessage(peopleID, null, data, notification);
     send(msg);
 }
Example #2
0
        public void sendRefresh(int peopleID, int type)
        {
            GCMData    data = new GCMData(type, ACTION_REFRESH, 0, "", "");
            GCMMessage msg  = new GCMMessage(peopleID, null, data, null, _host, _dataContext);

            send(msg);
        }
Example #3
0
        public static void sendRefresh(List<int> peopleIDs, int type)
        {
            if (peopleIDs.Count == 0) return;

            GCMData data = new GCMData(type, ACTION_REFRESH, 0, "", "");
            GCMMessage msg = new GCMMessage(peopleIDs, null, data, null);
            send(msg);
        }
Example #4
0
        public void sendNotification(int peopleID, int type, int id, string title, string message)
        {
            GCMPayload notification = new GCMPayload(title, message);
            GCMData    data         = new GCMData(type, ACTION_REFRESH_AND_NOTIFY, id, title, message);
            GCMMessage msg          = new GCMMessage(peopleID, null, data, notification, _host, _dataContext);

            send(msg);
        }
Example #5
0
        public static void sendNotification(List<int> peopleIDs, int type, int id, string title, string message)
        {
            if (peopleIDs.Count == 0) return;

            GCMPayload notification = new GCMPayload(title, message);
            GCMData data = new GCMData(type, ACTION_REFRESH_AND_NOTIFY, id, title, message);
            GCMMessage msg = new GCMMessage(peopleIDs, null, data, notification);
            send(msg);
        }
Example #6
0
        public void sendRefresh(List <int> peopleIDs, int type)
        {
            if (peopleIDs.Count == 0)
            {
                return;
            }

            GCMData    data = new GCMData(type, ACTION_REFRESH, 0, "", "");
            GCMMessage msg  = new GCMMessage(peopleIDs, null, data, null, _host, _dataContext);

            send(msg);
        }
Example #7
0
        public void sendNotification(List <int> peopleIDs, int type, int id, string title, string message)
        {
            if (peopleIDs.Count == 0)
            {
                return;
            }

            GCMPayload notification = new GCMPayload(title, message);
            GCMData    data         = new GCMData(type, ACTION_REFRESH_AND_NOTIFY, id, title, message);
            GCMMessage msg          = new GCMMessage(peopleIDs, null, data, notification, _host, _dataContext);

            send(msg);
        }
Example #8
0
        private static void send(GCMMessage message)
        {
            if (message.registration_ids.Count == 0) return;

            System.Threading.Tasks.Task.Factory.StartNew(() => {
                string json = JsonConvert.SerializeObject(message);
                string host = Util.Host;

                Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;

                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Authorization", "key=" + ConfigurationManager.AppSettings["GCMKey"]);
                    webClient.Headers.Add("Content-Type", "application/json");
                    webClient.Encoding = Encoding.UTF8;

                    string results = webClient.UploadString(GCM_URL, json);

                    GCMResponse response = JsonConvert.DeserializeObject<GCMResponse>(results);

                    var Db = DbUtil.Create(host);

                    for (int iX = 0; iX < message.registration_ids.Count; iX++)
                    {
                        if (response.results.Count > iX)
                        {
                            string registrationID = message.registration_ids[iX];
                            GCMResponseResult result = response.results[iX];

                            if (result.error != null && result.error.Length > 0)
                            {
                                switch (result.error)
                                {
                                    case "InvalidRegistration":
                                    case "NotRegistered":
                                    {
                                        var record = (from r in Db.MobileAppPushRegistrations
                                                      where r.RegistrationId == registrationID
                                                      select r).SingleOrDefault();

                                        if (record != null)
                                            Db.MobileAppPushRegistrations.DeleteOnSubmit(record);

                                        break;
                                    }
                                }
                            }
                            else if (result.error != null && result.registration_id.Length > 0)
                            {
                                var record = (from r in Db.MobileAppPushRegistrations
                                              where r.RegistrationId == registrationID
                                              select r).SingleOrDefault();

                                record.RegistrationId = result.registration_id;
                            }
                        }
                    }

                    Db.SubmitChanges();
                }
            });
        }
Example #9
0
 public static void sendRefresh(int peopleID, int type)
 {
     GCMData data = new GCMData(type, ACTION_REFRESH, 0, "", "");
     GCMMessage msg = new GCMMessage(peopleID, null, data, null);
     send(msg);
 }
Example #10
0
        private static void send(GCMMessage message)
        {
            string gcmkey = DbUtil.Db.Setting("GCMKey", ConfigurationManager.AppSettings["GCMKey"]);

            if (message.registration_ids.Count == 0 || gcmkey.Length == 0) return;

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                string json = JsonConvert.SerializeObject(message);
                string host = Util.Host;

                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Authorization", "key=" + gcmkey);
                    webClient.Headers.Add("Content-Type", "application/json");
                    webClient.Encoding = Encoding.UTF8;

                    string results = webClient.UploadString(GCM_URL, json);

                    GCMResponse response = JsonConvert.DeserializeObject<GCMResponse>(results);

                    var Db = DbUtil.Create(host);

                    for (int iX = 0; iX < message.registration_ids.Count; iX++)
                    {
                        if (response.results.Count > iX)
                        {
                            string registrationId = message.registration_ids[iX];
                            GCMResponseResult result = response.results[iX];

                            if (!string.IsNullOrEmpty(result.error))
                            {
                                switch (result.error)
                                {
                                    case "InvalidRegistration":
                                    case "NotRegistered":
                                    {
                                        var record = (from r in Db.MobileAppPushRegistrations
                                                      where r.RegistrationId == registrationId
                                                      select r).SingleOrDefault();

                                        if (record != null)
                                            Db.MobileAppPushRegistrations.DeleteOnSubmit(record);

                                        break;
                                    }
                                }
                            }
                            else if (result.error != null && result.registration_id.Length > 0)
                            {
                                var record = (from r in Db.MobileAppPushRegistrations
                                              where r.RegistrationId == registrationId
                                              select r).SingleOrDefault();

                                if (record != null)
                                    record.RegistrationId = result.registration_id;
                            }
                        }
                    }

                    Db.SubmitChanges();
                }
            });
        }
Example #11
0
        private void send(GCMMessage message)
        {
            if (!_host.HasValue())
            {
                return;
            }

            string gcmkey = _dataContext.Setting("GCMKey", ConfigurationManager.AppSettings["GCMKey"]);

            if (message.registration_ids.Count == 0 || gcmkey.Length == 0)
            {
                return;
            }

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var threadDb = CMSDataContext.Create(_host);

                string json = JsonConvert.SerializeObject(message);

                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Authorization", "key=" + gcmkey);
                    webClient.Headers.Add("Content-Type", "application/json");
                    webClient.Encoding = Encoding.UTF8;

                    string results = webClient.UploadString(GCM_URL, json);

                    GCMResponse response = JsonConvert.DeserializeObject <GCMResponse>(results);

                    for (int iX = 0; iX < message.registration_ids.Count; iX++)
                    {
                        if (response.results.Count <= iX)
                        {
                            continue;
                        }

                        string registrationId    = message.registration_ids[iX];
                        GCMResponseResult result = response.results[iX];

                        if (!string.IsNullOrEmpty(result.error))
                        {
                            switch (result.error)
                            {
                            case "InvalidRegistration":
                            case "NotRegistered":
                                {
                                    var record = (from r in threadDb.MobileAppPushRegistrations
                                                  where r.RegistrationId == registrationId
                                                  select r).SingleOrDefault();

                                    if (record != null)
                                    {
                                        threadDb.MobileAppPushRegistrations.DeleteOnSubmit(record);
                                    }

                                    break;
                                }
                            }
                        }
                        else if (result.error != null && result.registration_id.Length > 0)
                        {
                            var record = (from r in threadDb.MobileAppPushRegistrations
                                          where r.RegistrationId == registrationId
                                          select r).SingleOrDefault();

                            if (record != null)
                            {
                                record.RegistrationId = result.registration_id;
                            }
                        }
                    }

                    threadDb.SubmitChanges();
                }
            });
        }
Example #12
0
        private static void send(GCMMessage message)
        {
            string gcmkey = DbUtil.Db.Setting("GCMKey", ConfigurationManager.AppSettings["GCMKey"]);

            if (message.registration_ids.Count == 0 || gcmkey.Length == 0)
            {
                return;
            }

            System.Threading.Tasks.Task.Factory.StartNew(() => {
                string json = JsonConvert.SerializeObject(message);
                string host = Util.Host;

                Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;

                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Authorization", "key=" + gcmkey);
                    webClient.Headers.Add("Content-Type", "application/json");
                    webClient.Encoding = Encoding.UTF8;

                    string results = webClient.UploadString(GCM_URL, json);

                    GCMResponse response = JsonConvert.DeserializeObject <GCMResponse>(results);

                    var Db = DbUtil.Create(host);

                    for (int iX = 0; iX < message.registration_ids.Count; iX++)
                    {
                        if (response.results.Count > iX)
                        {
                            string registrationID    = message.registration_ids[iX];
                            GCMResponseResult result = response.results[iX];

                            if (result.error != null && result.error.Length > 0)
                            {
                                switch (result.error)
                                {
                                case "InvalidRegistration":
                                case "NotRegistered":
                                    {
                                        var record = (from r in Db.MobileAppPushRegistrations
                                                      where r.RegistrationId == registrationID
                                                      select r).SingleOrDefault();

                                        if (record != null)
                                        {
                                            Db.MobileAppPushRegistrations.DeleteOnSubmit(record);
                                        }

                                        break;
                                    }
                                }
                            }
                            else if (result.error != null && result.registration_id.Length > 0)
                            {
                                var record = (from r in Db.MobileAppPushRegistrations
                                              where r.RegistrationId == registrationID
                                              select r).SingleOrDefault();

                                record.RegistrationId = result.registration_id;
                            }
                        }
                    }

                    Db.SubmitChanges();
                }
            });
        }