private void SpotFeedRequestCallback( IAsyncResult ar ) { Thread.MemoryBarrier( ); var asyncChainedState = ( AsyncChainedState<TrackerState> ) ar.AsyncState; try { TrackerState result = this.currentRequest.EndRequest( ar ); if ( result.Error != null ) LogFailedRequestEnd( asyncChainedState, result ); bool needContinue = false; if ( result.Error == null || result.Error.Type == Data.ErrorType.ResponseHasNoData ) { // Might be there is a result from the prev.pages, so try to merge it: result = MergeWithExistingData( result, out needContinue ); // If it was an error with ResponseHasNoData, but there were data from the prev.pages, // then now result has Error == null. } bool isSubsequentRequestStarted = false; if ( result.Error == null ) { if ( !needContinue ) { LogSuccRequestEnd( asyncChainedState ); } else { this.currentRequest = new SpotFeedRequest( this.Id, this.currentRequest.Page + 1, asyncChainedState.Id, this.consequentErrorsCounter == null ? null : this.consequentErrorsCounter.UnexpectedForeignErrorsCounter ); // If isAborted but we're here then "bad" (timed out?) request was finished and closed. if ( !this.isAborted ) { this.currentRequest.BeginRequest( SpotFeedRequestCallback, asyncChainedState ); isSubsequentRequestStarted = true; } } } if ( !isSubsequentRequestStarted ) asyncChainedState.SetAsCompleted( result ); } catch ( Exception exc ) { asyncChainedState.SetAsCompleted( exc ); } }
public TestLocationRequest( RequestParams requestParams, string testXml ) : base(requestParams) { this.spotFeedRequest = new SpotFeedRequest( requestParams.Id, testXml, -1 ); }
public override IAsyncResult BeginReadLocation( AsyncCallback callback, object state ) { lock ( this.sync ) { if ( this.inCall ) throw new InvalidOperationException( "BeginReadLocation has already been called for this instance" ); this.inCall = true; } var asyncChainedState = new AsyncChainedState<TrackerState>( callback, state ); Lrid = asyncChainedState.Id; this.currentRequest = new SpotFeedRequest( this.Id, 0, asyncChainedState.Id, this.consequentErrorsCounter == null ? null : this.consequentErrorsCounter.UnexpectedForeignErrorsCounter ); Log.InfoFormat( "Created request for {0}, lrid {1}", this.Id, asyncChainedState.Id ); this.currentRequest.BeginRequest( SpotFeedRequestCallback, asyncChainedState ); return asyncChainedState.FinalAsyncResult; }