Exemple #1
0
        /// <summary>
        /// 根据参数配置,更新有效数据
        /// </summary>
        private void UpdateValidateDataBySettingManager()
        {
            if (!_isInitialized)
            {
                return;
            }
            ValidateDataNodes.Clear();
            //SettingManager对应-- -》RootNodeManager
            if (!SettingManager.IsEnable)
            {
                return;
            }

            foreach (SettingCollection rootSetting in SettingManager.Items)
            {
                //  SettingCollection对应 ---》RootNode
                bool   rootEnable = rootSetting.IsEnable;
                string rootName   = rootSetting.Name;
                if (!rootEnable)
                {
                    continue;
                }
                if (!_rootNodeManager.Children.Keys.Contains(rootName))
                {
                    continue;
                }
                RootNode rootNode = (RootNode)_rootNodeManager.Children[rootName];
                foreach (SettingItem item in rootSetting.Items)
                {
                    //  SettingItem对应 ---》CategoryNode
                    bool   categoryEnable = item.IsEnable;
                    string categoryName   = item.Name;
                    if (!categoryEnable)
                    {
                        continue;
                    }
                    if (rootNode.Children.Keys.Contains(categoryName))
                    {
                        CategoryNode categoryNode = (CategoryNode)rootNode.Children[categoryName];
                        ValidateDataNodes.AddRange(categoryNode.DataList);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 根据参数配置,更新有效数据
        /// </summary>
        private void UpdateValidateDataBySetting()
        {
            if (!_isInitialized)
            {
                return;
            }
            ValidateDataNodes.Clear();
            //如果总开关没有开,则直接返回。ValidateDataNodes为空
            ISettings settings = (ISettings)Setting;
            string    str      = settings.GetValue(SystemContext.EnableInspectionKey);

            if (!bool.TryParse(str, out bool b))
            {
                return;
            }

            //获取数据库中的配置,并按之过滤数据
            IEnumerable <InspectionModel> models = Setting.Records.ToArray().Select(x => new InspectionModel(x, Setting));
            var groups = models.GroupBy(x => x.Category).ToDictionary(x => x.Key, y => y.ToArray());

            foreach (var group in groups)
            {
                string rootName = group.Key;
                if (!_rootNodeManager.Children.Keys.Contains(rootName))
                {
                    continue;
                }
                RootNode rootNode = (RootNode)_rootNodeManager.Children[rootName];

                foreach (InspectionModel model in group.Value)
                {
                    if (model.IsSelect)
                    {
                        string       modelName    = model.Name;
                        CategoryNode categoryNode = (CategoryNode)rootNode.Children[modelName];
                        ValidateDataNodes.AddRange(categoryNode.DataList);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 获取全部数据。搜索Dir目录下的Xml文件,并且读取文件中RootName节点的数据;返回一个List<SensitiveData>数据
        /// </summary>
        /// <returns></returns>
        public void GetAllData(RootNodeManager rootNodeManager)
        {
            if (!IsInitialize)
            {
                return;
            }
            //从目录Dir中读取数据
            string[] files = Directory.GetFiles(Dir, "*.xml");
            foreach (var file in files)
            {
                XmlDocument xmdDoc = new XmlDocument();
                try
                {
                    xmdDoc.Load(file);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
                if (xmdDoc.DocumentElement == null ||
                    xmdDoc.DocumentElement.Name != ConstDefinition.RootName ||
                    !xmdDoc.DocumentElement.HasAttribute(NodeName) ||
                    !xmdDoc.DocumentElement.HasAttribute("SensitiveId"))
                {
                    continue;
                }

                //新建、获取RootNode节点curRootNode
                string rootNodeName = xmdDoc.DocumentElement.GetAttribute(NodeName);
                string sensitiveId  = xmdDoc.DocumentElement.GetAttribute("SensitiveId");
                if (!rootNodeManager.Children.Keys.Contains(rootNodeName))
                {
                    rootNodeManager.Children.Add(rootNodeName, new RootNode(rootNodeName));
                }
                RootNode curRootNode = (RootNode)rootNodeManager.Children[rootNodeName];

                XmlNodeList categoryNodes = xmdDoc.DocumentElement.ChildNodes;
                foreach (XmlElement categoryNode in categoryNodes)
                {
                    //新建、获取CategoryNode节点curNode
                    if (!categoryNode.HasAttribute(NodeName))
                    {
                        continue;
                    }

                    string categoryName = categoryNode.GetAttribute(NodeName);
                    if (!curRootNode.Children.Keys.Contains(categoryName))
                    {
                        CategoryNode node = new CategoryNode()
                        {
                            NodeName = categoryName
                        };
                        curRootNode.Children.Add(categoryName, node);
                    }
                    CategoryNode curCategoryNode = (CategoryNode)curRootNode.Children[categoryName];

                    foreach (XmlElement item in categoryNode.ChildNodes)
                    {
                        //新建、获取DataNode节点
                        if (item.HasAttribute("Value"))
                        {
                            string value = item.Attributes["Value"].Value;
                            curCategoryNode.DataList.Add(new DataNode()
                            {
                                SensitiveData = new SensitiveData(rootNodeName, categoryName, sensitiveId, value)
                            });
                        }
                    }
                }
            }
        }