Ejemplo n.º 1
0
        private void CheckProxyTunnel()
        {
            var validTunnelSleep   = TimeSpan.FromMinutes(5);
            var invalidTunnelSleep = TimeSpan.FromSeconds(10);

            for (; ;)
            {
                try
                {
                    SetStatusPending();
                    ProxyServer.Routes = null;
                    var routes = new List <Route>();
                    // iterative process, in order to have a quick working route
                    foreach (var route in GetRoutes())
                    {
                        routes.Add(route);
                        SetSuccessStatus(route);
                        ProxyServer.Routes = routes.ToArray();
                        RouteUpdated.Raise(this);
                    }
                    Thread.Sleep(validTunnelSleep);
                }
                catch (ProxyRouteException pre)
                {
                    SetFailureStatus(pre);
                    Thread.Sleep(invalidTunnelSleep);
                }
            }
        }
Ejemplo n.º 2
0
        private async void CalculateRoute()
        {
            Overlays[0].Graphics.Clear();
            HasRoute = false;
            OnPropertyChanged(nameof(HasRoute));

            if (Overlays[1].Graphics[0].Geometry == null ||
                Overlays[1].Graphics[1].Geometry == null)
            {
                return;                 //We don't have both to and from destination, so return
            }

            var t1 = RouteHelper.RouteAsync(Overlays[1].Graphics[0].Geometry as MapPoint,
                                            Overlays[1].Graphics[1].Geometry as MapPoint, false);
            var t2 = RouteHelper.RouteAsync(Overlays[1].Graphics[0].Geometry as MapPoint,
                                            Overlays[1].Graphics[1].Geometry as MapPoint, true);
            var route1 = await t1;

            if (route1 != null)
            {
                Overlays[0].Graphics.Add(new Graphic(route1.RouteGeometry));
                WalkTime     = route1.TotalTime.ToString("m\\:ss");
                WalkDistance = route1.TotalLength.ToString("0") + " m";
                OnPropertyChanged(nameof(WalkTime));
                OnPropertyChanged(nameof(WalkDistance));
            }
            var route2 = await t2;

            if (route2 != null)
            {
                Overlays[0].Graphics.Insert(0, new Graphic(route2.RouteGeometry)
                {
                    Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Black, 2)
                });
                WalkTimeAlt     = route2.TotalTime.ToString("m\\:ss");
                WalkDistanceAlt = route1.TotalLength.ToString("0") + " m";
                OnPropertyChanged(nameof(WalkTimeAlt));
                OnPropertyChanged(nameof(WalkDistanceAlt));
            }

            HasRoute = route1 != null;
            OnPropertyChanged(nameof(HasRoute));
            OnPropertyChanged(nameof(NoRoute));
            if (HasRoute)
            {
                ZoomToData();
            }
            RouteUpdated?.Invoke(this, EventArgs.Empty);
            if (route1 == null && route2 == null)
            {
                MapViewModel.RaiseErrorMessage("No possible route found");
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] RouteArgs args)
        {
            ValidateRouteArgs(args);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_entityIndex.Exists(ResourceType.Route, id))
            {
                return(NotFound());
            }

            if (!UserPermissions.IsAllowedToEdit(User.Identity, args.Status, _entityIndex.Owner(ResourceType.Route, id)))
            {
                return(Forbid());
            }

            var oldStatus = _entityIndex.Status(ResourceType.Route, id).GetValueOrDefault();

            if (args.Status == ContentStatus.Unpublished && oldStatus != ContentStatus.Published)
            {
                return(BadRequest(ErrorMessages.CannotBeUnpublished(ResourceType.Route)));
            }

            // validation passed, emit event
            var ev = new RouteUpdated
            {
                Id         = id,
                UserId     = User.Identity.GetUserIdentity(),
                Properties = args,
                Timestamp  = DateTimeOffset.Now,
            };

            await _eventStore.AppendEventAsync(ev);

            return(StatusCode(204));
        }
 public virtual void OnRouteUpdated(EventArgs e)
 {
     RouteUpdated?.Invoke(this, e);
 }