public TrafficResult GetTrafficAroundUrl(TrafficAround trafficAround) { Dictionary <string, string> kv = new Dictionary <string, string>(); //kv.Add("ip", "39.91.109.120"); foreach (PropertyInfo pro in typeof(TrafficAround).GetProperties()) { string value = pro.GetValue(trafficAround, null)?.ToString(); string name = pro.Name.ToLower(); if (string.IsNullOrEmpty(value)) { continue; } if (name == "sn") { continue; } kv.Add(name, value); } kv.Add("ak", BaiduMapRoad.AK); var sn = GetSN(trafficAround); string queryparams = kv.GetQueryString(); var url = BaiduMapRoad.Url + "?" + queryparams + "&sn=" + sn; TrafficResult res = HttpMethods.HttpGet <TrafficResult>(url, Encoding.UTF8); return(res); }
/// <summary> /// 查询交通态势信息 /// </summary> /// <param name="queryParam">查询参数</param> /// <returns>交通态势信息</returns> public TrafficResult SearchTraffic(TrafficParam queryParam) { queryParam.output = "JSON"; string jsonResult = SearchOriginalTraffic(queryParam); if (!string.IsNullOrWhiteSpace(jsonResult)) { jsonResult = jsonResult.Replace("[]", "\"\""); } TrafficResult queryResult = JsonConvert.DeserializeObject <TrafficResult>(jsonResult); return(queryResult); }
public void UnitTestTrafficProblem1_Scenario2() { //arrange Dictionary <Orbit, int> dict = new Dictionary <Orbit, int>(); dict[orbit1] = 14; dict[orbit2] = 20; traffic.SetCurrentState(windy, dict); TrafficResult expected = new TrafficResult(superCar, 90, orbit2); //act List <TrafficResult> results = traffic.GetTimeOfAllVehiclesOnAllOrbits(traffic.ListOfOrbits, traffic.ListOfVehicles.Where(v => v.Weathers.Contains(traffic.CurrentWeather)).ToList()); TrafficResult actual = traffic.DeterMineWinner(results); //assert Assert.AreEqual(actual.Vehicle, expected.Vehicle, string.Format("Expected Vehicle was {0} but is {1}", expected.Vehicle.Name, actual.Vehicle.Name)); Assert.AreEqual(actual.Orbit, expected.Orbit, string.Format("Expected Orbit was {0} but is {1}", expected.Orbit.Name, actual.Orbit.Name)); Assert.AreEqual(actual.TimeForTravel, expected.TimeForTravel, string.Format("Expected Time travel time was {0} but is {1}", expected.TimeForTravel, actual.TimeForTravel)); }
public static TrafficResult ToResult <TOut, TActivityResult>(this TrafficResult <TOut, TActivityResult> otRes) { return(new TrafficResult(otRes.signal, otRes.blocked_pipe_code, otRes.msg)); }
/// <summary> /// 管道堵塞 -- (4) 执行 - 阻塞实现 /// </summary> /// <param name="context"></param> /// <param name="tRes"></param> /// <returns></returns> internal async Task InterWatchBlock(TPara context, TrafficResult <TRes, TOut> tRes) { await Watch(PipeCode, PipeType, WatchActionType.Blocked, context, tRes.ToWatchResult()) .ConfigureAwait(false); await Block(context, tRes); }
/// <summary> /// 管道堵塞(堵塞可能来自本管道,也可能是通知下游管道返回堵塞 /// </summary> /// <param name="context"></param> /// <param name="tRes"></param> /// <returns></returns> protected virtual Task Block(TPara context, TrafficResult <TRes, TOut> tRes) { return(Task.CompletedTask); }
public static WatchResult ToWatchResult <TOut, TActivityResult>(this TrafficResult <TOut, TActivityResult> tRes) { return(new WatchResult(tRes.signal, tRes.result, tRes.blocked_pipe_code, tRes.msg)); }