/// <summary> /// Runs the Job with the given name. /// </summary> /// <param name="name">The full name (case insensitive) of an existing Job from the current Interface Definition.</param> /// <returns></returns> public ExecutionResult RunJob(string name) { if (IsInitialized == false) { throw new Exception(String.Format("{0} must be initialized before running a job", this.GetType().Name)); } ExecutionResult result = PrepareRuntimeResult(false); InterfaceDefinitionJobData jobData = (from j in _InterfaceDefinitionData.Jobs // compare case insensitive where j.Name.ToLower() == name.ToLower() select j).FirstOrDefault(); if (jobData == null) { _Broadcaster.Error("The job with the name '{0}' wasn't found.", name); return(result); } result.IsSuccess = RunJob(jobData); return(result); }
/// <summary> /// Initialize the interface definition, the database, the plugin managers, the SyneryMemory and the SyneryInterpreter /// This method must be called before running a job. /// </summary> /// <param name="environmentVariables">At least Broadcaster and InterfaceDefinitionDirectoryPath are required!</param> /// <returns>true = success / false = error (see broadcasted messages for details)</returns> public bool Initialize(ExecutionVariables environmentVariables) { IProviderPluginManager providerPluginManager; ILibraryPluginManager libraryPluginManager; EnvironmentVariables = environmentVariables; // check required environment variables if (EnvironmentVariables == null) { throw new ArgumentNullException("runtimeEnvironment", "The EnvironmentVariables are required."); } if (EnvironmentVariables.Broadcaster == null) { throw new ArgumentNullException("A Broadcaster is required"); } if (EnvironmentVariables.InterfaceDefinitionDirectoryPath == null) { throw new ArgumentNullException("The InterfaceDefinitionDirectoryPath is required"); } // set defaults if no values given if (EnvironmentVariables.InterfaceDefinitionCodeDirectoryPath == null) { EnvironmentVariables.InterfaceDefinitionCodeDirectoryPath = Path.Combine(EnvironmentVariables.InterfaceDefinitionDirectoryPath, DEFAULT_SYNERY_CODE_DIRECTORY_RELATIVE_PATH); } if (EnvironmentVariables.DatabaseDirectoryPath == null) { EnvironmentVariables.DatabaseDirectoryPath = Path.Combine(EnvironmentVariables.InterfaceDefinitionDirectoryPath, DEFAULT_SYNERY_DATABASE_DIRECTORY_RELATIVE_PATH); } if (EnvironmentVariables.FilesystemDirectoryPath == null) { EnvironmentVariables.FilesystemDirectoryPath = Path.Combine(EnvironmentVariables.InterfaceDefinitionDirectoryPath, DEFAULT_FILESYSTEM_DIRECTORY_RELATIVE_PATH); } if (EnvironmentVariables.ProviderPluginDirectoryPath == null) { EnvironmentVariables.ProviderPluginDirectoryPath = Path.Combine(EnvironmentVariables.InterfaceDefinitionDirectoryPath, DEFAULT_PROVIDER_PLUGINS_DIRECTORY_RELATIVE_PATH); } if (EnvironmentVariables.LibraryPluginDirectoryPath == null) { EnvironmentVariables.LibraryPluginDirectoryPath = Path.Combine(EnvironmentVariables.InterfaceDefinitionDirectoryPath, DEFAULT_LIBRARY_PLUGINS_DIRECTORY_RELATIVE_PATH); } // create a local reference _Broadcaster = EnvironmentVariables.Broadcaster; // initialize the interface definition try { string interfaceDefinitionFilePath = Path.Combine(EnvironmentVariables.InterfaceDefinitionDirectoryPath, INTERFACE_DEFINITION_XML_FILENAME); _InterfaceDefinitionData = InterfaceDefinitionDataController.Load(interfaceDefinitionFilePath); } catch (Exception ex) { _Broadcaster.Error(ex); return(false); } _Broadcaster.Info("Interface definition data successfully loaded."); // initialize the Synery Database try { if (Directory.Exists(EnvironmentVariables.DatabaseDirectoryPath) == false) { Directory.CreateDirectory(EnvironmentVariables.DatabaseDirectoryPath); } _SyneryDB = new SyneryDB(EnvironmentVariables.DatabaseDirectoryPath); } catch (SyneryDBException ex) { _Broadcaster.Error(ex, "SyneryDB"); return(false); } catch (Exception ex) { _Broadcaster.Error(ex); return(false); } // initialize the ProviderPluginManager try { providerPluginManager = new ProviderPluginManager(EnvironmentVariables.ProviderPluginDirectoryPath); // activate the provider plugin instance references from the interface definition providerPluginManager.Activate(_InterfaceDefinitionData.RequiredPlugins.ProviderPluginInstances); } catch (ProviderPluginManagerException ex) { _Broadcaster.Error(ex, "ProviderPluginManager"); return(false); } catch (Exception ex) { _Broadcaster.Error(ex); return(false); } // initialize the LibraryPluginManager try { libraryPluginManager = new LibraryPluginManager(EnvironmentVariables.LibraryPluginDirectoryPath); // activate the provider plugin instance references from the interface definition libraryPluginManager.Activate(_InterfaceDefinitionData.RequiredPlugins.LibraryPlugins); } catch (LibraryPluginManagerException ex) { _Broadcaster.Error(ex, "LibraryPluginManager"); return(false); } catch (Exception ex) { _Broadcaster.Error(ex); return(false); } // initialize the SyneryMemory _SyneryMemory = new SyneryMemory(_SyneryDB, _Broadcaster, providerPluginManager, libraryPluginManager); // initialize the SyneryInterpreter _SyneryClient = new InterpretationClient(_SyneryMemory); // success _IsInitialized = true; return(true); }