/// <summary> /// Initializes a new registry of NxBRE Inference Engines. /// </summary> /// <param name="registryConfigurationFile">The full path and file name of the registry configuration file.</param> public FileRegistry(string registryConfigurationFile) { // we use non-synchronized ListDictionary, switch to Hashtable if much more than 10 engines are in the registry. registry = new Dictionary <string, CachedEngine>(); fileIndex = new Dictionary <string, IList <CachedEngine> >(); // load the configuration configuration = (FileRegistryConfiguration) new XmlSerializer(typeof(FileRegistryConfiguration)).Deserialize(new FileStream(registryConfigurationFile, FileMode.Open, FileAccess.Read, FileShare.Read)); // store the configuration folder because the rule files and binders are stored into it var configurationFolder = ((configuration.Folder != null) && (configuration.Folder != String.Empty))?configuration.Folder:new FileInfo(registryConfigurationFile).DirectoryName; if (Logger.IsInferenceEngineInformation) { Logger.InferenceEngineSource.TraceEvent(TraceEventType.Information, 0, "Loaded configuration, Folder: " + configurationFolder + ", FileLockedPonderatingTime: " + configuration.FileLockedPonderatingTime + ", Engines: " + configuration.Engines.Length); } // parse the configuration to load up the different engines foreach (var cachedEngine in configuration.Engines.Select(engineConfiguration => new CachedEngine(configurationFolder, engineConfiguration))) { // initialize the engine cachedEngine.LoadRules(); // store the engine in the registry registry.Add(cachedEngine.ID, cachedEngine); // register the ruleFile -> CachedEngine & binderFile -> CachedEngine pairs AddEngineSpecificFileToCache(cachedEngine.RuleFile, cachedEngine); AddEngineSpecificFileToCache(cachedEngine.BinderFile, cachedEngine); } // activate the file system listener var watcher = new FileSystemWatcher(configurationFolder) { NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size }; watcher.Changed += new FileSystemEventHandler(this.OnFileChanged); watcher.Renamed += new RenamedEventHandler(this.OnFileRenamed); watcher.EnableRaisingEvents = true; }
/// <summary> /// Initializes a new registry of NxBRE Inference Engines. /// </summary> /// <param name="registryConfigurationFile">The full path and file name of the registry configuration file.</param> public FileRegistry(string registryConfigurationFile) { // we use non-synchronized ListDictionary, switch to Hashtable if much more than 10 engines are in the registry. registry = new Dictionary<string, CachedEngine>(); fileIndex = new Dictionary<string, IList<CachedEngine>>(); // load the configuration configuration = (FileRegistryConfiguration) new XmlSerializer(typeof(FileRegistryConfiguration)).Deserialize(new FileStream(registryConfigurationFile, FileMode.Open, FileAccess.Read, FileShare.Read)); // store the configuration folder because the rule files and binders are stored into it string configurationFolder = ((configuration.Folder != null) && (configuration.Folder != String.Empty))?configuration.Folder:new FileInfo(registryConfigurationFile).DirectoryName; if (Logger.IsInferenceEngineInformation) Logger.InferenceEngineSource.TraceEvent(TraceEventType.Information, 0, "Loaded configuration, Folder: " + configurationFolder + ", FileLockedPonderatingTime: " + configuration.FileLockedPonderatingTime + ", Engines: " + configuration.Engines.Length); // parse the configuration to load up the different engines foreach(EngineConfiguration engineConfiguration in configuration.Engines) { CachedEngine cachedEngine = new CachedEngine(configurationFolder, engineConfiguration); // initialize the engine cachedEngine.LoadRules(); // store the engine in the registry registry.Add(cachedEngine.ID, cachedEngine); // register the ruleFile -> CachedEngine & binderFile -> CachedEngine pairs AddEngineSpecificFileToCache(cachedEngine.RuleFile, cachedEngine); AddEngineSpecificFileToCache(cachedEngine.BinderFile, cachedEngine); } // activate the file system listener FileSystemWatcher watcher = new FileSystemWatcher(configurationFolder); watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size; watcher.Changed += new FileSystemEventHandler(this.OnFileChanged); watcher.Renamed += new RenamedEventHandler(this.OnFileRenamed); watcher.EnableRaisingEvents = true; }