Example #1
0
        private static void SeedTestData(InventoryApiContext context)
        {
            var testItem1 = new Models.Items
            {
                Label      = "TestLabel1",
                Expiration = DateTime.Now.AddYears(1),
                ItemType   = 1
            };

            context.Items.Add(testItem1);

            var testItem2 = new Models.Items
            {
                Label      = "TestLabel2",
                Expiration = DateTime.Now.AddYears(1),
                ItemType   = 1
            };

            context.Items.Add(testItem2);
            context.SaveChanges();
        }
Example #2
0
        public ItemMonitor(InventoryApiContext context, ITimerFactory TimerFactory, ILoggerFactory loggerFactory)
        {
            //initialize private variables
            _context        = context;
            TimerReferences = new Dictionary <string, Timer>();
            _timerFactory   = TimerFactory;
            _logger         = loggerFactory.CreateLogger <ItemMonitor>();

            //run periodic monitoring addition weekly
            _scheduleFromContextReRunInterval = new TimeSpan(7, 0, 0, 0);

            //the timer task will be scheduled to run weekly, but get set
            //timers for any expirations dates within 9 days so the timer
            //will be rerun before the covered window expires
            _taskScheduleLimit = _scheduleFromContextReRunInterval + new TimeSpan(2, 0, 0, 0);

            //schedule recurring item monitor, which will schedule expiration task for each item about to expire
            _scheduledRunFromContextTimer = _timerFactory.CreateTimer(x =>
            {
                ScheduleFromContext();
            }, null, _taskScheduleLimit, _scheduleFromContextReRunInterval);
        }