public bool Execute(string[] args)
        {
            IDictionary <string, string> parameters = InitializeParameters(args);

            if (parameters == null)
            {
                return(false);
            }

            if (parameters.ContainsKey("InterfaceDefinitionPath"))
            {
                if (InitializeProviderPluginDirectory(parameters["InterfaceDefinitionPath"]) == false)
                {
                    return(false);
                }

                ExecutionVariables environmentVariables = new ExecutionVariables()
                {
                    Broadcaster = Broadcaster,
                    InterfaceDefinitionDirectoryPath = parameters["InterfaceDefinitionPath"],
                };

                try
                {
                    Broadcaster.Info("Using interface definition from '{0}'", parameters["InterfaceDefinitionPath"]);

                    _CurrentRunner = new ExecutionManager();

                    if (_CurrentRunner.Initialize(environmentVariables) == false)
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Broadcaster.Error("An unexpected error occured while initializing the InterfaceDefinitionRunner: '{0}'.", ex.Message);
                    return(false);
                }

                if (parameters.ContainsKey("RunJob"))
                {
                    return(_CurrentRunner.RunJob(parameters["RunJob"]).IsSuccess);
                }
                else
                {
                    Broadcaster.Error("The startup parameter 'RunJob' must be set.");
                    return(false);
                }
            }
            else
            {
                Broadcaster.Error("The startup parameter 'InterfaceDefinitionPath' must be set.");
                return(false);
            }
        }
Beispiel #2
0
        /// <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);
        }