Esempio n. 1
0
        public void Start()
        {
            Monitor.Enter(monitorLock);

            if (_monitorThread != null)
            {
                Monitor.Exit(monitorLock);
                return;
            }

            // Re-read the Settings from the file here, this is called when the engine is Started, i.e. the settings may have changed
            MCEBuddyConf.GlobalMCEConfig = new MCEBuddyConf(GlobalDefs.ConfigFile);

            ReadConfig();
            _autoPause = GlobalDefs.Pause = false; // Reset just in case it was set earlier

            _monitorThread = new Thread(MonitorThread);
            _monitorThread.CurrentCulture = _monitorThread.CurrentUICulture = Localise.MCEBuddyCulture;
            _monitorThread.Start();

            if ((_wakeHour > -1) && (_wakeMinute > -1))
            {
                _wakeUp = new PowerManagement.WakeUp();
                _wakeUp.Woken += WakeUp_Woken;
                SetNextWake();
            }
            Log.AppLog.WriteEntry(this, Localise.GetPhrase("MCEBuddy engine started.  Setting engine last running state to start."), Log.LogEntryType.Debug, true);

            GeneralOptions go = MCEBuddyConf.GlobalMCEConfig.GeneralOptions;
            go.engineRunning = true;
            MCEBuddyConf.GlobalMCEConfig.UpdateGeneralOptions(go, true); // Write the engine settings

            Monitor.Exit(monitorLock);
        }
Esempio n. 2
0
        public void Stop(bool preserveState)
        {
            Monitor.Enter(monitorLock);

            _autoPause = GlobalDefs.Pause = false; // Reset suspension state
            GlobalDefs.Shutdown = true;

            if (_wakeUp != null)
            {
                _wakeUp.Abort();
                _wakeUp = null; //let the timer not fire again
            }

            while (_monitorThread != null)
            {
                Thread.Sleep(300);
            }

            Log.AppLog.WriteEntry(this, Localise.GetPhrase("MCEBuddy engine stopped"), Log.LogEntryType.Information, true);

            GeneralOptions go = MCEBuddyConf.GlobalMCEConfig.GeneralOptions;
            go.engineRunning = false;
            MCEBuddyConf.GlobalMCEConfig.UpdateGeneralOptions(go, preserveState); // Write the engine settings
            if (preserveState)
                MCEBuddyConf.GlobalMCEConfig.WriteSettings(); // Write all configuration settings to file (last used state)

            if (preserveState) // Check if we are asked to preserve the stop state
                Log.AppLog.WriteEntry(this, Localise.GetPhrase("Setting engine last running state to stop"), Log.LogEntryType.Information, true);

            Monitor.Exit(monitorLock);
        }