public void Execute(IServiceProvider serviceProvider) { ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); EBooksDB.Instance.Initialize(); try { QueryExpression query = context.InputParameterOrDefault <QueryExpression>("Query"); var visitor = new SearchVisitor(); query.Accept(visitor); EntityCollection results = new EntityCollection(); results.Entities.AddRange(EBooksDB.Instance.Ebooks.Entities); context.OutputParameters["BusinessEntityCollection"] = results; } catch (Exception e) { throw new InvalidPluginExecutionException(e.Message); } }
private TSqlExpression(QueryExpression expression, ICommandParameterFactory commandParameterFactory, string tableName) { _commandParameterFactory = commandParameterFactory; _tableName = tableName; CommandParameters = new List <CommandParameter>(); expression.Accept(this); }
public bool IsMatch() { _isMatch = true; _queryExpression.Accept(this); return(_isMatch); }
public static QueryExpression Rewrite(QueryExpression expression) { if (expression == null) { return(null); } return(expression.Accept(new Visitor(), null)); }
public override void Visit(QueryExpression node) { var visitor = new ChildBooleanComparisonVisitor(); node.Accept(visitor); if (visitor.UpperLowerFunctionCallInComparison) { QueryExpressionUpperLowerFunctionFound = true; } }
public static Expression <Func <TEntity, bool> > Translate(QueryExpression query) { if (query == null) { return(_ => true); } // Translate the query expression to a LINQ expression. var visitor = new QueryTranslator <TContext, TEntity>(); var context = new QueryTranslatorContext(typeof(TEntity)); var expression = query.Accept(visitor, context); // Parse the expression and rewrite it. return(Expression.Lambda <Func <TEntity, bool> >(expression, context.Parameter)); }
private EntityCollection RetrieveMultipleLogic(QueryExpression qe) { var collection = new EntityCollection(); if (qe != null) { var visitor = new WideWorlImportersQueryVisitor(); qe.Accept(visitor); var repo = new WideWorldImportersRepository(SQL, PUBLISHER); var task = repo.Search(qe.EntityName, visitor.SQLCriteria, visitor.Columns, visitor.Count).GetAwaiter().GetResult(); collection = task; } return(collection); }
public EntityCollection GetEntities(QueryExpression query) { _tracing.Trace("Entity Name: " + query.EntityName); var metadata = _service.GetEntityMetadata(query.EntityName); var visitor = new SqlVisitor(metadata); query.Accept(visitor); _tracing.Trace("Query: " + visitor.Query); var entities = ExecuteQuery(visitor.Query, metadata); return(new EntityCollection(entities.ToArray())); }
public static QueryExpression Rewrite(QueryExpression expression) { if (expression == null) { return(null); } expression = expression.Accept(new Visitor(), null); if (expression is PropertyExpression propertyExpression) { // A single property expression left? // Convert that one into a relational expression. expression = new RelationalExpression(propertyExpression, new ConstantExpression(true), RelationalOperator.EqualTo); } return(expression); }
public static Expression <Func <TEntity, bool> > Translate(QueryExpression query) { if (query == null) { var result = Expression.Constant(true); return(_ => true); } // Define the parameter that will be used with out lambda expression. var parameter = Expression.Parameter(typeof(TEntity), "entity"); // Translate the query expression to a LINQ expression. var visitor = new QueryTranslator <TContext, TEntity>(); var context = new QueryTranslatorContext(parameter); var expression = query.Accept(visitor, context); // Parse the expression and rewrite it. return(Expression.Lambda <Func <TEntity, bool> >(expression, parameter)); }
public QueryCustomFunctionCallExpression FindProcedure(QueryExpression expression) { expression.Accept(this); return this.procedureFunctionCall; }
public static IQueryState Resolve(QueryExpression queryExpression, ScopeParameterDictionary scopeParameters, KeyDictionary <string> scopeTables) { QueryExpressionResolver resolver = new QueryExpressionResolver(scopeParameters, scopeTables); return(queryExpression.Accept(resolver)); }
public QueryCustomFunctionCallExpression FindProcedure(QueryExpression expression) { expression.Accept(this); return(this.procedureFunctionCall); }
public static JoinQueryResult VisitQueryExpression(QueryExpression queryExpression, ResultElement resultElement, JoinType joinType, LambdaExpression conditionExpression, ScopeParameterDictionary scopeParameters) { JoinQueryExpressionVisitor visitor = new JoinQueryExpressionVisitor(resultElement, joinType, conditionExpression, scopeParameters); return(queryExpression.Accept(visitor)); }
public static IQueryState VisitQueryExpression(QueryExpression queryExpression, ScopeParameterDictionary scopeParameters, KeyDictionary <string> scopeTables) { QueryExpressionVisitor reducer = new QueryExpressionVisitor(scopeParameters, scopeTables); return(queryExpression.Accept(reducer)); }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns>Value of the expression.</returns> public string Convert(QueryExpression expression) { ExceptionUtilities.CheckArgumentNotNull(expression, "expression"); return(expression.Accept(this)); }
public void Execute(IServiceProvider serviceProvider) { ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); //https://api.chucknorris.io/#! try { QueryExpression query = context.InputParameterOrDefault <QueryExpression>("Query"); var visitor = new SearchVisitor(); query.Accept(visitor); EntityCollection results = new EntityCollection(); JokeIdHelper jokeIdHelper = new JokeIdHelper(); if (string.IsNullOrEmpty(visitor.SearchKeyWord)) { tracer.Trace("Getting random joke"); var getRandomJokeTask = Task.Run(async() => await GetRandomJoke(tracer)); Task.WaitAll(getRandomJokeTask); Result randomJoke = getRandomJokeTask.Result; Entity joke = JokeHelper.CreateJoke(tracer, randomJoke, jokeIdHelper); if (joke != null) { tracer.Trace($"Joke created: {joke.Id}"); results.Entities.Add(joke); } } else { tracer.Trace($"Searching jokes for: {visitor.SearchKeyWord}"); var getJokesByValueTask = Task.Run(async() => await GetJokesByValue(tracer, visitor.SearchKeyWord)); Task.WaitAll(getJokesByValueTask); Jokes jokes = getJokesByValueTask.Result; tracer.Trace($"Found {jokes.total} jokes"); foreach (Result result in jokes.result) { Entity joke = JokeHelper.CreateJoke(tracer, result, jokeIdHelper); if (joke == null) { continue; } tracer.Trace($"Joke created: {joke.GetAttributeValue<Guid>("lat_chucknorrisjokeid")}"); results.Entities.Add(joke); } } context.OutputParameters["BusinessEntityCollection"] = results; } catch (Exception e) { tracer.Trace($"{e.Message} {e.StackTrace}"); if (e.InnerException != null) { tracer.Trace($"{e.InnerException.Message} {e.InnerException.StackTrace}"); } throw new InvalidPluginExecutionException(e.Message); } }
public QueryCustomFunctionCallExpression ExtractServiceOperationCall(QueryExpression expression) { this.serviceOperationCallExpression = null; expression.Accept(this); return this.serviceOperationCallExpression; }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns>Value of the expression.</returns> internal string ComputeUriInternal(QueryExpression expression) { ExceptionUtilities.CheckArgumentNotNull(expression, "expression"); return(expression.Accept(this)); }
/// <summary> /// Replaces the query. /// </summary> /// <param name="queryExpression">Expression to replace.</param> /// <returns>Replaced expression.</returns> public new QueryExpression ReplaceExpression(QueryExpression queryExpression) { this.freeVariableAssignments = new Dictionary <string, ReadOnlyCollection <QueryExpression> >(); return(queryExpression.Accept(this)); }
/// <summary> /// Resolves the parameter names in the query expression (ensures that each parameter has a name). /// </summary> /// <param name="expression">The expression.</param> /// <returns>Resolved expression</returns> public QueryExpression ResolveParameterNames(QueryExpression expression) { return(expression.Accept(this)); }
/// <summary> /// Replaces the query. /// </summary> /// <param name="queryExpression">Expression to replace.</param> /// <returns>Replaced expression.</returns> public new QueryExpression ReplaceExpression(QueryExpression queryExpression) { this.freeVariableAssignments = new Dictionary<string, ReadOnlyCollection<QueryExpression>>(); return queryExpression.Accept(this); }
/// <summary> /// Replaces the expression. /// </summary> /// <param name="queryExpression">Expression to replace.</param> /// <returns>Replaced expression.</returns> public QueryExpression ReplaceExpression(QueryExpression queryExpression) { return(queryExpression.Accept(this)); }
public static JoinQueryResult Resolve(QueryExpression queryExpression, QueryModel queryModel, JoinType joinType, LambdaExpression conditionExpression, ScopeParameterDictionary scopeParameters) { JoinQueryExpressionResolver resolver = new JoinQueryExpressionResolver(queryModel, joinType, conditionExpression, scopeParameters); return(queryExpression.Accept(resolver)); }
public static IQueryState VisitQueryExpression(QueryExpression queryExpression) { return(queryExpression.Accept(_reducer)); }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns>Value of the expression.</returns> internal string ComputeUriInternal(QueryExpression expression) { ExceptionUtilities.CheckArgumentNotNull(expression, "expression"); return expression.Accept(this); }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns>Value of the expression.</returns> public QueryValue Evaluate(QueryExpression expression) { return(expression.Accept(this)); }
/// <summary> /// Resolves the parameter names in the query expression (ensures that each parameter has a name). /// </summary> /// <param name="expression">The expression.</param> /// <returns>Resolved expression</returns> public QueryExpression ResolveParameterNames(QueryExpression expression) { return expression.Accept(this); }
public void Execute(IServiceProvider serviceProvider) { //Get the trace provider ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); //get the execution context; IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); //Get the service agent IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); try { tracer.Trace("RetrieveMultiple is called"); QueryExpression query = context.InputParameterOrDefault <QueryExpression>("Query"); SearchVisitor visitor = new SearchVisitor(); query.Accept(visitor); IEntityDataSourceRetrieverService retrieveService = (IEntityDataSourceRetrieverService)serviceProvider.Get <IEntityDataSourceRetrieverService>(); Entity sourceEntity = retrieveService.RetrieveEntityDataSource(); string externalwebapiurl; if (string.IsNullOrEmpty(visitor.SearchKeyWords)) { //Get the settings of Data source externalwebapiurl = sourceEntity.GetAttributeValue <string>("new_externalwebapiurl") + "/Students"; } else { tracer.Trace("Search keywords is " + visitor.SearchKeyWords); //The search URL wil be like this: http://winstonodata4.azurewebsites.net/Students?$filter=contains(name,'D') externalwebapiurl = sourceEntity.GetAttributeValue <string>("new_externalwebapiurl") + "/Students?$filter=contains(name,'" + visitor.SearchKeyWords + "')"; } tracer.Trace("external web api url: " + externalwebapiurl); EntityCollection results = new EntityCollection(); results.EntityName = "new_student"; //Getting Data from ODATA tracer.Trace("Begin to get data"); var getAPIDataTask = Task.Run(async() => await HttpHelper.GetAPIdata(externalwebapiurl)); Task.WaitAll(getAPIDataTask); OData odata = getAPIDataTask.Result; foreach (QueryResult row in odata.Value) { Entity newrecord = new Entity("new_student"); newrecord.Attributes.Add("new_studentid", row.StudentId); newrecord.Attributes.Add("new_name", row.name); newrecord.Attributes.Add("new_familyaddress", row.familyaddress); //newrecord.Attributes.Add("new_age", row.age); //newrecord.Attributes.Add("new_grade", row.grade); newrecord.Attributes.Add("new_phoneno", row.phoneno); results.Entities.Add(newrecord); } context.OutputParameters["BusinessEntityCollection"] = results; } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } }
public virtual TResult Visit(QueryExpression expression, TArgument argument) { return(expression.Accept(this, argument)); }
/// <summary> /// Resolves type and body expression for functions in the model /// </summary> /// <param name="expression">the expression to resolve</param> /// <param name="strategy">the query evaluation strategy</param> /// <returns>the resolved expression</returns> public QueryExpression ResolveCustomFunctions(QueryExpression expression, IQueryEvaluationStrategy strategy) { this.queryEvaluationStrategy = strategy; return(expression.Accept(this)); }
/// <summary> /// Generates SystemCodeDom.CodeExpression tree representing Linq query using the method syntax along with free variables bound to the query. /// </summary> /// <param name="queryExpression">Expression from which code is generated.</param> /// <returns>Expression with free variables.</returns> public CodeExpressionWithFreeVariables GenerateQueryCode(QueryExpression queryExpression) { CodeExpression query = queryExpression.Accept(this); return(new CodeExpressionWithFreeVariables(query, this.freeVariables.Values)); }
public QueryCustomFunctionCallExpression ExtractServiceOperationCall(QueryExpression expression) { this.serviceOperationCallExpression = null; expression.Accept(this); return(this.serviceOperationCallExpression); }
public static JoinQueryResult VisitQueryExpression(QueryExpression queryExpression, ResultElement resultElement, DbJoinType joinType, LambdaExpression conditionExpression, List <IMappingObjectExpression> moeList) { JoinQueryExpressionVisitor visitor = new JoinQueryExpressionVisitor(resultElement, joinType, conditionExpression, moeList); return(queryExpression.Accept(visitor)); }
/// <summary> /// Generates System.CodeDom.CodeExpression from the given expression. /// </summary> /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param> /// <returns>Generated System.CodeDom.CodeExpression.</returns> protected CodeExpression GenerateCode(QueryExpression expression) { return(expression.Accept(this)); }
/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression to evaluate.</param> /// <returns>Value of the expression.</returns> public string Convert(QueryExpression expression) { ExceptionUtilities.CheckArgumentNotNull(expression, "expression"); return expression.Accept(this); }
/// <summary> /// Resolves type and body expression for functions in the model /// </summary> /// <param name="expression">the expression to resolve</param> /// <param name="strategy">the query evaluation strategy</param> /// <returns>the resolved expression</returns> public QueryExpression ResolveCustomFunctions(QueryExpression expression, IQueryEvaluationStrategy strategy) { this.queryEvaluationStrategy = strategy; return expression.Accept(this); }