Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
            private TSqlExpression(QueryExpression expression, ICommandParameterFactory commandParameterFactory, string tableName)
            {
                _commandParameterFactory = commandParameterFactory;
                _tableName        = tableName;
                CommandParameters = new List <CommandParameter>();

                expression.Accept(this);
            }
Exemplo n.º 3
0
        public bool IsMatch()
        {
            _isMatch = true;

            _queryExpression.Accept(this);

            return(_isMatch);
        }
Exemplo n.º 4
0
        public static QueryExpression Rewrite(QueryExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            return(expression.Accept(new Visitor(), null));
        }
Exemplo n.º 5
0
            public override void Visit(QueryExpression node)
            {
                var visitor = new ChildBooleanComparisonVisitor();

                node.Accept(visitor);
                if (visitor.UpperLowerFunctionCallInComparison)
                {
                    QueryExpressionUpperLowerFunctionFound = true;
                }
            }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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()));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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;
            }
Exemplo n.º 12
0
        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);
            }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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;
 }
Exemplo n.º 19
0
        /// <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));
        }
Exemplo n.º 20
0
 /// <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));
 }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
 public static IQueryState VisitQueryExpression(QueryExpression queryExpression)
 {
     return(queryExpression.Accept(_reducer));
 }
Exemplo n.º 26
0
        /// <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);
        }
Exemplo n.º 27
0
 /// <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);
 }
Exemplo n.º 29
0
        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);
            }
        }
Exemplo n.º 30
0
 public virtual TResult Visit(QueryExpression expression, TArgument argument)
 {
     return(expression.Accept(this, argument));
 }
Exemplo n.º 31
0
 /// <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));
 }
Exemplo n.º 32
0
        /// <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);
 }
Exemplo n.º 34
0
        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));
        }
Exemplo n.º 35
0
 /// <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);
 }