예제 #1
0
        private static void ExecuteLoadShedRules(Rules loadshedRules, List<lfa.pmgmt.data.DTO.BusinessRule.RuleSet> ruleSets)
        {
            foreach (lfa.pmgmt.data.DTO.BusinessRule.RuleSet ruleSet in ruleSets)
            {
                List<lfa.pmgmt.data.DTO.BusinessRule.Rule> rules = loadshedRules.ListRulesForRuleSet(ruleSet.Id);

                foreach (lfa.pmgmt.data.DTO.BusinessRule.Rule rule in rules)
                {
                    string[] ruleArray = rule.Condition.Split(".".ToCharArray());

                    int unitId = int.Parse(ruleArray[0].ToString());

                    if (rule.Priority.ToLower().Equals("none"))
                    {
                        if (loadshedRules.ExecuteRule(rule.Condition))
                        {
                            loadshedRules.Execute(rule.Result);

                            _ruleEnabledUnits.Add(unitId);
                        }
                    }
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting power management controller service...");

            try
            {
                _connectionString = ConfigurationManager.AppSettings["ConnectionString"];
                int defaultPort = int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString());

                Console.WriteLine("Power management controller service running...");

                Rules loadShed = new Rules(_connectionString,defaultPort);
                //bool hasLoadShedAll = loadShed.EntireLoadShed();
                bool hasLoadShedAll = false;

                if (!hasLoadShedAll)
                {
                    if (!HasRulesToExecute())
                    {
                        Scheduling schedule = new Scheduling(_connectionString);
                        schedule.Execute(defaultPort);
                    }
                    else
                    {
                        _ruleEnabledUnits = new List<int>();

                        Rules loadshedRules = new Rules(_connectionString, defaultPort);
                        List<lfa.pmgmt.data.DTO.BusinessRule.RuleSet> ruleSets = loadshedRules.ListActiveRuleSets();

                        if (ruleSets.Count > 0)
                        {
                            ExecuteScheduleOnNonRuleEnabledUnits();

                            //ExecuteLoadShedRules(loadshedRules, ruleSets);

                            _ruleEnabledUnits.Clear();
                        }
                        else
                        {
                            Scheduling schedule = new Scheduling(_connectionString);
                            schedule.Execute(int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString()));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
예제 #3
0
        private void tmrManager_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            bool _doLogging = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableLogging"].ToString());
            int _defaultPort = int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString());
            int _interval = int.Parse(ConfigurationManager.AppSettings["Interval"].ToString());
            string _connectionString = ConfigurationManager.AppSettings["ConnectionString"];

            try
            {
                #region OLD Timer Stop
                tmrManager.Stop();
                #endregion

                Rules loadShed = new Rules(_connectionString,_defaultPort);

                bool hasLoadShedAll = false;

                if (!hasLoadShedAll)
                {
                    if (!HasRulesToExecute(_connectionString))
                    {
                        Scheduling schedule = new Scheduling(_connectionString);
                        schedule.Execute(_defaultPort);
                        ((IDisposable)schedule).Dispose();
                    }
                    else
                    {
                        _ruleEnabledUnits = new List<int>();

                        Rules loadshedRules = new Rules(_connectionString, _defaultPort);
                        List<lfa.pmgmt.data.DTO.BusinessRule.RuleSet> ruleSets = loadshedRules.ListActiveRuleSets();

                        if (ruleSets.Count > 0)
                        {
                            ExecuteScheduleOnNonRuleEnabledUnits(_connectionString);

                            _ruleEnabledUnits.Clear();
                        }
                        else
                        {
                            Scheduling schedule = new Scheduling(_connectionString);
                            schedule.Execute(int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString()));
                            ((IDisposable)schedule).Dispose();
                        }
                    }

                    LogLoadShedRulesExecuted(_doLogging);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                GC.WaitForPendingFinalizers();

                this.Dispose(true);

                tmrManager.Interval = _interval;
                tmrManager.Start();

                #region OLD Timer Start
                //    tmrManager = new System.Timers.Timer();
            //    tmrManager.Enabled = true;
            //    tmrManager.Interval = _interval;
            //    tmrManager.Elapsed += new System.Timers.ElapsedEventHandler(tmrManager_Elapsed);
                //    tmrManager.Start();
                #endregion
            }
        }
예제 #4
0
        private void tmrManager_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                tmrManager.Stop();
                tmrManager.Enabled = false;

                _connectionString = ConfigurationManager.AppSettings["ConnectionString"];

                Rules loadShed = new Rules(_connectionString,_defaultPort);

                bool hasLoadShedAll = false;

                if (!hasLoadShedAll)
                {
                    if (!HasRulesToExecute())
                    {
                        Scheduling schedule = new Scheduling(_connectionString);
                        schedule.Execute(_defaultPort);
                    }
                    else
                    {
                        _ruleEnabledUnits = new List<int>();

                        Rules loadshedRules = new Rules(_connectionString, _defaultPort);
                        List<lfa.pmgmt.data.DTO.BusinessRule.RuleSet> ruleSets = loadshedRules.ListActiveRuleSets();

                        if (ruleSets.Count > 0)
                        {
                            ExecuteScheduleOnNonRuleEnabledUnits();

                            _ruleEnabledUnits.Clear();
                        }
                        else
                        {
                            Scheduling schedule = new Scheduling(_connectionString);
                            schedule.Execute(int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString()));
                        }
                    }

                    LogLoadShedRulesExecuted();
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                tmrManager = new System.Timers.Timer();
                tmrManager.Enabled = true;
                tmrManager.Interval = _interval;
                tmrManager.Elapsed += new System.Timers.ElapsedEventHandler(tmrManager_Elapsed);
                tmrManager.Start();
            }
        }