Пример #1
0
        public InterpretationController(IInterpreterFactory factory, ISyneryMemory memory)
        {
            Factory = factory;
            Memory  = memory;

            State = InterpreationStateEnum.Ready;
        }
Пример #2
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);
        }
Пример #3
0
        public void SetupTest()
        {
            _SyneryMemory = new SyneryMemory(null, new DefaultBroadcaster(), null, null);
            _Client       = new RecordTypeDeclarationInterpretationClient(_SyneryMemory);
            _Code         = @"
#Meat(STRING Animal) : #One.Meal;
#WhiteWine() : #Two.Wine;
#RoseWine() : #Two.Wine;
#RedWine() : #Two.Wine;
";

            _CodeOne = @"
#Cheese(INT Year) : #Meal;
#Food(INT Weight);
#Meal(BOOL IsEatenCold) : #Food;
";

            _CodeTwo = @"
#Beverage(DOUBLE Liter) : #One.Food;
#Water(BOOL IsSparkling) : #Beverage;
#Wine(INT Year, STRING CountryOfOrigin) : #Beverage;
";

            _IncludeCode = new Dictionary <string, string>();
            _IncludeCode.Add("One", _CodeOne);
            _IncludeCode.Add("Two", _CodeTwo);
        }
        public InterpretationClient(ISyneryMemory memory)
        {
            Memory = memory;

            IInterpreterFactory factory = InterpreterFactory.GetDefaultInterpreterFactory();

            Controller = new InterpretationController(factory, memory);
        }
        public SyneryFunctionDeclarationInterpretationClient(ISyneryMemory memory, IAntlrErrorListener <int> lexerErrorListener = null, IAntlrErrorListener <IToken> parserErrorListener = null)
        {
            Memory              = memory;
            LexerErrorListener  = lexerErrorListener;
            ParserErrorListener = parserErrorListener;

            IInterpreterFactory factory = InterpreterFactory.GetDefaultInterpreterFactory();

            factory.SetInterpreter(new SyneryFunctionBlockInterpreter());

            Controller = new InterpretationController(factory, memory);
        }
        /// <summary>
        /// If an identifier is used in a function of an IncludeFile and references another
        /// Object (e.g. function or record type) from within the file the identifier must
        /// be prepended with the CodeFileAlias of that IncludeFile.
        /// This method checks whether we are currently in the scope of a function from an
        /// IncludeFile and if so it prepends the CodeFileAlias of the IncludeFile.
        /// </summary>
        /// <param name="memory"></param>
        /// <param name="identifier">The name of the object (without alias)</param>
        /// <returns></returns>
        public static string GetIdentifierBasedOnFunctionScope(ISyneryMemory memory, string identifier)
        {
            if (memory.CurrentScope != null)
            {
                // check whether the function call comes from a function scope that sits inside of an include file
                IFunctionScope surroundingFunctionScope = memory.CurrentScope.ResolveFunctionScope();

                if (surroundingFunctionScope != null &&
                    String.IsNullOrEmpty(surroundingFunctionScope.FunctionData.CodeFileAlias) == false)
                {
                    // prepend the CodeFileAlias of the current function scope to get the correct FullName of the requested function
                    return(GetFullName(identifier, surroundingFunctionScope.FunctionData.CodeFileAlias));
                }
            }

            return(identifier);
        }
        /// <summary>
        /// Checks whether the record type <paramref name="checkTypeName"/> is derived from or equals to the given
        /// <paramref name="baseTypeName"/> record type.
        /// </summary>
        /// <param name="memory">The current memory state. Is needed to access the list of record types.</param>
        /// <param name="checkTypeName">the full name of the type that should be checked</param>
        /// <param name="baseTypeName">the full name of the potential base type</param>
        /// <returns>true = type is derived from or equal to the base type</returns>
        public static bool IsDerivedType(ISyneryMemory memory, string checkTypeName, string baseTypeName)
        {
            if (checkTypeName == baseTypeName)
            {
                return(true);
            }

            IRecordType checkType = (from t in memory.RecordTypes.Values
                                     where t.Name == checkTypeName
                                     select t).FirstOrDefault();

            if (checkType == null)
            {
                throw new SyneryException(String.Format("Record type wiht name='{0}' not found", baseTypeName));
            }

            return(checkType.IsType(baseTypeName));
        }
Пример #8
0
        /// <summary>
        /// Tries to find the function declaration with the matching function signature. It also considers that a parameter
        /// isn't set because a default value is available
        ///
        /// EXAMPLE:
        ///
        /// myFunc(string first, string second = "default")
        ///     // do something...
        /// END
        ///
        /// // call with one parameter
        /// myFunc("first parameter");
        /// </summary>
        /// <param name="memory">the SyneryMemory that contains a list with all available functions.</param>
        /// <param name="identifier">the name of the function</param>
        /// <param name="listOfParameterTypes">the types of all available parameters</param>
        /// <returns></returns>
        public static IFunctionData FindSyneryFunctionDeclaration(ISyneryMemory memory, string identifier, SyneryType[] listOfParameterTypes)
        {
            // try to find function(s) with the same name with at least the same number of parameters as given
            IEnumerable <IFunctionData> listOfFunctionData =
                from f in memory.Functions
                where f.FullName == IdentifierHelper.GetIdentifierBasedOnFunctionScope(memory, identifier) &&
                f.FunctionDefinition.Parameters.Count >= listOfParameterTypes.Count()
                select f;

            // try to find the matching function signature
            // also consider that a parameter isn't set because a default value is available
            foreach (IFunctionData data in listOfFunctionData)
            {
                bool isMatching = true;

                for (int i = 0; i < data.FunctionDefinition.Parameters.Count; i++)
                {
                    if (listOfParameterTypes.Count() > i && listOfParameterTypes[i] != null)
                    {
                        SyneryType expectedType = data.FunctionDefinition.Parameters[i].Type;
                        SyneryType givenType    = listOfParameterTypes[i];

                        // compare the types of the expected parameter and the given value
                        if (givenType != expectedType)
                        {
                            // maybe these are two record-types which derive from each other
                            if (givenType.UnterlyingDotNetType != typeof(IRecord) ||
                                expectedType.UnterlyingDotNetType != typeof(IRecord))
                            {
                                isMatching = false;
                            }
                            else
                            {
                                string expectedTypeName = IdentifierHelper.GetFullName(expectedType.Name, data.CodeFileAlias);

                                if (!RecordHelper.IsDerivedType(memory, givenType.Name, expectedTypeName))
                                {
                                    isMatching = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        // no value given for the parameter: check whether there is a default value
                        if (data.FunctionDefinition.Parameters[i].DefaultValue == null)
                        {
                            isMatching = false;
                        }
                    }
                }

                // the current function declaration seems to match -> return it
                if (isMatching == true)
                {
                    return(data);
                }
            }

            // no matching function declaration found
            return(null);
        }
Пример #9
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);
        }
 public void SetupTest()
 {
     _SyneryMemory = new SyneryMemory(null, new DefaultBroadcaster(), null, null);
     _Client       = new RecordTypeDeclarationInterpretationClient(_SyneryMemory);
 }