/// <summary> /// Thực hiện gửi từng bảng ghi cho fastTaxi /// </summary> /// <param name="fast"></param> private static void SendDataFastTaxi(SendFastTaxiData fast) { if (fast != null) { //if (Debug && !frmlog.Visible) //{ // frmlog.ShowForm(); //} //if (Debug) frmlog.WriteLog(fast.IdCuocGoi, fast.Msg, fast.Content, "Bắt đầu gửi" + (fast.GuiLai ? " Gửi lại" : "")); var flg = false; var soLan = 0; var thuchien = false; try { do { try { flg = fast.Func(); thuchien = true; } catch (Exception ex) { flg = false; //new Log().WriteLog(ThongTinDangNhap.USER_ID, "RefreshServerFastTaxi", DateTime.Now, "ID:"+fast.IdCuocGoi.ToString()+" - Số lần:"+soLan.ToString()); LogError.WriteLogError("SendDataFastTaxi", ex); } soLan++; if (!thuchien && soLan < 5) { Thread.Sleep(1); } else { // thuchien = true; } } while (!thuchien && soLan < 5); } catch (Exception ex) { //LogError.WriteLogError("SendDataFastTaxi", ex); //new Log().WriteLog(ThongTinDangNhap.USER_ID, "bwSync_SendFastTaxiCuocGoi_DoWork", DateTime.Now, "fast==null"); LogError.WriteLogError("SendDataFastTaxi 2", ex); flg = false; } finally { //if (Debug && !frmlog.Visible) //{ // frmlog.ShowForm(); //} //if (Debug) frmlog.WriteLog(fast.IdCuocGoi, fast.Msg, fast.Content, "Kq:" + (flg ? "Thành công" : "Thất bại") + ";" + "TH:" + (thuchien ? "Được" : "Không")); CuocGoi.FT_History_Create((int)fast.IdCuocGoi, fast.Content, (int)fast.Status, flg); if (!thuchien) { queueFastTaxiFail.Enqueue(fast); } } } else { LogError.WriteLogErrorForDebug("SendDataFastTaxi null"); //new Log().WriteLog(ThongTinDangNhap.USER_ID, "bwSync_SendFastTaxiCuocGoi_DoWork", DateTime.Now, "xảy ra lỗi khi gửi dữ liệu"); } }
/// <summary> /// Tạo công việc thực hiện chạy nền. /// </summary> public static void SendFastTaxi(CuocGoi cuocGoiRow, Enum_FastTaxi_Status status) { if (!cuocGoiRow.FT_IsFT) { return; } #region Ini Func <bool> func = () => false; string content = string.Empty; string msg = string.Empty; #endregion switch (status) { #region Chuyển sang đàm case Enum_FastTaxi_Status.ChuyenSangDam: //Trạng thái cập nhật dữ liệu func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterSigningCar(cuocGoiRow.PhoneNumber, cuocGoiRow.FT_ID)); //“[Địa chỉ đón]-[Địa chỉ trả]-[SL xe]-[Loại xe]” content = string.Format("{0}-{1}-{2}-{3}", cuocGoiRow.DiaChiDonKhach, cuocGoiRow.DiaChiTraKhach, cuocGoiRow.SoLuong, cuocGoiRow.LoaiXe); msg = "Chuyển sang đàm"; break; #endregion #region Tiếp nhận hủy case Enum_FastTaxi_Status.TiepNhanHuy: func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterOperationCancel(cuocGoiRow.PhoneNumber, cuocGoiRow.FT_ID)); //“[Địa chỉ đón]” content = string.Format("{0}", cuocGoiRow.DiaChiDonKhach); msg = "Tiếp nhận hủy"; break; #endregion #region Mời khách case Enum_FastTaxi_Status.MoiKhach: //Mời khách func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterCatchingCar(cuocGoiRow.PhoneNumber, cuocGoiRow.FT_ID)); content = string.Format("{0}-{1}-{2}-{3}-{4}", cuocGoiRow.DiaChiDonKhach, cuocGoiRow.DiaChiTraKhach, cuocGoiRow.SoLuong, cuocGoiRow.LoaiXe, cuocGoiRow.XeNhan); msg = "Mời khách"; break; #endregion #region không xe case Enum_FastTaxi_Status.KhongXe: //không xe func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterBookingFail(cuocGoiRow.PhoneNumber, string.Empty, Enum_TaxiOperation_CallStatus.KhongXe, cuocGoiRow.FT_ID)); content = "Không xe"; msg = "Không xe"; break; #endregion #region Không xe,Đã xin lỗi khách case Enum_FastTaxi_Status.KhongXe_DaXinLoi: //Không xe,Đã xin lỗi khách status = Enum_FastTaxi_Status.KhongXe; func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterBookingFail(cuocGoiRow.PhoneNumber, string.Empty, Enum_TaxiOperation_CallStatus.KhongXe, cuocGoiRow.FT_ID)); content = string.Format("Không xe,Đã xin lỗi khách"); msg = "Không xe,Đã xin lỗi khách"; break; #endregion #region Nhập xe nhận case Enum_FastTaxi_Status.NhapXeNhan: //Nhập xe nhận func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterSignedCar(cuocGoiRow.PhoneNumber, GetCarOnline(cuocGoiRow.XeNhan.Trim()), cuocGoiRow.FT_ID)); content = string.Format("{0}-{1}-{2}-{3}-{4}", cuocGoiRow.DiaChiDonKhach, cuocGoiRow.DiaChiTraKhach, cuocGoiRow.SoLuong, cuocGoiRow.LoaiXe, cuocGoiRow.XeNhan); msg = "Nhập xe nhận"; break; #endregion #region Nhập xe đến điểm case Enum_FastTaxi_Status.NhapXeNhan_XeDenDiem: //Nhập xe nhận func = () => { try { Service_Common.FastTaxi.Try(client => client.SendToMasterSignedCar(cuocGoiRow.PhoneNumber, GetCarOnline(cuocGoiRow.XeDenDiem.Trim()), cuocGoiRow.FT_ID)); Thread.Sleep(5000); Service_Common.FastTaxi.Try(client => client.SendToMasterCatchingCar(cuocGoiRow.PhoneNumber, cuocGoiRow.FT_ID)); return(true); } catch (Exception ex) { LogError.WriteLogError("NhapXeNhan_XeDenDiem", ex); return(false); } }; content = string.Format("{0}-{1}-{2}-{3}-{4}", cuocGoiRow.DiaChiDonKhach, cuocGoiRow.DiaChiTraKhach, cuocGoiRow.SoLuong, cuocGoiRow.LoaiXe, cuocGoiRow.XeNhan); msg = "Nhập xe đến điểm"; break; #endregion #region Nhập xe đón case Enum_FastTaxi_Status.NhapXeDon: //Nhập xe đón string xeDon = string.Empty; if (cuocGoiRow.XeDon.Trim() != "") { xeDon = cuocGoiRow.XeDon.Trim(); //.Split('.').Select(int.Parse).ToArray(); } func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterBookingDone(cuocGoiRow.PhoneNumber, GetCarOnline(xeDon), cuocGoiRow.FT_ID)); //“[Địa chỉ đón]-[Địa chỉ trả]-[SL xe]-[Loại xe]-[Xe nhận]” content = string.Format("{0}-{1}-{2}-{3}-{4}", cuocGoiRow.DiaChiDonKhach, cuocGoiRow.DiaChiTraKhach, cuocGoiRow.SoLuong, cuocGoiRow.LoaiXe, cuocGoiRow.XeDon); msg = "Nhập xe đón"; break; #endregion #region Trượt case Enum_FastTaxi_Status.Truot: func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterBookingFail(cuocGoiRow.PhoneNumber, string.Empty, Enum_TaxiOperation_CallStatus.Truot, cuocGoiRow.FT_ID)); content = "Trượt"; msg = "Trượt"; break; #endregion #region Hoãn case Enum_FastTaxi_Status.Hoan: func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterBookingFail(cuocGoiRow.PhoneNumber, string.Empty, Enum_TaxiOperation_CallStatus.Hoan, cuocGoiRow.FT_ID)); content = "Hoãn"; msg = "Hoãn"; break; #endregion #region Đã Hoãn case Enum_FastTaxi_Status.Hoan_DaHoan: status = Enum_FastTaxi_Status.Hoan; func = () => Service_Common.FastTaxi.Try(client => client.SendToMasterBookingFail(cuocGoiRow.PhoneNumber, string.Empty, Enum_TaxiOperation_CallStatus.Hoan, cuocGoiRow.FT_ID)); content = "Đã Hoãn"; msg = "Đã Hoãn"; break; #endregion } #region Thực hiện kiểm tra và đưa vào hàng đợi để xử lý if (content != string.Empty) { var fasttaxi = new SendFastTaxiData { Func = func, IdCuocGoi = cuocGoiRow.IDCuocGoi, Content = content, Status = status, Msg = msg , PhoneNumber = cuocGoiRow.PhoneNumber, DiaChiDon = cuocGoiRow.DiaChiDonKhach, XeDon = cuocGoiRow.XeDon, XeNhan = cuocGoiRow.XeNhan }; //đưa vào hàng đợi xử lý queueFastTaxi.Enqueue(fasttaxi);// bwSync_SendFastTaxiCuocGoi.RunWorkerAsync(fasttaxi); } #endregion }
/// <summary> /// Thực hiện thêm vào hàng đợi để xử lý /// </summary> /// <param name="data"></param> static void frm_GuiLaiFastTaxi(SendFastTaxiData data) { data.GuiLai = true; queueFastTaxi.Enqueue(data); }