Example #1
0
 private void AddEngineSpecificFileToCache(string file, CachedEngine cachedEngine)
 {
     if (file != null)
     {
         if (!fileIndex.ContainsKey(file))
         {
             fileIndex.Add(file, new List <CachedEngine>());
         }
         IList <CachedEngine> cachedEngineList = fileIndex[file];
         cachedEngineList.Add(cachedEngine);
     }
 }
Example #2
0
        /// <summary>
        /// Get a named instance of an inference engine out of the registry.
        /// </summary>
        /// <param name="engineID">The ID of the engine to get</param>
        /// <returns>The desired engine instance or null if it is not available in the registry</returns>
        public IInferenceEngine GetEngine(string engineID)
        {
            CachedEngine cachedEngine = registry[engineID];

            if (cachedEngine != null)
            {
                return(cachedEngine.Engine);
            }
            else
            {
                return(null);
            }
        }
 private void OnEngineChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (CachedEngine != nodeModel.Engine)
     {
         nodeWasModified = true;
         // Cover what switch did user make. Only track when the new engine option is different with the previous one.
         Analytics.TrackEvent(
             Dynamo.Logging.Actions.Switch,
             Dynamo.Logging.Categories.PythonOperations,
             CachedEngine.ToString());
     }
     editText.Options.ConvertTabsToSpaces = CachedEngine != PythonEngineVersion.IronPython2;
 }
Example #4
0
        /// <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;
        }
Example #5
0
        /// <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;
        }
Example #6
0
 private void AddEngineSpecificFileToCache(string file, CachedEngine cachedEngine)
 {
     if (file != null) {
         if (!fileIndex.ContainsKey(file)) fileIndex.Add(file, new List<CachedEngine>());
         IList<CachedEngine> cachedEngineList = fileIndex[file];
         cachedEngineList.Add(cachedEngine);
     }
 }