2 using System.Collections.Generic;
9 public abstract partial class FileManager : Updatable
20 get {
return Result ==
null ? true :
Result.IsCompleted; }
26 this.Callback = callback;
27 this.Lifetime = TimeSpan.FromSeconds( 15 );
30 public AsyncOperation( HttpWebRequest req, Action<StorageFile> callback, TimeSpan timeout )
33 this.Callback = callback;
34 this.Lifetime = timeout;
40 public List<AsyncOperation>
ops;
45 public AsyncTrigger( List<AsyncOperation> operations, Action endAction )
47 this.ops = operations;
48 this.onCompleted = endAction;
51 public AsyncTrigger( List<AsyncOperation> operations, TimeSpan timeout, Action endAction )
53 this.ops = operations;
54 this.onCompleted = endAction;
55 foreach ( var op
in ops ) op.Lifetime = timeout;
72 foreach ( var op
in trig.ops.FindAll( o => !o.IsCompleted ) )
74 op.Lifetime -= time.SinceLastUpdate;
76 if ( op.Lifetime.TotalSeconds <= 0 )
84 if ( trig.triggered + trig.failed >= trig.ops.Count )
109 using ( var f =
Open( fileName,
false ) )
134 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );
136 IAsyncResult result = request.BeginGetResponse(
DoWithCallback, op );
160 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );
162 IAsyncResult result = request.BeginGetResponse(
DoWithCallback, op );
172 WebResponse response = op.
Request.EndGetResponse( ar );
173 Stream resStream = response.GetResponseStream();
174 MemoryStream memStream =
new MemoryStream();
175 resStream.CopyStreamTo( memStream );
184 memStream.Seek( 0, SeekOrigin.Begin );
188 foreach ( var trig
in triggers.FindAll( t => t.ops.Any( o => o.Result == ar ) ) )
192 catch ( WebException )
223 triggers.Add(
new AsyncTrigger( actions.ToList().FindAll( o => !o.IsCompleted ), timeout, callback ) );