private bool RunJob(InterfaceDefinitionJobData jobData) { // display some information about the job _Broadcaster.Info("Found the job with the name '{0}'.", jobData.Name); //_Broadcaster.Info("Description: '{0}'", jobData.Description); //_Broadcaster.Info("Estimated Duration: '{0}'", jobData.EstimatedDurationRemarks); string codeFileName = String.Format("{0}.sny", jobData.Id.ToString()); string codeFilePath = Path.Combine(EnvironmentVariables.InterfaceDefinitionCodeDirectoryPath, codeFileName); if (File.Exists(codeFilePath) == false) { _Broadcaster.Error("Code file of job '{0}' not found at '{1}'.", jobData.Name, codeFilePath); return(false); } try { string code = File.ReadAllText(codeFilePath); Dictionary <string, string> listOfIncludeCode = null; if (jobData.IncludeFiles != null && jobData.IncludeFiles.Count != 0) { listOfIncludeCode = new Dictionary <string, string>(); foreach (var includeFileData in jobData.IncludeFiles) { string includeFilePath = Path.Combine(EnvironmentVariables.FilesystemDirectoryPath, includeFileData.RelativePath); if (File.Exists(includeFilePath)) { string includeFileCode = File.ReadAllText(includeFilePath); listOfIncludeCode.Add(includeFileData.Alias, includeFileCode); } else { _Broadcaster.Warning("Include file of job '{0}' not found at '{1}'.", jobData.Name, includeFilePath); } } } _Broadcaster.Info("Start running the file at '{0}'.", codeFilePath); RunFile(code, listOfIncludeCode); _Broadcaster.Info("Finished executing the job '{0}'.", jobData.Name); } catch (SyneryException ex) { _Broadcaster.Error(ex, "Synery"); return(false); } catch (Exception ex) { _Broadcaster.Error("An unknown error occurred while running the job '{0}'. Message: '{1}'.", jobData.Name, ex.Message); return(false); } return(true); }
/// <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); }