예제 #1
0
        public void Disable(
            DriverModuleName moduleName,
            DriverEnablementSchedule schedule
            )
        {
            var enablementSwitch
                = new DefaultOneDriverEnablementSwitch(
                      moduleName,
                      this.driverStatusGetter,
                      this.enablementController);
            var switchInitiator
                = new DefaultScheduledEnablementSwitchInitiator(
                      schedule, enablementSwitch);

            this.switchInitiators.Add(switchInitiator);

            enablementSwitch.ActivationRequested
                += (sender, ea)
                   => this.ActivationRequested?.Invoke(sender, ea);

            enablementSwitch.DeactivationRequested
                += (sender, ea)
                   => this.DeactivationRequested?.Invoke(sender, ea);

            this.ActivationRequested
                += (sender, dModuleName)
                   => this.ConsiderRestartingComputer(dModuleName);

            this.DeactivationRequested
                += (sender, dModuleName)
                   => this.ConsiderRestartingComputer(dModuleName);

            switchInitiator.Start();
        }
        public DefaultScheduledEnablementSwitchInitiator(
            DriverEnablementSchedule schedule,
            IOneDriverEnablementSwitch enablementSwitch
            )
        {
            this.schedule         = schedule;
            this.enablementSwitch = enablementSwitch;

            this.timepointToTimer
                = new Dictionary <DateTime, Timer>(schedule.Count);

            foreach (DateTime time in schedule.Keys)
            {
                var timer = new Timer {
                    AutoReset = false,
                    Enabled   = false
                };
                timer.Elapsed
                    += (sender, ea) =>
                       this.HandleDriverEnablementRequest(
                           sender, ea, schedule[time]);

                this.timepointToTimer[time] = timer;
            }
        }