コード例 #1
0
        private void SendFCM()
        {
            try
            {
                FCMAttributes attribute = new FCMAttributes();
                attribute.SenderId = this.record.SenderId;
                attribute.AppId    = this.record.AppId;

                FCMSender fcm_sender = new FCMSender();

                FCMNotificationData data = new FCMNotificationData();
                data.Title = "更新通知";
                data.Body  = "有一則推播通知";

                string response = null; // 回應結果內容
                fcm_sender.SendPushNotification <FCMNotificationData>(attribute, this.record.DeviceTokens, data, out response);

                MessageBox.Show(response);
            }
            catch (Exception ex)
            {
                MessageBox.Show("error happen:" + ex.ToString());
            }
        }
コード例 #2
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 }));
            }
        }
コード例 #3
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 }));
            }
        }
コード例 #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 }));
        }