/// <summary> /// Start a capture task. /// </summary> /// <param name="des"></param> /// <param name="option"></param> public void StartNewCaptureTask(DeviceDes des, DumpOptions options = null) { Microsoft.Win32.SaveFileDialog dlg = null; if (options == null) { dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "new_capture"; dlg.DefaultExt = ".pcap"; dlg.Filter = "Libpcap capture file (.pcap)|*.pcap"; Nullable <bool> res = dlg.ShowDialog(); if (res != true) { return; } } var op = options ?? new DumpOptions() { Path = dlg.FileName, Count = int.MaxValue, Durance = TimeSpan.MaxValue, Filter = null }; CaptureControlBlock cm = new CaptureControlBlock() { Device = des, Options = op }; RaiseCaptureCreated(cm); cm.StartCapture(); RaiseCaptureStarted(cm); ActivateDocument.Execute(pages.OfType <TaskListPage>().FirstOrDefault(), this); cm.CaptureTask.ContinueWith( (res) => { if (res.Exception != null) { MessageBox.Show(res.Exception.Message); } else if (res.IsCanceled) { string str = string.Format("{0} 上的捕获任务已停止!", cm.Device.FriendlyName); MessageBox.Show(str); } else { string str = string.Format("{0} 上的捕获任务完成!", cm.Device.FriendlyName); MessageBox.Show(str); } }); }
void ccbList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { CaptureControlBlock ccb = e.NewItems[0] as CaptureControlBlock; CommandBindings.Add(new CommandBinding(ccb.CancelTaskCommand, (o, args) => { ccb.Cancellation.Cancel(); })); ccb.CaptureTask.ContinueWith( (o) => { lvCTasks.Dispatcher.Invoke(() => ccbList.Remove(ccb)); }); } }