private void OnReleaseManifestSelected(object arg) { if (arg != null) { //Winform Manifest Master release ManifestMasterData mm = (ManifestMasterData)arg; if (mm.RequestId == null || mm.RequestId == Guid.Empty) { mm.RequestId = NewGuid(); } mm.status = status.Releasing; Logger.Info($"OnReleaseManifestSlected {mm.ToString()}"); Add(mm); UploadManifestMasterData(mm); } else { foreach (var mm in manifestMasterData) { mm.status = status.Releasing; Logger.Info($"OnReleaseManifestSlected {mm.ToString()}"); Add(mm); UploadManifestMasterData(mm); } } }
bool CheckManifestStatus(ManifestMasterData md) { bool bSuccess; try { Request valReq; if (dRequests.TryGetValue(md.RequestId, out valReq)) { Logger.Info($"ManifestVM::Update Init to Releasing for link: {md.LINK}"); valReq.LIds[md.LINK] = status.Pending; valReq.ChkIds.Add(md.LINK, status.Init); } else { throw new Exception($"Why are we checking for an unknown request? {md.RequestId}"); } md.Command = eCommand.CheckManifest; md.status = status.Pending; Add(md); Logger.Info($"ManifestVM::CheckManifestStatus: {md.ToString()}"); bSuccess = umdSrv.SendMessage(new manifestMaster(md)); } catch (Exception ex) { bSuccess = false; Logger.Error($"Error Checking for Manifest Status {ex.Message}."); } return(bSuccess); }
void UploadManifestMasterData(ManifestMasterData mm) { if (mm.IsSelected) { Logger.Info($"ManifestVM UploadManifestMasterData: {mm.ToString()}"); Clear(); var req = new Request() { reqGuid = mm.RequestId, LIds = new Dictionary <long, status>(), LinkMid = new Dictionary <long, List <long> >(), ChkIds = new Dictionary <long, status>() }; dRequests.Add(req.reqGuid, req); manifestMaster manUp = new manifestMaster(mm); manUp.command = eCommand.UploadManifest; ProcessMsgDelegateRXRaw pmRx = new ProcessMsgDelegateRXRaw(ProcessMessage); Logger.Info($"Upload Manifest reqie: {req.reqGuid}"); manifestMasterThread.OnStartProcess((new manifestRequest() { requestId = req.reqGuid.ToByteArray(), command = manUp.command, bData = manUp.ToArray(), id = manUp.id }), req, pmRx); } }
public void GetOrderMasterData(ManifestMasterData mmd) { var req = new manifestRequest() { command = eCommand.OrdersLoad, requestId = mmd.RequestId.ToByteArray(), id = mmd.ManifestId, date = mmd.SHIP_DTE.ToString("yyyy-MM-dd") }; sm(req); }
public void GetManifestDetails(ManifestMasterData manMaster, Func <byte[], Task> cbsend) { dt = manMaster.SHIP_DTE; var req = new manifestRequest() { command = eCommand.ManifestDetails, requestId = manMaster.RequestId.ToByteArray(), id = manMaster.ManifestId, valist = new List <long>() { manMaster.LINK } }; Logger.Info($"Upload Manifest - GetManifestDetails DrillDown/n sending manifestRequest/n/t{req.command.ToString()}" + $"/n/tmanId:{req.id} reqId: {req.requestId}"); sm(req); }
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { if (e.ColumnIndex >= 0) { DataGridView dgv = sender as DataGridView; if (dgv.Rows.Count < e.RowIndex) { return; } ManifestMasterData data = dgv.Rows[e.RowIndex].DataBoundItem as ManifestMasterData; switch (data.status) { case status.Init: e.CellStyle.BackColor = Color.Green; break; case status.Pending: e.CellStyle.BackColor = Color.Blue; break; case status.Released: e.CellStyle.BackColor = Color.Chartreuse; break; case status.Releasing: e.CellStyle.BackColor = Color.Yellow; break; case status.Uploaded: e.CellStyle.BackColor = Color.Red; break; case status.Completed: e.CellStyle.BackColor = Color.Yellow; break; } } } catch (Exception ex) { Logger.Error($"Manifest Generator Error dataGridView2_CellFormatting Exce= {ex.Message}"); } }
void Add(IMDMMessage icmd) { if (icmd.GetType() == typeof(ManifestMasterData)) { ManifestMasterData mcmd = (ManifestMasterData)icmd; if (!manifestMasterData.Contains(mcmd)) { ROUTECOUNT++; mcmd.COUNT = 1; lock (olock) ManifestMaster.Add(mcmd); } else { var mcnt = manifestMasterData.Where(m => m.LINK == mcmd.LINK).FirstOrDefault(); mcmd.COUNT = mcnt.COUNT + 1; lock (olock) { ManifestMaster.Remove(mcnt); if (mcnt.ManifestId != 0) { mcmd.ManifestId = mcnt.ManifestId; } ManifestMaster.Add(mcmd); } } } else if (icmd.GetType() == typeof(ManifestDetailsData)) { } else if (icmd.GetType() == typeof(OrderData)) { } else if (icmd.GetType() == typeof(OrderOptionsData)) { } }
public IEnumerable <IMDMMessage> InsertData(SPCmds SP, IMDMMessage dat) { if (dat != null) { switch (SP) { case SPCmds.INSERTMANIFEST: ManifestMasterData mst = (ManifestMasterData)dat; using (cnn = NewConnection()) { using (var adapter = new SqlDataAdapter()) { long manid; using (var command = new SqlCommand(SP.ToString(), cnn)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@DriverId", SqlDbType.Int).Value = 9; //use mst.UserId query the Driver table command.Parameters.AddWithValue("@TRK_CDE", SqlDbType.VarChar).Value = mst.TRK_CDE; command.Parameters.AddWithValue("@SHP_DTE", SqlDbType.Date).Value = mst.SHIP_DTE.Date; command.Parameters.AddWithValue("@DESC$", SqlDbType.VarChar).Value = mst.Desc; command.Parameters.AddWithValue("@LINK", SqlDbType.BigInt).Value = mst.LINK; command.Parameters.AddWithValue("@NOTES", SqlDbType.VarChar).Value = mst.NOTES; var retVal = command.Parameters.Add("@ManifestId", SqlDbType.BigInt); retVal.Direction = ParameterDirection.Output; adapter.InsertCommand = command; adapter.InsertCommand.ExecuteNonQuery(); manid = (long)retVal.Value; mst.ManifestId = manid; yield return(mst); } } } break; case SPCmds.INSERTMANIFESTDETAILS: ManifestDetailsData mdd = (ManifestDetailsData)dat; //SQL = @""; using (cnn = NewConnection()) { using (var adapter = new SqlDataAdapter()) { using (var command = new SqlCommand(SP.ToString(), cnn)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ManifestId", SqlDbType.Int).Value = mdd.ManId; command.Parameters.AddWithValue("@DSP_SEQ", SqlDbType.Int).Value = mdd.DSP_SEQ; command.Parameters.AddWithValue("@DLR_NO", SqlDbType.BigInt).Value = mdd.DLR_NO; adapter.InsertCommand = command; adapter.InsertCommand.ExecuteNonQuery(); yield return(mdd); } } } break; case SPCmds.INSERTORDER: OrderMasterData omd = (OrderMasterData)dat; //SQL = @""; using (cnn = NewConnection()) { using (var adapter = new SqlDataAdapter()) { using (var command = new SqlCommand(SP.ToString(), cnn)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ORD_NO", SqlDbType.BigInt).Value = omd.ORD_NO; command.Parameters.AddWithValue("@DLR_NO", SqlDbType.BigInt).Value = omd.DLR_NO; command.Parameters.AddWithValue("@SHP_DTE", SqlDbType.Date).Value = omd.SHP_DTE.Date; command.Parameters.AddWithValue("@DLR_NME", SqlDbType.VarChar).Value = omd.DLR_NME; command.Parameters.AddWithValue("@SHP_NME", SqlDbType.VarChar).Value = omd.SHP_NME; command.Parameters.AddWithValue("@SHP_ADDR", SqlDbType.VarChar).Value = omd.SHP_ADDR; command.Parameters.AddWithValue("@SHP_ADDR2", SqlDbType.VarChar).Value = omd.SHP_ADDR2; command.Parameters.AddWithValue("@SHP_TEL", SqlDbType.VarChar).Value = omd.SHP_TEL; command.Parameters.AddWithValue("@SHP_ZIP", SqlDbType.VarChar).Value = omd.SHP_ZIP; command.Parameters.AddWithValue("@CUS_NME", SqlDbType.VarChar).Value = omd.CUS_NME; command.Parameters.AddWithValue("@RTE_CDE", SqlDbType.VarChar).Value = omd.RTE_CDE; command.Parameters.AddWithValue("@SHP_QTY", SqlDbType.Int).Value = omd.SHP_QTY; command.Parameters.AddWithValue("@MAN_ID", SqlDbType.Int).Value = omd.ManId; var retVal = command.Parameters.Add("@CustomerIdOut", SqlDbType.Int); retVal.Direction = ParameterDirection.Output; adapter.InsertCommand = command; adapter.InsertCommand.ExecuteNonQuery(); yield return(omd); } } } break; case SPCmds.INSERTORDERDETAILS: OrderDetailsData odd = (OrderDetailsData)dat; //SQL = @""; using (cnn = NewConnection()) { using (var adapter = new SqlDataAdapter()) { using (var command = new SqlCommand(SP.ToString(), cnn)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ORD_NO", SqlDbType.BigInt).Value = odd.ORD_NO; command.Parameters.AddWithValue("@MDL_NO", SqlDbType.Int).Value = odd.MDL_NO; command.Parameters.AddWithValue("@DESC", SqlDbType.VarChar).Value = odd.DESC; command.Parameters.AddWithValue("@CLR", SqlDbType.Int).Value = odd.CLR; command.Parameters.AddWithValue("@WIDTH", SqlDbType.BigInt).Value = odd.WIDTH; command.Parameters.AddWithValue("@HEIGHT", SqlDbType.BigInt).Value = odd.HEIGHT; command.Parameters.AddWithValue("@MDL_CNT", SqlDbType.Int).Value = odd.MDL_CNT; command.Parameters.AddWithValue("@WIN_CNT", SqlDbType.Int).Value = odd.WIN_CNT; command.Parameters.AddWithValue("@Status", SqlDbType.VarChar).Value = "LOADED"; adapter.InsertCommand = command; adapter.InsertCommand.ExecuteNonQuery(); yield return(odd); } } } break; case SPCmds.INSERTORDEROPTIONS: OrderOptionsData oop = (OrderOptionsData)dat; //SQL = @""; using (cnn = NewConnection()) { using (var adapter = new SqlDataAdapter()) { using (var command = new SqlCommand(SP.ToString(), cnn)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ORD_NO", SqlDbType.BigInt).Value = oop.ORD_NO; command.Parameters.AddWithValue("@MDL_NO", SqlDbType.Int).Value = oop.MDL_NO; command.Parameters.AddWithValue("@DESC", SqlDbType.VarChar).Value = oop.DESC; command.Parameters.AddWithValue("@CLR", SqlDbType.Int).Value = oop.CLR; command.Parameters.AddWithValue("@MDL_CNT", SqlDbType.Int).Value = oop.MDL_CNT; // command.Parameters.AddWithValue("@WIN_CNT", SqlDbType.Int).Value = oop.WIN_CNT; command.Parameters.AddWithValue("@Status", SqlDbType.VarChar).Value = "LOADED"; adapter.InsertCommand = command; adapter.InsertCommand.ExecuteNonQuery(); yield return(oop); } } } break; default: throw new Exception("UM SQL Server Stored Procedure Not Found."); } } yield break; }
public IMDMMessage QueryData(Func <byte[], Task> cb, isaCommand dat) { IMDMMessage retVal = null; SPCmds SP; manifestRequest req; // (manifestRequest)dat; switch (dat.command) { case eCommand.Drivers: SP = SPCmds.GETAVAILABLEDRIVERS; break; case eCommand.Manifest: SP = SPCmds.GETDRIVERMANIFEST; break; case eCommand.Trucks: SP = SPCmds.GETTRUCKS; break; case eCommand.Stops: SP = SPCmds.GETSTOPS; break; case eCommand.Orders: case eCommand.OrdersLoad: SP = SPCmds.GETORDERS; break; case eCommand.GenerateManifest: SP = SPCmds.GETMANIFEST; break; default: throw new Exception("Not handled"); } using (SqlConnection cnn = new SqlConnection(UMDDB.connectionString)) { using (var adapter = new SqlDataAdapter()) { using (var command = new SqlCommand(SP.ToString(), cnn)) { command.CommandType = CommandType.StoredProcedure; switch (dat.command) { case eCommand.Drivers: req = (manifestRequest)dat; command.Parameters.AddWithValue("@SHP_DTE", SqlDbType.Date).Value = DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd"); dat.command = eCommand.DriversLoadComplete; retVal = new DriverData() { RequestId = new Guid(req.requestId) }; Logger.Info($"QueryData Drivers. Cmd:{retVal.Command.ToString()} reqId: {retVal.RequestId.ToString()} SHP_DTE: {DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd")}"); break; case eCommand.Manifest: req = (manifestRequest)dat; command.Parameters.AddWithValue("@DriverId", SqlDbType.Int).Value = req.id; retVal = new ManifestMasterData() { RequestId = new Guid(req.requestId) }; Logger.Info($"QueryData Manifest. Cmd:{retVal.Command.ToString()} reqId: {retVal.RequestId.ToString()} DriverId: {req.id} "); dat.command = eCommand.ManifestLoadComplete; break; case eCommand.Trucks: req = (manifestRequest)dat; command.Parameters.AddWithValue("@SHP_DTE", SqlDbType.Date).Value = DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd"); dat.command = eCommand.TrucksLoadComplete; Logger.Info($"QueryData Trucks. Cmd:{req.command.ToString()} reqId: {new Guid(req.requestId).ToString()} SHP_DTE: {DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd")}"); retVal = new TruckData() { RequestId = new Guid(req.requestId) }; break; case eCommand.Stops: req = (manifestRequest)dat; command.Parameters.AddWithValue("@ManifestId", SqlDbType.Int).Value = req.id; dat.command = eCommand.StopsLoadComplete; Logger.Info($"QueryData Stops. Cmd:{req.command.ToString()} reqId: {new Guid(req.requestId).ToString()} manId: {req.id}"); retVal = new StopData() { RequestId = new Guid(req.requestId) }; break; case eCommand.Orders: case eCommand.OrdersLoad: req = (manifestRequest)dat; command.Parameters.AddWithValue("@ManifestId", SqlDbType.Int).Value = req.id; dat.command = eCommand.OrdersLoadComplete; command.Parameters.AddWithValue("@Stop", SqlDbType.Int).Value = req.Stop; Logger.Info($"QueryData Orders. Cmd:{req.command.ToString()} reqId: {new Guid(req.requestId).ToString()} stop: {req.Stop.ToString()}"); retVal = new OrderMasterData() { RequestId = new Guid(req.requestId) }; break; case eCommand.GenerateManifest: // req = (manifestRequest)dat; command.Parameters.AddWithValue("@Link", SqlDbType.BigInt).Value = ((manifestMaster)dat).LINK; dat.command = eCommand.ManifestLoadComplete; Logger.Info($"QueryData GenerateManifest. " + $"Cmd:{dat.command.ToString()} " + $"reqId: {new Guid(dat.requestId).ToString()}" + $"link: { ((manifestMaster)dat).LINK}"); retVal = new ManifestMasterData() { LINK = ((manifestMaster)dat).LINK, RequestId = new Guid(dat.requestId) }; break; default: { Logger.Error($"QueryData Unkonwn Command. " + $"Cmd:{retVal.Command.ToString()} " + $"reqId: {retVal.RequestId.ToString()}"); throw new Exception("Not handled"); } } adapter.SelectCommand = command; SqlDataReader reader = null; try { cnn.Open(); reader = adapter.SelectCommand.ExecuteReader(); } catch (Exception ex) { } while (reader.Read()) { switch (retVal.Command) { case eCommand.Drivers: drivers drv = (drivers)MyQueryReader_Driver(reader, cb); drv.requestId = dat.requestId; drv.command = eCommand.Drivers; Logger.Info($"QueryData Manifest. Cmd:{drv.command.ToString()} reqId: {new Guid(drv.requestId).ToString()} Link: {drv.DriverId} manId: {drv.LastName}, {drv.FirstName} "); cb(drv.ToArray()); break; case eCommand.Manifest: case eCommand.GenerateManifest: manifestMaster micmd = (manifestMaster)myQueryData_GetManifest(reader, cb); micmd.requestId = dat.requestId; micmd.command = eCommand.Manifest; Logger.Info($"QueryData Manifest. Cmd:{micmd.command.ToString()} reqId: {new Guid(micmd.requestId).ToString()} Link: {micmd.LINK} manId: {micmd.id} "); cb(micmd.ToArray()); break; case eCommand.Trucks: trucks tcmd = (trucks)MyQueryReader_Trucks(reader, cb); tcmd.requestId = dat.requestId; tcmd.command = eCommand.Trucks; Logger.Info($"QueryData Trucks. Cmd:{tcmd.command.ToString()} reqId: {new Guid(tcmd.requestId).ToString()} TRK_CDE: {tcmd.TruckCode} ManId: {tcmd.ManifestId}"); cb(tcmd.ToArray()); break; case eCommand.Stops: stops scmd = (stops)MyQueryReader_Stops(reader, cb); scmd.requestId = dat.requestId; scmd.command = eCommand.Stops; Logger.Info($"QueryData Stops. Cmd:{scmd.command.ToString()} reqId: {new Guid(scmd.requestId).ToString()} manId: {scmd.ManifestId}"); cb(scmd.ToArray()); break; case eCommand.Orders: case eCommand.OrdersLoad: var ocmd = (orders)MyQueryReader_Orders(reader, cb); ocmd.requestId = dat.requestId; ocmd.command = eCommand.OrdersLoad; Logger.Info($"QueryData Orders. Cmd:{ocmd.command.ToString()} reqId: {new Guid(ocmd.requestId).ToString()}"); cb(ocmd.ToArray()); break; default: throw new Exception("Not handled"); } } Logger.Info($"QueryData Completed. Cmd:{dat.command.ToString()} reqId: {new Guid(dat.requestId).ToString()}"); cb(dat.ToArray()); } } } return(retVal); }
private void ProcessMessage(ManifestMasterData inp, Func <byte[], Task> cbsend) { throw new NotImplementedException(); }
void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { object[] parameters = e.UserState as object[]; isaCommand cmd = (isaCommand )parameters[0]; Func <byte[], Task> cbsend = null; if (parameters.Length == 3) { cbsend = (Func <byte[], Task>)parameters[2]; } IMDMMessage mcmd = null; switch (cmd.command) { case eCommand.Manifest: mcmd = new ManifestMasterData((manifestMaster)cmd, ((manifestMaster)cmd).id); Sendback((O)mcmd, cbsend); break; case eCommand.ManifestLoadComplete: manifestRequest mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var it in mreq.valist) { mcmd = new ManifestMasterData() { RequestId = new Guid(cmd.requestId), LINK = it, SHIP_DTE = DateTime.Today, Command = eCommand.ManifestLoadComplete }; Sendback((O)mcmd, cbsend); } } else { mcmd = new ManifestMasterData() { RequestId = new Guid(cmd.requestId), LINK = -1, SHIP_DTE = DateTime.Today, Command = eCommand.ManifestLoadComplete }; Sendback((O)mcmd, cbsend); } break; case eCommand.CheckManifestComplete: mcmd = new ManifestMasterData((manifestMaster)cmd, ((manifestMaster)cmd).id, false); Sendback((O)mcmd, cbsend); break; case eCommand.CheckManifest: mcmd = new ManifestMasterData((manifestMaster)cmd, ((manifestMaster)cmd).id, false); Sendback((O)mcmd, cbsend); break; case eCommand.Drivers: mcmd = new DriverData() { Command = cmd.command }; Sendback((O)mcmd, cbsend); break; case eCommand.DriversLoadComplete: mcmd = (DriverData)cmd; Sendback((O)mcmd, cbsend); CompleteBackgroundWorker(new Guid(cmd.requestId)); break; case eCommand.ManifestDetails: mcmd = new ManifestDetailsData() { Command = cmd.command }; Sendback((O)mcmd, cbsend); break; case eCommand.AccountReceivable: mcmd = new AccountsReceivableData((accountReceivable)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.ManifestDetailsComplete: mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var it in mreq.valist) { mcmd = new ManifestDetailsData() { RequestId = new Guid(cmd.requestId), DLR_NO = it, Command = eCommand.ManifestDetailsComplete }; Sendback((O)mcmd, cbsend); } } else { mcmd = new ManifestMasterData() { RequestId = new Guid(cmd.requestId), LINK = -1, SHIP_DTE = DateTime.Today, Command = eCommand.ManifestLoadComplete }; Sendback((O)mcmd, cbsend); } //mcmd = new ManifestDetailsData((manifestDetails)cmd); //Sendback((O)mcmd, cbsend); //CompleteBackgroundWorker(new Guid(cmd.requestId)); break; //case eCommand.OrdersLoad: // mcmd = new OrderMasterData() { // Command = cmd.command, // ORD_NO=((orderMaster)cmd).ORD_NO, // Status = ((orderMaster)cmd).Status // }; // Sendback((O)mcmd, cbsend); // break; case eCommand.OrdersUpload: mcmd = new OrderMasterData() { Command = cmd.command, ORD_NO = ((orderMaster)cmd).ORD_NO, Status = ((orderMaster)cmd).Status }; Sendback((O)mcmd, cbsend); break; case eCommand.OrderUpdatesComplete: mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var it in mreq.valist) { mcmd = new OrderMasterData() { RequestId = new Guid(cmd.requestId), ORD_NO = (int)it, Command = eCommand.ManifestDetailsComplete }; Sendback((O)mcmd, cbsend); } } break; case eCommand.OrderDetails: mcmd = new OrderDetailsData((orderDetails)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.OrderDetailsComplete: mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var it in mreq.valist) { mcmd = new OrderDetailsData() { RequestId = new Guid(cmd.requestId), ORD_NO = it, LineNumber = mreq.Stop, // using as the count (number of OrderDetail Records Expected) Command = eCommand.OrderDetailsComplete }; Sendback((O)mcmd, cbsend); } } break; case eCommand.OrderOptions: mcmd = new OrderOptionsData((orderOptions)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.OrderOptionsComplete: mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var it in mreq.valist) { mcmd = new OrderOptionsData() { RequestId = new Guid(cmd.requestId), ORD_NO = (int)it, Count = mreq.Stop, // using as the count (number of OrderDetail Records Expected) Command = eCommand.OrderOptionsComplete }; Sendback((O)mcmd, cbsend); } } break; case eCommand.ScanFile: mcmd = new ScanFileData((scanFile)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.Trucks: mcmd = new TruckData((trucks)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.TrucksLoadComplete: mreq = (manifestRequest)cmd; mcmd = new TruckData() { RequestId = new Guid(cmd.requestId), ManifestId = mreq.id, Command = eCommand.TrucksLoadComplete }; Sendback((O)mcmd, cbsend); break; case eCommand.Stops: mcmd = new StopData((stops)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.StopsLoadComplete: mcmd = new StopData() { Command = cmd.command, RequestId = new Guid(cmd.requestId) }; mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var id in mreq.valist) { mcmd = new StopData() { Command = cmd.command, //TruckCode = TRK_CDE, RequestId = new Guid(cmd.requestId) }; Sendback((O)mcmd, cbsend); } } else { mcmd = new StopData() { Command = cmd.command, //TruckCode = TRK_CDE, RequestId = new Guid(cmd.requestId) }; Sendback((O)mcmd, cbsend); } break; case eCommand.OrdersLoad: mcmd = new OrderData((orders)cmd); Sendback((O)mcmd, cbsend); break; case eCommand.OrdersLoadComplete: mreq = (manifestRequest)cmd; if (mreq.valist != null) { foreach (var id in mreq.valist) { mcmd = new OrderData() { Command = cmd.command, DLR_NO = (int)id, RequestId = new Guid(cmd.requestId) }; Sendback((O)mcmd, cbsend); } } else { Logger.Info($"OrdersLoadComplete: {cmd.ToString()}"); mcmd = new OrderData() { Command = cmd.command, // DLR_NO = id, RequestId = new Guid(cmd.requestId) }; Sendback((O)mcmd, cbsend); } break; case eCommand.UploadManifestComplete: mcmd = new ManifestMasterData() { Command = cmd.command, RequestId = NewGuid(cmd.requestId) }; Sendback((O)mcmd, cbsend); break; default: Logger.Error($"Unhandled command Backgrtound worker handler {Enum.GetName(typeof(eCommand), cmd.command)}."); break; } }
public void HandleClientCmd(byte[] bytes_cmd, Func <byte[], Task> cbsend) { isaCommand cmd = new Command().FromArray(bytes_cmd); switch (cmd.command) { case eCommand.Ping: Logger.Debug("HandleClientCmd - Received Ping / Replying Pong.."); cbsend(new Command() { command = eCommand.Pong }.ToArray()); break; case eCommand.Pong: Logger.Debug("HandleClientCmd - Received Pong"); break; case eCommand.GenerateManifest: Logger.Info($"HandleClientCmd - Generate Manifest:{cmd.ToString()}"); manifestMaster mM = (manifestMaster) new manifestMaster().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd Generate Manifest from Winsys and SqlServer:{mM.ToString()}"); if (mM.LINK != 0) { ManifestMasterData mmd1 = (ManifestMasterData)UMDServer.QueryData(cbsend, mM); Logger.Info($"API Manager GenerateManifest QueryData Complete. {mmd1.ToString()}"); } else { WinSysSM.SendMessage(cmd); } break; case eCommand.CheckManifest: Logger.Info($"HandleClientCmd - CheckManifest: {cmd.ToString()}"); manifestMaster mMst = (manifestMaster) new manifestMaster().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd Check Manifest in ManagerAPI/SqlServer: {mMst.ToString()}"); ManifestMasterData mamd = (ManifestMasterData)UMDServer.QueryData(cbsend, mMst); Logger.Info($"API Manager Check Manifest. {mamd.ToString()}"); break; case eCommand.Manifest: Logger.Info($"HandleClientCmd - Manifest: {cmd.ToString()}"); cbsend(cmd.ToArray()); break; case eCommand.OrdersUpload: Logger.Info($"HandleClientCmd - Orders: {cmd.ToString()}"); orderMaster om = (orderMaster) new orderMaster().FromArray(bytes_cmd); List <OrderMasterData> ordList = new List <OrderMasterData>(); Logger.Info($"Persist INSERTORDER {om.ToString()}"); // om.Status = OrderStatus.Shipped; foreach (OrderMasterData omd in UMDServer.Persist(SPCmds.INSERTORDER, new OrderMasterData(om))) { ordList.Add(omd); Logger.Info($"Orders - drillDown.GetOrderDetailsData: {omd.ToString()}"); omd.Command = eCommand.OrdersLoadComplete; } //foreach (var ord in ordList) //{ // drillDown.GetOrderDetailsData(ord); // drillDown.GetOrderOptionsData(ord); //} drillDown.GetOrderDetailsData(ordList); drillDown.GetOrderOptionsData(ordList); Logger.Info($"INSERTORDER Complete. OrdersLoadComplete: {om.ToString()}"); om.command = eCommand.ManifestDetailsComplete; cbsend(om.ToArray()); break; case eCommand.CompleteOrder: Logger.Info($"HandleClientCmd - Close Order: {cmd.ToString()}"); manifestRequest mreq = (manifestRequest) new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - CompleteOrder: {mreq.ToString()}"); orderMaster cs = (orderMaster) new orderMaster().FromArray(mreq.bData); Logger.Info($"Persist COMPLETEORDER {cs.ToString()}"); var no = new OrderMasterData(cs); foreach (OrderMasterData omd in UMDServer.Persist(SPCmds.COMPLETEORDER, no)) { Logger.Info($"Persisted COMPLETEORDER {omd.ToString()}"); cbsend(new orderMaster(omd).ToArray()); } break; case eCommand.CompleteStop: Logger.Info($"HandleClientCmd - Close Stop for Orders: {cmd.ToString()}"); manifestRequest mreqs = (manifestRequest) new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - CompleteStop: {mreqs.ToString()}"); StopData sd = new StopData(); sd.POD = mreqs.bData; sd.ManifestId = mreqs.id; sd.DisplaySeq = (int)mreqs.DATA; sd.Orders = new List <OrderMasterData>(); //temp - uncomment! // mreqs.valist.ForEach(v => sd.Orders.Add(new OrderMasterData() { DSP_SEQ=sd.DisplaySeq, ManifestId=sd.ManifestId, ORD_NO = v })); Logger.Info($"Persist COMPLETESTOP {sd.ToString()}"); foreach (StopData omd in UMDServer.Persist(SPCmds.COMPLETESTOP, sd)) { Logger.Info($"Persisted COMPLETESTOP {sd.ToString()}"); cbsend(new stops(sd).ToArray()); } break; case eCommand.OrderOptions: //throw new Exception("This should be handled by the Receive Message handler."); Logger.Info($"HandleClientCmd - OrderOptions:{cmd.ToString()}"); manifestRequest mreqoo = (manifestRequest) new manifestRequest().FromArray(bytes_cmd); OrderOptionsData ood = (OrderOptionsData)UMDServer.QueryData(cbsend, mreqoo); Logger.Info($"API Manager QueryData OrderOptionsData. {ood.ToString()}"); break; case eCommand.OrderDetails: Logger.Info($"HandleClientCmd - OrderDetails:{cmd.ToString()}"); manifestRequest mreqod = (manifestRequest) new manifestRequest().FromArray(bytes_cmd); OrderDetailsData odd = (OrderDetailsData)UMDServer.QueryData(cbsend, mreqod); Logger.Info($"API Manager OrderDetailsData QueryData. {odd.ToString()}"); break; case eCommand.UploadManifest: Logger.Info($"HandleClientCmd - UploadManifest:{cmd.ToString()}"); mreq = (manifestRequest) new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - UploadManifest: {mreq.ToString()}"); manifestMaster mm = (manifestMaster) new manifestMaster().FromArray(mreq.bData); if (!dRetCall.ContainsKey(NewGuid(mm.requestId))) { dRetCall.Add(NewGuid(mm.requestId), cbsend); } Logger.Info($"UploadManifest cb dRetCall: {mm.ToString()}"); try { foreach (ManifestMasterData mmdit in UMDServer.Persist(SPCmds.INSERTMANIFEST, new ManifestMasterData(mm, mm.id))) { Logger.Info($"HandleClientCmd - UploadManifest Persisted:{mmdit.ToString()}"); Logger.Info($"UploadManifest - Get ManifestDetails: {mmdit.ToString()}"); if (!dManDetails.ContainsKey(mmdit.RequestId.ToString() + mmdit.ManifestId.ToString())) { dManDetails.Add(mmdit.RequestId.ToString() + mmdit.ManifestId.ToString(), new List <ManifestDetailsData>()); } drillDown.GetManifestDetails(mmdit); } mm.command = eCommand.UploadManifestComplete; Logger.Info($"UploadManifest - ManifestLoadComplete: {mm.ToString()}"); cbsend(mm.ToArray()); } catch (Exception e) { Logger.Debug("HandleClientCmd - Error exception = " + e.Message); dRetCall.Remove(NewGuid(mm.requestId)); } break; case eCommand.Trucks: isaCommand req = new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - Trucks: {req.ToString()}"); TruckData td = (TruckData)UMDServer.QueryData(cbsend, req); Logger.Info($"HandleClientCmd - Trucks: {td.ToString()}"); break; case eCommand.Drivers: req = new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - Drivers: {req.ToString()}"); DriverData dd = (DriverData)UMDServer.QueryData(cbsend, req); Logger.Info($"HandleClientCmd - Drivers: {dd.ToString()}"); break; case eCommand.Stops: req = new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd Stops: {req.ToString()}"); StopData sdt = (StopData)UMDServer.QueryData(cbsend, req); Logger.Info($"Stops QueryData: {sdt.ToString()}"); break; case eCommand.OrdersLoad: req = new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - OrdersLoad (Start QueryData): {req.ToString()}"); OrderData od = (OrderData)UMDServer.QueryData(cbsend, req); Logger.Info($"OrdersLoad QueryData: {od.ToString()}"); break; case eCommand.AccountReceivable: req = new manifestRequest().FromArray(bytes_cmd); manifestRequest mr = (manifestRequest)req; accountReceivable arecv = (accountReceivable) new accountReceivable().FromArray(mr.bData); Logger.Info($"HandleClientCmd - AccountRecievable"); AccountsReceivableData ard = (AccountsReceivableData) UMDServer.QueryData(cbsend, arecv); Logger.Info($"AccountsReceivables Complete."); break; default: Logger.Error("HandleClientCmd - ERROR Unknown command. Parse Error MDM-API"); break; } }
public void HandleClientCmd(byte[] bytes_cmd, Func <byte[], Task> cbsend) { isaCommand cmd = new Command().FromArray(bytes_cmd); switch (cmd.command) { case eCommand.Ping: Logger.Debug("HandleClientCmd - Received Ping / Replying Pong.."); cbsend(new Command() { command = eCommand.Pong }.ToArray()); break; case eCommand.Pong: Logger.Debug("HandleClientCmd - Received Pong"); break; case eCommand.LoadFiles: Logger.Info("HandleClientCmd - Copy Files from Winsys Server Paths top App Server Paths:{cmd.ToString()}"); //CopyFilesToServer(DateTime.Today); Logger.Info("HandleClientCmd - Replying LoadFilesComplete..."); cbsend(new Command() { command = eCommand.LoadFilesComplete }.ToArray()); break; case eCommand.GenerateManifest: Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}"); manifestMaster mM = (manifestMaster) new manifestMaster().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd Generate Manifest from Winsys and SqlServer:{mM.ToString()}"); if (mM.LINK != 0) { ManifestMasterData mmd = (ManifestMasterData)UMDServer.QueryData(cbsend, mM); Logger.Info($"API Manager GenerateManifest. {mmd.ToString()}"); } else { WinSysSM.SendMessage(cmd); } break; case eCommand.CheckManifest: Logger.Info($"HandleClientCmd - CheckManifest:{cmd.ToString()}"); //ManifestMasterData mMstData = (ManifestMasterData)new ManifestMasterData(bytes_cmd); manifestMaster mMst = (manifestMaster) new manifestMaster().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd Compare Manifest from Winsys to SqlServer: {mMst.ToString()}"); ManifestMasterData mamd = (ManifestMasterData)UMDServer.QueryData(cbsend, mMst); Logger.Info($"API Manager GenerateManifest. {mamd.ToString()}"); break; case eCommand.RunQuery: Logger.Info($"HandleClientCmd - ManifestDetails: {cmd.ToString()}"); //DriverData dd = (DriverData)GetDrivers(cbsend); break; case eCommand.Manifest: Logger.Info($"HandleClientCmd - Manifest from Winsys and SqlServer:{cmd.ToString()}"); cbsend(cmd.ToArray()); break; case eCommand.Trucks: Logger.Info($"HandleClientCmd - Trucks: {cmd.ToString()}"); isaCommand req = new manifestRequest().FromArray(bytes_cmd); TruckData td = (TruckData)UMDServer.QueryData(cbsend, req); Logger.Info($"HandleClientCmd - Trucks. reqId:{req.ToString()}"); break; case eCommand.ManifestDetails: Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}"); isaCommand reqmd = new manifestRequest().FromArray(bytes_cmd); // ManifestDetailsData mdd = manifestDetails manDet = new manifestDetails(); ManifestDetailsData manDetData = (ManifestDetailsData)manDet.FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - ManifestDetails:{manDetData.ToString()}"); foreach (var mmd in UMDServer.Persist(SPCmds.INSERTMANIFESTDETAILS, manDetData)) { drillDown.GetOrderMasterData((ManifestDetailsData)mmd); mmd.Command = eCommand.ManifestDetails; mmd.RequestId = new Guid(manDet.requestId); Logger.Info($"HandleClientCmd - ManifestDetails. Sending GetOrderMasterData:{mmd.ToString()}"); cbsend(((manifestDetails)mmd).ToArray()); } break; case eCommand.Orders: Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}"); var om = (orderMaster) new orderMaster().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - Orders. reqId: {om.ToString()}"); foreach (var omd in UMDServer.Persist(SPCmds.INSERTORDER, new OrderMasterData(om))) { drillDown.GetOrderDetailsData((OrderMasterData)omd); } break; case eCommand.OrderOptions: Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}"); var oo = (orderOptions) new orderOptions().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - OrderOptions:{cmd.ToString()}"); foreach (var mmd in UMDServer.Persist(SPCmds.INSERTORDEROPTIONS, new OrderOptionsData(oo))) { var oopt = new orderOptions((OrderOptionsData)mmd); oopt.command = eCommand.OrderOptionsComplete; cbsend(oopt.ToArray()); } break; case eCommand.OrderDetails: Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}"); var odt = (orderDetails) new orderDetails().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - OrderDetails: {odt.ToString()}"); foreach (var mmd in UMDServer.Persist(SPCmds.INSERTORDERDETAILS, new OrderDetailsData(odt))) { orderDetails odd = new orderDetails((OrderDetailsData)mmd); odd.command = eCommand.OrderDetailsComplete; cbsend(odd.ToArray()); } break; case eCommand.Drivers: Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}"); req = new manifestRequest().FromArray(bytes_cmd); DriverData dd = (DriverData)UMDServer.QueryData(cbsend, req); //drivers drvs = new drivers(dd); //drvs.command = eCommand.DriversLoadComplete; //cbsend(drvs.ToArray()); //cbsend(new Command() { command = eCommand.DriversLoadComplete, value = dd.DriverId.ToString() }.ToArray()); break; case eCommand.UploadManifest: Logger.Info($"HandleClientCmd - UploadManifest:{cmd.ToString()}"); manifestRequest mreq = (manifestRequest) new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - UploadManifest: {mreq.ToString()}"); //ManifestMasterData Mmd = (ManifestMasterData)cmd; manifestMaster mm = (manifestMaster) new manifestMaster().FromArray(mreq.bData); IEnumerable <IMDMMessage> mmdata = UMDServer.Persist(SPCmds.INSERTMANIFEST, new ManifestMasterData(mm, mm.id)); Logger.Info($"HandleClientCmd - UploadManifest Persisted:{mm.ToString()}"); try { ManifestMasterData mmd = null; foreach (var mmdIt in mmdata) { mmd = (ManifestMasterData)mmdIt; Logger.Info($"HandleClientCmd - UploadManifest - Get ManifestDetails sending ManMastData Trk:{mmd.ToString()}"); drillDown.GetManifestDetails(mmd, cbsend); } if (mmd != null) { manifestMaster mmRet = new manifestMaster(mmd); mmRet.command = eCommand.ManifestLoadComplete; Logger.Info($"HandleClientCmd - UploadManifest - Done (ManifestLoadComplete):{mreq.ToString()}"); cbsend(mmRet.ToArray()); } } catch (Exception e) { Logger.Debug("HandleClientCmd - Error exception = " + e.Message); } break; case eCommand.Stops: Logger.Info($"HandleClientCmd - Stops. reqId:{cmd.ToString()}"); req = new manifestRequest().FromArray(bytes_cmd); StopData sd = (StopData)UMDServer.QueryData(cbsend, req); stops stps = new stops(sd); stps.command = eCommand.StopsLoadComplete; cbsend(stps.ToArray()); break; case eCommand.OrdersLoad: req = new manifestRequest().FromArray(bytes_cmd); Logger.Info($"HandleClientCmd - OrdersLoad (Start QueryData): {req.ToString()}"); OrderData od = (OrderData)UMDServer.QueryData(cbsend, req); orders odrs = new orders(od); odrs.command = eCommand.OrdersLoadComplete; Logger.Info($"HandleClientCmd - OrdersLoad (OrdersLoadComplete): {odrs.ToString()}"); cbsend(odrs.ToArray()); break; default: Logger.Error("HandleClientCmd - ERROR Unknown command. Parse Error MDM-API"); break; } }
public void ReleaseManifest(ManifestMasterData mmd) { OnReleaseManifestSelected(mmd); }