void InitPlayer(AbnormalViewModel p) { string folderPath = p.Meta.FramePath; Player = new PlayerModel { Target = Convert.ToInt32(p.Abnormal.Position)//目标帧号 }; try { DirectoryInfo root = new DirectoryInfo(folderPath); FileInfo[] files = root.GetFiles("*.jpg"); files = files.OrderBy(y => y.Name, new FileComparer()).ToArray(); foreach (var item in files) { string name = item.FullName; imagePath.Add(name); } Player.Calculate(imagePath.Count); } catch (PathTooLongException) { MessageBox.Show("文件路径过长"); } catch (ArgumentException) { MessageBox.Show("该路径下文件错误"); } catch (Exception e) { MessageBox.Show("发生异常:" + e.ToString()); } }
private void ExecuteSelectCommand(AbnormalViewModel p) { Debug.WriteLine("worker.isBusy:" + worker.IsBusy); if (worker.IsBusy) { return; } //将该异常的STATE修改为2000 AbnormalService.GetService().ChangeState(p.AbnormalId, 2000); Messenger.Default.Send("enableDeleteBtn", "BTVM2BTV"); //更新左下角显示区域 SelectedAVM = p; CombboxItem = CombboxList[p.Abnormal.Type]; //播放视频 //找到文件 InitPlayer(p); worker.RunWorkerAsync(Player); }
public void ExecuteAddCmd(int p) { CheckWorkerState(); Debug.WriteLine("get abnornal id :" + p); //修改数据库 int newId = AbnormalService.GetService().AddItem(p); bool isAbnormal = true; //修改列表显示 for (int i = 0; i < AbnormalVMs.Count; i++) { if (AbnormalVMs[i].AbnormalId == p) { Debug.WriteLine("get item in AbnormalVMs :" + p); if (AbnormalVMs[i].Abnormal.Type == 0 || AbnormalVMs[i].Abnormal.Type == 6) { isAbnormal = false; } AbnormalViewModel abnormalViewModel = AbnormalVMs[i]; MetaModel mm = new MetaModel(); AbnormalModel am = new AbnormalModel(); AbnormalViewModel avm = new AbnormalViewModel(); mm.Addr = abnormalViewModel.Meta.Addr; mm.PipeCode = abnormalViewModel.Meta.PipeCode; mm.PipeType = (int)abnormalViewModel.Meta.PipeType; mm.FramePath = abnormalViewModel.Meta.FramePath; if (!string.IsNullOrEmpty(abnormalViewModel.Meta.StartTime)) { mm.StartTime = abnormalViewModel.Meta.StartTime; } else { mm.StartTime = "未填写"; } am.VideoId = (int)abnormalViewModel.Abnormal.VideoId; am.Type = (int)abnormalViewModel.Abnormal.Type; am.Position = abnormalViewModel.Abnormal.Position; //新加的状态和任务编号 am.State = 1000; am.TaskId = (int)abnormalViewModel.Abnormal.TaskId; avm.AbnormalId = newId; avm.Meta = mm; avm.Abnormal = am; DispatcherHelper.CheckBeginInvokeOnUI(() => { AbnormalVMs.Insert(i, avm); }); break; } } //修改右下角展示区显示 //重新计算现有的总异常 if (isAbnormal) { ErrorNum++; } }
private bool CanExecuteSelectCommand(AbnormalViewModel p) { CheckWorkerState(); return(!string.IsNullOrEmpty(p.Meta.FramePath)); }
private void ExecuteSelectCommand(AbnormalViewModel p) { stop = true; //tokenSource.Cancel(); //更新左下角显示区域 SelectedAVM = p; CombboxItem = CombboxList[p.Abnormal.Type]; //播放视频 //找到文件 string folderPath = p.Meta.FramePath; player = new PlayerModel { Target = Convert.ToInt32(p.Abnormal.Position)//目标帧号 }; try { DirectoryInfo root = new DirectoryInfo(folderPath); FileInfo[] files = root.GetFiles("*.jpg"); files = files.OrderBy(y => y.Name, new FileComparer()).ToArray(); foreach (var item in files) { string name = item.FullName; imagePath.Add(name); } player.Calculate(imagePath.Count, 120); //播放函数 var t = new Task(() => { int nowPic = player.StartNum; int end = player.EndNum; stop = false; while (!stop && nowPic <= end) { token.ThrowIfCancellationRequested(); DispatcherHelper.CheckBeginInvokeOnUI(() => { ImgSource = imagePath[nowPic]; }); nowPic++; Thread.Sleep(player.Speed); } stop = true; }); t.Start(); } catch (PathTooLongException e) { MessageBox.Show("文件路径过长"); log.Warn("文件路径过长", e); } catch (ArgumentException e) { MessageBox.Show("该路径下文件错误"); log.Warn("该路径下文件错误", e); } catch (Exception e) { MessageBox.Show("发生异常:" + e.ToString()); log.Warn("发生异常", e); } }