Пример #1
0
        public HttpResponseMessage SendSpectroDataToFCM(FcmRequest model)
        {
            bool IsSuccess = false;

            try
            {
                FCMRootObject FCMData          = new FCMRootObject();
                Notification  NotificationBody = new Notification();
                Data          NotificationData = new Data();

                string dt = ""; // getDeviceID();
                if (!string.IsNullOrWhiteSpace(dt))
                {
                    FCMData.to = dt;
                    NotificationData.Description = model.JsonModel;
                    NotificationBody.title       = "GI ADMIN";
                    NotificationBody.body        = model.JsonModel;
                    FCMData.data = NotificationData;

                    FCMResponse FCMResp = new FCMSender().SendClientNotification(FCMData);
                    IsSuccess = true;
                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new { FCMResp, IsSuccess }));
                }
                else
                {
                    IsSuccess = false;
                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new { Response = "Token Invalid.", IsSuccess }));
                }
            }
            catch (Exception ex)
            {
                ERRORREPORTING.Report(ex, Request.RequestUri.AbsoluteUri, new Guid("00000000-0000-0000-0000-000000000000"), "Gujarat_Intrux", "Function Name : SendSpectroDataToFCM()");
                IsSuccess = false;
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, new { ex.Message, IsSuccess }));
            }
        }
Пример #2
0
        public HttpResponseMessage InsertHeatStartStopReportAPI(ENT.HeatStartStopReport obj)
        {
            bool IsSuccess = false, IsSendToFcm = false; string ResMessage = string.Empty;

            try
            {
                if (obj != null)
                {
                    // insert data into live database
                    //if (new DAL.FurnaceSwitch().InsertFurnaceSwitchAPI(obj))
                    //{
                    //    ResMessage = "Data save successfully.";

                    #region Send Heat Data To FCM
                    if (!string.IsNullOrWhiteSpace(obj.heat_json))
                    {
                        FCMRootObject FCMData          = new FCMRootObject();
                        Notification  NotificationBody = new Notification();
                        Data          NotificationData = new Data();

                        // Send notification if device token found.
                        int count = 0;
                        List <ENT.Device> lstENT = getDeviceID();
                        for (int i = 0; i < lstENT.Count; i++)
                        {
                            if (!string.IsNullOrWhiteSpace(lstENT[i].DeviceId))
                            {
                                FCMData.to = lstENT[i].DeviceId;
                                NotificationData.Description = obj.heat_json;
                                NotificationBody.title       = "GI ADMIN";
                                NotificationBody.body        = obj.heat_json;
                                FCMData.data = NotificationData;
                                // FCMData.notification = NotificationBody;

                                // send notification using FCM sender
                                FCMResponse s = new FCMSender().SendClientNotification(FCMData);
                                if (s.success > 0)
                                {
                                    // successfull send notification count
                                    count++;
                                }
                            }
                        }
                        if (count == lstENT.Count)
                        {
                            IsSendToFcm = true;
                        }
                        else
                        {
                            IsSendToFcm = false;
                        }
                        ResMessage += "[" + count.ToString() + "] Notification Send Successfull Out of [" + lstENT.Count + "].";
                    }
                    #endregion

                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new { response = ResMessage }));

                    //}
                    //else
                    //{
                    //    return ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, new { response = "Internal Server Error." });
                    //}
                }
                else
                {
                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new { response = "Data should not be empty or null." }));
                }
            }
            catch (Exception ex)
            {
                ERRORREPORTING.Report(ex, Request.RequestUri.AbsoluteUri, new Guid("00000000-0000-0000-0000-000000000000"), "Gujarat_Intrux", "Function Name : SaveDeviceID()");
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, new { ex.Message }));
            }
        }
Пример #3
0
    public FCMResponse PushNotifyAsync(string to, string message, Guid userid, int deviceType = 1)
    {
        FCMResponse res      = new FCMResponse();
        string      response = string.Empty;

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

            // create data object
            FCMRootObject dataObject = new FCMRootObject();
            dataObject.priority          = "high";
            dataObject.content_available = true;
            dataObject.to = to;

            Notification NotificationBody = new Notification
            {
                body  = message,
                title = "WEB RECHARGE",
                sound = "default"
            };

            // if devicetype = 0 then IOS and 1 for android
            // so we are not passing NotificationBody to android
            if (deviceType == 0)
            {
                dataObject.notification = NotificationBody;
            }

            Data data = new Data
            {
                Description       = message,
                NotificationTitle = "WEB RECHARGE",
                UserId            = userid,
            };

            // create data object end
            dataObject.data = data;

            string jsonNotificationFormat = Newtonsoft.Json.JsonConvert.SerializeObject(dataObject);
            Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);

            tRequest.Headers.Add(string.Format("Authorization: key={0}", ServerKey));
            tRequest.Headers.Add(string.Format("Sender: id={0}", SenderID));

            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))
                        {
                            response = tReader.ReadToEnd();
                            res      = Newtonsoft.Json.JsonConvert.DeserializeObject <FCMResponse>(response);
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            response = ex.Message;
        }
        return(res);
    }
Пример #4
0
        public HttpResponseMessage SaveSpectroMaster(ENT.SpectroMaster Model)
        {
            bool   IsSuccess = false, IsSendToFcm = false;
            string ResMessage = string.Empty;

            try
            {
                #region Send Spectro Data To FCM

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

                int count = 0;
                List <ENT.Device> lstENT = getDeviceID();
                for (int i = 0; i < lstENT.Count; i++)
                {
                    if (!string.IsNullOrWhiteSpace(lstENT[i].DeviceId))
                    {
                        FCMData.to = lstENT[i].DeviceId;
                        NotificationData.Description = Model.SpectroJson;
                        NotificationBody.title       = "GI ADMIN";
                        NotificationBody.body        = Model.SpectroJson;
                        FCMData.data = NotificationData;
                        // FCMData.notification = NotificationBody;

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

                #endregion

                #region Save Master To Local Database

                Int64 SpectroNo = new DAL.SpectroEntry().GetTopOneSpectroNo();
                Model.Mode      = "ADD";
                Model.SpectroID = Guid.NewGuid();
                Model.SpectroNo = SpectroNo + 1;

                DateTime dt1    = DateTime.Now;
                string[] dtDate = Model.SpectroDate.Split('/');
                if (dtDate.Length == 3)
                {
                    dt1 = new DateTime(Convert.ToInt32(dtDate[2]), Convert.ToInt32(dtDate[0]), Convert.ToInt32(dtDate[1]));
                }
                Model.SpectroDate = dt1.ToString("dd/MMM/yyyy");
                if (new DAL.SpectroEntry().InsertUpdateDeleteSpectroMaster(Model))
                {
                    ResMessage += " Entry Save Successfully.";
                    IsSuccess   = true;
                }
                else
                {
                    ResMessage += " Entry Not Save Successfully.";
                    IsSuccess   = false;
                }

                #endregion
            }
            catch (Exception ex)
            {
                ResMessage += ResMessage + " Error: " + ex.Message;
                IsSuccess   = false;
                ERRORREPORTING.Report(ex, Request.RequestUri.AbsoluteUri, new Guid("00000000-0000-0000-0000-000000000000"), "Gujarat_Intrux", "Function Name : SaveSpectroMaster()");
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, new { ResMessage, IsSuccess, IsSendToFcm }));
            }
            return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, new { ResMessage, IsSuccess, IsSendToFcm }));
        }