public void UpdateDateTimeToUtc(object o)
        {
            if (o == null)
            {
                return;
            }

            foreach (PropertyInfo p in o.GetType().GetProperties())
            {
                var t = p.PropertyType;
                if (t == typeof(DateTime))
                {
                    p.SetValue(o, _dateTimeHelper.ConvertLocalToUtcTime((DateTime)p.GetValue(o)));
                }
                else if (t == typeof(DateTime?))
                {
                    var existingValue = (DateTime?)p.GetValue(o);
                    if (existingValue.HasValue)
                    {
                        p.SetValue(o, _dateTimeHelper.ConvertLocalToUtcTime(existingValue.Value));
                    }
                }
                else if (t.IsGenericType && t.GetGenericTypeDefinition() != null &&
                         t.GetGenericTypeDefinition().GetInterfaces().Contains(typeof(IEnumerable)) &&
                         t.IsGenericType && t.GetGenericTypeDefinition() != null &&
                         t.GetGenericTypeDefinition().GetInterfaces().Contains(typeof(IEnumerable)))
                {
                    var listItems = p.GetValue(o);
                    if (listItems != null)
                    {
                        var listItem = p.GetValue(o);
                        if (listItem != null)
                        {
                            foreach (var oo in (IEnumerable <object>)listItem)
                            {
                                UpdateDateTimeToLocal(oo);
                            }
                        }
                    }
                }
                else if (t.IsSubclassOf(typeof(EntityBase)) || t.IsSubclassOf(typeof(ModelBase)))
                {
                    UpdateDateTimeToLocal(p.GetValue(o));
                }
            }
        }
Beispiel #2
0
        public ICollection <TerminalArrivalEstimation> GetArrivalEstimations(Plan plan, IEnumerable <int> locationIds, bool recalculateStatistics = true, TimeZonePreference timeZone = TimeZonePreference.Utc)
        {
            var result = new List <TerminalArrivalEstimation>();

            if (plan != null)
            {
                // force recalculation of statistics if requested or if DriverPlan contains a Metric object that is null
                if (recalculateStatistics ||
                    (plan.DriverPlans.Any() && plan.DriverPlans.Where(p => p.RouteSegmentMetrics == null).ToList().Any()))
                {
                    _planGenerator.RecalculatePlanStatistics(plan);
                }

                foreach (var driverPlans in plan.DriverPlans)
                {
                    var driverMetrics = driverPlans.RouteSegmentMetrics.ToList();
                    for (int i = 0; i < driverMetrics.Count; i++)
                    {
                        var m = driverMetrics[i];
                        if (m.EndStop.LocationId.HasValue && (locationIds == null || locationIds.Contains(m.EndStop.LocationId.Value)))
                        {
                            if (m.StartTime.HasValue == false)
                            {
                                continue;
                            }

                            var match = new TerminalArrivalEstimation()
                            {
                                JobId           = m.EndStop.JobId,
                                RouteStopId     = m.EndStop.Id,
                                StartLocationId = m.StartStop.LocationId,
                                EndLocationId   = m.EndStop.LocationId.Value,
                                ArrivalTime     = plan.PlanConfig.DueDate.Date.AddTicks(m.StartTime.Value + m.TotalTravelTime),
                            };

                            if (i > 0)
                            {
                                match.ArrivalTime = match.ArrivalTime.Value.AddTicks(m.TotalExecutionTime);
                            }

                            if (timeZone == TimeZonePreference.Utc && match.ArrivalTime.HasValue)
                            {
                                match.ArrivalTime = _dateTimeHelper.ConvertLocalToUtcTime(match.ArrivalTime.Value);
                            }

                            result.Add(match);
                        }
                    }
                }
            }

            return(result);
        }