static void LoadPara(string[] args) { if (args.Length % 2 != 0) { Logger.Error.WriteLine("Para Input Error!"); return; } Dictionary <string, string> para = new Dictionary <string, string>(); for (int i = 0; i < args.Length; i += 2) { para.Add(args[i], args[i + 1]); } // 不指定参数则尝试加载默认配置 if (para.Count == 0) { para.Add("-t", "para.txt"); } // 从配置文件中加载参数 if (para.ContainsKey("-t")) { if (File.Exists(para["-t"])) { var str = File.ReadAllText(para["-t"]); List <string> buff = new List <string>(); args = File.ReadAllText(para["-t"]).Split(" "); for (int i = 0; i < args.Length; i++) { // "\"" 内可能有" " // 需要将其合并 if (args[i].Contains("\"")) { for (int j = i + 1; j < args.Length; j++) { args[i] += " " + args[j]; if (args[j].Contains("\"")) { buff.Add(args[i].Trim('\"')); i = j; break; } } } else { buff.Add(args[i]); } } args = buff.ToArray(); for (int i = 0; i < args.Length; i += 2) { para.Add(args[i], args[i + 1]); } } else { Logger.Error.WriteLine("No Such ParaFile!"); return; } } string[] paths = null; // 加载单一文件 if (para.ContainsKey("-f")) { if (File.Exists(para["-f"]) && para["-f"].EndsWith(".lcl")) { paths = new string[] { para["-f"] }; } else { Logger.Error.WriteLine("No Such File!"); return; } } // 加载文件夹 else if (para.ContainsKey("-p")) { if (Directory.Exists(para["-p"])) { paths = Directory.GetFiles(para["-p"], "*.lcl"); } else { Logger.Error.WriteLine("No Such Path!"); return; } } else { Logger.Error.WriteLine("No File Path!"); return; } // 加载映射关系 var map = new Dictionary <IPEndPoint, IPEndPoint>(); if (para.ContainsKey("-m")) { var ppp = para["-m"].Split(" "); foreach (var it in ppp) { var pp = it.Split("=>"); ParseInputIpPort(pp[0], out string ipO, out ushort portO); ParseInputIpPort(pp[1], out string ipM, out ushort portM); map.Add(new IPEndPoint(IPAddress.Parse(ipO), portO), new IPEndPoint(IPAddress.Parse(ipM), portM)); } } else { Logger.Error.WriteLine("No Map Para!"); } UDPSender sender = new UDPSender(); core = new Core.ReplayCore(paths); // 获取文件 info _fInfo = core.FileInfo; //Core.ReplayCore.DeleSendHandler sendHandler = (ReadOnlySpan<byte> bytes, IPEndPoint point) => //{ // sender.Send(bytes.ToArray(), point); //}; Core.ReplayCore.DeleSendHandler sendHandler = (Core.ReplayCore.SendInfo msg) => { sender.Send(msg.bytes.ToArray(), msg.point); }; Core.ReplayCore.DeleInfoHandler infoHandler = (Core.ReplayCore.ReplayInfo info) => { Console.WriteLine(info.time + ": " + (100.0 * (double)info.index / ((double)_fInfo.totalIndex - 1)).ToString("f2") + "%" + " " + info.index + " " + info.pkgCostTime); }; // 设置回放的 point map // 设置回放的 sendHandler 需要注意此处的委托只能做发送 需要尽可能快的返回 // 设置回放的 infoHandler 此处是异步触发 core.Initial(map, sendHandler, infoHandler); Logger.Info.WriteLine("TotalIndex: " + _fInfo.totalIndex + " StartTime: " + _fInfo.time + " TotalTime: " + _fInfo.totalIndex * _fInfo.timeInterval + "s"); Logger.Info.WriteLine("Notes: " + _fInfo.notes); Logger.Info.WriteLine("Maps: "); foreach (var point in _fInfo.points) { if (map.ContainsKey(point)) { Logger.Info.WriteLine(point + " => " + map[point]); } else { Logger.Info.WriteLine(point + " => "); } } }
private void Replayer_Button_Play_Click(object sender, RoutedEventArgs e) { if (_replayer == null) { MessageBox.Show("Please select file firstly!"); return; } // not playing // paused or stoped if (!_replayer.IsPlaying) { // Check map Replayer_Map_Item buff = null; Dictionary <IPEndPoint, IPEndPoint> map = new Dictionary <IPEndPoint, IPEndPoint>(); try { foreach (Replayer_Map_Item item in Replayer_Map.Items) { buff = item; // ignore if (!(bool)item.Valid.IsChecked) { continue; } var point = item.Point.Get_IPEND(); map.Add(item._point, point); } } catch (Exception) { MessageBox.Show("Wrong Input!\nCheck the Map List At " + buff?.Num.Text); Recorder_Stop(); return; } _replayer.Initial(map, (Core.ReplayCore.SendInfo msg) => { _sender.Send(msg.bytes.ToArray(), msg.point); }, (Core.ReplayCore.ReplayInfo info) => { this.Dispatcher.Invoke(() => { var finfo = _replayer.FileInfo; if (info.index == finfo.totalIndex - 1) { if ((bool)Replayer_Flag_Loop.IsChecked) { _replayer.JumpTo(0); } } if (!Replayer_Flag_IsDraging) { Replayer_Slider.Value = info.index; } Replayer_Info.Text = info.time.AddHours(8) + " Progress Percentage: " + (100.0 * (double)info.index / ((double)finfo.totalIndex - 1)).ToString("f2") + "%" + "\nProgress Index: " + info.index + " Total Index: " + finfo.totalIndex + " Cost Time:" + info.pkgCostTime; }); }); _replayer.P(); Replayer_IsPlaying(); // save params Save_Replay_Params(); } else { _replayer.P(); Replayer_NotPlaying(); } }