Exemplo n.º 1
0
        internal static FanoutSearchModule GetClientModule()
        {
            FanoutSearchModule ret = new FanoutSearchModule();

            ret.ClientInitialize(RunningMode.Server);
            return(ret);
        }
Exemplo n.º 2
0
        /// <returns>null if no cached query result is found.</returns>
        internal AggregationObject GetCachedQueryResult(FanoutQueryMessageReader query)
        {
            string key = GetQueryResultCacheRequestKey(query);
            QueryResultCacheEntry entry = (QueryResultCacheEntry)m_memory_cache.Get(key);

            if (entry == null)
            {
                return(null);
            }
            int result_cnt = entry.aggregation_obj.results.Count;

            if (result_cnt < FanoutSearchModule.MinimalRequiredResultCount(query))
            {
                return(null);
            }

            Log.WriteLine(LogLevel.Debug, "QueryResultCache: Cache hit.");

            return(entry.aggregation_obj);
        }
Exemplo n.º 3
0
        private static Expression <Func <ICellAccessor, Action> > ConstructVisitNodeAction(ExpressionSyntax traverseAction)
        {
            /***********************************************
            * Syntax: (VISITNODE)
            *
            * 1. VisitNode(FanoutSearch.Action action, IEnumerable<string> select = null)
            * 2. VisitNode(Expression<Func<ICellAccessor, FanoutSearch.Action>> action, IEnumerable<string> select = null)
            *
            * The select part is handled by the caller.
            ***********************************************/

            var action_expr       = TryGet <MemberAccessExpressionSyntax>(traverseAction);
            var lambda_expression = TryGet <LambdaExpressionSyntax>(traverseAction);
            Expression <Func <ICellAccessor, Action> > ret = null;

            if (action_expr != null)
            {
                // Action enum
                var id_expr = Get <IdentifierNameSyntax>(action_expr.Expression);
                if (id_expr.ToString() != s_LIKQ_Action)
                {
                    goto throw_badtype;
                }

                Action result_action;
                ThrowIf(!Enum.TryParse(action_expr.Name.ToString(), out result_action), "Invalid traverse action", action_expr);

                return(ExpressionBuilder.WrapAction(result_action));
            }
            else
            {
                if (lambda_expression == null)
                {
                    goto throw_badtype;
                }

                // FanoutSearch.Action is ambiguous with with System.Action
                var action_visitor = new FanoutSearchActionRewritter();
                lambda_expression = action_visitor.Visit(lambda_expression) as LambdaExpressionSyntax;

                ScriptOptions scriptOptions = ScriptOptions.Default;
                var           mscorlib      = typeof(System.Object).Assembly;
                var           systemCore    = typeof(System.Linq.Enumerable).Assembly;
                var           expression    = typeof(Expression).Assembly;
                var           fanout        = typeof(FanoutSearchModule).Assembly;
                var           trinity       = typeof(Trinity.Global).Assembly;

                scriptOptions = scriptOptions.AddReferences(mscorlib, systemCore, expression, fanout, trinity);

                scriptOptions = scriptOptions.AddImports(
                    "System",
                    "System.Linq",
                    "System.Linq.Expressions",
                    "System.Collections.Generic",
                    "FanoutSearch",
                    "FanoutSearch.LIKQ",
                    "Trinity",
                    "Trinity.Storage");

                try
                {
                    //  Allocate a cancellation token source, which signals after our timeout setting (if we do have timeout setting)
                    CancellationToken cancel_token = default(CancellationToken);
                    if (FanoutSearchModule._QueryTimeoutEnabled())
                    {
                        checked
                        {
                            cancel_token = new CancellationTokenSource((int)FanoutSearchModule.GetQueryTimeout()).Token;
                        }
                    }
                    //  It is guaranteed that the lambda_expression is really a lambda.
                    //  Evaluating a lambda and expecting an expression tree to be obtained now.
                    using (var eval_task = CSharpScript.EvaluateAsync <Expression <Func <ICellAccessor, Action> > >(lambda_expression.ToString(), scriptOptions, cancellationToken: cancel_token))
                    {
                        eval_task.Wait(cancel_token);
                        ret = eval_task.Result;
                    }
                }
                catch (ArithmeticException) { /* that's a fault not an error */ throw; }
                catch { /*swallow roslyn scripting engine exceptions.*/ }

                ThrowIf(null == ret, "Invalid lambda expression.", traverseAction);
                return(ret);
            }

throw_badtype:
            ThrowIf(true, "Expecting an argument of type FanoutSearch.Action, or a lambda expression.", traverseAction);
            return(null);//not going to happen
        }
Exemplo n.º 4
0
 static MessageDispatcher()
 {
     s_ServerCount = Global.CloudStorage.ServerCount;
     s_Module      = Global.CloudStorage.GetCommunicationModule <FanoutSearchModule>();
 }