Beispiel #1
0
        public bool sned_Str37(string cmd_id, CMDCancelType actType)
        {
            ValueDefMapActionBase mapAction = null;

            mapAction = getExcuteMapAction();
            return(mapAction.send_Str37(cmd_id, actType));
        }
Beispiel #2
0
        private async void btn_cancel_abort_Click(object sender, EventArgs e)
        {
            try
            {
                if (selection_index == -1)
                {
                    return;
                }
                btn_cancel_abort.Enabled = false;
                var           mcs_cmd     = cmdMCSshowList[selection_index];
                CMDCancelType cnacel_type = default(CMDCancelType);
                if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                {
                    cnacel_type = CMDCancelType.CmdCancel;
                }
                else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                {
                    cnacel_type = CMDCancelType.CmdAbort;
                }
                else
                {
                    MessageBox.Show($"Command ID:{mcs_cmd.CMD_ID.Trim()} can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}", "Cancel / Abort command fail.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                await Task.Run(() => mainform.BCApp.SCApplication.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd.CMD_ID, cnacel_type));

                updateTransferCommand();
            }
            catch { }
            finally
            {
                btn_cancel_abort.Enabled = true;
            }
        }
Beispiel #3
0
        public override bool send_Str37(string cmd_id, CMDCancelType actType)
        {
            //加入StackTrace,來找出他會下達Cancel的入口 by Kevin
            try
            {
                StackTrace st        = new StackTrace(true);
                string     trace_msg = SCUtility.ShowCallerInfo(st, $"Call EQTcpIpMapAction.send_Str37(),cmd id:{cmd_id},act type:{actType}");
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(EQTcpIpMapAction), Device: "OHxC",
                              Data: trace_msg,
                              VehicleID: eqpt.VEHICLE_ID,
                              Details: st.ToString(),
                              CarrierID: eqpt.CST_ID);
            }
            catch { }
            bool isScuess = false;

            try
            {
                string rtnMsg = string.Empty;
                ID_37_TRANS_CANCEL_REQUEST   stSend;
                ID_137_TRANS_CANCEL_RESPONSE stRecv;
                stSend = new ID_37_TRANS_CANCEL_REQUEST()
                {
                    CmdID   = cmd_id,
                    ActType = actType
                };

                WrapperMessage wrapper = new WrapperMessage
                {
                    ID             = VHMSGIF.ID_TRANS_CANCEL_REQUEST,
                    TransCancelReq = stSend
                };

                SCUtility.RecodeReportInfo(eqpt.VEHICLE_ID, 0, stSend);
                com.mirle.iibg3k0.ttc.Common.TrxTcpIp.ReturnCode result = snedRecv(wrapper, out stRecv, out rtnMsg);
                SCUtility.RecodeReportInfo(eqpt.VEHICLE_ID, 0, stRecv, result.ToString());
                if (result == TrxTcpIp.ReturnCode.Normal)
                {
                    if (stRecv.ReplyCode == 0)
                    {
                        isScuess = true;
                    }
                    else
                    {
                        isScuess = false;
                    }
                }
                else
                {
                    isScuess = false;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
            return(isScuess);
        }
        public override (bool isSendOK, int replyCode) send_Str37(string cmd_id, CMDCancelType actType)
        {
            bool is_scuess  = false;
            int  reply_code = 0;

            try
            {
                //由於A00的要求,希望可以在收到命令後 走完一個Section後再進行Cancel,因此先加入此Function
                //WaitPassOneSection();

                string rtnMsg = string.Empty;
                ID_37_TRANS_CANCEL_REQUEST   stSend;
                ID_137_TRANS_CANCEL_RESPONSE stRecv;
                stSend = new ID_37_TRANS_CANCEL_REQUEST()
                {
                    CmdID   = cmd_id,
                    ActType = actType
                };

                WrapperMessage wrapper = new WrapperMessage
                {
                    ID             = WrapperMessage.TransCancelReqFieldNumber,
                    TransCancelReq = stSend
                };

                SCUtility.RecodeReportInfo(eqpt.VEHICLE_ID, 0, stSend);
                com.mirle.iibg3k0.ttc.Common.TrxTcpIp.ReturnCode result = snedRecv(wrapper, out stRecv, out rtnMsg);
                SCUtility.RecodeReportInfo(eqpt.VEHICLE_ID, 0, stRecv, result.ToString());
                is_scuess  = result == TrxTcpIp.ReturnCode.Normal;
                reply_code = stRecv.ReplyCode;
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
            return(is_scuess, reply_code);
        }
Beispiel #5
0
        //public bool fireDoorOpen { get; set; }
        //public bool fireDoorCloseGrant { get; set; }
        //public bool fireDoorCrossingSignal { get; set; }

        public void fireDoorCancelAbortCommand(SCApplication scApp)
        {
            //Cancel當前Queue的會找不到路徑的命令。
            List <ACMD_MCS> queue_mcs_cmds = scApp.CMDBLL.loadMCS_Command_Queue();

            foreach (ACMD_MCS cmd in queue_mcs_cmds)
            {
                bool isWalkable       = true;
                bool source_is_a_port = scApp.PortStationBLL.OperateCatch.IsExist(cmd.HOSTSOURCE);
                if (source_is_a_port)
                {
                    APORTSTATION source_port_station = scApp.PortStationBLL.OperateCatch.getPortStation(cmd.HOSTSOURCE);
                    APORTSTATION dest_port_station   = scApp.PortStationBLL.OperateCatch.getPortStation(cmd.HOSTDESTINATION);
                    isWalkable = scApp.GuideBLL.IsRoadWalkable(source_port_station.ADR_ID, dest_port_station.ADR_ID);
                }
                else
                {
                    AVEHICLE     carry_vh          = scApp.VehicleBLL.cache.getVehicleByRealID(cmd.HOSTSOURCE);
                    APORTSTATION dest_port_station = scApp.PortStationBLL.OperateCatch.getPortStation(cmd.HOSTDESTINATION);
                    isWalkable = scApp.GuideBLL.IsRoadWalkable(carry_vh.CUR_ADR_ID, dest_port_station.ADR_ID);
                }



                if (!isWalkable)
                {
                    //await Task.Run(() => mainform.BCApp.scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd.CMD_ID, cnacel_type));
                    scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(cmd.CMD_ID, CMDCancelType.CmdCancel);
                }
            }
            //Abort已經執行,但是會經過防火門的命令。
            List <ACMD_MCS> executing_mcs_cmds = scApp.CMDBLL.loadMCS_Command_Executing();

            foreach (ACMD_MCS cmd in executing_mcs_cmds)
            {
                bool isWalkable       = true;
                bool source_is_a_port = scApp.PortStationBLL.OperateCatch.IsExist(cmd.HOSTSOURCE);
                if (source_is_a_port)
                {
                    APORTSTATION source_port_station = scApp.PortStationBLL.OperateCatch.getPortStation(cmd.HOSTSOURCE);
                    APORTSTATION dest_port_station   = scApp.PortStationBLL.OperateCatch.getPortStation(cmd.HOSTDESTINATION);
                    isWalkable = scApp.GuideBLL.IsRoadWalkable(source_port_station.ADR_ID, dest_port_station.ADR_ID);
                }
                else
                {
                    AVEHICLE     carry_vh          = scApp.VehicleBLL.cache.getVehicleByRealID(cmd.HOSTSOURCE);
                    APORTSTATION dest_port_station = scApp.PortStationBLL.OperateCatch.getPortStation(cmd.HOSTDESTINATION);
                    isWalkable = scApp.GuideBLL.IsRoadWalkable(carry_vh.CUR_ADR_ID, dest_port_station.ADR_ID);
                }

                if (!isWalkable)
                {
                    //await Task.Run(() => mainform.BCApp.scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd.CMD_ID, cnacel_type));
                    CMDCancelType cnacel_type = default(CMDCancelType);
                    if (cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                    {
                        cnacel_type = CMDCancelType.CmdCancel;
                    }
                    else if (cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                    {
                        cnacel_type = CMDCancelType.CmdAbort;
                    }
                    else
                    {
                        continue;
                    }
                    scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(cmd.CMD_ID, cnacel_type);
                }
            }
        }
        private void RegisterVehilceEvent()
        {
            Get["AVEHICLES/{ID}"] = (p) =>
            {
                string   vh_id    = p.ID;
                AVEHICLE vh       = SCApplication.getInstance().VehicleBLL.getVehicleByID(vh_id);
                var      response = (Response)vh.ToString();
                response.ContentType = restfulContentType;

                return(response);
            };
            Get["AVEHICLES"] = (p) =>
            {
                string          vh_id    = p.ID;
                List <AVEHICLE> vhs      = SCApplication.getInstance().getEQObjCacheManager().getAllVehicle();
                var             response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };
            //Get["AVEHICLES/(?<all>)"] = (p) =>
            Get["AVEHICLES/_search"] = (p) =>
            {
                List <AVEHICLE> vhs = null;

                foreach (string name in Request.Query)
                {
                    switch (name)
                    {
                    case "SectionID":
                        string sec_id = Request.Query[name] ?? string.Empty;
                        vhs = SCApplication.getInstance().VehicleBLL.loadVehicleBySEC_ID(sec_id);
                        break;
                    }
                }
                var response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["metrics"] = (p) =>
            {
                int total_idle_vh_clean        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Clean);
                int total_idle_vh_Dirty        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Dirty);
                int total_cmd_is_queue_count   = SCApplication.getInstance().CMDBLL.getCMD_MCSIsQueueCount();
                int total_cmd_is_running_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsRunningCount();

                string ohxc_excute_info = string.Empty;

                StringBuilder sb = new StringBuilder();
                setOhxCContent(sb, nameof(total_idle_vh_clean), total_idle_vh_clean, "current idle clean car");
                setOhxCContent(sb, nameof(total_idle_vh_Dirty), total_idle_vh_Dirty, "current idle dirty car");
                setOhxCContent(sb, nameof(total_cmd_is_queue_count), total_cmd_is_queue_count, "cmd number being queued");
                setOhxCContent(sb, nameof(total_cmd_is_running_count), total_cmd_is_running_count, "cmd number being executed");

                var response = (Response)sb.ToString();
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ViewerUpdate"] = (p) =>
            {
                SCApplication   scApp = SCApplication.getInstance();
                List <AVEHICLE> vhs   = scApp.getEQObjCacheManager().getAllVehicle();

                //foreach (AVEHICLE vh in vhs)
                //{
                //    scApp.VehicleService.PublishVhInfo(vh, null);
                //    SpinWait.SpinUntil(() => false, 10);
                //}

                var response = (Response)"OK";
                response.ContentType = restfulContentType;
                return(response);
            };

            //Post["api/io/T2STK100T01/waitin/CST01"] = (p) =>
            //{

            //    var response = (Response)"OK";
            //    response.ContentType = restfulContentType;
            //    return response;
            //};


            Post["AVEHICLES/SendCommand"] = (p) =>
            {
                var        scApp        = SCApplication.getInstance();
                bool       isSuccess    = true;
                string     vh_id        = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string     carrier_id   = Request.Query.carrier_id.Value ?? Request.Form.carrier_id.Value ?? string.Empty;
                string     from_port_id = Request.Query.from_port_id.Value ?? Request.Form.from_port_id.Value ?? string.Empty;
                string     to_port_id   = Request.Query.to_port_id.Value ?? Request.Form.to_port_id.Value ?? string.Empty;
                E_CMD_TYPE e_cmd_type   = default(E_CMD_TYPE);
                string     cmd_type     = Request.Query.cmd_type.Value ?? Request.Form.cmd_type.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    ACMD_OHTC cmd_obj  = null;
                    AVEHICLE  assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    if (isSuccess)
                    {
                        isSuccess = Enum.TryParse(cmd_type, out e_cmd_type);
                        if (isSuccess)
                        {
                            switch (e_cmd_type)
                            {
                            case E_CMD_TYPE.Move:
                            case E_CMD_TYPE.Load:
                            case E_CMD_TYPE.Unload:
                            case E_CMD_TYPE.LoadUnload:
                            case E_CMD_TYPE.MoveToMTL:
                            case E_CMD_TYPE.SystemOut:
                                string from_adr = from_port_id;
                                string to_adr   = to_port_id;
                                //scApp.MapBLL.getAddressID(from_port_id, out from_adr);
                                //scApp.MapBLL.getAddressID(to_port_id, out to_adr);
                                scApp.CMDBLL.doCreatTransferCommand(vh_id, out cmd_obj,
                                                                    cmd_type: e_cmd_type,
                                                                    source: from_adr,
                                                                    destination: to_adr,
                                                                    carrier_id: carrier_id,
                                                                    gen_cmd_type: SCAppConstants.GenOHxCCommandType.Manual);
                                sc.BLL.CMDBLL.OHTCCommandCheckResult check_result_info =
                                    sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.OHTCCommandCheckResult>
                                        (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT);
                                isSuccess = check_result_info.IsSuccess;
                                result    = check_result_info.ToString();
                                if (isSuccess)
                                {
                                    isSuccess = scApp.VehicleService.doSendOHxCCmdToVh(assignVH, cmd_obj);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command to vehicle failed!";
                                    }
                                }
                                else
                                {
                                    result = "Command create failed!";
                                    //bcf.App.BCFApplication.onWarningMsg(this, new bcf.Common.LogEventArgs("Command create fail.", check_result_info.Num));
                                }
                                break;

                            case E_CMD_TYPE.Home:
                                string cmd_id = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual);
                                isSuccess = scApp.VehicleService.TransferRequset(vh_id, cmd_id, ActiveType.Home,
                                                                                 "", new string[0], new string[0], "", "");
                                break;

                            case E_CMD_TYPE.Teaching:
                                isSuccess = scApp.VehicleService.TeachingRequest(vh_id, from_port_id, to_port_id);
                                break;
                            }
                        }
                        else
                        {
                            result = $"Try parse Command Type:[{cmd_type}] failed!";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendReset"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string result    = string.Empty;
                try
                {
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(VehicleInfo), Device: "OHTC",
                                  Data: $"Process vh:{vh_id} position reset request from viewer...",
                                  VehicleID: vh_id);
                    AVEHICLE assignVH = null;
                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    //確認要求的VH,是否存在
                    if (isSuccess)
                    {
                        if (assignVH == null)
                        {
                            isSuccess = false;
                            result    = $"vh:{vh_id} is not exist.";
                        }
                    }
                    //確認是否還是連線著,如果是,則不能夠進行位置的重置
                    if (isSuccess)
                    {
                        if (assignVH.isTcpIpConnect)
                        {
                            isSuccess = false;
                            result    = $"vh:{vh_id} current is connect. can't excute reset.";
                        }
                    }
                    //確認該Vh是否還有Block,如果有也不能重置
                    if (isSuccess)
                    {
                        var non_release_block = scApp.MapBLL.loadNonReleaseBlockQueueByCarID(vh_id);
                        if (non_release_block != null && non_release_block.Count > 0)
                        {
                            isSuccess = false;
                            result    = $"vh:{vh_id} current has blocking zone, can't excute. please check block management.";
                        }
                    }
                    if (isSuccess)
                    {
                        //isSuccess = scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                        isSuccess = scApp.VehicleService.VhPositionReset(vh_id);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "excute reset failed.";
                        }
                    }
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(VehicleInfo), Device: "OHTC",
                                  Data: $"End process vh:{vh_id} position reset request from viewer. is success:{isSuccess} result:{result}",
                                  VehicleID: vh_id);
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendCancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    AVEHICLE assignVH = null;

                    assignVH = scApp.VehicleBLL.getVehicleByID(vh_id);

                    isSuccess = assignVH != null;

                    if (isSuccess)
                    {
                        string mcs_cmd_id = assignVH.MCS_CMD;
                        if (!string.IsNullOrWhiteSpace(mcs_cmd_id))
                        {
                            ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                            if (mcs_cmd == null)
                            {
                                result = $"Can't find MCS command:[{mcs_cmd_id}] in database.";
                            }
                            else
                            {
                                CMDCancelType actType = default(CMDCancelType);
                                if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                                {
                                    actType   = CMDCancelType.CmdCancel;
                                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command cancel/abort failed.";
                                    }
                                }
                                else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                                {
                                    actType   = CMDCancelType.CmdAbort;
                                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command cancel/abort failed.";
                                    }
                                }
                                else
                                {
                                    result = $"MCS command:[{mcs_cmd_id}] can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                                }
                            }
                        }
                        else
                        {
                            string ohtc_cmd_id = assignVH.OHTC_CMD;
                            if (string.IsNullOrWhiteSpace(ohtc_cmd_id))
                            {
                                result = $"Vehicle:[{vh_id}] do not have command.";
                            }
                            else
                            {
                                ACMD_OHTC ohtc_cmd = scApp.CMDBLL.getCMD_OHTCByID(ohtc_cmd_id);
                                if (ohtc_cmd == null)
                                {
                                    result = $"Can't find vehicle command:[{ohtc_cmd_id}] in database.";
                                }
                                else
                                {
                                    CMDCancelType actType = ohtc_cmd.CMD_STAUS >= E_CMD_STATUS.Execution ? CMDCancelType.CmdAbort : CMDCancelType.CmdCancel;
                                    isSuccess = scApp.VehicleService.doAbortCommand(assignVH, ohtc_cmd_id, actType);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send vehicle status request failed.";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseEvent"] = (p) =>
            {
                bool          isSuccess  = false;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                PauseEvent    pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(event_type, out pauseEvent);
                if (isSuccess)
                {
                    isSuccess = scApp.VehicleService.PauseRequest
                                    (vh_id, pauseEvent, SCAppConstants.OHxCPauseType.Normal);
                }

                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["AVEHICLES/PauseStatusChange"] = (p) =>
            {
                bool          isSuccess  = false;
                string        result     = string.Empty;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        pauseType  = Request.Query.pauseType.Value ?? Request.Form.pauseType.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                SCAppConstants.OHxCPauseType pause_type = default(SCAppConstants.OHxCPauseType);
                PauseEvent pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(pauseType, out pause_type);

                if (isSuccess)
                {
                    isSuccess = Enum.TryParse(event_type, out pauseEvent);

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.PauseRequest
                                        (vh_id, pauseEvent, pause_type);
                        if (isSuccess)
                        {
                            //AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            //vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Send pause request to vehicle:{vh_id} failed.";
                        }
                    }
                    else
                    {
                        result = $"Can't recognize Pause Event:{event_type}.";
                    }
                }
                else
                {
                    result = $"Can't recognize Pause Type:{pauseType}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ModeStatusChange"] = (p) =>
            {
                bool          isSuccess   = false;
                string        result      = string.Empty;
                SCApplication scApp       = SCApplication.getInstance();
                string        vh_id       = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        modeStatus  = Request.Query.modeStatus.Value ?? Request.Form.modeStatus.Value ?? string.Empty;
                VHModeStatus  mode_status = default(VHModeStatus);
                isSuccess = Enum.TryParse(modeStatus, out mode_status);

                if (isSuccess)
                {
                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleBLL.updataVehicleMode(vh_id, mode_status);
                        if (isSuccess)
                        {
                            AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Update vehicle:{vh_id} mode status failed.";
                        }
                    }
                }
                else
                {
                    result = $"Can't recognize mode status:{modeStatus}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ResetAlarm"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["Engineer/ForceCmdFinish"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                bool   isSuccess = scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                if (isSuccess)
                {
                    var vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                    vh.NotifyVhExcuteCMDStatusChange();
                }
                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };
        }
        private void RegisterVehilceEvent()
        {
            Get["AVEHICLES/{ID}"] = (p) =>
            {
                string   vh_id    = p.ID;
                AVEHICLE vh       = SCApplication.getInstance().VehicleBLL.getVehicleByID(vh_id);
                var      response = (Response)vh.ToString();
                response.ContentType = restfulContentType;

                return(response);
            };
            Get["AVEHICLES"] = (p) =>
            {
                string          vh_id    = p.ID;
                List <AVEHICLE> vhs      = SCApplication.getInstance().getEQObjCacheManager().getAllVehicle();
                var             response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };
            //Get["AVEHICLES/(?<all>)"] = (p) =>
            Get["AVEHICLES/_search"] = (p) =>
            {
                List <AVEHICLE> vhs = null;

                foreach (string name in Request.Query)
                {
                    switch (name)
                    {
                    case "SectionID":
                        string sec_id = Request.Query[name] ?? string.Empty;
                        vhs = SCApplication.getInstance().VehicleBLL.loadVehicleBySEC_ID(sec_id);
                        break;
                    }
                }
                var response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["metrics"] = (p) =>
            {
                int total_idle_vh_clean        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Clean);
                int total_idle_vh_Dirty        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Dirty);
                int total_cmd_is_queue_count   = SCApplication.getInstance().CMDBLL.getCMD_MCSIsQueueCount();
                int total_cmd_is_running_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsRunningCount();

                string ohxc_excute_info = string.Empty;

                StringBuilder sb = new StringBuilder();
                setOhxCContent(sb, nameof(total_idle_vh_clean), total_idle_vh_clean, "current idle clean car");
                setOhxCContent(sb, nameof(total_idle_vh_Dirty), total_idle_vh_Dirty, "current idle dirty car");
                setOhxCContent(sb, nameof(total_cmd_is_queue_count), total_cmd_is_queue_count, "cmd number being queued");
                setOhxCContent(sb, nameof(total_cmd_is_running_count), total_cmd_is_running_count, "cmd number being executed");

                var response = (Response)sb.ToString();
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ViewerUpdate"] = (p) =>
            {
                SCApplication   scApp = SCApplication.getInstance();
                List <AVEHICLE> vhs   = scApp.getEQObjCacheManager().getAllVehicle();

                //foreach (AVEHICLE vh in vhs)
                //{
                //    scApp.VehicleService.PublishVhInfo(vh, null);
                //    SpinWait.SpinUntil(() => false, 10);
                //}

                var response = (Response)"OK";
                response.ContentType = restfulContentType;
                return(response);
            };

            //Post["api/io/T2STK100T01/waitin/CST01"] = (p) =>
            //{
            //    var response = (Response)"OK";
            //    response.ContentType = restfulContentType;
            //    return response;
            //};

            Post["AVEHICLES/SendCommand"] = (p) =>
            {
                var        scApp        = SCApplication.getInstance();
                bool       isSuccess    = true;
                string     vh_id        = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string     cst_id       = Request.Query.cst_id.Value ?? Request.Form.cst_id.Value ?? string.Empty;
                string     box_id       = Request.Query.box_id.Value ?? Request.Form.box_id.Value ?? string.Empty;
                string     lot_id       = Request.Query.lot_id.Value ?? Request.Form.lot_id.Value ?? string.Empty;
                string     from_port_id = Request.Query.from_port_id.Value ?? Request.Form.from_port_id.Value ?? string.Empty;
                string     to_port_id   = Request.Query.to_port_id.Value ?? Request.Form.to_port_id.Value ?? string.Empty;
                E_CMD_TYPE e_cmd_type   = default(E_CMD_TYPE);
                string     cmd_type     = Request.Query.cmd_type.Value ?? Request.Form.cmd_type.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    ACMD_OHTC cmd_obj  = null;
                    AVEHICLE  assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    if (isSuccess)
                    {
                        isSuccess = Enum.TryParse(cmd_type, out e_cmd_type);
                        if (isSuccess)
                        {
                            switch (e_cmd_type)
                            {
                            case E_CMD_TYPE.Move:
                            case E_CMD_TYPE.Scan:
                            case E_CMD_TYPE.Load:
                            case E_CMD_TYPE.Unload:
                            case E_CMD_TYPE.LoadUnload:
                            case E_CMD_TYPE.MoveToMTL:
                            case E_CMD_TYPE.SystemOut:
                                string from_adr = "";
                                string to_adr   = "";
                                scApp.MapBLL.getAddressID(from_port_id, out from_adr);
                                scApp.MapBLL.getAddressID(to_port_id, out to_adr);

                                scApp.CMDBLL.doCreatTransferCommand(vh_id, out cmd_obj,
                                                                    cmd_type: e_cmd_type,
                                                                    source: from_port_id,
                                                                    destination: to_port_id,
                                                                    cst_id: cst_id,
                                                                    box_id: box_id,
                                                                    lot_id: lot_id,
                                                                    source_address: from_adr,
                                                                    destination_address: to_adr,
                                                                    gen_cmd_type: SCAppConstants.GenOHxCCommandType.Manual);
                                sc.BLL.CMDBLL.OHTCCommandCheckResult check_result_info =
                                    sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.OHTCCommandCheckResult>
                                        (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT);
                                isSuccess = check_result_info.IsSuccess;
                                result    = check_result_info.ToString();
                                if (isSuccess)
                                {
                                    isSuccess = scApp.VehicleService.doSendOHxCCmdToVh(assignVH, cmd_obj);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command to vehicle failed!";
                                    }
                                }
                                else
                                {
                                    result = "Command create failed!";
                                    //bcf.App.BCFApplication.onWarningMsg(this, new bcf.Common.LogEventArgs("Command create fail.", check_result_info.Num));
                                }
                                break;

                            case E_CMD_TYPE.Home:
                                string cmd_id = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual);
                                //isSuccess = scApp.VehicleService.TransferRequset(vh_id, cmd_id, ActiveType.Home,
                                //                                    "", "", "", new string[0], new string[0], new string[0], new string[0],
                                //                                    "", "", "", "");
                                break;

                            case E_CMD_TYPE.Teaching:
                                isSuccess = scApp.VehicleService.TeachingRequest(vh_id, from_port_id, to_port_id);
                                break;
                            }
                        }
                        else
                        {
                            result = $"Try parse Command Type:[{cmd_type}] failed!";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendReset"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    AVEHICLE assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Send vehicle status request failed.";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendCancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                //try
                //{
                //    AVEHICLE assignVH = null;

                //    assignVH = scApp.VehicleBLL.getVehicleByID(vh_id);

                //    isSuccess = assignVH != null;

                //    if (isSuccess)
                //    {
                //        string mcs_cmd_id = assignVH.MCS_CMD;
                //        if (!string.IsNullOrWhiteSpace(mcs_cmd_id))
                //        {
                //            ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                //            if (mcs_cmd == null)
                //            {
                //                result = $"Can't find MCS command:[{mcs_cmd_id}] in database.";
                //            }
                //            else
                //            {
                //                CMDCancelType actType = default(CMDCancelType);
                //                if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                //                {
                //                    actType = CMDCancelType.CmdCancel;
                //                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                //                    if (isSuccess) result = "OK";
                //                    else result = "Send command cancel/abort failed.";
                //                }
                //                else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                //                {
                //                    actType = CMDCancelType.CmdAbort;
                //                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                //                    if (isSuccess) result = "OK";
                //                    else result = "Send command cancel/abort failed.";
                //                }
                //                else
                //                {
                //                    result = $"MCS command:[{mcs_cmd_id}] can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                //                }
                //            }
                //        }
                //        else
                //        {
                //            string ohtc_cmd_id = assignVH.OHTC_CMD;
                //            if (string.IsNullOrWhiteSpace(ohtc_cmd_id))
                //            {
                //                result = $"Vehicle:[{vh_id}] do not have command.";
                //            }
                //            else
                //            {
                //                ACMD_OHTC ohtc_cmd = scApp.CMDBLL.getCMD_OHTCByID(ohtc_cmd_id);
                //                if (ohtc_cmd == null)
                //                {
                //                    result = $"Can't find vehicle command:[{ohtc_cmd_id}] in database.";
                //                }
                //                else
                //                {
                //                    CMDCancelType actType = ohtc_cmd.CMD_STAUS >= E_CMD_STATUS.Execution ? CMDCancelType.CmdAbort : CMDCancelType.CmdCancel;
                //                    isSuccess = scApp.VehicleService.doAbortCommand(assignVH, ohtc_cmd_id, actType);
                //                    if (isSuccess)
                //                    {
                //                        result = "OK";
                //                    }
                //                    else
                //                    {
                //                        result = "Send vehicle status request failed.";
                //                    }
                //                }
                //            }
                //        }
                //    }
                //    else
                //    {
                //        result = $"Vehicle :[{vh_id}] not found!";
                //    }
                //}
                //catch (Exception ex)
                //{
                //    isSuccess = false;
                //    result = "Execption happend!";
                //    logger.Error(ex, "Execption:");
                //}
                (isSuccess, result) = scApp.VehicleService.ProcessVhCmdCancelAbortRequest(vh_id);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseEvent"] = (p) =>
            {
                bool          isSuccess  = false;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                PauseEvent    pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(event_type, out pauseEvent);
                if (isSuccess)
                {
                    isSuccess = scApp.VehicleService.PauseRequest
                                    (vh_id, pauseEvent, SCAppConstants.OHxCPauseType.Normal);
                }

                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseStatusChange"] = (p) =>
            {
                bool          isSuccess  = false;
                string        result     = string.Empty;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        pauseType  = Request.Query.pauseType.Value ?? Request.Form.pauseType.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                SCAppConstants.OHxCPauseType pause_type = default(SCAppConstants.OHxCPauseType);
                PauseEvent pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(pauseType, out pause_type);

                if (isSuccess)
                {
                    isSuccess = Enum.TryParse(event_type, out pauseEvent);

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.PauseRequest
                                        (vh_id, pauseEvent, pause_type);
                        if (isSuccess)
                        {
                            //AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            //vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Send pause request to vehicle:{vh_id} failed.";
                        }
                    }
                    else
                    {
                        result = $"Can't recognize Pause Event:{event_type}.";
                    }
                }
                else
                {
                    result = $"Can't recognize Pause Type:{pauseType}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ModeStatusChange"] = (p) =>
            {
                bool          isSuccess   = false;
                string        result      = string.Empty;
                SCApplication scApp       = SCApplication.getInstance();
                string        vh_id       = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        modeStatus  = Request.Query.modeStatus.Value ?? Request.Form.modeStatus.Value ?? string.Empty;
                VHModeStatus  mode_status = default(VHModeStatus);
                isSuccess = Enum.TryParse(modeStatus, out mode_status);

                if (isSuccess)
                {
                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleBLL.updataVehicleMode(vh_id, mode_status);
                        if (isSuccess)
                        {
                            AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Update vehicle:{vh_id} mode status failed.";
                        }
                    }
                }
                else
                {
                    result = $"Can't recognize mode status:{modeStatus}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ResetAlarm"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    //isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    isSuccess = scApp.TransferService.OHBC_AlarmAllCleared(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/Debug_Function"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string resuleJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resuleJson = reader.ReadToEnd();
                    }
                }
                var     fun_enable         = JsonConvert.DeserializeObject(resuleJson);
                JObject jo                 = JObject.Parse(resuleJson);
                dynamic dyna               = fun_enable as dynamic;
                var     func_num           = dyna.Func_Num?.Value ?? 0;
                string  func_name          = dyna.Func_Name?.Value ?? string.Empty;
                string  vh_id              = dyna.VH_ID?.Value ?? string.Empty;
                string  cst_id             = dyna.Cst_ID?.Value ?? string.Empty;
                string  from_adr           = dyna.From_Adr?.Value ?? string.Empty;
                string  to_adr             = dyna.To_Adr?.Value ?? string.Empty;
                var     operatingMode      = dyna.OperatingMode?.Value ?? null;
                var     operatingPowerMode = dyna.OperatingPowerMode?.Value ?? null;
                var     abort_type         = dyna.Abort_Type?.Value ?? null;
                var     pauseEvent         = dyna.PauseEvent?.Value ?? null;
                var     pauseType          = dyna.PauseType?.Value ?? null;
                var     blockzoneQueue     = dyna.BlockZoneQueue?.Value ?? null;
                var     pauseFirst         = dyna.PauseFirst?.Value ?? null;
                var     seg_id             = dyna.Seg_ID?.Value ?? null;
                //string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                var noticeCar = scApp.getEQObjCacheManager().getVehicletByVHID(vh_id);
                try
                {
                    if (func_num != 0)
                    {
                        if (func_num is Int64 i)
                        {
                            switch (i)
                            {
                            case 1:
                                asyExecuteAction(scApp.VehicleService.HostBasicVersionReport, vh_id);
                                break;

                            case 2:
                                asyExecuteAction(scApp.VehicleService.HostBasicVersionReport, vh_id);
                                break;

                            case 11:
                                asyExecuteAction(scApp.VehicleService.BasicInfoReport, vh_id);
                                break;

                            case 13:
                                asyExecuteAction(scApp.VehicleService.TavellingDataReport, vh_id);
                                break;

                            case 15:
                                asyExecuteAction(scApp.VehicleService.SectionDataReport, vh_id);
                                break;

                            case 17:
                                asyExecuteAction(scApp.VehicleService.AddressDataReport, vh_id);
                                break;

                            case 19:
                                asyExecuteAction(scApp.VehicleService.ScaleDataReport, vh_id);
                                break;

                            case 21:
                                asyExecuteAction(scApp.VehicleService.ControlDataReport, vh_id);
                                break;

                            case 23:
                                asyExecuteAction(scApp.VehicleService.GuideDataReport, vh_id);
                                break;

                            case 35:
                                scApp.VehicleService.CarrierIDRenameRequset(vh_id, noticeCar.CST_ID, cst_id);
                                break;

                            case 71:
                                scApp.VehicleService.TeachingRequest(vh_id, from_adr, to_adr);
                                break;

                            case 41:
                                OperatingVHMode vhMode = (OperatingVHMode)operatingMode;
                                scApp.VehicleService.ModeChangeRequest(vh_id, vhMode);
                                break;

                            case 45:
                                OperatingPowerMode powerMode = (OperatingPowerMode)operatingPowerMode;
                                scApp.VehicleService.PowerOperatorRequest(vh_id, operatingPowerMode);
                                break;

                            case 37:
                                CMDCancelType cmdCancelType = (CMDCancelType)abort_type;
                                noticeCar.sned_Str37(noticeCar.OHTC_CMD, abort_type);
                                break;

                            case 39:
                                PauseEvent _pauseEvent = (PauseEvent)pauseEvent;
                                PauseType  _pauseType  = (PauseType)pauseType;
                                scApp.VehicleService.PauseRequest(vh_id, _pauseEvent, pauseType);
                                break;

                            case 61:
                                asyExecuteAction(scApp.VehicleService.IndividualUploadRequest, vh_id);
                                break;

                            case 63:
                                asyExecuteAction(scApp.VehicleService.IndividualChangeRequest, vh_id);
                                break;

                            case 91:
                                asyExecuteAction(scApp.VehicleService.AlarmResetRequest, vh_id);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(func_name))
                    {
                        if (func_name is string str)
                        {
                            switch (str)
                            {
                            case "btn_SendAll":
                                asyExecuteAction(scApp.VehicleService.doDataSysc, vh_id);
                                break;

                            case "btn_reset_teach_result":
                                List <ASECTION> sections = scApp.CatchDataFromDB_Section;
                                foreach (var sec in sections)
                                {
                                    if (scApp.MapBLL.resetSecTechingTime(sec.SEC_ID))
                                    {
                                        sec.LAST_TECH_TIME = null;
                                    }
                                }
                                break;

                            case "btn_cmd_override_test":
                                scApp.VehicleService.VhicleChangeThePath(vh_id, pauseFirst);
                                break;

                            case "btn_Force_FinishCmd":
                                scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                                break;

                            case "btn_Refresh_Vh_Status":
                                scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                                break;

                            case "btn_forceReleaseAllBlock":
                                scApp.VehicleService.forceReleaseBlockControl(vh_id);
                                break;

                            case "btn_open_tcp_port":
                                scApp.VehicleService.startVehicleTcpIpServer(vh_id);
                                break;

                            case "btn_close_tcp_port":
                                scApp.VehicleService.stopVehicleTcpIpServer(vh_id);
                                break;

                            case "btn_changeToRemove":
                                if (!noticeCar.IS_INSTALLED)
                                {
                                    result = ($"{vh_id} is removed ready!");
                                    break;
                                }
                                scApp.VehicleService.Remove(vh_id);
                                result = $"{vh_id} remove ok";
                                break;

                            case "btn_changeToInstall":
                                if (noticeCar.IS_INSTALLED)
                                {
                                    result = ($"{vh_id} is install ready!");
                                    break;
                                }
                                scApp.VehicleService.Install(vh_id);
                                result = $"{vh_id} install ok";
                                break;

                            case "btn_changeToAutoRemote":
                                scApp.VehicleService.VehicleAutoModeCahnge(vh_id, VHModeStatus.AutoRemote);
                                break;

                            case "btn_changeToAutoLocal":
                                scApp.VehicleService.VehicleAutoModeCahnge(vh_id, VHModeStatus.AutoLocal);
                                break;

                            case "btn_forceReleaseALLBlock":
                                scApp.VehicleService.forceReleaseBlockControl();
                                break;

                            case "btn_release_block":
                                scApp.VehicleService.reCheckBlockControl(blockzoneQueue);
                                break;

                            case "btn_refresh_vh_order_in_seg":
                                var seg_obj = scApp.SegmentBLL.cache.GetSegment(seg_id);
                                seg_obj.RefreshVhOrder(scApp.VehicleBLL, scApp.SectionBLL);
                                break;

                            case "btn_portInServeice":

                                break;

                            case "btn_portOutOfServeice":

                                break;

                            default:
                                break;
                            }
                        }
                    }

                    isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["Engineer/ForceCmdFinish"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                bool   isSuccess = scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                if (isSuccess)
                {
                    var vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                    vh.NotifyVhExcuteCMDStatusChange();
                }
                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ScanSelected/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                //string action = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic d = JsonConvert.DeserializeObject(resultJson);
                //string shelf_id = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "ScanSelected",
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    var shelf = d.shelf;
                    foreach (string item in shelf)
                    {
                        if (scApp.TransferService.isShelfPort(item))
                        {
                            scApp.TransferService.SetScanCmd("", "", item);
                        }
                    }
                    //foreach (var v in )
                    //{
                    //	if (isShelfPort(v.Carrier_LOC))
                    //	{
                    //		SetScanCmd("", "", v.Carrier_LOC);
                    //	}
                    //}
                    //bool enable = d.enable?.Value;
                    //string s = scApp.TransferService.Manual_ShelfEnable(shelf_id, enable);
                    isSuccess = true;
                    result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ScanAll/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                //string action = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic d = JsonConvert.DeserializeObject(resultJson);
                //string shelf_id = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "ScanAll",
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    scApp.TransferService.ScanALL();
                    isSuccess = true;
                    result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
 public virtual bool send_Str37(string cmd_id, CMDCancelType actType)
 {
     return(true);
 }
        private void RegisterTransferManagementEvent()
        {
            Post["TransferManagement/MCSQueueSwitch"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                try
                {
                    string AutoAssign   = Request.Query.AutoAssign.Value ?? Request.Form.AutoAssign.Value ?? string.Empty;
                    bool   isAutoAssign = Convert.ToBoolean(AutoAssign);
                    scApp.getEQObjCacheManager().getLine().MCSCommandAutoAssign = isAutoAssign;
                    result = "OK";
                }
                catch (Exception ex)
                {
                    result = "MCS Queue Switch update failed with exception happened";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/CancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                CMDCancelType cnacel_type = default(CMDCancelType);
                string        mcs_cmd_id  = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    if (mcs_cmd == null)
                    {
                        result = $"Can not find transfer command:[{mcs_cmd_id}].";
                    }
                    else
                    {
                        if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                        {
                            cnacel_type = CMDCancelType.CmdCancel;
                            bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                            if (btemp)
                            {
                                result = "OK";
                            }
                            else
                            {
                                result = $"Transfer command:[{mcs_cmd_id}] cancel failed.";
                            }
                        }
                        else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                        {
                            cnacel_type = CMDCancelType.CmdAbort;
                            bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                            if (btemp)
                            {
                                result = "OK";
                            }
                            else
                            {
                                result = $"Transfer command:[{mcs_cmd_id}] adort failed.";
                            }
                        }
                        else
                        {
                            result = $"Command ID:{mcs_cmd.CMD_ID.Trim()} can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                        }
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["TransferManagement/ForceFinish"] = (p) =>
            {
                var      scApp            = SCApplication.getInstance();
                bool     isSuccess        = true;
                string   result           = string.Empty;
                string   mcs_cmd_id       = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                AVEHICLE excute_cmd_of_vh = scApp.VehicleBLL.cache.getVehicleByMCSCmdID(mcs_cmd_id);
                ACMD_MCS mcs_cmd          = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                try
                {
                    if (excute_cmd_of_vh != null)
                    {
                        scApp.VehicleBLL.doTransferCommandFinish(excute_cmd_of_vh.VEHICLE_ID, excute_cmd_of_vh.OHTC_CMD, CompleteStatus.CmpStatusForceFinishByOp, 0);
                        scApp.VIDBLL.initialVIDCommandInfo(excute_cmd_of_vh.VEHICLE_ID);
                    }
                    scApp.CMDBLL.updateCMD_MCS_TranStatus2Complete(mcs_cmd_id, E_TRAN_STATUS.Aborted);
                    scApp.ReportBLL.newReportTransferCommandFinish(mcs_cmd, excute_cmd_of_vh, sc.Data.SECS.AGVC.SECSConst.CMD_Result_Unsuccessful, null);
                    result = "OK";
                }
                catch
                {
                    result = "ForceFinish failed.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/AssignVehicle"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.assignCommnadToVehicle(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Assign command to  vehicle failed with exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
            Post["TransferManagement/ShiftCommand"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.commandShift(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Shift command failed with exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/ChangeStatus"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string sstatus    = Request.Query.status.Value ?? Request.Form.status.Value ?? string.Empty;
                try
                {
                    ACMD_MCS      mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    E_TRAN_STATUS status  = (E_TRAN_STATUS)Enum.Parse(typeof(E_TRAN_STATUS), sstatus, false);

                    if (mcs_cmd != null)
                    {
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_TranStatus(mcs_cmd_id, status);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update status failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update status failed with exception happened.";
                }

                //Todo by Mark

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/Priority"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string priority   = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd   = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    int      iPriority = Convert.ToInt32(priority);
                    if (mcs_cmd != null)
                    {
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_PrioritySUM(mcs_cmd, iPriority);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update priority failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update priority failed with exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
Beispiel #10
0
 public virtual (bool isSendOK, int replyCode) send_Str37(string cmd_id, CMDCancelType actType)
 {
     return(true, int.MinValue);
 }
Beispiel #11
0
        private void RegisterTransferManagementEvent()
        {
            Post["TransferManagement/MCSQueueSwitch"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                try
                {
                    string AutoAssign   = Request.Query.AutoAssign.Value ?? Request.Form.AutoAssign.Value ?? string.Empty;
                    bool   isAutoAssign = Convert.ToBoolean(AutoAssign);
                    scApp.getEQObjCacheManager().getLine().MCSCommandAutoAssign = isAutoAssign;
                    result = "OK";
                }
                catch (Exception ex)
                {
                    result = "MCS Queue Switch update failed with exception happened";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/CancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                CMDCancelType cnacel_type = default(CMDCancelType);
                string        mcs_cmd_id  = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);

                    scApp.TransferService.Manual_DeleteCmd(mcs_cmd_id, "正式 UI");

                    UserOperationLog userOperationLog = new UserOperationLog()
                    {
                        Action     = "TransferCancelAbort",
                        ActionTime = DateTime.Now,
                        CommandID  = mcs_cmd_id,
                    };
                    SCUtility.UserOperationLog(userOperationLog);
                    //if (mcs_cmd == null)
                    //{
                    //    result = $"Can not find transfer command:[{mcs_cmd_id}].";
                    //}
                    //else
                    //{
                    //    if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                    //    {
                    //        cnacel_type = CMDCancelType.CmdCancel;
                    //        bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                    //        if (btemp)
                    //        {
                    //            result = "OK";
                    //        }
                    //        else
                    //        {
                    //            result = $"Transfer command:[{mcs_cmd_id}] cancel failed.";
                    //        }
                    //    }
                    //    else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                    //    {
                    //        cnacel_type = CMDCancelType.CmdAbort;
                    //        bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                    //        if (btemp)
                    //        {
                    //            result = "OK";
                    //        }
                    //        else
                    //        {
                    //            result = $"Transfer command:[{mcs_cmd_id}] adort failed.";
                    //        }
                    //    }
                    //    else
                    //    {
                    //        result = $"Command ID:{mcs_cmd.CMD_ID.Trim()} can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["TransferManagement/ForceFinish"] = (p) =>
            {
                var      scApp            = SCApplication.getInstance();
                bool     isSuccess        = true;
                string   result           = string.Empty;
                string   mcs_cmd_id       = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                AVEHICLE excute_cmd_of_vh = scApp.VehicleBLL.cache.getVehicleByMCSCmdID(mcs_cmd_id);
                ACMD_MCS mcs_cmd          = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                try
                {
                    if (excute_cmd_of_vh != null)
                    {
                        scApp.VehicleBLL.doTransferCommandFinish(excute_cmd_of_vh.VEHICLE_ID, excute_cmd_of_vh.OHTC_CMD, CompleteStatus.CmpStatusForceFinishByOp);
                        scApp.VIDBLL.initialVIDCommandInfo(excute_cmd_of_vh.VEHICLE_ID);
                    }
                    //scApp.CMDBLL.updateCMD_MCS_TranStatus2Complete(mcs_cmd.CMD_ID, E_TRAN_STATUS.Aborting);
                    scApp.ReportBLL.newReportTransferCommandNormalFinish(mcs_cmd, excute_cmd_of_vh, sc.Data.SECS.CSOT.SECSConst.CMD_Result_Unsuccessful, null);
                    result = "OK";
                }
                catch
                {
                    result = "ForceFinish failed.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferForceFinish",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/AssignVehicle"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.assignCommnadToVehicle(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Assign command to  vehicle failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferAssignVehicle",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
            Post["TransferManagement/ShiftCommand"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.commandShift(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Shift command failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferShiftCommand",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/ChangeStatus"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string sstatus    = Request.Query.status.Value ?? Request.Form.status.Value ?? string.Empty;
                try
                {
                    ACMD_MCS      mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    E_TRAN_STATUS status  = (E_TRAN_STATUS)Enum.Parse(typeof(E_TRAN_STATUS), sstatus, false);

                    if (mcs_cmd != null)
                    {
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_TranStatus(mcs_cmd_id, status);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update status failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update status failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferChangeStatus",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                //Todo by Mark

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/Priority"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string priority   = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd   = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    int      iPriority = Convert.ToInt32(priority);
                    if (mcs_cmd != null)
                    {
                        //isSuccess = scApp.CMDBLL.updateCMD_MCS_PrioritySUM(mcs_cmd, iPriority);
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_PortPriority(mcs_cmd.CMD_ID, iPriority);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update priority failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update priority failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferPriority",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/TransferCreate"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;

                int    Y      = DateTime.Now.Year % 100;
                string stDate = string.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}", Y, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

                string mcs_cmd_id = "MANAUL-" + stDate;//Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;

                string priority = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;

                string box_id = Request.Query.box_id.Value ?? Request.Form.box_id.Value ?? string.Empty;
                string cst_id = Request.Query.cst_id.Value ?? Request.Form.cst_id.Value ?? string.Empty;
                string source = Request.Query.source.Value ?? Request.Form.source.Value ?? string.Empty;
                string dest   = Request.Query.dest.Value ?? Request.Form.dest.Value ?? string.Empty;
                string lot_id = Request.Query.lot_id.Value ?? Request.Form.lot_id.Value ?? string.Empty;
                result = scApp.TransferService.Manual_InsertCmd(source, dest, 5);

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferCreate",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                    Source     = source,
                    Dest       = dest,
                    BOXID      = box_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Get["TransferManagement/TransferCheck/AGVStation/{AGVStationID}"] = (p) =>
            {
                SCApplication scApp = SCApplication.getInstance();
                //string queue_count = 0;
                scApp.TransferService.swapTriggerWaitin = false;
                string agv_station_id = p.AGVStationID;
                string excute_count   = Request.Query.unfinishCmdCount.Value ?? Request.Form.unfinishCmdCount.Value ?? string.Empty;
                string is_emergency   = Request.Query.isEmergency.Value ?? Request.Form.isEmergency.Value ?? string.Empty;
                bool   emergency      = false;
                if (is_emergency == "true")
                {
                    emergency = true;
                }
                else if (is_emergency == "false")
                {
                    emergency = false;
                }
                // Change the default return from false to true.
                // 因為目前回復NG時會產生AGV走行命令回到AGV Station,但目前預設值設定為false 因避免exception情形(AGVC Cmd == 0 時回復True 不會停止觸發OHBC)
                bool is_ok = false;
                //todo 執行確認能否讓AGVC開始進行該AGV Station進貨的流程
                bool check_method = scApp.TransferService.oneInoneOutMethodUse;
                if (check_method)
                {
                    is_ok = scApp.TransferService.CanExcuteUnloadTransferAGVStationFromAGVC_OneInOneOut(agv_station_id.Trim(), Int32.Parse(excute_count), emergency);
                }
                else
                {
                    is_ok = scApp.TransferService.CanExcuteUnloadTransferAGVStationFromAGVC(agv_station_id.Trim(), Int32.Parse(excute_count), emergency);
                }
                var response = (Response)(is_ok ? "OK" : "NG");
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["TransferManagement/TransferCheck/Swap/AGVStation/{AGVStationID}"] = (p) =>
            {
                SCApplication scApp = SCApplication.getInstance();
                //string queue_count = 0;
                scApp.TransferService.swapTriggerWaitin = true;
                string agv_station_id = p.AGVStationID;
                string excute_count   = Request.Query.unfinishCmdCount.Value ?? Request.Form.unfinishCmdCount.Value ?? string.Empty;
                string is_emergency   = Request.Query.isEmergency.Value ?? Request.Form.isEmergency.Value ?? string.Empty;
                bool   emergency      = false;
                is_emergency = is_emergency.ToUpper();
                if (is_emergency.Contains("T"))
                {
                    emergency = true;
                }
                else if (is_emergency.Contains("F"))
                {
                    emergency = false;
                }
                // Change the default return from false to true.
                // 因為目前回復NG時會產生AGV走行命令回到AGV Station,但目前預設值設定為false 因避免exception情形(AGVC Cmd == 0 時回復True 不會停止觸發OHBC)
                bool is_ok       = false;
                bool is_more_out = false;

                //todo 執行確認能否讓AGVC開始進行該AGV Station進貨的流程
                (is_ok, is_more_out) = scApp.TransferService.CanExcuteUnloadTransferAGVStationFromAGVC_Swap(agv_station_id.Trim(), Int32.Parse(excute_count), emergency);

                string check_result            = is_ok ? "OK" : "NG";
                E_AGVStationTranMode tran_mode = is_more_out ? E_AGVStationTranMode.MoreOut : E_AGVStationTranMode.MoreIn;

                int s_tran_mode = (int)tran_mode;
                //var response = (Response)(is_ok ? "OK" : "NG");
                var response = (Response)($"{check_result},{s_tran_mode}");
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["TransferManagement/PreOpenAGVStationCover/AGVStationPorts/{AGVStationPortID}"] = (p) =>
            {
                SCApplication scApp = SCApplication.getInstance();
                string        agv_station_port_id = p.AGVStationPortID;

                bool is_ok = true;
                is_ok = scApp.TransferService.SetAGV_PortOpenBOX(agv_station_port_id, "TransferManagement");

                var response = (Response)(is_ok ? "OK" : "NG");
                response.ContentType = restfulContentType;

                return(response);
            };
        }
        private void RegisterTransferManagementEvent()
        {
            Post["TransferManagement/MCSQueueSwitch"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                try
                {
                    string AutoAssign   = Request.Query.AutoAssign.Value ?? Request.Form.AutoAssign.Value ?? string.Empty;
                    bool   isAutoAssign = Convert.ToBoolean(AutoAssign);
                    scApp.getEQObjCacheManager().getLine().MCSCommandAutoAssign = isAutoAssign;
                    result = "OK";
                }
                catch (Exception ex)
                {
                    result = "MCS Queue Switch update failed with exception happened";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/CancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                CMDCancelType cnacel_type = default(CMDCancelType);
                string        mcs_cmd_id  = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);

                    scApp.TransferService.Manual_DeleteCmd(mcs_cmd_id, "正式 UI");
                    //if (mcs_cmd == null)
                    //{
                    //    result = $"Can not find transfer command:[{mcs_cmd_id}].";
                    //}
                    //else
                    //{
                    //    if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                    //    {
                    //        cnacel_type = CMDCancelType.CmdCancel;
                    //        bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                    //        if (btemp)
                    //        {
                    //            result = "OK";
                    //        }
                    //        else
                    //        {
                    //            result = $"Transfer command:[{mcs_cmd_id}] cancel failed.";
                    //        }
                    //    }
                    //    else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                    //    {
                    //        cnacel_type = CMDCancelType.CmdAbort;
                    //        bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                    //        if (btemp)
                    //        {
                    //            result = "OK";
                    //        }
                    //        else
                    //        {
                    //            result = $"Transfer command:[{mcs_cmd_id}] adort failed.";
                    //        }
                    //    }
                    //    else
                    //    {
                    //        result = $"Command ID:{mcs_cmd.CMD_ID.Trim()} can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["TransferManagement/ForceFinish"] = (p) =>
            {
                var      scApp            = SCApplication.getInstance();
                bool     isSuccess        = true;
                string   result           = string.Empty;
                string   mcs_cmd_id       = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                AVEHICLE excute_cmd_of_vh = scApp.VehicleBLL.cache.getVehicleByMCSCmdID(mcs_cmd_id);
                ACMD_MCS mcs_cmd          = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                try
                {
                    if (excute_cmd_of_vh != null)
                    {
                        scApp.VehicleBLL.doTransferCommandFinish(excute_cmd_of_vh.VEHICLE_ID, excute_cmd_of_vh.OHTC_CMD, CompleteStatus.CmpStatusForceFinishByOp);
                        scApp.VIDBLL.initialVIDCommandInfo(excute_cmd_of_vh.VEHICLE_ID);
                    }
                    //scApp.CMDBLL.updateCMD_MCS_TranStatus2Complete(mcs_cmd.CMD_ID, E_TRAN_STATUS.Aborting);
                    scApp.ReportBLL.newReportTransferCommandNormalFinish(mcs_cmd, excute_cmd_of_vh, sc.Data.SECS.CSOT.SECSConst.CMD_Result_Unsuccessful, null);
                    result = "OK";
                }
                catch
                {
                    result = "ForceFinish failed.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/AssignVehicle"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.assignCommnadToVehicle(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Assign command to  vehicle failed with exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
            Post["TransferManagement/ShiftCommand"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.commandShift(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Shift command failed with exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/ChangeStatus"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string sstatus    = Request.Query.status.Value ?? Request.Form.status.Value ?? string.Empty;
                try
                {
                    ACMD_MCS      mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    E_TRAN_STATUS status  = (E_TRAN_STATUS)Enum.Parse(typeof(E_TRAN_STATUS), sstatus, false);

                    if (mcs_cmd != null)
                    {
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_TranStatus(mcs_cmd_id, status);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update status failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update status failed with exception happened.";
                }

                //Todo by Mark

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/Priority"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string priority   = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd   = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    int      iPriority = Convert.ToInt32(priority);
                    if (mcs_cmd != null)
                    {
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_PrioritySUM(mcs_cmd, iPriority);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update priority failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update priority failed with exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/TransferCreate"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;

                int    Y      = DateTime.Now.Year % 100;
                string stDate = string.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}", Y, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

                string mcs_cmd_id = "MANAUL-" + stDate;//Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;

                string priority = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;

                string box_id = Request.Query.box_id.Value ?? Request.Form.box_id.Value ?? string.Empty;
                string cst_id = Request.Query.cst_id.Value ?? Request.Form.cst_id.Value ?? string.Empty;
                string source = Request.Query.source.Value ?? Request.Form.source.Value ?? string.Empty;
                string dest   = Request.Query.dest.Value ?? Request.Form.dest.Value ?? string.Empty;
                string lot_id = Request.Query.lot_id.Value ?? Request.Form.lot_id.Value ?? string.Empty;
                result = scApp.TransferService.Manual_InsertCmd(source, dest, lot_id);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Get["TransferManagement/TransferCheck/AGVStation/{AGVStationID}"] = (p) =>
            {
                SCApplication scApp          = SCApplication.getInstance();
                string        agv_station_id = p.AGVStationID;
                bool          is_ok          = false;
                //todo 執行確認能否讓AGVC開始進行該AGV Station進貨的流程
                //is_ok = scApp.TransferService.canExcuteUnloadTransferAGVStationFromAGVC.....todo


                var response = (Response)(is_ok ? "OK" : "NG");
                response.ContentType = restfulContentType;

                return(response);
            };
        }