コード例 #1
0
        public virtual void Validate(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if (myPluginManager.HasPlugin <IGQLFunction>(FuncName))
            {
                Function = myPluginManager.GetAndInitializePlugin <IGQLFunction>(FuncName);
            }
            else
            {
                throw new AggregateOrFunctionDoesNotExistException(FuncName);
            }

            #region parameter exceptions

            #region check number of parameters

            Boolean containsVariableNumOfParams = this.Function.GetParameters().Exists(p => p.VariableNumOfParams);

            if (this.Function.GetParameters().Count != Parameters.Count && (!containsVariableNumOfParams))
            {
                throw new FunctionParameterCountMismatchException(this.Function.PluginShortName, this.Function.GetParameters().Count, Parameters.Count);
            }
            else if (containsVariableNumOfParams && Parameters.Count == 0)
            {
                throw new FunctionParameterCountMismatchException(this.Function.PluginShortName, 1, Parameters.Count);
            }

            #endregion

            #endregion
        }
コード例 #2
0
ファイル: ImportNode.cs プロジェクト: zhouweiaccp/sones
        public override IQueryResult Execute(IGraphDB myGraphDB,
                                             IGraphQL myGraphQL,
                                             GQLPluginManager myPluginManager,
                                             String myQuery,
                                             SecurityToken mySecurityToken,
                                             Int64 myTransactionToken)
        {
            var sw = Stopwatch.StartNew();

            IEnumerable <IVertexView> result = null;

            var plugin = myPluginManager.GetAndInitializePlugin <IGraphDBImport>(ImportFormat.ToUpper());

            if (plugin != null)
            {
                try
                {
                    result = plugin.Import(SourceLocation,
                                           myGraphDB,
                                           myGraphQL,
                                           mySecurityToken,
                                           myTransactionToken,
                                           ParallelTasks,
                                           Comments,
                                           Offset,
                                           Limit,
                                           VerbosityType,
                                           Options);

                    return(QueryResult.Success(myQuery, SonesGQLConstants.GQL, result, (ulong)sw.ElapsedMilliseconds));
                }
                catch (ASonesException ex)
                {
                    return(QueryResult.Failure(myQuery, SonesGQLConstants.GQL, ex, result, (ulong)sw.ElapsedMilliseconds));
                }
                catch (Exception ex)
                {
                    return(QueryResult.Failure(myQuery, SonesGQLConstants.GQL, new UnknownException(ex), result, (ulong)sw.ElapsedMilliseconds));
                }
            }
            return(QueryResult.Failure(myQuery, ImportFormat, new ImportFormatDoesNotExistsException(ImportFormat)));
        }
コード例 #3
0
ファイル: DumpNode.cs プロジェクト: zhouweiaccp/sones
        public override IQueryResult Execute(IGraphDB myGraphDB,
                                             IGraphQL myGraphQL,
                                             GQLPluginManager myPluginManager,
                                             String myQuery,
                                             SecurityToken mySecurityToken,
                                             Int64 myTransactionToken)
        {
            var sw = Stopwatch.StartNew();

            try
            {
                if (_DumpFormat.ToString().ToUpper().Equals("GQL"))
                {
                    var plugin = myPluginManager.GetAndInitializePlugin <IGraphDBExport>("GQLEXPORT");

                    if (plugin != null)
                    {
                        var result = plugin.Export(_DumpDestination,
                                                   _DumpableGrammar,
                                                   myGraphDB,
                                                   myGraphQL,
                                                   mySecurityToken,
                                                   myTransactionToken,
                                                   _TypesToDump,
                                                   null,
                                                   _DumpType);

                        return(QueryResult.Success(myQuery, SonesGQLConstants.GQL, result, Convert.ToUInt64(sw.ElapsedMilliseconds)));
                    }
                }
                return(QueryResult.Failure(myQuery, SonesGQLConstants.GQL, new InvalidDumpFormatException(_DumpFormat.ToString(), string.Empty)));
            }
            catch (ASonesException ex)
            {
                return(QueryResult.Failure(myQuery, SonesGQLConstants.GQL, ex));
            }
            catch (Exception ex)
            {
                return(QueryResult.Failure(myQuery, SonesGQLConstants.GQL, new UnknownDBException(ex)));
            }
        }
コード例 #4
0
        public override void Validate(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if (!myPluginManager.HasPlugin <IGQLAggregate>(FuncName))
            {
                throw new AggregateOrFunctionDoesNotExistException(FuncName);
            }

            Aggregate = myPluginManager.GetAndInitializePlugin <IGQLAggregate>(FuncName);

            if (Parameters.Count != 1)
            {
                throw new AggregateParameterCountMismatchException(FuncName, 1, Parameters.Count);
            }

            _Parameter = Parameters.FirstOrDefault() as IDChainDefinition;
            if (_Parameter == null)
            {
                throw new AggregateNotAllowedException(this.FuncName);
            }

            _Parameter.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, false);
        }
コード例 #5
0
        /// <summary>
        /// <seealso cref=" ADescribeDefinition"/>
        /// </summary>
        public override IEnumerable <IVertexView> GetResult(
            GQLPluginManager myPluginManager,
            IGraphDB myGraphDB,
            SecurityToken mySecurityToken,
            Int64 myTransactionToken)
        {
            var resultingVertices = new List <IVertexView>();

            //aggregate name is not empty
            if (!String.IsNullOrEmpty(_AggregateName))
            {
                #region Specific aggregate

                //aggregate is user defined
                if (_AggregateName.Contains("."))
                {
                    //get plugin
                    var aggregate = myPluginManager.GetAndInitializePlugin <IGQLAggregate>(_AggregateName);

                    if (aggregate != null)
                    {
                        resultingVertices = new List <IVertexView>()
                        {
                            GenerateOutput(aggregate, _AggregateName)
                        };
                    }
                    else
                    {
                        throw new AggregateOrFunctionDoesNotExistException(typeof(IGQLAggregate), _AggregateName, "");
                    }
                }
                //try get aggregate
                else
                {
                    try
                    {
                        //get plugin
                        var aggregate = myPluginManager.GetAndInitializePlugin <IGQLAggregate>(_AggregateName);

                        if (aggregate != null)
                        {
                            resultingVertices = new List <IVertexView>()
                            {
                                GenerateOutput(aggregate, _AggregateName)
                            };
                        }
                        else
                        {
                            throw new AggregateOrFunctionDoesNotExistException(typeof(IGQLAggregate), _AggregateName, "");
                        }
                    }
                    catch (ASonesException e)
                    {
                        //maybe user forgot prefix 'sones.'
                        //get plugin
                        var aggregate = myPluginManager.GetAndInitializePlugin <IGQLAggregate>("SONES." + _AggregateName);

                        if (aggregate != null)
                        {
                            resultingVertices = new List <IVertexView>()
                            {
                                GenerateOutput(aggregate, "SONES." + _AggregateName)
                            };
                        }
                        else
                        {
                            throw new AggregateOrFunctionDoesNotExistException(typeof(IGQLAggregate), _AggregateName, "");
                        }
                    }
                }

                #endregion
            }
            else
            {
                #region All aggregates

                myPluginManager.GetPluginNameForType <IGQLAggregate>();
                foreach (var aggregateName in myPluginManager.GetPluginNameForType <IGQLAggregate>())
                {
                    var aggregate = myPluginManager.GetAndInitializePlugin <IGQLAggregate>(aggregateName);

                    if (aggregate != null)
                    {
                        resultingVertices.Add(GenerateOutput(aggregate, aggregateName));
                    }
                    else
                    {
                        throw new AggregateOrFunctionDoesNotExistException(typeof(IGQLAggregate), _AggregateName, "");
                    }
                }

                #endregion
            }

            return(resultingVertices);
        }
コード例 #6
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
        }