Beispiel #1
0
        public List<IRule> getAllRules(bool forceReload)
        {
            if (_ruleList != null && !forceReload)
                return _ruleList;

            FileInfo[] fileList;
            try
            {
                DirectoryInfo rulesDir = new DirectoryInfo(_rulesPath);
                fileList = rulesDir.GetFiles();
            }
            catch(Exception ex)
            {
                throw new IOException("Unable to read rule files from " + _rulesPath, ex);
            }
               var newList = new List<IRule>(fileList.Length);

            foreach (FileInfo thisFile in fileList)
            {
                try
                {
                    StreamReader thisFileReader;
                    XmlSerializer mySer = new XmlSerializer(typeof(rule));
                    using (thisFileReader = new StreamReader(thisFile.FullName))
                    {
                        // Add our  rule name to our listView, with a .tag() set to the rule object itself.
                        newList.Add((rule)mySer.Deserialize(thisFileReader));
                    }
                }
                catch
                {
                    rule r = new rule(thisFile.Name.Substring(0,thisFile.Name.IndexOf('.')));
                    r.state = ruleState.errored;
                    r.addError(new fileReadError(thisFile.FullName));
                    newList.Add(r);
                }
            }

            lock (_ruleLock)
                _ruleList = newList;

            return _ruleList;
        }