コード例 #1
0
ファイル: ExitModel.cs プロジェクト: direktspeed/sbs-app
 public ExitModel(string routePathId, RouteJunction routeJunction, Location fromLocation, Location toLocation)
 {
     this.RouteJunction = routeJunction;
     this.RoutePathId   = routePathId;
     this.FromLocation  = fromLocation;
     this.ToLocation    = toLocation;
 }
コード例 #2
0
ファイル: PoiListModel.cs プロジェクト: direktspeed/sbs-app
 public PoiListModel(RouteJunction junction, IEnumerable <PoiOnJunction> pois, PoiType poiTypeToShow, string routeId)
 {
     this.Pois          = pois;
     this.RouteJunction = junction;
     this.PoiTypeToShow = poiTypeToShow;
     this.RouteId       = routeId;
 }
コード例 #3
0
        private static RouteJunction GetJunctionFromExitId(string exitId, out long osmId)
        {
            RouteJunction routeJunction = null;

            osmId = 0;
            if (long.TryParse(Regex.Match(exitId, "osm-(?<id>[0-9]+)").Groups["id"].Value, out osmId))
            {
                var junction = StopByStopService.Instance.GetJunctionFromOSMID(osmId, true);
                routeJunction = new RouteJunction()
                {
                    Junction = junction
                };
            }
            return(routeJunction);
        }
コード例 #4
0
ファイル: PoiGroupModel.cs プロジェクト: direktspeed/sbs-app
        public PoiGroupModel(string routePathId, RouteJunction routeJunction, PoiOnJunction[] pois, string poiGroupType, PoiType poiType, Location fromLocation, Location toLocation)
        {
            this.FromLocation  = fromLocation;
            this.ToLocation    = toLocation;
            this.RouteJunction = routeJunction;
            this.Pois          = pois;
            this.PoiGroupType  = poiGroupType;
            this.RoutePathId   = routePathId;
            this.PoiType       = poiType;

            if (Pois.Length > 0)
            {
                this.ClosestPoi = pois.OrderBy(p => p.DistanceFromJunction).First();
            }
        }
コード例 #5
0
        public ActionResult PoiGroup(string id, string exitId, string poiTypeString)
        {
            long          osmId;
            RouteJunction routeJunction = GetJunctionFromExitId(exitId, out osmId);

            if (routeJunction == null)
            {
                StopByStop.Route route = GetRouteFromRoutePathId(id);
                if (route != null)
                {
                    routeJunction = route.RouteSegments
                                    .SelectMany(rs => rs.RouteJunctions)
                                    .SingleOrDefault(rj => rj.Junction.SBSID.Equals(exitId, StringComparison.OrdinalIgnoreCase));

                    if (routeJunction != null)
                    {
                        telemetryClient.TrackEvent("PoiGroupToOSMFormatRedirect");
                        string requestFullUrl = HttpContext.Request.Url.ToString();
                        string redirectUrl    = requestFullUrl
                                                .Substring(0, requestFullUrl.IndexOf("route")) +
                                                string.Format("route/{0}/exit/osm-{1}/{2}", id, routeJunction.Junction.OSMID, poiTypeString);

                        return(RedirectPermanent(redirectUrl));
                    }
                }
                else
                {
                    telemetryClient.TrackEvent("RouteNotFound",
                                               new Dictionary <string, string>()
                    {
                        { "MissingRoute", id }
                    });
                    telemetryClient.TrackException(
                        new InvalidOperationException(string.Format("PoiGroup Action - Cannot find route. id={0}, exitId={1}", id, exitId)));

                    return(RedirectToAction("Index", "Home"));
                }
            }

            if (routeJunction != null)
            {
                Location fromLocation, toLocation;
                var      fromAndTo = StopByStopService.Instance.GetRouteLocationsFromRoutePathId(id);
                fromLocation = fromAndTo[0];
                toLocation   = fromAndTo[1];


                PoiType poiType;
                string  poiTypeName;

                poiType     = PoiType.General;
                poiTypeName = string.Empty;

                switch (poiTypeString.ToLowerInvariant())
                {
                case "gas":
                    poiTypeName = "Gas stations";
                    poiType     = PoiType.Gas;
                    break;

                case "food":
                    poiTypeName = "Places to eat";
                    poiType     = PoiType.Food;
                    break;
                }

                if (poiType != PoiType.General)
                {
                    PoiOnJunction[] pois = routeJunction.Junction.Pois.Where(p => p.Poi.PoiType == poiType).ToArray();
                    if (pois.Length > 0)
                    {
                        return(View(new PoiGroupModel(id, routeJunction, pois, poiTypeName, poiType, fromLocation, toLocation)));
                    }
                }

                return(View("Exit", new ExitModel(id, routeJunction, fromLocation, toLocation)));
            }
            else
            {
                // routeJunction not found
                StopByStop.Route route = GetRouteFromRoutePathId(id);
                if (route != null)
                {
                    telemetryClient.TrackEvent("ExitNotFound",
                                               new Dictionary <string, string>()
                    {
                        { "MissingExit", id + "/" + exitId }
                    });
                    telemetryClient.TrackException(
                        new InvalidOperationException(string.Format("PoiGroup Action - Cannot find exit. id={0}, exitId={1}", id, exitId)));
                    return(View("Route", new RouteModel(route, id)));
                }
                else
                {
                    telemetryClient.TrackEvent("RouteNotFound",
                                               new Dictionary <string, string>()
                    {
                        { "MissingRoute", id }
                    });
                    telemetryClient.TrackException(
                        new InvalidOperationException(string.Format("PoiGroup Action - Cannot find route. id={0}, exitId={1}", id, exitId)));
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
コード例 #6
0
        public ActionResult PoiGroup(string id, string exitId, string poiTypeString)
        {
            long          osmId;
            RouteJunction routeJunction = null;

            StopByStop.Route route = GetRouteFromRoutePathId(id);

            if (route != null)
            {
                routeJunction = GetJunctionFromExitId(exitId, out osmId);
            }

            if (routeJunction == null)
            {
                if (route != null)
                {
                    routeJunction = route.RouteSegments
                                    .SelectMany(rs => rs.RouteJunctions)
                                    .SingleOrDefault(rj => rj.Junction.SBSID.Equals(exitId, StringComparison.OrdinalIgnoreCase));

                    if (routeJunction != null)
                    {
                        telemetryClient.TrackEvent("PoiGroupToOSMFormatRedirect");
                        string requestFullUrl = HttpContext.Request.Url.ToString();
                        string redirectUrl    = requestFullUrl
                                                .Substring(0, requestFullUrl.IndexOf("route")) +
                                                string.Format("route/{0}/exit/osm-{1}/{2}", id, routeJunction.Junction.OSMID, poiTypeString);

                        return(RedirectPermanent(redirectUrl));
                    }
                }
                else
                {
                    telemetryClient.TrackEvent("RouteNotFound",
                                               new Dictionary <string, string>()
                    {
                        { "MissingRoute", id }
                    });
                    telemetryClient.TrackException(
                        new InvalidOperationException(string.Format("PoiGroup Action - Cannot find route. id={0}, exitId={1}", id, exitId)));

                    return(RedirectToAction("Index", "Home"));
                }
            }


            PoiType poiType = PoiType.General;
            var     model   = new MainModel(this.Url)
            {
                Page    = ClientPage.Route,
                RouteId = id,
                Route   = route,
                ExitId  = exitId,
            };

            if (routeJunction != null)
            {
                switch (poiTypeString.ToLowerInvariant())
                {
                case "gas":
                    poiType = PoiType.Gas;
                    break;

                case "food":
                    poiType = PoiType.Food;
                    break;
                }

                model.Page    = ClientPage.Exit;
                model.ExitId  = exitId;
                model.PoiType = poiType;
            }
            else
            {
                if (route != null)
                {
                    telemetryClient.TrackEvent("ExitNotFound",
                                               new Dictionary <string, string>()
                    {
                        { "MissingExit", id + "/" + exitId }
                    });
                    telemetryClient.TrackException(
                        new InvalidOperationException(string.Format("PoiGroup Action - Cannot find exit. id={0}, exitId={1}", id, exitId)));
                    model.Page = ClientPage.Route;
                }
                else
                {
                    telemetryClient.TrackEvent("RouteNotFound",
                                               new Dictionary <string, string>()
                    {
                        { "MissingRoute", id }
                    });
                    telemetryClient.TrackException(
                        new InvalidOperationException(string.Format("PoiGroup Action - Cannot find route. id={0}, exitId={1}", id, exitId)));
                    model.Page = ClientPage.Home;
                }
            }

            return(View("~/client/Views/Main.cshtml", new MainModel(this.Url)
            {
                Page = ClientPage.Exit,
                RouteId = id,
                Route = route,
                ExitId = exitId,
                PoiType = poiType
            }));
        }