예제 #1
0
        public TimeMap GetTimeMap()
        {
            if (_timeMapInstance == null || IsTimeMapExpired())
            {
                lock (_syncRoot)
                {
                    if (_timeMapInstance == null || IsTimeMapExpired())
                    {
                        IOrderUnitOfWork database = _container.Resolve <IOrderUnitOfWork>();
                        IConfig          config   = _container.Resolve <IConfig>();

                        DateTime todayStartDate = DateTimeHelper.GetStartDateOfToday();
                        DateTime todayEndDate   = DateTimeHelper.GetEndDateOfToday();

                        var todayOrdersMap = database.Orders.Find(o =>
                                                                  o.TargetStartDate >= todayStartDate &&
                                                                  o.TargetEndDate <= todayEndDate
                                                                  ).ToList <Order>();

                        var timeMapConfig = new TimeMapConfig(config.WorkingDayStartTime.ToTimeSpan(),
                                                              config.WorkingDayEndTime.ToTimeSpan(),
                                                              config.TimeMapTraySize.ToTimeSpan(),
                                                              config.CookingDelayTime.ToTimeSpan(),
                                                              config.OrderExpireTime.ToTimeSpan(),
                                                              config.TimeMapRules.ToList <TimeMapRule>());

                        _timeMapInstance = new TimeMap(todayOrdersMap, timeMapConfig);

                        database.Dispose();
                    }
                }
            }

            return(_timeMapInstance);
        }
 public void Dispose()
 {
     _ordersDatabase.Dispose();
     _contactService.Dispose();
 }