Exemplo n.º 1
0
        public void SetupTest()
        {
            string solutionDirectoryPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())));

            _PluginMainDirectoryPath        = Path.Combine(solutionDirectoryPath, @"_TestData\InterfaceBooster\ProviderPluginDirectory");
            _LibraryPluginMainDirectoryPath = Path.Combine(solutionDirectoryPath, @"_TestData\InterfaceBooster\LibraryPluginDirectory");
            _DatabaseWorkingDirectoryPath   = Path.Combine(solutionDirectoryPath, @"_TestData\InterfaceBooster\SyneryDB", Guid.NewGuid().ToString());

            if (Directory.Exists(_DatabaseWorkingDirectoryPath))
            {
                Directory.Delete(_DatabaseWorkingDirectoryPath, true);
            }

            Directory.CreateDirectory(_DatabaseWorkingDirectoryPath);

            _Database    = new SyneryDB(_DatabaseWorkingDirectoryPath);
            _Broadcaster = new DefaultBroadcaster();

            _ProviderPluginManager = new ProviderPluginManager(_PluginMainDirectoryPath);
            _LibraryPluginManager  = new LibraryPluginManager(_LibraryPluginMainDirectoryPath);

            _SyneryMemory = new SyneryMemory(_Database, _Broadcaster, _ProviderPluginManager, _LibraryPluginManager);

            _SyneryClient = new InterpretationClient(_SyneryMemory);
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            _IsInitialized           = false;
            _InterfaceDefinitionData = null;
            _Broadcaster             = null;
            _SyneryClient            = null;
            EnvironmentVariables     = null;

            if (_SyneryDB != null)
            {
                _SyneryDB.Dispose();
            }
        }
Exemplo n.º 3
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);
        }