public CardTransport(DirectionId direction, RouteType type, RouteId route) { _viewmodel = new TransportCardViewModel(direction, type, route); BindingContext = _viewmodel; InitializeComponent(); Update(); }
/// <remarks> /// Default values for `path` and `method` is `*, any`. /// I.e. config without path and\or method always match. /// </remarks> private static bool IsRouteConfig(IConfiguration config, RouteId route) { var path = config.GetValue <string>("path"); var method = config.GetValue <string>("method"); if (path == null) { return(IsMethodsMatch(method, route.Verb)); } var glob = Glob.Parse(path); return(glob.IsMatch(route.Path) && IsMethodsMatch(method, route.Verb)); bool IsMethodsMatch(string configMethod, HttpMethod routeMethod) { if (string.IsNullOrEmpty(configMethod)) { return(true); } if (configMethod.Equals("any", StringComparison.OrdinalIgnoreCase)) { return(true); } var routeMethodString = routeMethod.ToString(); return(configMethod.Equals(routeMethodString, StringComparison.OrdinalIgnoreCase)); } }
/// <summary> /// Requests the next departure for the specified route, direction, stop id and route type /// </summary> /// <param name="r">Route id</param> /// <param name="d">Direction id</param> /// <param name="s">Stop id</param> /// <param name="t">Route type</param> /// <returns>The next departure in a Departure object</returns> public static async Task <Departure> GetNextDeparture(RouteId r, DirectionId d, RouteType t) { StopId s = t == RouteType.Train ? StopId.GlenferrieTrain : d == DirectionId.MelbUniViaStKilda ? StopId.GlenferrieTramMelbUni : StopId.GlenferrieTramKew; Departure departure = (await PTV.RequestPTVPayloadAsync($"departures/route_type/{(int)t}/stop/{(int)s}/route/{(int)r}?direction_id={(int)d}&max_results=1")).Departures[0]; return(departure); }
public override int GetHashCode() { if (string.IsNullOrWhiteSpace(RouteId)) { return(0); } return(RouteId.GetHashCode()); }
public void SendPacket(SimPacket packet) { var source = packet.Source.Machine; var destination = packet.Destination.Machine; var routeId = new RouteId(GetNetwork(source), GetNetwork(destination)); Routes[routeId].Send(packet); }
/// <summary> /// Constructor to create a new Transport Card View Model /// </summary> /// <param name="direction">Direction id for the card</param> /// <param name="type"></param> public TransportCardViewModel(DirectionId direction, RouteType type, RouteId route) { Direction = direction; Type = type; Time = "--"; Route = route; }
private static MockServerRouteOptions GetDefaultRouteOptions(RouteId route) => new MockServerRouteOptions { Path = route.Path, Method = ConvertMethod(route.Verb), Handler = "default", Config = new ConfigurationRoot(new List <IConfigurationProvider>()), };
public SimRoute(SimScheduler scheduler, SimCluster network, RouteId route, RouteDef def) { _scheduler = scheduler; _network = network; _route = route; _factory = new TaskFactory(_scheduler); _def = def; }
public RouteContext GetContext(RouteId id, HttpContext ctx) { var spec = Specs[id]; var options = RouteOptionsBuilder.Build(id, Config); var callCtx = RequestContextBuilder.Build(ctx); var handler = HandlerProvider.GetHandler(options.Handler, options.Config, responseContext: null); return(new RouteContext(options, spec, callCtx, handler, Logger)); }
// Used to diff for config changes internal int GetConfigHash() { var hash = 0; if (!string.IsNullOrEmpty(RouteId)) { hash ^= RouteId.GetHashCode(); } if (Methods != null && Methods.Count > 0) { // Assumes un-ordered hash ^= Methods.Select(item => item.GetHashCode()) .Aggregate((total, nextCode) => total ^ nextCode); } if (!string.IsNullOrEmpty(Host)) { hash ^= Host.GetHashCode(); } if (!string.IsNullOrEmpty(Path)) { hash ^= Path.GetHashCode(); } if (Priority.HasValue) { hash ^= Priority.GetHashCode(); } if (!string.IsNullOrEmpty(ClusterId)) { hash ^= ClusterId.GetHashCode(); } if (!string.IsNullOrEmpty(AuthorizationPolicy)) { hash ^= AuthorizationPolicy.GetHashCode(); } if (Metadata != null) { hash ^= Metadata.Select(item => HashCode.Combine(item.Key.GetHashCode(), item.Value.GetHashCode())) .Aggregate((total, nextCode) => total ^ nextCode); } if (Transforms != null) { hash ^= Transforms.Select(transform => transform.Select(item => HashCode.Combine(item.Key.GetHashCode(), item.Value.GetHashCode())) .Aggregate((total, nextCode) => total ^ nextCode)) // Unordered Dictionary .Aggregate(seed: 397, (total, nextCode) => total * 31 ^ nextCode); // Ordered List } return(hash); }
public override string ToString() { return(RouteId.ToString() + "?" + TrainName + "?" + DepartureDate + "?" + DepartureHour + "?" + Price + "?" + Time); }
public override int GetHashCode() { unchecked { int result = (RouteId != null ? RouteId.GetHashCode() : 0); result = (result * 397) ^ (RegionId != null ? RegionId.GetHashCode() : 0); result = (result * 397) ^ RouteDate.GetHashCode(); return(result); } }
public override int GetHashCode() { var hashCode = AgencyId.GetHashCode(); hashCode = (hashCode * 397) ^ RouteId.GetHashCode(); hashCode = (hashCode * 397) ^ RouteType.GetHashCode(); hashCode = (hashCode * 397) ^ TripId.GetHashCode(); hashCode = (hashCode * 397) ^ StopId.GetHashCode(); return(hashCode); }
public static MockServerRouteOptions Build(RouteId route, IConfiguration config) { var options = config.GetSection("routes") .GetChildren() .Where(x => IsRouteConfig(x, route)) .Select(x => GetRouteOptions(x, route)) .ToArray(); return(options.Length == 0 ? GetDefaultRouteOptions(route) : options.Aggregate(MergeRouteOptions)); }
private Task HandleMockRequest(HttpContext ctx) { var mockId = ctx.GetRouteId(); var path = mockId.Path.Substring(6); var id = new RouteId(path, mockId.Verb); var requestContext = ContextProvider.GetContext(id, ctx); requestContext.Config.Handler = "mock"; return(HandleRequest(requestContext, ctx.Response)); }
public void ReturnDefaultsIfNoRoutesConfigured() { var config = GetConfig(new Dictionary <string, string>()); var route = new RouteId("/", HttpMethod.Get); var expected = new MockServerRouteOptions { Path = "/", Method = MockServerOptionsHttpMethod.Get, Handler = "default" }; var actual = RouteOptionsBuilder.Build(route, config); AssertEqual(expected, actual); }
public void ReturnDefaultOptionsIfRouteIsNotConfigured() { var config = GetConfig("/", "get", "test"); var route = new RouteId("/test", HttpMethod.Get); var expected = new MockServerRouteOptions { Path = "/test", Method = MockServerOptionsHttpMethod.Get, Handler = "default" }; var actual = RouteOptionsBuilder.Build(route, config); AssertEqual(expected, actual); }
public void CanBuildRouteOptions(string glob, string configMethod) { var config = GetConfig(glob, configMethod, "test"); var route = new RouteId("/foo/bar", HttpMethod.Get); var expected = new MockServerRouteOptions { Path = "/foo/bar", Method = MockServerOptionsHttpMethod.Get, Handler = "test" }; var actual = RouteOptionsBuilder.Build(route, config); AssertEqual(expected, actual); }
private static MockServerRouteOptions GetRouteOptions(IConfiguration routeConfig, RouteId route) => new MockServerRouteOptions { Path = route.Path, Method = ConvertMethod(route.Verb), Handler = routeConfig["handler"] ?? "default", Config = routeConfig };
public override string ToString() { return(string.Format( $"{string.Format(RouteId.ToString().Substring(RouteId.ToString().Length - 5))}|Length : {Length} Time : {EstimatedTime}")); }
public bool TryGetRoute(string from, string to, out SimRoute r) { var linkId = new RouteId(GetNetwork(from), GetNetwork(to)); return(Routes.TryGetValue(linkId, out r)); }
/// <summary> /// Builds the route URL. /// </summary> /// <param name="parms">The parms.</param> /// <returns></returns> private string BuildRouteURL(Dictionary <string, string> parms) { string routeUrl = string.Empty; foreach (Route route in RouteTable.Routes) { if (route.DataTokens != null && route.DataTokens.ContainsKey("RouteId") && route.DataTokens["RouteId"].ToString() == RouteId.ToString()) { routeUrl = route.Url; break; } } // get dictionary of parms in the route Dictionary <string, string> routeParms = new Dictionary <string, string>(); bool allRouteParmsProvided = true; var r = new Regex(@"{([A-Za-z0-9\-]+)}"); foreach (Match match in r.Matches(routeUrl)) { // add parm to dictionary routeParms.Add(match.Groups[1].Value, match.Value); // check that a value for that parm is available if (parms == null || !parms.ContainsKey(match.Groups[1].Value)) { allRouteParmsProvided = false; } } // if we have a value for all route parms build route url if (allRouteParmsProvided) { // merge route parm values foreach (KeyValuePair <string, string> parm in routeParms) { // merge field routeUrl = routeUrl.Replace(parm.Value, parms[parm.Key]); // remove parm from dictionary parms.Remove(parm.Key); } // add remaining parms to the query string if (parms != null) { string delimitor = "?"; foreach (KeyValuePair <string, string> parm in parms) { routeUrl += delimitor + parm.Key + "=" + HttpUtility.UrlEncode(parm.Value); delimitor = "&"; } } return(routeUrl); } else { return(string.Empty); } }
public RouteSpec this[RouteId key] => Source[key];