Пример #1
0
 public void InsertRule(CRule rule)
 {
     using (var context = _contextFactory.Get <CDbContext>())
     {
         context.TryAdd(rule);
     }
 }
Пример #2
0
 public void UpdateRule(CRule rule)
 {
     using (var context = _contextFactory.Get <CDbContext>())
     {
         context.TryUpdate(rule);
     }
 }
Пример #3
0
        private Dictionary <IModelData, Dictionary <int, Dictionary <int, RuleExcuter> > > mRunningRules = new Dictionary <IModelData, Dictionary <int, Dictionary <int, RuleExcuter> > >();    // -- 仅记录阻塞

        public bool StartRule(int ruleID, IModelData target)
        {
            if (SearchRuleIsRunning(ruleID, target))
            {
                return(false);
            }

            CRule rule = GetRule(ruleID);

            if (null == rule)
            {
                return(false);
            }

            rule.StartRule(target);

            Dictionary <int, Dictionary <int, RuleExcuter> > runningRuleInfo;

            if (!mRunningRules.TryGetValue(target, out runningRuleInfo))
            {
                runningRuleInfo = new Dictionary <int, Dictionary <int, RuleExcuter> >();
                mRunningRules.Add(target, runningRuleInfo);
            }
            Dictionary <int, RuleExcuter> runningExcutersInfo;

            if (!runningRuleInfo.TryGetValue(ruleID, out runningExcutersInfo))
            {
                runningExcutersInfo = new Dictionary <int, RuleExcuter>();
                runningRuleInfo.Add(ruleID, runningExcutersInfo);
            }
            return(true);
        }
Пример #4
0
        private RuleManager()
        {
            XmlData data = XmlTool.LoadFile(ERuleKey.RuleConfigUrl);

            RuleRepertory = new Dictionary <int, CRule>();

            foreach (var ruleData in data.Childs)
            {
                CRule rule = new CRule(ruleData);
                RuleRepertory.Add(rule.RuleID, rule);
            }
        }
Пример #5
0
        private bool IsRelevantEvent(CEventInfo eventInfo, out CRule connectedRule)
        {
            connectedRule = null;

            if (eventInfo.FileEvent == EFileEvents.None)
            {
                return(false);
            }

            var eventSystemPath    = new CFileSystemPath(Path.GetDirectoryName(eventInfo.ObjectName));
            var rulesSameDirectory = _rules.Where(r => r.FolderPath.Equals(eventSystemPath));

            foreach (var rule in rulesSameDirectory)
            {
                if (!rule.FileEvents.HasFlag(eventInfo.FileEvent))
                {
                    continue;
                }

                string fileName = eventInfo.ObjectName;
                if (!string.IsNullOrEmpty(rule.MasksExclude))
                {
                    var excludeMasks = rule.MasksExclude.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    if (FileNameMatchesAnyMask(fileName, excludeMasks))
                    {
                        continue;
                    }
                }

                if (!string.IsNullOrEmpty(rule.MasksInclude))
                {
                    var includeMasks = rule.MasksInclude.Split(Convert.ToChar(Environment.NewLine));
                    if (FileNameMatchesAnyMask(fileName, includeMasks))
                    {
                        connectedRule = rule;
                        return(true);
                    }
                }
                else
                {
                    connectedRule = rule;
                    return(true);
                }
            }
            return(false);
        }
Пример #6
0
        public bool SendNotification(CEventInfo eventInfo, CRule rule)
        {
            bool success = false;

            try
            {
                _notificationService.Send(ESenders.Smtp, new CMessage
                {
                    Receiver = rule.Email,
                    Body     = $"New event with file. Event: {eventInfo}, Rule: {rule}",
                    Subject  = $"New event with file {eventInfo.FileEvent}"
                });
                success = true;
            }
            catch (Exception ex)
            {
                s_logger.Error(ex);
            }
            return(success);
        }
Пример #7
0
        public void CreateRule(CRuleViewData data)
        {
            CRule item = new CRule
            {
                Folder            = data.Folder,
                IncludeSubfolders = data.IncludeSubfolders,
                Email             = data.Email,
                Notify            = data.Notify,
                MasksInclude      = data.MasksInclude,
                MasksExclude      = data.MasksExclude,
                State             = string.IsNullOrEmpty(data.State)
                    ? default(ERuleState)
                    : (ERuleState)Enum.Parse(typeof(ERuleState), data.State),
                FileEvents   = data.FileEvents,
                ClientInfoId = _client.ClientInfoId
            };

            _storageService.InsertRule(item);
            Mediator.NotifyColleagues(EMessageTypes.MsgRuleSaved, data);
        }
Пример #8
0
 private List <CRule> CreateRules()
 {
     return(new List <CRule>
     {
         CRule.CreateRule(Guid.NewGuid(),
                          "C:/Folder1",
                          true,
                          "*****@*****.**",
                          true,
                          "*.txt",
                          "*.tmp",
                          EFileEvents.Changed | EFileEvents.Renamed,
                          ERuleState.Active,
                          new Guid()
                          ),
         CRule.CreateRule(Guid.NewGuid(),
                          "C:/Folder2",
                          false,
                          "",
                          false,
                          "",
                          "",
                          EFileEvents.Deleted,
                          ERuleState.Paused,
                          new Guid()
                          ),
         CRule.CreateRule(Guid.NewGuid(),
                          "C:/Folder3",
                          true,
                          "*****@*****.**",
                          true,
                          "*.xls\n*.pdf",
                          "*.tmp",
                          EFileEvents.Changed | EFileEvents.Renamed | EFileEvents.Created | EFileEvents.Deleted,
                          ERuleState.Active,
                          new Guid()
                          )
     });
 }
Пример #9
0
        /// <summary>
        /// Add a new rule to the goal.
        /// </summary>
        /// <param name="name">The name of the goal. A leading "r" will be added.</param>
        /// <returns>A handle that can be used to refer to the new rule.</returns>
        public int AddRule(string name)
        {
            CRule rule = new CRule();
            rule.decays = false;
            rule.Name = "r" + name;

            // Store the rule and add it to the goal
            rules.Add(rule);
            goal.ruleSet.Add(rule);

            // Return the index we've just added, which will be final index, one below the count
            return rules.Count - 1;
        }
Пример #10
0
        public override c_Fuzzy_System Generate(Fuzzy_system.Class_Pittsburgh.c_Fuzzy_System Classifier, Abstract_generator_conf config)
        {
            Random         rand   = new Random();
            c_Fuzzy_System result = Classifier;

            if (result.Count_Rulles_Databases == 0)
            {
                Knowlege_base_CRules temp_rules = new Knowlege_base_CRules();
                result.Rulles_Database_Set.Add(temp_rules);
            }



            Type_Term_Func_Enum type_term = ((Generator_Rulles_simple_random_conf)config).Функция_принадлежности;
            int stable_terms = (int)((Generator_Rulles_simple_random_conf)config).Тип_Термов;
            int count_rules  = ((Generator_Rulles_simple_random_conf)config).Количество_правил;

            for (int j = 0; j < count_rules; j++)
            {
                int[] order = new int[result.Count_Vars];
                Type_Term_Func_Enum temp_type_term;
                if (stable_terms == 0)
                {
                    temp_type_term = type_term;
                }
                else
                {
                    temp_type_term = Generator_type_term();
                }

                List <Term> temp_term_list = new List <Term>();
                for (int k = 0; k < result.Count_Vars; k++)
                {
                    double[] parametrs = new double[c_Fuzzy_System.Count_Params_For_Term(temp_type_term)];

                    switch (temp_type_term)
                    {
                    case Type_Term_Func_Enum.Треугольник:
                        parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[2] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        Array.Sort(parametrs);
                        break;

                    case Type_Term_Func_Enum.Гауссоида: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[1] = (rand.NextDouble() + 0.01) * 0.5 *
                                       (result.Learn_Samples_set.Attribute_Max(k) -
                                        result.Learn_Samples_set.Attribute_Min(k));
                        break;

                    case Type_Term_Func_Enum.Парабола: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        Array.Sort(parametrs);
                        break;

                    case Type_Term_Func_Enum.Трапеция: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[2] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));
                        parametrs[3] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k));

                        Array.Sort(parametrs);

                        break;
                    }
                    Term temp_term = new Term(parametrs, temp_type_term, k);
                    result.Rulles_Database_Set[0].Terms_Set.Add(temp_term);
                    temp_term_list.Add(temp_term);
                    order[k] = result.Rulles_Database_Set[0].Terms_Set.Count - 1;
                }
                string class_label = result.Nearest_Class(temp_term_list);
                CRule  temp_Rule   = new CRule(result.Rulles_Database_Set[0].Terms_Set, order, class_label, 1.0);
                result.Rulles_Database_Set[0].Rules_Database.Add(temp_Rule);
            }



            result.unlaid_protection_fix();
            return(result);
        }
Пример #11
0
 public RuleObject()
 {
     RuleHost = new CRule(0);
 }
Пример #12
0
 public CRuleItemViewData(IRulesController controller, CRule rule)
 {
     _rulesController = controller;
     Rule             = rule;
 }
Пример #13
0
        public static c_Fuzzy_System load_UFS(this c_Fuzzy_System Classifier, string file_name)
        {
            c_Fuzzy_System result = Classifier;

            Knowlege_base_CRules New_dataBase = new Knowlege_base_CRules();

            List <string> added_term = new List <string>();


            XmlDocument Source = new XmlDocument();

            Source.Load(file_name);

            XmlNode rulles_node = Source.DocumentElement.SelectSingleNode("descendant::Rules");

            if (rulles_node == null)
            {
                throw new System.FormatException("Нет базы правил в ufs файле");
            }
            int     count_rulles  = XmlConvert.ToInt32(rulles_node.Attributes.GetNamedItem("Count").Value);
            XmlNode varibles_node = Source.DocumentElement.SelectSingleNode("descendant::Variables");

            if (varibles_node == null)
            {
                throw new System.FormatException("Нет термов в базе правил, ошибка UFS");
            }
            for (int i = 0; i < count_rulles; i++)
            {
                XmlNode antecedent_node       = rulles_node.ChildNodes[i].SelectSingleNode("Antecedent");
                int     count_antecedent_term = XmlConvert.ToInt32(antecedent_node.Attributes.GetNamedItem("Count").Value);
                int []  Order_term            = new int[count_antecedent_term];
                for (int j = 0; j < count_antecedent_term; j++)
                {
                    double[]            Value_temp;
                    Type_Term_Func_Enum type_term = Type_Term_Func_Enum.Треугольник;
                    int    num_var   = Classifier.Learn_Samples_set.Input_Attributes.IndexOf(Classifier.Learn_Samples_set.Input_Attributes.Find(x => x.Name.Equals(antecedent_node.ChildNodes[j].Attributes.GetNamedItem("Variable").Value, StringComparison.OrdinalIgnoreCase)));
                    string name_term = antecedent_node.ChildNodes[j].Attributes.GetNamedItem("Term").Value;
                    if (added_term.Contains(name_term))
                    {
                        Order_term[j] = added_term.IndexOf(name_term);
                    }
                    else
                    {
                        XmlNode term_node = varibles_node.SelectSingleNode("descendant::Term[@Name='" + name_term + "']");
                        int     count_MB  = 0;
                        switch (term_node.Attributes.GetNamedItem("Type").Value)
                        {
                        case "Triangle": { count_MB = 3; type_term = Type_Term_Func_Enum.Треугольник; break; }

                        case "Gauss": { count_MB = 2; type_term = Type_Term_Func_Enum.Гауссоида; break; }

                        case "Parabolic": { count_MB = 2; type_term = Type_Term_Func_Enum.Парабола; break; }

                        case "Trapezoid": { count_MB = 4; type_term = Type_Term_Func_Enum.Трапеция; break; }
                        }
                        Value_temp = new double[count_MB];
                        term_node  = term_node.SelectSingleNode("Params");
                        for (int p = 0; p < count_MB; p++)
                        {
                            string tett         = term_node.ChildNodes[p].Attributes.GetNamedItem("Number").Value;
                            int    number_param = XmlConvert.ToInt32(term_node.ChildNodes[p].Attributes.GetNamedItem("Number").Value);
                            Value_temp[number_param] = XmlConvert.ToDouble(term_node.ChildNodes[p].Attributes.GetNamedItem("Value").Value);
                        }

                        Term temp_term = new Term(Value_temp, type_term, num_var);

                        New_dataBase.Terms_Set.Add(temp_term);
                        added_term.Add(name_term);
                        Order_term[j] = New_dataBase.Terms_Set.Count - 1;
                    }
                }

                XmlNode consequnt_node = rulles_node.ChildNodes[i].SelectSingleNode("Consequent");

                string Classifier_value  = consequnt_node.Attributes.GetNamedItem("Class").Value;
                double Classifier_weigth = XmlConvert.ToDouble(consequnt_node.Attributes.GetNamedItem("CF").Value);


                CRule temp_rule = new CRule(New_dataBase.Terms_Set, Order_term, Classifier_value, Classifier_weigth);
                New_dataBase.Rules_Database.Add(temp_rule);
            }
            result.Rulles_Database_Set.Clear();
            result.Rulles_Database_Set.Add(New_dataBase);

            GC.Collect();
            return(result);
        }
Пример #14
0
 public void SaveNewRule(CRule rule)
 {
     rule.ClientInfoId = _client.ClientInfoId;
     rule.State        = ERuleState.Paused;
     _storageService.InsertRule(rule);
 }
Пример #15
0
 private bool _OutputSingleRule(CRule rule)
 {
     return(XmlTool.ReplaceXmlData(ERuleParam4Editor.RuleConfigUrl, rule, string.Format("root/node[@id='{0}']", rule.RuleID)));
 }