Beispiel #1
0
        #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private async void doSomething(long diff)
        #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            lock (synobj)
            {
                ObservedValuesDAO observedValuesDao = new ObservedValuesDAO();
                ObservedValues    ov  = observedValuesDao.GetObservedValues();
                DateTime          now = DateTime.Now;

                // If at least one of the rules is true, code is here.
                ov.Duration   = (ov.ActualDate != null && ov.Duration != null && ov.ActualDate.Value.Date.Equals(now.Date)) ? (ov.Duration = ov.Duration + diff) : diff;
                ov.ActualDate = now.Date;
                observedValuesDao.StoreObservedValues(ov);

                logger.Debug("Duration ... " + ov.Duration);

                // We need list of the rules. And control it.
                RulesDAO rulesDao    = new RulesDAO();
                Rule[]   rules       = rulesDao.ListRules();
                bool     canContinue = CanContinue(now, ov, rules);


                // If we can not continue, shutdown computer ...
                if (!canContinue)
                {
                    logger.Info("Condition is not truthfully, run command for shutdown ...");

                    BaseSettings bs = baseSettings.GetBaseSettings();
                    if (bs.ShutdownCommand != null && bs.ShutdownCommand.Length > 0)
                    {
                        System.Diagnostics.Process process =
                            System.Diagnostics.Process.Start("cmd", "/C \"" + bs.ShutdownCommand + "\"");
                        // TODO Do something with process outputs.
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Getting actual observed values.
 /// </summary>
 /// <returns></returns>
 public ObservedValues GetObservedValues()
 {
     return(observedValuesDAO.GetObservedValues());
 }