Exemple #1
0
        public void ProcessCVOpInRequest(Data.VO.OHCV ohcv)
        {
            if (ohcv == null)
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(RoadControlService), Device: "OHxC",
                              Data: $"Start process ohcv op in request, but ohcv object is null.");
                return;
            }

            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                          Data: $"Start process ohcv:{ohcv?.EQPT_ID} op in request...",
                          VehicleID: ohcv?.EQPT_ID);
            string   segment_location       = ohcv.SegmentLocation;
            ASEGMENT pre_control_segment_vo = SegmentBLL.cache.GetSegment(segment_location);

            if (System.Threading.Interlocked.Exchange(ref pre_control_segment_vo.segment_prepare_control_SyncPoint, 1) == 0)
            {
                try
                {
                    //將segment 更新成 pre disable
                    ASEGMENT pre_control_segment_do = MapBLL.PreDisableSegment(segment_location);
                    pre_control_segment_vo.put(pre_control_segment_do);
                    segmentListChanged?.Invoke(this, pre_control_segment_vo);

                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                  Data: $"pre disable segment{segment_location} success.",
                                  VehicleID: ohcv.EQPT_ID);
                    bool is_road_clear = WaitRoadClear(pre_control_segment_vo, ohcv);
                    if (is_road_clear)
                    {
                        doEnableDisableSegment(segment_location, E_PORT_STATUS.OutOfService, ASEGMENT.DisableType.Safety, Data.SECS.CSOT.SECSConst.LANECUTTYPE_LaneCutOnHMI);
                        pre_control_segment_vo.NotifyControlComplete();
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                      Data: $"disable segment{segment_location} success.",
                                      VehicleID: ohcv.EQPT_ID);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exception:");
                }
                finally
                {
                    System.Threading.Interlocked.Exchange(ref pre_control_segment_vo.segment_prepare_control_SyncPoint, 0);
                }
            }
            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                          Data: $"End process ohcv:{ohcv?.EQPT_ID} op in request.",
                          VehicleID: ohcv?.EQPT_ID);
        }
Exemple #2
0
        public bool doEnableDisableSegment(string segment_id, E_PORT_STATUS status, ASEGMENT.DisableType disableType, string laneCutType)
        {
            bool     is_success = true;
            ASEGMENT seg_do     = null;

            try
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                              Data: $"Start process segment:{segment_id} excute:{status} ,disable type:{disableType} ,lane cut type:{laneCutType}");

                bool     is_status_change = false;
                ASEGMENT seg_vo           = SegmentBLL.cache.GetSegment(segment_id);
                lock (seg_vo)
                {
                    List <APORTSTATION> port_stations = PortStationBLL.OperateCatch.loadAllPortBySegmentID(segment_id, SectionBLL);
                    using (TransactionScope tx = SCUtility.getTransactionScope())
                    {
                        using (DBConnection_EF con = DBConnection_EF.GetUContext())
                        {
                            switch (status)
                            {
                            case E_PORT_STATUS.InService:
                                seg_do = RouteGuide.OpenSegment(segment_id, disableType);
                                break;

                            case E_PORT_STATUS.OutOfService:
                                seg_do = RouteGuide.CloseSegment(segment_id, disableType);
                                break;
                            }
                            is_status_change = seg_vo.STATUS != seg_do.STATUS;
                            if (is_status_change)
                            {
                                foreach (APORTSTATION port_station in port_stations)
                                {
                                    PortStationBLL.OperateDB.updatePortStationStatus(port_station.PORT_ID, status);
                                    PortStationBLL.OperateCatch.updatePortStationStatus(port_station.PORT_ID, status);
                                }
                            }
                            tx.Complete();
                        }
                    }
                    seg_vo.put(seg_do);
                    segmentListChanged?.Invoke(this, seg_vo);

                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                  Data: $"end process segment:{segment_id} excute:{status} ,disable type:{disableType} ,lane cut type:{laneCutType}" +
                                  $"finial status:{seg_vo.STATUS},DISABLE_FLAG_USER:{seg_vo.DISABLE_FLAG_USER},DISABLE_FLAG_SAFETY:{seg_vo.DISABLE_FLAG_SAFETY}" +
                                  $",DISABLE_FLAG_HID:{seg_vo.DISABLE_FLAG_HID},DISABLE_FLAG_SYSTEM:{seg_vo.DISABLE_FLAG_SYSTEM}");

                    if (is_status_change)
                    {
                        List <AMCSREPORTQUEUE> reportqueues = new List <AMCSREPORTQUEUE>();
                        List <ASECTION>        sections     = SectionBLL.cache.loadSectionsBySegmentID(segment_id);
                        string segment_start_adr            = sections.First().FROM_ADR_ID;
                        string segment_end_adr = sections.Last().TO_ADR_ID;
                        switch (seg_vo.STATUS)
                        {
                        case E_SEG_STATUS.Active:
                            ReportBLL.newReportLaneInService(segment_start_adr, segment_end_adr, laneCutType, reportqueues);
                            break;

                        case E_SEG_STATUS.Closed:
                            ReportBLL.newReportLaneOutOfService(segment_start_adr, segment_end_adr, laneCutType, reportqueues);
                            break;
                        }
                        foreach (APORTSTATION port_station in port_stations)
                        {
                            switch (seg_vo.STATUS)
                            {
                            case E_SEG_STATUS.Active:
                                ReportBLL.newReportPortInServeice(port_station.PORT_ID, reportqueues);
                                break;

                            case E_SEG_STATUS.Closed:
                                ReportBLL.newReportPortOutOfService(port_station.PORT_ID, reportqueues);
                                break;
                            }
                        }
                        ReportBLL.newSendMCSMessage(reportqueues);
                    }
                }
            }
            catch (Exception ex)
            {
                seg_do = null;
                logger.Error(ex, "Exception:");
                is_success = false;
            }
            return(is_success);
            //return seg_do;
        }