Exemplo n.º 1
0
        private async Task FollowAvailibleRoute(ResponderIcon responderIcon)
        {
            if (!responderIcon.OnPatrolRoute)
            {
                if (responderIcon.IncidentResponsePath == null)
                {
                    var route     = _routes.FirstOrDefault(x => x.Id == responderIcon.Responder.RouteId);
                    var lastPoint = new Geopoint(route.RoutePoints.Last());
                    var routeMap  =
                        await MapControlService.ResolveMapRouteAsync(responderIcon.Responder.GeoLocation, lastPoint);

                    responderIcon.IncidentResponsePath = routeMap.Path.Positions;
                    responderIcon.RouteIndex           = 0;
                }

                var completedRoute = FollowCustomRoute(responderIcon);
                if (completedRoute)
                {
                    responderIcon.OnPatrolRoute        = true;
                    responderIcon.IncidentResponsePath = null;
                    responderIcon.RouteIndex           = 0;
                }
            }
            else
            {
                FollowDefaultRoute(responderIcon);
            }

            SearchForAvailibleIncident(responderIcon);
        }
Exemplo n.º 2
0
        private async Task FollowIncidentRoute(ResponderIcon responderIcon)
        {
            var incident = responderIcon.Responder.Incident;

            if (incident != null)
            {
                if (responderIcon.IncidentResponsePath == null)
                {
                    var routeMap =
                        await
                        MapControlService.ResolveMapRouteAsync(responderIcon.Responder.GeoLocation,
                                                               incident.GeoLocation);

                    responderIcon.IncidentResponsePath = routeMap.Path.Positions;
                    responderIcon.RouteIndex           = 0;
                    responderIcon.RouteStepIndex       = 0;
                }

                var completedRoute = FollowCustomRoute(responderIcon);
                if (completedRoute)
                {
                    responderIcon.RouteIndex                      = 0;
                    responderIcon.RouteStepIndex                  = 0;
                    responderIcon.IncidentResponsePath            = null;
                    responderIcon.IncidentArrivalTime             = DateTime.Now;
                    responderIcon.Responder.Request.UnitResponded = true;
                    await UpdateResponderStatus(responderIcon, ResponseStatus.Busy);
                }
            }
            else
            {
                await UpdateResponderStatus(responderIcon, ResponseStatus.Available);
            }
        }
Exemplo n.º 3
0
        private async Task ResolveRoutePaths()
        {
            foreach (var route in _routes)
            {
                var list       = new List <BasicGeoposition>();
                var startPoint = route.RoutePoints.Last();
                foreach (var point in route.RoutePoints)
                {
                    var start    = new Geopoint(startPoint);
                    var end      = new Geopoint(point);
                    var routeMap = await MapControlService.ResolveMapRouteAsync(start, end);

                    startPoint = point;
                    list.AddRange(routeMap.Path.Positions);
                }
                route.FullRoute = list;
            }
        }
Exemplo n.º 4
0
        private bool FollowCustomRoute(ResponderIcon responderIcon)
        {
            if (responderIcon.RouteIndex < (responderIcon.IncidentResponsePath.Count - 1))
            {
                var currPoint = responderIcon.IncidentResponsePath[responderIcon.RouteIndex];
                var nextPoint = responderIcon.IncidentResponsePath[responderIcon.RouteIndex + 1];

                if (responderIcon.RouteStepIndex == 0)
                {
                    var    latDiff  = (nextPoint.Latitude - currPoint.Latitude);
                    var    lonDiff  = (nextPoint.Longitude - currPoint.Longitude);
                    double latSteps = Math.Abs(latDiff) / Configuration.MovementSpeed;
                    double lonSteps = Math.Abs(lonDiff) / Configuration.MovementSpeed;
                    responderIcon.RouteStepMax = (int)Math.Max(latSteps, lonSteps);
                    if (responderIcon.RouteStepMax > 0)
                    {
                        var latStepSpeed = Math.Abs(latDiff / responderIcon.RouteStepMax);
                        var lonStepSpeed = Math.Abs(lonDiff / responderIcon.RouteStepMax);
                        responderIcon.RouteStepLatitude  = (latDiff > 0) ? latStepSpeed : latStepSpeed * -1;
                        responderIcon.RouteStepLongitude = (lonDiff > 0) ? lonStepSpeed : lonStepSpeed * -1;
                    }
                }
                else
                {
                    var lat = currPoint.Latitude + (responderIcon.RouteStepIndex * responderIcon.RouteStepLatitude);
                    var lon = currPoint.Longitude + (responderIcon.RouteStepIndex * responderIcon.RouteStepLongitude);
                    currPoint = new BasicGeoposition {
                        Latitude = lat, Longitude = lon
                    };
                }

                MapControlService.UpdateResponderPosition(responderIcon, new Geopoint(currPoint));
                responderIcon.RouteStepIndex += 1;
                if (responderIcon.RouteStepIndex >= responderIcon.RouteStepMax)
                {
                    responderIcon.RouteIndex    += 1;
                    responderIcon.RouteStepIndex = 0;
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        private async void SearchForAvailibleIncident(ResponderIcon responderIcon)
        {
            IncidentModel[] availibleForResponder = new IncidentModel[0];
            // Filter to responder type
            await responderIcon.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                availibleForResponder =
                    _availableIncidentList.Where(
                        x =>
                        x.Responders.Any(
                            y =>
                            !y.UnitResponding && y.DepartmentType == responderIcon.Responder.ResponderDepartment))
                    .ToArray();
            });

            Tuple <MapRoute, IncidentModel> closestIncidentData = null;

            for (int i = 0; i < availibleForResponder.Length; i++)
            {
                var incident = availibleForResponder[i];
                if (incident != null)
                {
                    // Find Closest
                    var routeMap =
                        await
                        MapControlService.ResolveMapRouteAsync(responderIcon.Responder.GeoLocation,
                                                               incident.GeoLocation);

                    if (routeMap != null) // TODO: why would this be NULL?
                    {
                        if (closestIncidentData == null ||
                            routeMap.EstimatedDuration < closestIncidentData.Item1.EstimatedDuration)
                        {
                            closestIncidentData = new Tuple <MapRoute, IncidentModel>(routeMap, incident);
                        }
                    }
                }
            }

            // Assign if available incident found
            if (closestIncidentData != null)
            {
                var responderRequest =
                    closestIncidentData.Item2.Responders.FirstOrDefault(
                        x => !x.UnitResponding && x.DepartmentType == responderIcon.Responder.ResponderDepartment);
                if (responderRequest != null)
                {
                    responderRequest.RespondToRequest(responderIcon);
                    responderIcon.Responder.Request    = responderRequest;
                    responderIcon.Responder.Incident   = closestIncidentData.Item2;
                    responderIcon.RouteIndex           = 0;
                    responderIcon.OnPatrolRoute        = false;
                    responderIcon.IncidentResponsePath = closestIncidentData.Item1.Path.Positions;

                    await UpdateResponderStatus(responderIcon, ResponseStatus.EnRoute);
                }
            }

            // Clear any incidents no longer available
            await responderIcon.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var incidentsToRemove =
                    _availableIncidentList.Where(x => x.Responders.All(y => y.UnitResponding)).ToList();
                foreach (var incident in incidentsToRemove)
                {
                    _availableIncidentList.Remove(incident);
                }
            });
        }