// Constructors // ReSharper disable MemberCanBeProtected.Global public SubQuery(ProjectionExpression projectionExpression, TranslatedQuery query, Parameter <Tuple> parameter, Tuple tuple, ItemMaterializationContext context) // ReSharper restore MemberCanBeProtected.Global { this.provider = context.Session.Query.Provider; var tupleParameterBindings = new Dictionary <Parameter <Tuple>, Tuple>(projectionExpression.TupleParameterBindings); var currentTranslatedQuery = query; var outerParameterContext = context.ParameterContext; var parameterContext = new ParameterContext(outerParameterContext); // Gather Parameter<Tuple> values from current ParameterScope for future use. outerParameterContext.SetValue(parameter, tuple); foreach (var tupleParameter in currentTranslatedQuery.TupleParameters) { var value = outerParameterContext.GetValue(tupleParameter); tupleParameterBindings[tupleParameter] = value; parameterContext.SetValue(tupleParameter, value); } this.projectionExpression = new ProjectionExpression( projectionExpression.Type, projectionExpression.ItemProjector, tupleParameterBindings, projectionExpression.ResultAccessMethod); var translatedQuery = new TranslatedQuery( query.DataSource, query.Materializer, query.ResultAccessMethod, tupleParameterBindings, EnumerableUtils <Parameter <Tuple> > .Empty); delayedQuery = new DelayedQuery <TElement>(context.Session, translatedQuery, parameterContext); context.Session.RegisterUserDefinedDelayedQuery(delayedQuery.Task); context.MaterializationContext.MaterializationQueue.Enqueue(MaterializeSelf); }
private void MaterializeSelf() { if (materializedSequence != null) { return; } materializedSequence = delayedQuery.ToList(); delayedQuery = null; }
/// <summary> /// Tries connecting to a peer specified by an IP end point. If the peer is already connected, it will be immediately returned. If /// a connection can not be made, the query will be cancelled. /// </summary> public Query<UDPPeer> Connect(IPEndPoint EndPoint) { UDPPeer peer; if (this._Peers.TryGetValue(EndPoint, out peer)) { return peer; } _ConnectionRequest cr; if (this._ConnectionRequests.TryGetValue(EndPoint, out cr)) { // If there is already a connection request, reset the timeout cr.Remain = this._Settings.ConnectionRequestTimeout; return cr.Query; } else { UDPHubSettings settings = this._Settings; DelayedQuery<UDPPeer> query = new DelayedQuery<UDPPeer>(); this._ConnectionRequests[EndPoint] = cr = new _ConnectionRequest { AcknowledgementNumber = settings.Random.Integer(), Delay = 0.0, Query = query, Remain = settings.ConnectionRequestTimeout, Time = 0.0 }; return query; } }