예제 #1
0
        //public bool CompleteStop(isaCommand inputparam)
        //{
        //    //var output = mp.CompleteStop(inputparam);
        //    return true;
        //}


        void SendMsgEventAsync(isaCommand cmd)
        {
            if (oclient == null)
            {
                Logger.Info($"UMDServerConnection:Task SendMsgEventAsync: Client {name} not connected");
                if (!bStopped)
                {
                    bRunning = false;
                    //StartAsync();
                    Thread.Sleep(100);
                }
            }
            Logger.Info($"UMDServerConnection SendMsgEventAsync {name} {cmd.ToString()}");
            Task retTsk = oclient.Send(cmd.ToArray());

            if (timer != null)
            {
                timer.Change(200, 10000);
            }
            if (retTsk.Status == TaskStatus.Faulted)
            {
                Logger.Info($"UMDServerConnection:Task SendMsgEventAsync: faulted {name}  " + cmd.ToString());
            }
        }
        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 isaCommand ReceiveMessage(isaCommand cmd)
        {
            switch (cmd.command)
            {
            case eCommand.Ping:
                Logger.Debug($"ReceiveMessage - Received Ping / Replying Pong..");
                WinSysSM.SendMessage(new Command()
                {
                    command = eCommand.Pong
                });
                break;

            case eCommand.Pong:
                Logger.Debug($"ReceiveMessage - Received Pong");
                break;

            case eCommand.LoadFiles:
                Logger.Info($"ReceiveMessage - Copy Files from Winsys Server Paths top App Server Paths:{cmd.ToString()}");
                //CopyFilesToServer(DateTime.Today);
                Logger.Info($"ReceiveMessage - Replying LoadFilesComplete...");
                WinSysSM.SendMessage(new Command()
                {
                    command = eCommand.LoadFilesComplete
                });
                //cbsend(new Command() { command = eCommand.LoadFilesComplete }.ToArray());
                break;

            case eCommand.GenerateManifest:
                Logger.Info($"ReceiveMessage - Generate Manifest from Winsys and SqlServer:{cmd.ToString()}");
                manifestRequest req = (manifestRequest)cmd;
                WinSysSM.SendMessage(req);
                break;

            case eCommand.ManifestDetails:
                Logger.Info($"ReceiveMessage - Generate Manifest Details from Winsys - API Drill Down:{cmd.ToString()}");
                manifestDetails manDet = (manifestDetails)cmd;

                ManifestDetailsData manDetData = new ManifestDetailsData(manDet);
                Logger.Info($"INSERTMANIFESTDETAILS (Persist): {manDetData.ToString()}");

                if (!dManDetails.ContainsKey(manDetData.RequestId.ToString() + manDetData.ManId.ToString()))
                {
                    dManDetails.Add(manDetData.RequestId.ToString() + manDetData.ManId.ToString(), new List <ManifestDetailsData>());
                }

                foreach (var omdit in UMDServer.Persist(SPCmds.INSERTMANIFESTDETAILS, manDetData))
                {
                    dManDetails[manDetData.RequestId.ToString() + manDetData.ManId.ToString()].Add(manDetData);
                }

                Logger.Info($"ManifestDetails Complete: {manDet.ToString()}");
                break;

            case eCommand.ManifestDetailsComplete:
                Logger.Info($"ReceiveMessage - ManifestDetailsComplete:{cmd.ToString()}");
                req = (manifestRequest)cmd;
                List <ManifestDetailsData> mdd = null;
                if (dManDetails.ContainsKey(NewGuid(req.requestId).ToString() + req.id.ToString()))
                {
                    mdd = dManDetails[NewGuid(req.requestId).ToString() + req.id.ToString()];
                    dManDetails.Remove(NewGuid(req.requestId).ToString() + req.id.ToString());
                }
                if (!dManDetails.ContainsKey(NewGuid(req.requestId).ToString()) && mdd != null && mdd.Count > 0)
                {
                    drillDown.GetOrderMasterData(new manifestRequest()
                    {
                        valist = req.valist, requestId = req.requestId, date = req.date, id = req.id
                    });
                }

                dRetCall[NewGuid(cmd.requestId)](req.ToArray());
                //drillDown.reportMDProgressChanged(100, cmd);
                break;

            case eCommand.OrdersUpload:
                Logger.Info($"ReceiveMessage - Orders  reqId: {cmd.requestId}");
                List <IMDMMessage> lstOrd = new List <IMDMMessage>();

                OrderMasterData omd = new OrderMasterData(((orderMaster)cmd));
                orderMaster     om  = new orderMaster(omd);
                //omd.Status = OrderStatus.Shipped;

                lock (dOrdLock)
                {
                    if (!dOrdersMaster.ContainsKey(omd.RequestId.ToString() + omd.ManId.ToString()))
                    {
                        dOrdersMaster.Add(omd.RequestId.ToString() + omd.ManId.ToString(), new List <OrderMasterData>());
                    }
                }
                if (!dOrdersMaster[omd.RequestId.ToString() + omd.ManId.ToString()].Contains(omd))
                {
                    foreach (var omdit in UMDServer.Persist(SPCmds.INSERTORDER, omd))
                    {
                        lock (dOrdLock)
                            dOrdersMaster[omd.RequestId.ToString() + omd.ManId.ToString()].Add((OrderMasterData)omdit);
                    }
                }

                break;

            case eCommand.OrdersLoad:
                Logger.Info($"ReceiveMessage - OrdersLoad  reqId: {cmd.requestId}");
                orderMaster     ord    = (orderMaster)cmd;
                OrderMasterData omdata = new OrderMasterData(ord);

                lock (dOrdLock)
                {
                    if (!dOrdersMaster.ContainsKey(NewGuid(ord.requestId).ToString() + ord.ManId.ToString()))
                    {
                        dOrdersMaster.Add(NewGuid(ord.requestId).ToString() + ord.ManId.ToString(), new List <OrderMasterData>());
                    }
                }
                if (!dOrdersMaster[omdata.RequestId.ToString() + omdata.ManId.ToString()].Contains(omdata))
                {
                    foreach (var omdit in UMDServer.Persist(SPCmds.INSERTORDER, omdata))
                    {
                        lock (dOrdLock)
                            dOrdersMaster[omdata.RequestId.ToString() + omdata.ManId.ToString()].Add((OrderMasterData)omdit);
                    }
                }

                break;

            case eCommand.OrdersLoadComplete:
                Logger.Info($"ReceiveMessage - OrdersLoadComplete:{cmd.ToString()}");
                req = (manifestRequest)cmd;

                if (dOrdersMaster.ContainsKey(NewGuid(cmd.requestId).ToString() + req.id))
                {
                    List <OrderMasterData> lMOrd = dOrdersMaster[NewGuid(cmd.requestId).ToString() + req.id.ToString()].Distinct().ToList();
                    lMOrd.ForEach(x => Logger.Info($"ordldcmp{x.ORD_NO}"));
                    drillDown.GetDrillDownData(req.valist, eCommand.OrderDetails, req.requestId, 1);
                    drillDown.GetDrillDownData(req.valist, eCommand.OrderOptions, req.requestId);
                    lock (dOrdLock)
                        dOrdersMaster.Remove(NewGuid(cmd.requestId).ToString() + req.id);
                }
                else
                {
                    Logger.Info($"No Orders for {cmd.ToString()}");
                }
//                        throw new Exception("OrdersLoadComplete - response not mapped in dOrderMaster.  " +
//                          "Request Id: {NewGuid(cmd.requestId).ToString()} , id: {req.id}. ");
                dRetCall[NewGuid(cmd.requestId)](req.ToArray());

                break;

            case eCommand.OrderDetails:
                Logger.Info($"ReceiveMessage - OrderDetails:{cmd.ToString()}");
                try
                {
                    orderDetails     od  = (orderDetails)cmd;
                    OrderDetailsData odd = new OrderDetailsData(od);

                    lock (dOrdLock)
                    {
                        if (!dOrdersDetails.ContainsKey(odd.RequestId))
                        {
                            dOrdersDetails.Add(odd.RequestId, new List <OrderDetailsData>());
                        }
                    }
                    foreach (var odit in UMDServer.Persist(SPCmds.INSERTORDERDETAILS, odd))
                    {
                        Logger.Info($"INSERTORDERDETAILS Complete: {odit.ToString()}");
                    }

                    //dRetCall[NewGuid(od.requestId)](cmd.ToArray());
                }
                catch (Exception ex) { Logger.Error($"eCommand.OrderDetails {ex.Message}"); }

                break;

            case eCommand.OrderDetailsComplete:
                Logger.Info($"ReceiveMessage - OrderDetailsComplete:{cmd.ToString()}");
                // Can we detrmine the completed transaction at this point from the cmd in order to clean the completed tx for dRetCall
                req = (manifestRequest)cmd;

                lock (dOrdLock)
                {
                    if (dOrdersDetails.ContainsKey(NewGuid(cmd.requestId)))
                    {
                        //                        drillDown.GetOrderOptionsData(dOrdersDetails[NewGuid(cmd.requestId)].Distinct().ToList());
                        //drillDown.GetOrderOptionsData(ordersToRequestDetails[NewGuid(cmd.requestId)]);
                        dOrdersDetails.Remove(NewGuid(cmd.requestId));
                    }
                }

                //dRetCall[NewGuid(cmd.requestId)](req.ToArray());

                break;

            case eCommand.OrderOptions:
                Logger.Info($"ReceiveMessage - OrderOptions  reqId:{cmd.ToString()}");
                try
                {
                    orderOptions     oo  = (orderOptions)cmd;
                    OrderOptionsData ood = new OrderOptionsData(oo);

                    foreach (var oodit in UMDServer.Persist(SPCmds.INSERTORDEROPTIONS, ood))
                    {
                        Logger.Info($"INSERTORDEROPTIONS Complete: {oodit.ToString()}");
                    }

                    //oo.command = eCommand.OrderOptionsComplete;
                    //dRetCall[NewGuid(oo.requestId)](cmd.ToArray());
                }
                catch (Exception ex) { Logger.Error($"eCommand.OrderOptions {ex.Message}"); }

                break;

            case eCommand.OrderOptionsComplete:

                Logger.Info($"ReceiveMessage - OrderOptionsComplete:{cmd.ToString()}");
                // Can we detrmine the completed transaction at this point from the cmd in order to clean the completed tx for dRetCall
                req = (manifestRequest)cmd;
                dRetCall[NewGuid(cmd.requestId)](req.ToArray());

                break;

            case eCommand.OrderUpdatesComplete:
                Logger.Info($"ReceiveMessage - OrderUpdatesComplete:{cmd.ToString()}");

                req = (manifestRequest)cmd;
                dRetCall[NewGuid(cmd.requestId)](req.ToArray());
                break;

            case eCommand.ManifestLoadComplete:
                Logger.Info($"ReceiveMessage - OrdersLoadComplete:{cmd.ToString()}");
                Logger.Info($"ReceiveMessage - OrderDetailsComplete:{cmd.ToString()}");

                req = (manifestRequest)cmd;
                dRetCall[NewGuid(cmd.requestId)](req.ToArray());
                break;

            case eCommand.ScanFile:
                Logger.Info($"ReceiveMessage Cached Success - ScanFile:{cmd.ToString()}");
                scanFile     sf  = (scanFile)cmd;
                ScanFileData sfd = new ScanFileData(sf);

                foreach (var scnfle in UMDServer.Persist(SPCmds.INSERTSCANFILE, sfd))
                {
                    Logger.Info($"INSERTSCNFLE Complete: {scnfle.ToString()}");
                }

                //if(cmd.requestId==null)
                //    dRetCall.FirstOrDefault().Value(sf.ToArray());
                //else
                //    dRetCall[NewGuid(cmd.requestId)](sf.ToArray());

                break;

            default:
                Logger.Error("ReceiveMessage - ERROR Unknown command.  Parse Error MDM-API");
                break;
            }
            return(cmd);
        }
예제 #4
0
        public isaCommand ReceiveMessage(isaCommand cmd)
        {
            switch (cmd.command)
            {
            case eCommand.Ping:
                Logger.Debug($"ReceiveMessage - Received Ping / Replying Pong..");
                WinSysSM.SendMessage(new Command()
                {
                    command = eCommand.Pong
                });
                break;

            case eCommand.Pong:
                Logger.Debug($"ReceiveMessage - Received Pong");
                break;

            case eCommand.LoadFiles:
                Logger.Info($"ReceiveMessage - Copy Files from Winsys Server Paths top App Server Paths:{cmd.ToString()}");
                //CopyFilesToServer(DateTime.Today);
                Logger.Info($"ReceiveMessage - Replying LoadFilesComplete...");
                WinSysSM.SendMessage(new Command()
                {
                    command = eCommand.LoadFilesComplete
                });
                //cbsend(new Command() { command = eCommand.LoadFilesComplete }.ToArray());
                break;

            case eCommand.GenerateManifest:
                Logger.Info($"ReceiveMessage - Generate Manifest from Winsys and SqlServer:{cmd.ToString()}");
                manifestRequest req = (manifestRequest)cmd;
                WinSysSM.SendMessage(req);
                break;

            case eCommand.ManifestDetails:
                Logger.Info($"ReceiveMessage - Generate Manifest Details from Winsys - API Drill Down:{cmd.ToString()}");
                //drillDown.reportMDProgressChanged(50, cmd );
                foreach (var mmd in UMDServer.Persist(SPCmds.INSERTMANIFESTDETAILS, new ManifestDetailsData((manifestDetails)cmd)))
                {
                    drillDown.GetOrderMasterData((ManifestDetailsData)mmd);
                }
                break;

            case eCommand.ManifestDetailsComplete:
                Logger.Info($"ReceiveMessage - ManifestDetailsComplete:{cmd.ToString()}");
                //drillDown.reportMDProgressChanged(100, cmd);
                break;

            case eCommand.Orders:
                Logger.Info($"ReceiveMessage - Orders  reqId: {cmd.requestId}");
                foreach (var omd in UMDServer.Persist(SPCmds.INSERTORDER, new OrderMasterData((orderMaster)cmd)))
                {
                    drillDown.GetOrderDetailsData((OrderMasterData)omd);
                    drillDown.GetOrderOptionsData((OrderMasterData)omd);
                }
                break;

            case eCommand.OrderOptions:
                Logger.Info($"ReceiveMessage - OrderOptions  reqId:{cmd.ToString()}");
                UMDServer.Persist(SPCmds.INSERTORDEROPTIONS, new OrderOptionsData((orderOptions)cmd));

                break;

            case eCommand.OrderDetails:
                Logger.Info($"ReceiveMessage - OrderDetails:{cmd.ToString()}");
                UMDServer.Persist(SPCmds.INSERTORDERDETAILS, new OrderDetailsData((orderDetails)cmd));
                //  drillDown.GetOrderMasterData((ManifestDetailsData)mmd);
                break;

            case eCommand.RunQuery:
                //DriverData dd = (DriverData)GetDrivers(cbsend);
                break;

            case eCommand.Drivers:
                Logger.Info($"ReceiveMessage - Drivers:{cmd.ToString()}");
                break;

            case eCommand.OrderDetailsComplete:
                Logger.Info($"ReceiveMessage - OrderDetailsComplete:{cmd.ToString()}");
                break;

            case eCommand.OrderOptionsComplete:
                Logger.Info($"ReceiveMessage - OrderOptionsComplete:{cmd.ToString()}");
                break;

            case eCommand.OrderUpdatesComplete:
                Logger.Info($"ReceiveMessage - OrderUpdatesComplete:{cmd.ToString()}");
                break;

            default:
                Logger.Error("ReceiveMessage - ERROR Unknown command.  Parse Error MDM-API");
                break;
            }
            return(cmd);
        }