コード例 #1
0
        /// <summary>
        /// Creates a new sones GQL instance
        /// </summary>
        /// <param name="myIGraphDBInstace">The graph database instance on which the gql statements are executed</param>
        public SonesQueryLanguage(IGraphDB myIGraphDBInstace)
        {
            _IGraphDBInstance = myIGraphDBInstace;
            _settings = new GraphApplicationSettings(SonesGQLConstants.ApplicationSettingsLocation);

            #region plugin manager

            _GQLPluginManager = new GQLPluginManager();

            #endregion

            #region create gql grammar and set extendable members

            _GQLGrammar = new SonesGQLGrammar(myIGraphDBInstace);

            SetExtendableMember(_GQLGrammar);

            #endregion

            //build parser
            _parser = new Parser(_GQLGrammar);

            //check language
            if (_parser.Language.ErrorLevel != GrammarErrorLevel.Warning && _parser.Language.ErrorLevel != GrammarErrorLevel.NoError)
            {
                throw new IronyInitializeGrammarException(_parser.Language.Errors, "");
            }
        }
コード例 #2
0
        private void SetExtendableMember(SonesGQLGrammar myGQLGrammar)
        {
            #region aggregate

            List<IGQLAggregate> aggregates = new List<IGQLAggregate>();
            foreach (var plugin in _GQLPluginManager.GetPluginNameForType<IGQLAggregate>())
            {
                aggregates.Add(_GQLPluginManager.GetAndInitializePlugin<IGQLAggregate>(plugin));
            }

            if (aggregates.Count == 0)
            {
                throw new GQLGrammarSetExtandableMemberException(typeof(IGQLAggregate), 
                            "There is no plugin found to set in GQL grammar.");
            }
            myGQLGrammar.SetAggregates(aggregates);

            #endregion

            #region functions

            List<IGQLFunction> functions = new List<IGQLFunction>();
            foreach (var plugin in _GQLPluginManager.GetPluginNameForType<IGQLFunction>())
            {
                functions.Add(_GQLPluginManager.GetAndInitializePlugin<IGQLFunction>(plugin) as IGQLFunction);
            }

            if (functions.Count == 0)
            {
                throw new GQLGrammarSetExtandableMemberException(typeof(IGQLFunction), 
                            "There is no plugin found to set in GQL grammar.");
            }
            myGQLGrammar.SetFunctions(functions);

            #endregion

            #region indces

            List<String> indices = new List<string>();

            indices.AddRange(_GQLPluginManager.GetPluginNameForType<ISonesVersionedIndex>());
            indices.AddRange(_GQLPluginManager.GetPluginNameForType<ISonesIndex>());

            if (indices.Count < 1)
            {
                throw new GQLGrammarSetExtandableMemberException(typeof(ISonesIndex),
                            @"There is no valid index plugin found to set in GQL grammar.");
                           
            }

            myGQLGrammar.SetIndices(indices);

            #endregion

            #region import

            List<IGraphDBImport> importer = new List<IGraphDBImport>();
            foreach (var plugin in _GQLPluginManager.GetPluginNameForType<IGraphDBImport>())
            {
                importer.Add(_GQLPluginManager.GetAndInitializePlugin<IGraphDBImport>(plugin));
            }

            if (importer.Count == 0)
            {
                throw new GQLGrammarSetExtandableMemberException(typeof(IGraphDBImport), 
                            "There is no plugin found to set in GQL grammar.");
            }
            myGQLGrammar.SetGraphDBImporter(importer);

            #endregion

            #region export

            List<IGraphDBExport> exporter = new List<IGraphDBExport>();
            foreach (var plugin in _GQLPluginManager.GetPluginNameForType<IGraphDBExport>())
            {
                exporter.Add(_GQLPluginManager.GetAndInitializePlugin<IGraphDBExport>(plugin));
            }

            if (exporter.Count == 0)
            {
                throw new GQLGrammarSetExtandableMemberException(typeof(IGraphDBExport), 
                            "There is no plugin found to set in GQL grammar.");
            }
            myGQLGrammar.SetGraphDBExporter(exporter);

            #endregion

            #region additional statements

            List<IGQLStatementPlugin> statements = new List<IGQLStatementPlugin>();
            foreach (var plugin in _GQLPluginManager.GetPluginNameForType<IGQLStatementPlugin>())
            {
                statements.Add(_GQLPluginManager.GetAndInitializePlugin<IGQLStatementPlugin>(plugin,
                    new Dictionary<string, object>
                    {
                        {"sonesGQL", myGQLGrammar},
                        {"graphDB", _IGraphDBInstance}
                    }));
            }

            myGQLGrammar.SetStatements(statements);

            #endregion
        }