private void OnIOComplete(IAsyncResult result) { if (!result.CompletedSynchronously) { int asyncState = (int)result.AsyncState; IPersistencePipelineModule module = this.pendingModules[asyncState]; this.pendingModules[asyncState] = null; if (this.IOComplete(result, module)) { base.Complete(false, this.exception); } } }
private void OnIOComplete(IAsyncResult result) { if (result.CompletedSynchronously) { return; } int i = (int)result.AsyncState; IPersistencePipelineModule module = _pendingModules[i]; Fx.Assert(module != null, "There should be a pending result for this result"); _pendingModules[i] = null; if (IOComplete(result, module)) { Complete(false, _exception); } }
private void Abort() { for (int j = 0; j < _pendingModules.Length; j++) { IPersistencePipelineModule module = _pendingModules[j]; if (module != null) { try { module.Abort(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } throw Fx.Exception.AsError(new CallbackException(SRCore.PersistencePipelineAbortThrew(module.GetType().Name), exception)); } } } }
private bool IOComplete(IAsyncResult result, IPersistencePipelineModule module) { try { if (this.isLoad) { module.EndOnLoad(result); } else { module.EndOnSave(result); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.ProcessException(exception); } return(this.CompleteOne()); }
public IOAsyncResult(PersistencePipeline pipeline, bool isLoad, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { _pipeline = pipeline; _isLoad = isLoad; _pendingModules = _pipeline._modules.Where(value => value.IsIOParticipant).ToArray(); _remainingModules = _pendingModules.Length; bool completeSelf = false; if (_pendingModules.Length == 0) { completeSelf = true; } else { for (int i = 0; i < _pendingModules.Length; i++) { Fx.Assert(!completeSelf, "Shouldn't have been completed yet."); IPersistencePipelineModule module = _pendingModules[i]; IAsyncResult result = null; try { if (_isLoad) { result = module.BeginOnLoad(_pipeline._readWriteView, timeout, Fx.ThunkCallback(new AsyncCallback(OnIOComplete)), i); } else { result = module.BeginOnSave(_pipeline._readWriteView, _pipeline._writeOnlyView, timeout, Fx.ThunkCallback(new AsyncCallback(OnIOComplete)), i); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } _pendingModules[i] = null; ProcessException(exception); } if (result == null) { if (CompleteOne()) { completeSelf = true; } } else if (result.CompletedSynchronously) { _pendingModules[i] = null; if (IOComplete(result, module)) { completeSelf = true; } } } } if (completeSelf) { Complete(true, _exception); } }
public IOAsyncResult(PersistencePipeline pipeline, bool isLoad, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.pipeline = pipeline; this.isLoad = isLoad; this.pendingModules = (from value in this.pipeline.modules where value.IsIOParticipant select value).ToArray <IPersistencePipelineModule>(); this.remainingModules = this.pendingModules.Length; bool flag = false; if (this.pendingModules.Length == 0) { flag = true; } else { for (int i = 0; i < this.pendingModules.Length; i++) { IPersistencePipelineModule module = this.pendingModules[i]; IAsyncResult result = null; try { if (this.isLoad) { result = module.BeginOnLoad(this.pipeline.readWriteView, timeout, Fx.ThunkCallback(new AsyncCallback(this.OnIOComplete)), i); } else { result = module.BeginOnSave(this.pipeline.readWriteView, this.pipeline.writeOnlyView, timeout, Fx.ThunkCallback(new AsyncCallback(this.OnIOComplete)), i); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.pendingModules[i] = null; this.ProcessException(exception); } if (result == null) { if (this.CompleteOne()) { flag = true; } } else if (result.CompletedSynchronously) { this.pendingModules[i] = null; if (this.IOComplete(result, module)) { flag = true; } } } } if (flag) { base.Complete(true, this.exception); } }