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

            foreach (PropertyInfo p in o.GetType().GetProperties())
            {
                Type t = p.PropertyType;
                if (t == typeof(DateTime))
                {
                    p.SetValue(o, _dateTimeHelper.ConvertUtcToLocalTime((DateTime)p.GetValue(o)));
                }
                else if (t == typeof(DateTime?))
                {
                    var existingValue = (DateTime?)p.GetValue(o);
                    if (existingValue.HasValue)
                    {
                        p.SetValue(o, _dateTimeHelper.ConvertUtcToLocalTime(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)))
                {
                    if (t == typeof(Drayage.Optimization.Model.Orders.RouteStop))
                    {
                        UpdateDateTimeToLocal(p.GetValue(o));
                    }
                }
            }
        }
Exemple #2
0
        public void MapDomainToModel(Job job, Drayage.Optimization.Model.Orders.Job optimizationJob, DateTime?planDate)
        {
            optimizationJob.InjectFrom <DomainToModelValueInjection>(job);

            var equipmentConfiguration = new EquipmentConfiguration();

            equipmentConfiguration.InjectFrom <DomainToModelValueInjection>(job);

            optimizationJob.EquipmentConfiguration = equipmentConfiguration;

            var modelRouteStops = optimizationJob.RouteStops.ToList();

            optimizationJob.RouteStops.Clear();

            if (job.RouteStops != null && optimizationJob.RouteStops != null)
            {
                job.RouteStops = job.RouteStops.OrderBy(p => p.SortOrder).ToList();


                int addDaysValue = 0;
                if (job.DueDate.HasValue && planDate.HasValue && job.DueDate.Value > planDate)
                {
                    addDaysValue = (int)job.DueDate.Value.Subtract(planDate.Value).TotalDays;
                    for (var x = 0; x < job.RouteStops.Count; x++)
                    {
                        if (addDaysValue >= 1)
                        {
                            //job.RouteStops[x].WindowStart =
                            //    job.RouteStops[x].WindowStart +

                            //    TimeSpan.FromDays(addDaysValue).Ticks;
                            //job.RouteStops[x].WindowEnd = job.RouteStops[x].WindowEnd +
                            //                                TimeSpan.FromDays(addDaysValue).Ticks;
                        }
                    }
                }

                var routeStopIndex = 0;
                foreach (var routeStop in job.RouteStops)
                {
                    var modelRouteStop = modelRouteStops.FirstOrDefault(f => f.Id == routeStop.Id);
                    if (modelRouteStop != null)
                    {
                        routeStop.SortOrder = routeStopIndex++;

                        if (routeStop.Location != null && routeStop.Location.WaitingTime.HasValue)
                        {
                            modelRouteStop.QueueTime = new TimeSpan(0, routeStop.Location.WaitingTime.Value, 0);
                        }

                        // fixed hotspot
                        if (routeStop.LocationId != null && routeStop.Location == null)
                        {
                            var location = _locationService.GetById((int)routeStop.LocationId);
                            routeStop.LocationId = location.Id;
                            routeStop.Location   = location;
                        }

                        if (routeStop.StopAction != null)
                        {
                            modelRouteStop.StopAction = StopActions.Actions.FirstOrDefault(p => p.ShortName == routeStop.StopAction.ShortName);
                        }

                        if (routeStop.StopDelay.HasValue)
                        {
                            modelRouteStop.ExecutionTime = new TimeSpan(0, Convert.ToInt32(routeStop.StopDelay.Value), 0);
                        }

                        var dueDateLocal = _dateTimeHelper.ConvertUtcToLocalTime(job.DueDate.Value);


                        modelRouteStop.WindowStart = new TimeSpan(routeStop.WindowStart);
                        modelRouteStop.WindowEnd   = new TimeSpan(routeStop.WindowEnd);

                        // map stop action
                        modelRouteStop.StopAction = MapDomainToModel(routeStop.StopAction);
                        // Remove Dynamic stops
                        if (routeStop.IsDynamicStop)
                        {
                            optimizationJob.RouteStops.Remove(modelRouteStop);
                        }

                        optimizationJob.RouteStops.Add(modelRouteStop);
                    }
                    else
                    {
                        var nullModelRouteStop = modelRouteStop;
                    }
                }
            }

            _routeSanitizer.PrepareJob(optimizationJob);
        }