public void CreateStationForecastFromRealTimeInfo_() { UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader(); loader.AddStations(new Station() { Abbreviation = "STS", Name = "St. Stephen's Green", IsInUse = true }); loader.AddStations(new Station() { Abbreviation = "PAR", Name = "Parnell", IsInUse = true }); loader.AddStations(new Station() { Abbreviation = "SAN", Name = "Sandyford", IsInUse = true }); Stations stations = new Stations(loader); RealTimeInfo realTimeInfo = CreateRealTimeInfoFromXml("<stopInfo created=\"2019-12-31T12:00:00\" stop=\"St. Stephen's Green\" stopAbv=\"STS\"><message>Green Line services operating normally</message><direction name=\"Inbound\"><tram destination=\"Parnell\" dueMins=\"1\" /></direction><direction name=\"Outbound\"><tram dueMins=\"6\" destination=\"Sandyford\" /></direction></stopInfo>"); StationForecast forecast = StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfo, stations); Assert.Equal(realTimeInfo.Stop, forecast.Station.Name); Assert.Single(forecast.InboundTrams); Assert.Single(forecast.OutboundTrams); }
public void CreateStationForecastFromRealTimeInfo_RealTimeInfoIsNull_ThrowsArgumentException() { RealTimeInfo realTimeInfoXml = null; Stations stations = new Stations(new UnitTestStationInformationLoader()); Assert.Throws <ArgumentException>(() => StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfoXml, stations)); }
public void CreateStationForecastFromRealTimeInfo_StationsIsNull_ThrowsArgumentException() { RealTimeInfo realTimeInfoXml = new RealTimeInfo(); Stations stations = null; Assert.Throws <ArgumentException>(() => StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfoXml, stations)); }
public void CreateFromStream_CorrectXmlSchema_ReturnsObject() { string xml = "<stopInfo created=\"2019-12-28T12:06:00\" stop=\"St. Stephen's Green\" stopAbv=\"STS\"><message>Green Line Service Disruption See News</message><direction name=\"Inbound\"><tram destination=\"See news for information\" dueMins=\"\" /></direction><direction name=\"Outbound\"><tram dueMins=\"6\" destination=\"Sandyford\" /></direction></stopInfo>"; Stream stream = ConvertStringToStream(xml); Assert.IsType <RealTimeInfo>(RealTimeInfo.CreateFromStream(stream)); }
public static StationForecast CreateStationForecastFromRealTimeInfo(RealTimeInfo realTimeInfo, Stations stations) { if (realTimeInfo == null) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument '{0}' is null.", nameof(realTimeInfo))); } if (stations == null) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument '{0}' is null.", nameof(stations))); } List <TramXml> inboundForecasts = realTimeInfo.Directions.FirstOrDefault(d => d.DirectionName == "Inbound").Trams; List <TramXml> outboundForecasts = realTimeInfo.Directions.FirstOrDefault(d => d.DirectionName == "Outbound").Trams; StationForecast stationForecast = new StationForecast { Station = stations.GetStation(realTimeInfo.StopAbbreviation), Message = realTimeInfo.Message, Created = realTimeInfo.Created, InboundTrams = inboundForecasts.Select(tram => TramForecast.CreateTramForecastFromTramXml(tram, stations)).Where(forecast => forecast != null).ToList(), OutboundTrams = outboundForecasts.Select(tram => TramForecast.CreateTramForecastFromTramXml(tram, stations)).Where(forecast => forecast != null).ToList() }; return(stationForecast); }
public void CreateFromStream_IncorrectXmlSchema_ThrowsInvalidOperation() { string xml = "<sample></sample>"; Stream stream = ConvertStringToStream(xml); Assert.Throws <InvalidOperationException>(() => RealTimeInfo.CreateFromStream(stream)); }
public void CreateFromStream_EmptyString_ThrowsInvalidOperation() { string xml = string.Empty; Stream stream = ConvertStringToStream(xml); Assert.Throws <InvalidOperationException>(() => RealTimeInfo.CreateFromStream(stream)); }
public void InsertAllTable(PacketSimpInfo packetSimpInfo , PacketCompInfo packetCompInfo , PacketInfo packetInfo , RealTimeInfo realTimeInfo) { using (db = dbFactory.Open()) { db.Insert <PacketSimpInfo>(packetSimpInfo); db.Insert <PacketCompInfo>(packetCompInfo); db.Insert <PacketInfo>(packetInfo); db.Insert <RealTimeInfo>(realTimeInfo); } }
void _timer_Elapsed(object sender, ElapsedEventArgs e) { RealTimeInfo info = new RealTimeInfo(); info.CodiceUtenza = "1234"; info.Portata = 1213.14; info.Pressione = 2133.44; info.SetPoint = 6544.323; info.Allarmi = new List <string>() { "muffa", "aiuto", "aaaa" }; info.TimeStamp = DateTime.Now.ToLongTimeString(); //Attualmente il nostro hub (se non modifico il webConfig, puo ricevere connessioni solo IntraDomani e non ExtraDomain. //ToAdd -> Policy core Clients.All.notifyme(info); }
public bool InsertRT(RealTimeInfo realTimeInfo) { using (db = dbFactory.Open()) { try { var flag = db.Insert <RealTimeInfo>(realTimeInfo); //Console.WriteLine("insert: {0} {1} flag:{2}", realTimeInfo.DateTime.ToString(), DateTime.Now.ToString(), flag); if (flag >= 0) { return(true); } } catch (Exception) { } return(false); } }
private void refreshData(int capnum, int fraLen, DateTime dateTime, double seconds, string timeVal, string epochTime , string linkType, string sMac, string dMac, int linkHeadLen, string ethType, string sIp, string dIp, int TTL, int IpTotalLen , int ipHeadLen, int ipChecksum, int version, string ipType, int sPort, int dPort, long seqNum, long ackNum , int tranTotalLen, int tranHeadLen, int windowSize, int tranChecksum, int dataLen, string info, string flag, bool compMAC, bool compIP) { //1插入简单 PacketSimpInfo packetSimpInfo = new PacketSimpInfo(capnum, timeVal, sIp, dIp, ipType, fraLen, info); ThreadPool.QueueUserWorkItem(delegate { this.Dispatcher.Invoke(new Action(() => { packetSimpInfos.Add(packetSimpInfo); }), null); }); //2.插入复杂 PacketCompInfo packetCompInfo = new PacketCompInfo(capnum, capnum, fraLen, fraLen, epochTime, sMac, dMac, ethType, sIp, dIp, sPort, dPort, timeVal, ipHeadLen, TTL, ipType, flag); packetCompInfos.Add(packetCompInfo); //3。插入完整 PacketInfo packetInfo = new PacketInfo(capnum, fraLen, dateTime, seconds, timeVal, epochTime, linkType, sMac, dMac, ethType , sIp, dIp, TTL, IpTotalLen, ipHeadLen, ipChecksum, version, ipType, sPort, dPort, seqNum , ackNum, tranHeadLen, windowSize, tranChecksum, dataLen, info, flag); packetInfos.Add(packetInfo); //4.插入实时 (更改datetime) RealTimeInfo realTimeInfo = new RealTimeInfo(capnum, new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second), seconds, ethType, fraLen, ipType); //5.插入实时本地 //System.Object lockthis = (System.Object)seconds; //lock (lockthis) //{ if (!IOChartStatisticsWindow.RealTimeInfos.ContainsKey((int)seconds)) { RealChartItem realChartItem = new RealChartItem((int)seconds, dateTime, 1, fraLen); IOChartStatisticsWindow.RealTimeInfos.Add((int)seconds, realChartItem); } else { IOChartStatisticsWindow.RealTimeInfos[(int)seconds].Count++; IOChartStatisticsWindow.RealTimeInfos[(int)seconds].SumLen += fraLen; } //} //统计1插入 StatisticsInfo statisticsInfo = null; if (compIP == true) {//换 if (compMAC == true) { statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, dMac, sMac, linkHeadLen, ethType, dIp, sIp, IpTotalLen, ipHeadLen, ipType, dPort, sPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP); } else { statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, sMac, dMac, linkHeadLen, ethType, dIp, sIp, IpTotalLen, ipHeadLen, ipType, dPort, sPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP); } } else { if (compMAC == true) { statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, dMac, sMac, linkHeadLen, ethType, sIp, dIp, IpTotalLen, ipHeadLen, ipType, sPort, dPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP); } else { statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, sMac, dMac, linkHeadLen, ethType, sIp, dIp, IpTotalLen, ipHeadLen, ipType, sPort, dPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP); } } //5 更新数据库 //serviceStackDBHelper.InsertAllTable(packetSimpInfo, packetCompInfo, packetInfo, realTimeInfo); new Thread(() => { serviceStackDBHelper.InsertSimpPcap(packetSimpInfo); serviceStackDBHelper.InsertCompPcap(packetCompInfo); serviceStackDBHelper.InsertPcap(packetInfo); serviceStackDBHelper.InsertRT(realTimeInfo); serviceStackDBHelper.InsertStatistics(statisticsInfo); }).Start(); }
public async Task <StationForecast> GetRealTimeInfoAsync(string stationAbbreviation) { if (string.IsNullOrEmpty(stationAbbreviation)) { throw new ArgumentException("Can't get the forecast of a station that does not exist.", nameof(stationAbbreviation)); } Uri uri = new Uri(string.Format(CultureInfo.InvariantCulture, LuasApiUrl, stationAbbreviation)); using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.GetAsync(uri).ConfigureAwait(false)) using (HttpContent content = response.Content) using (Stream stream = await content.ReadAsStreamAsync().ConfigureAwait(false)) { return(StationForecast.CreateStationForecastFromRealTimeInfo(RealTimeInfo.CreateFromStream(stream), stations)); } }