예제 #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());
            }
        }
예제 #2
0
        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);
        }
        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.GetNewHeads:
                Logger.Debug("GetNewHeads");
                manifestRequest req = (manifestRequest)cmd;
                dRetCall[NewGuid(cmd.requestId)](req.ToArray());
//                    cbsend(new Command() { command = eCommand.GetNewHeads }.ToArray());
                break;

            case eCommand.CreateCustomerAccount:
                Logger.Debug("CreateCustomerAccount");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                // cbsend(new Command() { command = eCommand.CreateCustomerAccount }.ToArray());
                break;

            case eCommand.GetCustomerBalance:
                Logger.Debug("GetCustomerBalance");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                break;

            case eCommand.CreateOrder:
                Logger.Debug("CreateOrder");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                break;

            case eCommand.ConfirmDelivery:
                Logger.Debug("ConfirmDelivery");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                break;

            case eCommand.Withdraw:
                Logger.Debug("Withdraw");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                break;

            case eCommand.SweepToCold:
                Logger.Debug("SweepToCold");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                break;

            case eCommand.TransferToHot:
                Logger.Debug("TransferToHot");
                dRetCall[NewGuid(cmd.requestId)](cmd.ToArray());
                break;

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