public void InsertOfflineSynchException(string accessToken, OfflineSyncLog objexlog) { try { string baseUrl = Convert.ToString(App.Current.Properties["BaseURL"]); using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Add the Authorization header with the AccessToken. client.DefaultRequestHeaders.Add("Authorization", "bearer " + accessToken); // create the URL string. string url = "api/InstaOperator/postOPAPPOfflineSyncExceptionLog"; // make the request var json = JsonConvert.SerializeObject(objexlog); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(url, content).Result; if (response.IsSuccessStatusCode) { string jsonString = response.Content.ReadAsStringAsync().Result; if (jsonString != null) { APIResponse apiResult = JsonConvert.DeserializeObject <APIResponse>(jsonString); } } } } catch (Exception ex) { } }
public string InsertOfflineSynchException(OfflineSyncLog objOfflineSync) { int strResult; string OperResult = string.Empty; try { using (SqlConnection sqlconn_obj = new SqlConnection(SqlHelper.GetDBConnectionString())) { using (SqlCommand sqlcmd_obj = new SqlCommand("OPAPP_PROC_InsertOfflineSyncLog", sqlconn_obj)) { sqlcmd_obj.CommandType = CommandType.StoredProcedure; sqlcmd_obj.Parameters.AddWithValue("@RegistrationNumber", objOfflineSync.RegistrationNumber); sqlcmd_obj.Parameters.AddWithValue("@ExceptionMessage ", objOfflineSync.ExceptionMessage); sqlcmd_obj.Parameters.AddWithValue("@IsSync", objOfflineSync.IsSync); sqlcmd_obj.Parameters.AddWithValue("@CustomerParkingSlotID ", objOfflineSync.CustomerParkingSlotID == 0?(object)DBNull.Value : objOfflineSync.CustomerParkingSlotID); sqlcmd_obj.Parameters.AddWithValue("@LocationParkingLotName ", objOfflineSync.LocationParkingLotName == "" ? (object)DBNull.Value : objOfflineSync.LocationParkingLotName); sqlcmd_obj.Parameters.AddWithValue("@LocationParkingLotID ", objOfflineSync.LocationParkingLotID == 0 ? (object)DBNull.Value : objOfflineSync.LocationParkingLotID); sqlcmd_obj.Parameters.AddWithValue("@ExpectedStartTime ", objOfflineSync.ExpectedStartTime == null?(object)DBNull.Value: objOfflineSync.ExpectedStartTime); sqlcmd_obj.Parameters.AddWithValue("@ExpectedEndTime ", objOfflineSync.ExpectedEndTime == null ? (object)DBNull.Value : objOfflineSync.ExpectedEndTime); sqlcmd_obj.Parameters.AddWithValue("@CreatedBy", objOfflineSync.CreatedBy == 0 ? (object)DBNull.Value : objOfflineSync.CreatedBy); sqlconn_obj.Open(); sqlcmd_obj.CommandTimeout = 0; strResult = sqlcmd_obj.ExecuteNonQuery(); sqlconn_obj.Close(); if (strResult > 0) { OperResult = "Success"; } else { OperResult = "Failed to load error"; } } } } catch (Exception ex) { throw; } return(OperResult); }
public async Task <string> CheckInOfflineSync(string apitoken, User loguser) { int totalCounts = 0; StringBuilder sbUnMoved = new StringBuilder(); DALExceptionManagment dal_Exceptionlog = new DALExceptionManagment(); try { var lstchekIns = await App.SQLiteDb.GetAllVehicleAsync(); if (lstchekIns != null) { if (lstchekIns.Count > 0) { foreach (var items in lstchekIns) { if (DeviceInternet.InternetConnected()) { var objexlog = new OfflineSyncLog(); try { var resultCustomerID = SaveVehicleNewCheckIn(apitoken, items); if (resultCustomerID != null) { try { objexlog.CustomerParkingSlotID = resultCustomerID.CustomerParkingSlotID; objexlog.RegistrationNumber = items.RegistrationNumber; objexlog.LocationParkingLotName = loguser.LocationParkingLotID.LocationParkingLotName; objexlog.LocationParkingLotID = loguser.LocationParkingLotID.LocationParkingLotID; objexlog.CreatedBy = resultCustomerID.CreatedBy; if (resultCustomerID.CustomerParkingSlotID != 0) { objexlog.ExceptionMessage = "Success"; objexlog.IsSync = true; if (!string.IsNullOrEmpty(items.ParkingStartTime) && !string.IsNullOrEmpty(items.ParkingEndTime)) { objexlog.ExpectedStartTime = Convert.ToDateTime(items.ParkingStartTime); objexlog.ExpectedEndTime = Convert.ToDateTime(items.ParkingEndTime); } } else { if (sbUnMoved.Length == 0) { sbUnMoved.AppendLine(items.RegistrationNumber); } else { sbUnMoved.AppendLine(", " + items.RegistrationNumber); } objexlog.ExceptionMessage = "Failed"; objexlog.IsSync = false; DeSyncVehicleCheckIn objdesync = new DeSyncVehicleCheckIn(); objdesync.VehicleTypeCode = items.VehicleTypeCode; objdesync.BayRange = items.BayRange; objdesync.RegistrationNumber = items.RegistrationNumber; objdesync.LocationParkingLotName = items.LocationParkingLotName; await App.SQLiteDb.SaveDeSyncCheckInAsync(objdesync); } } catch (Exception ex) { objexlog.ExceptionMessage = "Failed"; objexlog.IsSync = false; dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message + ",At:" + "Item after Online Sync" + resultCustomerID.CustomerParkingSlotID, "DALCheckIn.cs", items.RegistrationNumber + "," + items.ParkingStartTime + "," + items.ParkingEndTime + "," + "", "CheckInOfflineSync"); } finally { dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", "Finally at:" + "Item after Online Sync" + resultCustomerID.CustomerParkingSlotID, "DALCheckIn.cs", items.RegistrationNumber + "," + items.ParkingStartTime + "," + items.ParkingEndTime + "," + "", "CheckInOfflineSync"); dal_Exceptionlog.InsertOfflineSynchException(Convert.ToString(App.Current.Properties["apitoken"]), objexlog); await App.SQLiteDb.DeleteItemAsync(items); } } else { dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", "No Records found ", "DALCheckIn.cs", "", "CheckInOfflineSync"); } } catch (Exception ex) { if (sbUnMoved.Length == 0) { sbUnMoved.AppendLine(items.RegistrationNumber); } else { sbUnMoved.AppendLine(", " + items.RegistrationNumber); } await App.SQLiteDb.DeleteItemAsync(items); dal_Exceptionlog.InsertOfflineSynchException(Convert.ToString(App.Current.Properties["apitoken"]), objexlog); dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message, "DALCheckIn.cs", items.RegistrationNumber + "," + items.ParkingStartTime + "," + items.ParkingEndTime, "CheckInOfflineSync"); } } else { if (sbUnMoved.Length == 0) { sbUnMoved.AppendLine(items.RegistrationNumber); } else { sbUnMoved.AppendLine(", " + items.RegistrationNumber); } } } } else { dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", "No Records in VehicleCheckIn", "DALCheckIn.cs", "", "CheckInOfflineSync"); } } else { dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", "No Records in VehicleCheckIn", "DALCheckIn.cs", "", "CheckInOfflineSync"); } } catch (Exception ex) { StackTrace st = new StackTrace(ex, true); //Get the first stack frame StackFrame frame = st.GetFrame(0); //Get the file name string fileName = frame.GetFileName(); //Get the method name string methodName = frame.GetMethod().Name; //Get the line number from the stack frame int line = frame.GetFileLineNumber(); string exDetails = fileName + "," + methodName + "," + line; dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message, "DALCheckIn.cs", exDetails, "CheckInOfflineSync"); } return(sbUnMoved.ToString()); }