private double fastertimes; //内部使用 public void ReadXml() { XmlReaderSettings mySettings = new XmlReaderSettings(); mySettings.IgnoreComments = true; mySettings.IgnoreWhitespace = true; using (XmlReader reader = XmlReader.Create(m_path + "\\回放数据xml\\" + replayXmlName + ".xml", mySettings)) { lock (this.stopRead) { isStopRead = false; isPauseRead = false; } isStop = false; int preTime = 0; int nextTime = 0; int spanTime = 0; object pack = null; string type = null; while (reader.Read()) { lock (this.stopRead) { if (isStopRead == true)//在主线程中修改使子线程自然退出 { isStopRead = false; break; } else if (isPauseRead == true) { isPauseRead = false; isStop = true; } fastertimes = fasterTimes;//主线程中若修改fasterTimes将影响读包速度,不过太快时误差增大因此要限速 } if (isStop == true) { isStop = false; try { Thread.Sleep(-1); } catch (Exception) { } } if (reader.Name.Equals("Packet")) { type = reader.GetAttribute("Type"); nextTime = Convert.ToInt32(reader.GetAttribute("Time")); spanTime = nextTime - preTime; if (spanTime <= 0) { spanTime = 2; } spanTime = (int)(spanTime / fastertimes);//加快读取进度 try { Thread.Sleep(spanTime); } catch (Exception)//(System.Threading.ThreadInterruptedException e) { } preTime = nextTime; switch (type) { case "StkScenarioIC": RD_Scenset pasen = new RD_Scenset(); pasen.ScenarioName = reader.GetAttribute("ScenarioName"); pasen.StartTime = reader.GetAttribute("StartTime"); pasen.StopTime = reader.GetAttribute("StopTime"); pasen.StepTime = Convert.ToDouble(reader.GetAttribute("StepTime")); pasen.InPlaneSatelliteNumber = Convert.ToInt32(reader.GetAttribute("InPlaneSatelliteNumber")); pasen.OrbitalInclination = Convert.ToDouble(reader.GetAttribute("OrbitalInclination")); pasen.RightAscensionOfAscendingNode = Convert.ToDouble(reader.GetAttribute("RightAscensionOfAscendingNode")); pasen.SatelliteAltitude = Convert.ToDouble(reader.GetAttribute("SatelliteAltitude")); pasen.OrbitalNumber = Convert.ToInt32(reader.GetAttribute("OrbitalNumber")); pasen.PhaseParameters = Convert.ToDouble(reader.GetAttribute("PhaseParameters")); pasen.raanspread = Convert.ToDouble(reader.GetAttribute("raanspread")); pack = pasen; break; case "ChainInfo": RD_ChainInfo pacinfo = new RD_ChainInfo(); pacinfo.id = reader.GetAttribute("id"); pacinfo.StartOrEnd = reader.GetAttribute("StartOrEnd"); pacinfo.usetime = Convert.ToDouble(reader.GetAttribute("usetime")); string[] temp; temp = reader.GetAttribute("PathNodes").Split('-'); foreach (var o in temp) { pacinfo.PathNodes.Add(o); } pack = pacinfo; break; case "StartOpnetIC": RD_Op pacop = new RD_Op(); pack = pacop; break; case "XGYHCoordinate": RD_XGY pacxy = new RD_XGY(); pacxy.XGYHLongitude = reader.GetAttribute("XGYHLongitude"); pacxy.XGYHLatitude = reader.GetAttribute("XGYHLatitude"); pacxy.XGYHName = reader.GetAttribute("XGYHName"); pacxy.XGYHType = reader.GetAttribute("XGYHType"); pack = pacxy; break; case "OpSimTime": RD_SimTime pac = new RD_SimTime(); pac.simeTime = Convert.ToInt64(reader.GetAttribute("SimTime")); pack = pac; break; case "RouteTraffic": RD_RouteTraffic pacRouteTraffic = new RD_RouteTraffic(); pacRouteTraffic.SatRouteCostSent = Convert.ToDouble(reader.GetAttribute("SatRouteCostSent")); pacRouteTraffic.SatRouteCostRcvd = Convert.ToDouble(reader.GetAttribute("SatRouteCostRcvd")); pacRouteTraffic.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacRouteTraffic; break; case "S2GLinkAbility": RD_S2GLinkAbility pacS2GLinkAbility = new RD_S2GLinkAbility(); pacS2GLinkAbility.SatName = reader.GetAttribute("SatName"); pacS2GLinkAbility.SatbeamID = Convert.ToInt32(reader.GetAttribute("SatbeamID")); pacS2GLinkAbility.UplinkTrafficBps = Convert.ToDouble(reader.GetAttribute("UpTraBps")); pacS2GLinkAbility.DownlinkTrafficBps = Convert.ToDouble(reader.GetAttribute("DwTraBps")); pacS2GLinkAbility.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacS2GLinkAbility; break; case "SatUserParameter": RD_SatUser pacSatUser = new RD_SatUser(); pacSatUser.SatUserName = reader.GetAttribute("SatUserName"); pacSatUser.SatUserAltitude = Convert.ToDouble(reader.GetAttribute("SatUserAltitude")); pacSatUser.SatUserOrbitalInclination = Convert.ToDouble(reader.GetAttribute("SatUserOrbitalInclination")); pacSatUser.SatUserRightAscensionOfAscendingNode = Convert.ToDouble(reader.GetAttribute("SatUserRightAscensionOfAscendingNode")); pack = pacSatUser; break; case "S2SLinkAbility": RD_S2SLinkAbility pacS2SLinkAbility = new RD_S2SLinkAbility(); pacS2SLinkAbility.SatName1_2 = reader.GetAttribute("SatName1_2"); pacS2SLinkAbility.UplinkTrafficBps = Convert.ToDouble(reader.GetAttribute("UpTraBps")); pacS2SLinkAbility.DownlinkTrafficBps = Convert.ToDouble(reader.GetAttribute("DwTraBps")); pacS2SLinkAbility.UplinkUtilizationRadio = Convert.ToDouble(reader.GetAttribute("UpUseRadio")); pacS2SLinkAbility.DownlinkUtilizationRadio = Convert.ToDouble(reader.GetAttribute("DwUseRadio")); pacS2SLinkAbility.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacS2SLinkAbility; break; case "NetTraffic": RD_NetTraffic pacNetTraffic = new RD_NetTraffic(); pacNetTraffic.AppTrafficRcvd = Convert.ToDouble(reader.GetAttribute("AppTrafficRcvd")); pacNetTraffic.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacNetTraffic; break; case "ResOccupancy": RD_ResOccupancy pacResOccupancy = new RD_ResOccupancy(); pacResOccupancy.SatName1_5 = reader.GetAttribute("SatName1_5"); pacResOccupancy.ResourceOccupancyRate1_5 = reader.GetAttribute("ResourceOccupancyRate1_5"); pacResOccupancy.Type1 = reader.GetAttribute("Type1"); pacResOccupancy.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacResOccupancy; break; case "QosPerfomance": RD_QosPerfomance pacQosPerfomance = new RD_QosPerfomance(); pacQosPerfomance.TrafficName_SD = reader.GetAttribute("TrafficName_SD"); pacQosPerfomance.AppTrafficSend = Convert.ToDouble(reader.GetAttribute("AppTrafficSend")); pacQosPerfomance.AppTrafficRcvd = Convert.ToDouble(reader.GetAttribute("AppTrafficRcvd")); pacQosPerfomance.DelayTime = Convert.ToDouble(reader.GetAttribute("DelayTime")); pacQosPerfomance.DelayVar = Convert.ToDouble(reader.GetAttribute("DelayVar")); pacQosPerfomance.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacQosPerfomance; break; case "AccessAbility": RD_AccessAbility pacAccessAbility = new RD_AccessAbility(); pacAccessAbility.AccessSignalingCost = Convert.ToInt32(reader.GetAttribute("SignalingCost")); pacAccessAbility.AccessTimeAverage = Convert.ToDouble(reader.GetAttribute("TimeAverage")); pacAccessAbility.AccessSuccessRate = Convert.ToDouble(reader.GetAttribute("SuccessRate")); pacAccessAbility.ChannelApplyAverage = Convert.ToDouble(reader.GetAttribute("ChannelApply")); pack = pacAccessAbility; break; case "UserAllNum": RD_UserAllNum pacUserAllNum = new RD_UserAllNum(); pacUserAllNum.UserAllNum = Convert.ToInt32(reader.GetAttribute("UserAllNum")); pack = pacUserAllNum; break; case "UserOnline": RD_UserOnline pacUserOnline = new RD_UserOnline(); pacUserOnline.UserOnlineNum = Convert.ToInt32(reader.GetAttribute("UserOnlineNum")); pacUserOnline.simTime = Convert.ToDouble(reader.GetAttribute("SimTime")); pack = pacUserOnline; break; case "PKLossRate": RD_PKLossRate pacPKLossRate = new RD_PKLossRate(); pacPKLossRate.PkLossRatioValue = Convert.ToDouble(reader.GetAttribute("PkLossRatio")); pack = pacPKLossRate; break; case "Mobility": RD_Mobility pacMobility = new RD_Mobility(); pacMobility.MobileNodeName = reader.GetAttribute("MobileNodeName"); pacMobility.MobileStartTime = reader.GetAttribute("MobileStartTime"); pacMobility.EndLatitude = reader.GetAttribute("EndLatitude"); pacMobility.EndLongitude = reader.GetAttribute("EndLongitude"); pacMobility.StartLatitude = reader.GetAttribute("StartLatitude"); pacMobility.StartLongitude = reader.GetAttribute("StartLongitude"); pacMobility.MobileSpeed = reader.GetAttribute("MobileSpeed"); pack = pacMobility; break; case "LinkTraDesign": RD_LinkTraDesign pacLinkTraDesign = new RD_LinkTraDesign(); pacLinkTraDesign.StogDownstrmDatarate = Convert.ToDouble(reader.GetAttribute("StogDwDataRate")); pacLinkTraDesign.StogUpstrmDatarate = Convert.ToDouble(reader.GetAttribute("StogUpDataRate")); pacLinkTraDesign.StosDatarate = Convert.ToDouble(reader.GetAttribute("StosDataRate")); pack = pacLinkTraDesign; break; case "Finish": RD_Finish pacFinish = new RD_Finish(); pack = pacFinish; break; case "InterSatellitePath": RD_InterSatellitePath pacInterSatellitePath = new RD_InterSatellitePath(); pacInterSatellitePath.ISLPath = reader.GetAttribute("ISLPath"); pacInterSatellitePath.ISLid = Convert.ToInt16(reader.GetAttribute("ISLid")); pack = pacInterSatellitePath; break; default: continue; } if (DealPacketCallback != null) { try { DealPacketCallback(type, pack); } catch (Exception e) //(System.Threading.ThreadInterruptedException e) { //这里还是不要提示比较好了 //MessageBox.Show(e.ToString(),"唤起函数出错"); } } } } lock (this.stopRead) { isStopRead = false; } } }