public bool CheckToken(ref DeTokenProperties input) { string byPass = ConfigurationSettings.AppSettings["token"].ToString(); if (input.inputToken == byPass) { return(true); } else { return(false); } }
public IHttpActionResult CheckPointSendNotic([FromBody] GetRequestDataRequests req) { int stage; bool debugEmail = Convert.ToBoolean(ConfigurationManager.AppSettings["debugEmail"]); if (debugEmail == true) { MailCustom mailM = new MailCustom("*****@*****.**", "*****@*****.**", "bayernmunichm21"); mailM.sendMail("DeviceDataChanged", JsonConvert.SerializeObject(req)); } #region Check Token var re = Request; var headers = re.Headers; string tokenHeader = ""; if (headers.Contains("Authorization")) { tokenHeader = headers.Authorization.Parameter; } DeTokenProperties detoken = new DeTokenProperties(); detoken.inputIp = GetUser_IP(); detoken.inputToken = tokenHeader; if (!_authen.CheckToken(ref detoken)) { return(Unauthorized()); } #endregion try { TrackingResponse traksend = new TrackingResponse(); LogDatabase updateLog = new LogDatabase(); CallService callService = new CallService(); int countPosition = 0; string lastLatPoint, lastLonPoint, areaStatusInOut, lastDifCurrent, inOutSaveZone, a; string returnStatus = null; string nameTh = string.Empty; string nameEn = string.Empty; bool NoPosition = false; DataTable dtResultIden = new DataTable(); DataTable dtResultCallInOut = new DataTable(); DataTable dtUpdateDeviceCurrent = new DataTable(); DataTable dtInsertDataToLocationLog = new DataTable(); DataTable dtReUpdateDeviceCurrent = new DataTable(); DataTable dtInsertActivityLog = new DataTable(); dtResultIden = null; dtReUpdateDeviceCurrent = null; dtInsertActivityLog = null; //ตรวจสอบข้อมูล เเละทำการส่ง SOS if (req.sos == 1) { bool checkHaveTicket = callService.sosSend(req); } stage = 0; //ตรวจสอบมีจุดส่งมาหรือไม่ ถ้าไม่มีไม่ต้องไป Iden // ** จุดไม่มี , จุดมี if (req.position.Count() > 0) { countPosition = req.position.Count() - 1; lastLatPoint = req.position[countPosition].latitude.ToString(); lastLonPoint = req.position[countPosition].longitude.ToString(); dtResultIden = callService.Identify(lastLatPoint, lastLonPoint); dtResultCallInOut = CheckInOutArea(lastLatPoint, lastLonPoint, req.deviceId); } else { NoPosition = true; lastLatPoint = string.Empty; lastLonPoint = string.Empty; dtResultCallInOut.Columns.Add("AreaStatus"); dtResultCallInOut.Columns.Add("AreaId"); DataRow row = dtResultCallInOut.NewRow(); row["AreaStatus"] = null; row["AreaId"] = null; dtResultCallInOut.Rows.Add(row); } if (dtResultCallInOut.Rows[0]["AreaStatus"].ToString() == "0" || dtResultCallInOut.Rows[0]["AreaStatus"].ToString() == null) { dtResultCallInOut.Rows[0]["AreaStatus"] = DBNull.Value; } if (dtResultCallInOut.Rows[0]["AreaId"].ToString() == "0" || dtResultCallInOut.Rows[0]["AreaId"].ToString() == null) { dtResultCallInOut.Rows[0]["AreaId"] = DBNull.Value; } //Call service :: Push Notification Event by Device // Online Offline dtInsertActivityLog = updateLog.InsertActivityLog(req, "onlineoffline", dtResultCallInOut.Rows[0]["AreaStatus"].ToString()); bool dtPushEvent = callService.callMobilServiceEvent(dtInsertActivityLog); //battery Level dtInsertActivityLog = updateLog.InsertActivityLog(req, "baterryLevel", dtResultCallInOut.Rows[0]["AreaStatus"].ToString()); dtPushEvent = callService.callMobilServiceEvent(dtInsertActivityLog); // In out Area dtInsertActivityLog = updateLog.InsertActivityLog(req, "InoutArea", dtResultCallInOut.Rows[0]["AreaStatus"].ToString()); dtPushEvent = callService.callMobilServiceEvent(dtInsertActivityLog); stage = 4; // req : ตัวที่ได้มาจาก Raw data dtResultIden : ได้มาจาก Identify , NoPosition : ใช้ตรวจสอบว่ามี ตำแหน่งส่งมาหรือไม่ , dtResultCallInOut : ได้มาจากการ Update InoutArea , dtInsertActivityLog ได้มาจากตัว set Activitylog dtInsertDataToLocationLog = updateLog.InsertDataToLocationLog(req, dtResultIden, NoPosition, dtResultCallInOut); stage = 5; dtReUpdateDeviceCurrent = UpdateDeviceCurrent(dtResultIden, req, NoPosition, dtResultCallInOut); stage = 6; //การ set ค่า input status ที่จะส่งไปที่ signalR returnStatus = dtReUpdateDeviceCurrent.Rows[0]["AreaStatus"].ToString(); if (dtResultIden != null) { nameTh = dtReUpdateDeviceCurrent.Rows[0]["locationNameTh"].ToString(); nameEn = dtReUpdateDeviceCurrent.Rows[0]["locationNameEn"].ToString(); traksend.latitude = Convert.ToDouble(dtReUpdateDeviceCurrent.Rows[0]["Latitude"]); traksend.longitude = Convert.ToDouble(dtReUpdateDeviceCurrent.Rows[0]["Longitude"]); traksend.inout_status = returnStatus; if (nameTh == "" || nameTh == null) { traksend.thai_address = dtReUpdateDeviceCurrent.Rows[0]["locationProvinceTh"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationDistrictTh"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationSubDistrictTh"].ToString(); } else { traksend.thai_address = dtReUpdateDeviceCurrent.Rows[0]["locationNameTh"].ToString(); } if (nameEn == "" || nameEn == null) { traksend.english_address = dtReUpdateDeviceCurrent.Rows[0]["locationProvinceEn"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationDistrictEn"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationSubDistrictEn"].ToString(); } else { traksend.english_address = dtReUpdateDeviceCurrent.Rows[0]["locationNameEn"].ToString(); } traksend.battery = Convert.ToInt32(dtReUpdateDeviceCurrent.Rows[0]["BatteryLevel"]); traksend.current_datetime = dtReUpdateDeviceCurrent.Rows[0]["Timestamp"].ToString(); traksend.online_status = dtReUpdateDeviceCurrent.Rows[0]["OnlineStatus"].ToString(); } else { // ตรงนี้ไม่เข้านะ if (countPosition > 0) { traksend.latitude = Convert.ToDouble(req.position[countPosition].latitude); traksend.longitude = Convert.ToDouble(req.position[countPosition].longitude); traksend.thai_address = traksend.latitude.ToString() + "," + traksend.longitude.ToString(); traksend.english_address = traksend.latitude.ToString() + "," + traksend.longitude.ToString(); traksend.inout_status = returnStatus; traksend.battery = Convert.ToInt32(req.batteryLevel); traksend.current_datetime = req.position[countPosition].gpsDateTime.ToString(); traksend.online_status = dtReUpdateDeviceCurrent.Rows[0]["OnlineStatus"].ToString(); } else { traksend.latitude = Convert.ToDouble(dtReUpdateDeviceCurrent.Rows[0]["Latitude"]); traksend.longitude = Convert.ToDouble(dtReUpdateDeviceCurrent.Rows[0]["Longitude"]); traksend.thai_address = dtReUpdateDeviceCurrent.Rows[0]["locationProvinceTh"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationDistrictTh"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationSubDistrictTh"].ToString(); traksend.english_address = dtReUpdateDeviceCurrent.Rows[0]["locationProvinceEn"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationDistrictEn"].ToString() + "," + dtReUpdateDeviceCurrent.Rows[0]["locationSubDistrictEn"].ToString(); traksend.battery = Convert.ToInt32(req.batteryLevel); traksend.inout_status = returnStatus; traksend.current_datetime = dtReUpdateDeviceCurrent.Rows[0]["Timestamp"].ToString(); traksend.online_status = dtReUpdateDeviceCurrent.Rows[0]["OnlineStatus"].ToString(); } } //Call service :: Signal R bool Recalltrack = callService.CallTracking(traksend, req.imei); stage = 7; ReaponseNotic resPonse = new ReaponseNotic(); resPonse.imei = req.imei; resPonse.deviceId = req.deviceId; resPonse.stage = stage; resPonse.userId = req.userId; return(Ok(resPonse)); } catch (Exception ex) { //MailCustom mailM = new MailCustom("*****@*****.**", "*****@*****.**", "gtpatchaya@005853"); //mailM.sendMail("tamroi:error", ex.ToString()); return(InternalServerError(ex)); } }