ActivEarth.DAO.ActiveRouteDAO.ProcessRoute C# (CSharp) Метод

ProcessRoute() приватный статический Метод

Processes the contents of a route and updates the corresponding user statistics.
private static ProcessRoute ( Route route ) : void
route ActivEarth.Objects.Profile.Route Route to process.
Результат void
        private static void ProcessRoute(Route route)
        {
            if (route == null) return;

            double distance = MetersToMiles(route.Distance);
            double time = route.EndTime.Subtract(route.StartTime).TotalHours;
            string mode = route.Mode;

            float oldDistance, oldTotalDistance, oldTime, oldTotalTime, oldSteps;

            oldTotalDistance = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.AggregateDistance).Value;
            oldTotalTime = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.AggregateTime).Value;

            switch (mode.ToLower())
            {
                case "running":
                    // Update RunDistance, RunTime, and Steps
                    oldDistance = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.RunDistance).Value;
                    oldTime = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.RunTime).Value;
                    oldSteps = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.Steps).Value;

                    StatisticManager.SetUserStatistic(route.UserId, Statistic.RunDistance, (float)(distance + oldDistance));
                    StatisticManager.SetUserStatistic(route.UserId, Statistic.RunTime, (float)(time + oldTime));
                    StatisticManager.SetUserStatistic(route.UserId, Statistic.Steps, (float)(route.Steps + oldSteps));
                    break;

                case "biking":
                    // Update BikeDistance and BikeTime
                    oldDistance = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.BikeDistance).Value;
                    oldTime = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.BikeTime).Value;

                    StatisticManager.SetUserStatistic(route.UserId, Statistic.BikeDistance, (float)(distance + oldDistance));
                    StatisticManager.SetUserStatistic(route.UserId, Statistic.BikeTime, (float)(time + oldTime));
                    break;

                case "walking":
                    // Update WalkDistance, WalkTime, and Steps
                    oldDistance = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.WalkDistance).Value;
                    oldTime = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.WalkTime).Value;
                    oldSteps = UserStatisticDAO.GetStatisticFromUserIdAndStatType(route.UserId, Statistic.Steps).Value;

                    StatisticManager.SetUserStatistic(route.UserId, Statistic.WalkDistance, (float)(distance + oldDistance));
                    StatisticManager.SetUserStatistic(route.UserId, Statistic.WalkTime, (float)(time + oldTime));
                    StatisticManager.SetUserStatistic(route.UserId, Statistic.Steps, (float)(route.Steps + oldSteps));
                    break;

                default:

                    break;
            }

            StatisticManager.SetUserStatistic(route.UserId, Statistic.AggregateDistance, (float)(distance + oldTotalDistance));
            StatisticManager.SetUserStatistic(route.UserId, Statistic.AggregateTime, (float)(time + oldTotalTime));
        }