Exemplo n.º 1
0
        /// <summary>
        /// this function is not in use
        /// </summary>
        /// <returns></returns>
        private static string SendNotification(string jsonNotification)
        {
            string ResMessage = string.Empty;

            try
            {
                #region Send Spectro Data To FCM

                ENT.FCMRootObject FCMData          = new ENT.FCMRootObject();
                ENT.Notification  NotificationBody = new ENT.Notification();
                ENT.Data          NotificationData = new ENT.Data();

                int count = 0;
                List <ENT.Device> lstENT = GetDeviceTokenList();
                Console.WriteLine(lstENT.Count + " Device Found.");
                WriteLog(lstENT.Count + " Device Found.");

                for (int i = 0; i < lstENT.Count; i++)
                {
                    if (!string.IsNullOrWhiteSpace(lstENT[i].DeviceId))
                    {
                        FCMData.to = lstENT[i].DeviceId;
                        NotificationData.Description = jsonNotification;
                        NotificationBody.title       = "GI ADMIN";
                        NotificationBody.body        = jsonNotification;
                        FCMData.data = NotificationData;
                        // FCMData.notification = NotificationBody;

                        ENT.FCMResponse s = new ENT.FCMSender().SendClientNotification(FCMData);
                        if (s.success > 0)
                        {
                            count++;
                        }
                    }
                }
                ResMessage = count.ToString() + " notification send successfull out of " + lstENT.Count + ".";

                #endregion
            }
            catch (Exception ex)
            {
                ResMessage = ex.Message;
                return(ResMessage);
            }
            return(ResMessage);
        }
Exemplo n.º 2
0
        public FCMResponse SendClientNotification(FCMRootObject dataObject)
        {
            FCMResponse response = new FCMResponse();

            try
            {
                WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                tRequest.Method              = "POST";
                tRequest.ContentType         = "application/json";
                dataObject.priority          = "high";
                dataObject.content_available = true;

                string jsonNotificationFormat = Newtonsoft.Json.JsonConvert.SerializeObject(dataObject);

                Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);

                tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAA5HUiHNg:APA91bFxsl58O6JwOos7lubeXi7-P7VhyFwOrqZEK3CA4qz2cklFjSQyhRwD-CeBPvL6YF23ii7dcCkLKy0F5-YaIhrYbPzLCpv0whwLIPT1L02jC7iioTTWotWVbjHXS7BVo87SRnuP"));
                tRequest.Headers.Add(string.Format("Sender: id={0}", "981217713368"));

                tRequest.ContentLength = byteArray.Length;
                tRequest.ContentType   = "application/json";
                using (Stream dataStream = tRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);

                    using (WebResponse tResponse = tRequest.GetResponse())
                    {
                        using (Stream dataStreamResponse = tResponse.GetResponseStream())
                        {
                            using (StreamReader tReader = new StreamReader(dataStreamResponse))
                            {
                                String responseFromFirebaseServer = tReader.ReadToEnd();

                                response = Newtonsoft.Json.JsonConvert.DeserializeObject <FCMResponse>(responseFromFirebaseServer);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return(response);
        }
Exemplo n.º 3
0
        public FCMResponse SendClientNotification(FCMRootObject dataObject)
        {
            FCMResponse response = new FCMResponse();

            try
            {
                WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                tRequest.Method              = "POST";
                tRequest.ContentType         = "application/json";
                dataObject.priority          = "high";
                dataObject.content_available = true;

                string jsonNotificationFormat = Newtonsoft.Json.JsonConvert.SerializeObject(dataObject);

                Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);

                tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAAzUlKJsQ:APA91bGszjREoPf3qU-lC1ZpJ6l2adVlFEsF2N26PFIVZ5Mq4lz4JaWrKph55tHBuOV17GBpkAvaBUKba5gpSjU1jvUt4vYj_VjVfuhdVq4edW-4hgwviVO9C0VBDofmU_qm0R2hcxbV"));
                tRequest.Headers.Add(string.Format("Sender: id={0}", "881697892036"));

                tRequest.ContentLength = byteArray.Length;
                tRequest.ContentType   = "application/json";
                using (Stream dataStream = tRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);

                    using (WebResponse tResponse = tRequest.GetResponse())
                    {
                        using (Stream dataStreamResponse = tResponse.GetResponseStream())
                        {
                            using (StreamReader tReader = new StreamReader(dataStreamResponse))
                            {
                                String responseFromFirebaseServer = tReader.ReadToEnd();

                                response = Newtonsoft.Json.JsonConvert.DeserializeObject <FCMResponse>(responseFromFirebaseServer);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(response);
        }