예제 #1
0
 /// <summary>
 /// Creates a proxy for a given type.  This method supports two discrete usage scenarios.<p/>
 /// If T is an interface, the target should be an implementation of that interface. In
 /// this scenario, T should be <i>explicitly</i> specified unless the type of <i>target</i>
 /// at the calling site is of that interface.  In other words, if the calling site has the
 /// <i>target</i> declared as the concrete implementation, the proxy will be generated
 /// for the implementation, rather than for the interface.
 ///
 /// If T is a class, the target should be an instance of that class, and a subclassing
 /// proxy will be created for it.  However, because target is specified in this case,
 /// the base class behavior will be ignored (it will all be delegated to the target).
 /// </summary>
 /// <typeparam name="T">The type to create the proxy for.  May be an interface or a
 /// concrete base class.</typeparam>
 /// <param name="invocationHandler">This is where you get to inject your logic.</param>
 /// <param name="predicate">Optional predicate to determine if the interception should happen.  Useful
 /// improving performance in certain situations</param>
 /// <returns>The new instance of the proxy that is an instance of T</returns>
 public static T CreateProxy <T>(Func <Invocation, object> invocationHandler, ProxyPredicate <T> predicate = null)
 {
     return(Proxy <T> .CreateProxy(default(T), invocationHandler, predicate));
 }
예제 #2
0
 ///  <summary>
 ///  Creates a proxy for a given type.  This method supports two discrete usage scenarios.<p/>
 ///  If T is an interface, the target should be an implementation of that interface. In
 ///  this scenario, T should be <i>explicitly</i> specified unless the type of <i>target</i>
 ///  at the calling site is of that interface.  In other words, if the calling site has the
 ///  <i>target</i> declared as the concrete implementation, the proxy will be generated
 ///  for the implementation, rather than for the interface.
 ///
 ///  If T is a class, the target should be an instance of that class, and a subclassing
 ///  proxy will be created for it.  However, because target is specified in this case,
 ///  the base class behavior will be ignored (it will all be delegated to the target).
 ///  </summary>
 ///  <typeparam name="T">The type to create the proxy for.  May be an interface or a
 ///  concrete base class.</typeparam>
 ///  <param name="invocationHandler">This is where you get to inject your logic.</param>
 ///  <param name="predicate">Optional predicate to determine if the interception should happen.  Useful
 ///  improving performance in certain situations</param>
 /// <param name="asyncMode">Controls what happens when an async invocation handler performs async related actions
 /// where the original method being proxied is not an async method.</param>
 /// <returns>The new instance of the proxy that is an instance of T</returns>
 public static T CreateProxy <T>(Func <Invocation, Task <object> > invocationHandler, ProxyPredicate <T> predicate = null,
                                 AsyncInvocationMode asyncMode = AsyncInvocationMode.Throw)
 {
     return(CreateProxy(default(T), invocationHandler, predicate, asyncMode));
 }
예제 #3
0
 /// <summary>
 /// Creates a proxy for a given type.  This method supports two discrete usage scenarios.<p/>
 /// If T is an interface, the target should be an implementation of that interface. In
 /// this scenario, T should be <i>explicitly</i> specified unless the type of <i>target</i>
 /// at the calling site is of that interface.  In other words, if the calling site has the
 /// <i>target</i> declared as the concrete implementation, the proxy will be generated
 /// for the implementation, rather than for the interface.
 ///
 /// If T is a class, the target should be an instance of that class, and a subclassing
 /// proxy will be created for it.  However, because target is specified in this case,
 /// the base class behavior will be ignored (it will all be delegated to the target).
 /// </summary>
 /// <typeparam name="T">The type to create the proxy for.  May be an interface or a
 /// concrete base class.</typeparam>
 /// <param name="target">The instance of T that should be the recipient of all invocations
 /// on the proxy via Invocation.Proceed.</param>
 /// <param name="invocationHandler">This is where you get to inject your logic.</param>
 /// <param name="predicate">Optional predicate to determine if the interception should happen.  Useful
 /// improving performance in certain situations</param>
 /// <param name="asyncMode">Controls what happens when an async invocation handler performs async related actions
 /// where the original method being proxied is not an async method.</param>
 /// <returns>The new instance of the proxy that is an instance of T</returns>
 public static T CreateProxy <T>(T target, Func <Invocation, Task <object> > invocationHandler, ProxyPredicate <T> predicate = null,
                                 AsyncInvocationMode asyncMode = AsyncInvocationMode.Throw)
 {
     return(Proxy <T> .CreateProxy(target, invocationHandler, predicate, asyncMode));
 }
예제 #4
0
 /// <summary>
 /// Creates a proxy for a given type.  This method supports two discrete usage scenarios.<p/>
 /// If T is an interface, the target should be an implementation of that interface. In
 /// this scenario, T should be <i>explicitly</i> specified unless the type of <i>target</i>
 /// at the calling site is of that interface.  In other words, if the calling site has the
 /// <i>target</i> declared as the concrete implementation, the proxy will be generated
 /// for the implementation, rather than for the interface.
 ///
 /// If T is a class, the target should be an instance of that class, and a subclassing
 /// proxy will be created for it.  However, because target is specified in this case,
 /// the base class behavior will be ignored (it will all be delegated to the target).
 /// </summary>
 /// <typeparam name="T">The type to create the proxy for.  May be an interface or a
 /// concrete base class.</typeparam>
 /// <param name="target">The instance of T that should be the recipient of all invocations
 /// on the proxy via Invocation.Proceed.</param>
 /// <param name="invocationHandler">This is where you get to inject your logic.</param>
 /// <param name="predicate">Optional predicate to determine if the interception should happen.  Useful
 /// improving performance in certain situations</param>
 /// <returns>The new instance of the proxy that is an instance of T</returns>
 public static T CreateProxy <T>(T target, Func <Invocation, object> invocationHandler, ProxyPredicate <T> predicate = null)
 {
     return(Proxy <T> .CreateProxy(target, invocationHandler, predicate));
 }
예제 #5
0
        public QueryPlan GetQueryPlan(IDmObject parsedQuery, IQuery query, IQueryStore queryStore, MetadataIndex rowsEnumerator)
        {
            //Todo: Plan's cache's key decision (query-string based plan cache/optimizable-section based cache).
            OrderedList <double, IProxyPredicate> sortedPlans = new OrderedList <double, IProxyPredicate>();
            var optimizableQuery = parsedQuery as IFilterObject;

            var criteria  = AddQueryCriteria(parsedQuery, query.Parameters, queryStore);
            var queryPlan = new QueryPlan {
                Criteria = criteria
            };

            if (optimizableQuery != null && optimizableQuery.WherePredicate != null)
            {
                ITreePredicate whereExpression = optimizableQuery.WherePredicate;

                ITreePredicate contractedExpression = whereExpression.Contract();

                if (contractedExpression == null)
                {
                    contractedExpression = whereExpression;
                }

                List <ITreePredicate> distribCombinations = new List <ITreePredicate>();
                distribCombinations.Add(contractedExpression);

                //Todo: Restrict this call if there doesn't exist a compound index.
                while (contractedExpression.Expand() != null)
                {
                    distribCombinations.Add(contractedExpression.Expand());
                    contractedExpression = contractedExpression.Expand();
                }

                foreach (var treePredicate in distribCombinations)
                {
                    if (treePredicate is OrTreePredicate || treePredicate is AndTreePredicate)
                    {
                        break;
                    }
                    if (treePredicate is ComparisonPredicate)
                    {
                        DocumentKey documentKey = null;
                        if (((ComparisonPredicate)treePredicate).TryGetProxyKeyPredicate(rowsEnumerator, out documentKey))
                        {
                            IProxyPredicate optimizablePredicate = new ProxyPredicate(new KeyPredicate(documentKey, rowsEnumerator), treePredicate);
                            sortedPlans.Add(optimizablePredicate.Statistics[Statistic.ExpectedIO], optimizablePredicate);
                            queryPlan.Predicate = sortedPlans.FirstValues[0].GetExecutionPredicate(queryStore);
                            return(queryPlan);
                        }
                    }
                }

                foreach (var expressionState in distribCombinations)
                {
                    IProxyPredicate optimizablePredicate = expressionState.GetProxyExecutionPredicate(_indexManager, queryStore, rowsEnumerator);
                    sortedPlans.Add(optimizablePredicate.Statistics[Statistic.ExpectedIO], optimizablePredicate);
                    //Todo: Add optimizedPredicate to the SortedList by the cost.
                }

                queryPlan.Predicate = sortedPlans.FirstValues[0].GetExecutionPredicate(queryStore);
            }
            else
            {
                if (criteria.GroupFields != null && criteria.GroupFields.Count == 1 && criteria.GroupFields[0] is AllField && criteria.ContainsAggregations)
                {
                    if (criteria.Aggregations.Count == 1 && criteria.Aggregations[0].Aggregation is COUNT &&
                        criteria.Aggregations[0].Evaluation is AllEvaluable)
                    {
                        queryPlan.Criteria.GroupByField = null;
                        queryPlan.Predicate             = new SpecialCountPredicate(rowsEnumerator.KeyCount);
                        queryPlan.IsSpecialExecution    = true;
                        return(queryPlan);
                    }
                }

                //Todo:1 Projection variable-based index assigning (Functions' arguments + attributes).
                queryPlan.Predicate = GetSelectAllPredicate(criteria, rowsEnumerator);
            }

            return(queryPlan);
        }