/// <summary> /// Handles the activate event, which occurs when a route is being activated. /// </summary> /// <param name="iRoutable">Routable view model.</param> /// <param name="eventHandler">Activate event handler.</param> public static void OnActivated(this IRoutable iRoutable, EventHandler <ActivatedEventArgs> eventHandler) { if (iRoutable.RoutingState == null) { iRoutable.RoutingState = new RoutingState(); } iRoutable.RoutingState.Activated += eventHandler; }
/// <summary> /// Handles the routed event, which occurs when this view model is being routed to. /// </summary> /// <param name="routable">Routable view model.</param> /// <param name="eventHandler">Routed event handler.</param> public static void OnRouted(this IRoutable routable, EventHandler <RoutedEventArgs> eventHandler) { if (routable.RoutingState == null) { routable.RoutingState = new RoutingState(); } routable.RoutingState.Routed += eventHandler; }
private void Add(Company c) { var f = new PathFinder(c); storage.List <Residence>().ForEach(r => { // all R => one C for the goal f.Edge(r, c, Vector3.Distance(r.transform.position, c.transform.position)); // all R => all G for the goal storage.List <Gate>().ForEach(g => f.Edge(r, g, Vector3.Distance(r.transform.position, g.transform.position))); }); storage.List <Gate>().ForEach(g => { // all G => one C for the goal f.Edge(g, c, Vector3.Distance(g.transform.position, c.transform.position)); // all G <=> G storage.List <Gate>().Where(oth => g != oth).ToList().ForEach(oth => { f.Edge(g, oth, Vector3.Distance(g.transform.position, oth.transform.position)); }); // all [G <=> P] for the goal g.BelongsTo.Platforms.ForEach(p => { f.Edge(p, g, Vector3.Distance(p.transform.position, g.transform.position)); f.Edge(g, p, Vector3.Distance(g.transform.position, p.transform.position)); }); }); storage.List <DeptTask>().ForEach(dept => { // all P => one lt for the goal f.Edge(dept.Stay, dept, 0); }); // lt => P storage.List <Platform>().ForEach(dest => { storage.List <DeptTask>().ForEach(dept => { IRoutable prev = dept; do { var next = prev.Route.NextFor(dest); if (next != null) { f.Edge(prev, next, prev.Route.DistanceFor(next), prev.Route.PaymentFor(next)); } prev = next; } while (prev != null && prev != dept); }); }); Finders.Add(f); Reset(); }
public static IRoutable getEndpoint(string name) { try { IRoutable chosen = endpoints[name]; return(chosen); } catch { return(null); } }
/// <summary> /// Defines a route that belongs to another view model. /// </summary> /// <param name="routable">Routable view model.</param> /// <param name="redirectRoot">Root path of the route. If the path partially matches the view model's root path, they will be combined.</param> /// <param name="path">Route path.</param> /// <returns>Route object to be bound to vmRoute on the view.</returns> public static Route Redirect(this IRoutable routable, string redirectRoot, string path) { if (routable.RoutingState == null) { routable.RoutingState = new RoutingState(); } return(new Route { RedirectRoot = redirectRoot, Path = path }); }
/** * 指定された目的地に向かうには、どれほどのコストがかかり、次にどこに向かう必要があるか設定します */ public void SetNext(IRoutable next, IRoutable goal, float dist, float payment) { if (dict.ContainsKey(goal)) { dict[goal].Next = next; dict[goal].Dist = dist; dict[goal].Payment = payment; } else { dict.Add(goal, new Route(next, goal, dist, payment)); } }
public void Unedge(IRoutable from, IRoutable to) { var rmList = Edges .Where(e => e.From.Origin == from && e.To.Origin == to) .Select((e) => { e.From.Out.Remove(e); e.To.In.Remove(e); return(e); }); Edges.RemoveAll(e => rmList.Contains(e)); }
/// <summary> /// Returns HTML data attribute markup that contains routing initialization arguments. /// This needs to be placed in the same DOM element that has the "data-vm" attribute. /// </summary> /// <param name="routable">Routable view model.</param> /// <param name="viewData">Routing view data.</param> /// <returns>HTML data attribute markup.</returns> public static string InitArgs(this IRoutable routable, object viewData) { var routingState = routable.RoutingState; string originRoot = ""; if (viewData is RoutingViewData) { var routingViewData = viewData as RoutingViewData; originRoot = routingViewData.OriginRoot; routingViewData.OriginRoot = routingViewData.OriginRoot?.TrimEnd('/') + "/" + routingState.Root; } return(string.Format("data-vm-root=\"{0}\" data-vm-arg = \"{{'RoutingState.Active': '{1}', 'RoutingState.Origin': '{2}'}}\"", originRoot, routingState.Active, routingState.Origin)); }
/** * 指定されたオブジェクトをノードとして登録します */ public PathNode Node(IRoutable org) { if (org == null) { throw new ArgumentNullException(); } var res = Nodes.Find(n => n.Origin == org); if (res == null) { var n = new PathNode(org); Nodes.Add(n); return(n); } return(res); }
public void Complete() { var prev = Next; Next = Next.Route.NextFor(Destination); // 会社到着 if (Next == null) { if (rideTime > 0) { listener.Fire(EventType.CREATED, new CommuteEvent(rideTime)); } listener.Fire(EventType.CREATED, new DieEvent(state)); Remove(); } }
/// <summary> /// Performs routing. The URL path is given inside the view data, along with the initial route template to start from. /// This is a recursive method that will be called again by the nested views until the route is resolved. /// </summary> /// <param name="routable">Routable view model.</param> /// <param name="viewData">Routing view data.</param> public static void RouteUrl(this IRoutable routable, ref RoutingViewData viewData) { var routingState = routable.RoutingState; if (routingState == null) { return; } viewData.ActiveTemplate = null; routingState.Origin = viewData.Origin; if (routingState.Templates != null) { viewData.Root = viewData.Root?.TrimEnd('/') + "/" + routingState.Root; var bestMatch = MatchTemplate(routingState.Templates, viewData.UrlPath, viewData.Root); Trace.WriteLine($"[dotNetify] Matched route {viewData.UrlPath}: {bestMatch?.Value}"); if (bestMatch != null) { viewData.ActiveTemplate = bestMatch.Value.Key; if (bestMatch.Value.Value != null && bestMatch.Value.Key.VMType != null) { routingState.Active = bestMatch.Value.Value; } else { routingState.Active = null; } } // If there's no match, but the Active path has a default value, resolve its route. else if (routingState.Active != null) { bestMatch = MatchTemplate(routingState.Templates, routingState.Active, null); if (bestMatch != null) { viewData.ActiveTemplate = bestMatch.Value.Key; } } } // Pass along information from this view to the next nested view. viewData.Origin = routingState.Active; }
public void Unnode(IRoutable org) { var res = Nodes.Find(n => n.Origin == org); if (res != null) { var rmList1 = Edges.Where(e => e.From == res).Select(e => { e.To.In.Remove(e); return(e); }); var rmList2 = Edges.Where(e => e.To == res).Select(e => { e.From.Out.Remove(e); return(e); }); Edges.RemoveAll(e => rmList1.Contains(e) || rmList2.Contains(e)); Nodes.Remove(res); } }
/// <summary> /// Call this method from the controller to perform routing. /// </summary> /// <param name="iViewData">Routing view data.</param> /// <param name="oModel">Model to be passed to the view.</param> /// <returns>View URL.</returns> public static string Route(ref RoutingViewData iViewData, out IRoutable oModel) { var template = iViewData.ActiveTemplate; if (template != null) { try { oModel = template.VMType != null ? Activator.CreateInstance(template.VMType) as IRoutable : null; if (oModel != null) oModel.RouteUrl(ref iViewData); return template.ViewUrl; } catch (Exception ex) { Trace.Fail(ex.ToString()); } } oModel = null; return null; }
/// <summary> /// Defines a route from a route template that belongs to the view model. /// </summary> /// <param name="routable">Routable view model.</param> /// <param name="templateId">Identifies a template that belongs to this view model.</param> /// <param name="path">Optional path, to be used to replace parameterized template's URL pattern.</param> /// <returns>Route object to be bound to vmRoute on the view.</returns> public static Route GetRoute(this IRoutable routable, string templateId, string path = null) { if (routable.RoutingState == null) { routable.RoutingState = new RoutingState(); } RouteTemplate template = null; if (routable.RoutingState.Templates != null) { template = routable.RoutingState.Templates.FirstOrDefault(i => i.Id == templateId); } if (template == null) { throw new InvalidOperationException(String.Format("ERROR: Route template '{0}' was not found.", templateId)); } return(new Route { TemplateId = template.Id, Path = path ?? template.UrlPattern }); }
public void Reroute() { Next = router.NextFor(Destination); }
/// <summary> /// Registers route templates. /// </summary> /// <param name="routable">Routable view model.</param> /// <param name="root">Root path to which all other paths will be evaluated.</param> /// <param name="routeTemplates">Route templates that belong to the view model.</param> public static void RegisterRoutes(this IRoutable routable, string root, List <RouteTemplate> routeTemplates) { routable.RoutingState = new RoutingState { Root = root, Templates = routeTemplates }; }
public PathNode(IRoutable origin) { Origin = origin; }
/** * 指定された目的地に移動するには、次にどの地点に向かう必要があるか返します */ public IRoutable NextFor(IRoutable goal) { return(dict.ContainsKey(goal) ? dict[goal].Next : null); }
public PathEdge Edge(IRoutable from, IRoutable to, float cost) { return(Edge(from, to, cost, 0)); }
/** * 指定された地点までの移動コストを返します */ public float DistanceFor(IRoutable goal) { return(dict.ContainsKey(goal) ? dict[goal].Dist : float.NaN); }
public PathFinder(IRoutable goal) { Nodes = new List <PathNode>(); Edges = new List <PathEdge>(); Goal = Node(goal); }
/** * 指定された地点までの運賃を返します */ public float PaymentFor(IRoutable goal) { return(dict.ContainsKey(goal) ? dict[goal].Payment : 0); }
public void SetNext(IRoutable next, IRoutable goal, float dist) { SetNext(next, goal, dist, 0); }
private void AssertNextStep(Coord from, IRoutable shouldBe) { Assert.AreEqual(shouldBe, this.walker.NextStep(from)); }
public void ParseContext(RequestContext cxt, IRoutable h) { if (h != null) { if (string.IsNullOrEmpty(RegExp)) { h.ActionName = cxt.RouteData.Values[WebConstants.const_action].AsString(true); h.Args = cxt.RouteData.Values[WebConstants.const_params].AsString(true); if (!string.IsNullOrEmpty(Action)) { if (!string.IsNullOrEmpty(h.Args)) { h.Args = h.ActionName + '/' + h.Args; } else { h.Args = h.ActionName; } h.ActionName = Action; } } else { var m = new Regex(RegExp, RegexOptions.IgnoreCase).Match(cxt.HttpContext.Request.Url.AbsolutePath); if (m.Index >= 0) { h.Groups = m.Groups; var act = m.Groups[WebConstants.const_action]; var arg = m.Groups[WebConstants.const_params]; if (act != null) { if (string.IsNullOrEmpty(Action)) { h.ActionName = act.Value; } else { h.ActionName = Action; h.Args = act.Value + "/" + h.Args; } } if (arg != null) { h.Args = arg.Value; } } } h.RouteItem = this; } }