Beispiel #1
0
        public void StopCharging()
        {
            IsChargingThread = false;
            IsCharging       = false;
            SqlLiteHelper.SaveTranineesInfo(_trnLicense);
            SqlLiteHelper.SaveChargesInfo(_chargesDisplayInfo);
            SqlLiteHelper.SaveTraningInfo(_trnLicense);
            writeToDisk();

            if (StopNewExamDelegate != null)
            {
                StopNewExamDelegate();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Stops the train.
 /// </summary>
 /// <param name="isSave">if set to <c>true</c> [is save Train Info].</param>
 public void StopTrain(bool isSave)
 {
     if (!IsChargerControlHide)
     {
         IsRunning        = false;
         IsChargingThread = false;
         IsCharging       = false;
         HideChargeControl();
         if (ResetUiViewDelegate != null)
         {
             ResetUiViewDelegate();
         }
         if (isSave)
         {
             SqlLiteHelper.SaveTranineesInfo(_trnLicense);
             SqlLiteHelper.SaveChargesInfo(_chargesDisplayInfo);
             SqlLiteHelper.SaveTraningInfo(_trnLicense);
             writeToDisk();
         }
         IsChargerControlHide = true;
     }
 }
Beispiel #3
0
        private void CheckTrainProcThread()
        {
            bool canGo = false;
            bool isEnd = false;

            while (IsRunning)
            {
                if (_trainProcQueue.Count > 0)
                {
                    _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "发现" + _trainProcQueue.Count + "条过程数据,开始处理……");
                    TrainProc tp;
                    if (!_trainProcQueue.TryDequeue(out tp) || tp == null)
                    {
                        throw new InvalidOperationException("队列处理失败");
                    }
                    _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "过程数据:" + tp.Code + "," + tp.Type);
                    if (tp.Code == "10000" && tp.Type == "S")
                    {
                        cacheTime     = 0;
                        detailTime    = 0;
                        detailMileage = 0;
                        detailTries   = 0;
                        startTime     = DateTime.Now;
                        canGo         = true;
                        isEnd         = false;
                        if (_trnLicense.TrainDetail == null)
                        {
                            _trnLicense.TrainDetail = new TrainDetail
                            {
                                TrainStartTs = startTime
                            };
                        }
                        else
                        {
                            detailMileage = _trnLicense.TrainDetail.TrainMileage;
                            detailTime    = _trnLicense.TrainDetail.TrainTime;
                            detailTries   = _trnLicense.TrainDetail.TrainTries;
                        }
                        if (_trnLicense.TrainDetail.TrainProcList == null)
                        {
                            _trnLicense.TrainDetail.TrainProcList = new List <TrainProc>();
                        }
                        SaveTrainingInfo(tp);
                        SqlLiteHelper.SaveChargesInfo(_chargesDisplayInfo);
                        SqlLiteHelper.SaveTraningInfo(_trnLicense);
                        writeToDisk();
                        _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "过程数据为10000,状态为S,初始化状态信息……");

                        IsCharging = true;
                        _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "状态信息初始化完毕,开启训练线程……");
                        continue;
                    }
                    if (!canGo)
                    {
                        if (tp.Code == "10000" && tp.Type == "T")
                        {
                            StopCharging();
                            _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "训练未开始,关闭训练!");
                        }
                        else
                        {
                            _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "训练未开始,当前数据无效,已丢弃!");
                        }
                        continue;
                    }
                    if (tp.Code == "10000" && tp.Type == "T")
                    {
                        if (!IsRunning)
                        {
                            continue;
                        }
                        if (_trnLicense.TrainDetail != null)
                        {
                            _trnLicense.TrainDetail.TrainEndTs = DateTime.Now;
                        }
                        _lincenseState = LicenseState.Invaild;
                        _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + @"过程数据为10000,状态为T,准备保存状态信息……");
                        SaveTrainingInfo(tp);
                        StopTrain(true);
                        _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "本次状态信息保存完毕,关闭训练界面,返回验证界面……");
                        continue;
                    }
                    if (tp.Code == "10000" && tp.Type == "E")
                    {
                        if (!isEnd)
                        {
                            isEnd = true;
                            SaveTrainingInfo(tp);
                            if (_trnLicense.ChargeMode == "Tries")
                            {
                                _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + @"过程数据为10000,状态为E,计费模式为[次数],检查许可信息……");
                                if (_trnLicense.TriesLmt <= 0)
                                {
                                    _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "训练次数为0,停止计费……");
                                    StopCharging();
                                    if (StopDelegate != null)
                                    {
                                        StopDelegate();
                                    }
                                    continue;
                                }
                            }
                            StopCharging();
                            _sw.WriteLine(DateTime.Now.ToLocalTime() + ":" + "本次训练过程信息保存完毕,本次训练结束……");
                        }
                        continue;
                    }
                    SaveTrainingInfo(tp);
                    SqlLiteHelper.SaveChargesInfo(_chargesDisplayInfo);
                    SqlLiteHelper.SaveTraningInfo(_trnLicense);
                    writeToDisk();
                }
                Thread.Sleep(100);
            }
        }