2using System.Collections.Generic;
9 public 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 ) );
AsyncOperation(HttpWebRequest req, Action< StorageFile > callback, TimeSpan timeout)
Action< StorageFile > Callback
AsyncOperation(HttpWebRequest req, Action< StorageFile > callback)
List< AsyncOperation > ops
AsyncTrigger(List< AsyncOperation > operations, Action endAction)
AsyncTrigger(List< AsyncOperation > operations, TimeSpan timeout, Action endAction)
void DoWithCallback(IAsyncResult ar)
void TriggerOnComplete(Action callback, params AsyncOperation[] actions)
Laukaisee aliohjelman kun annetut operaatiot on suoritettu.
void Update(Time time)
Päivitysfunktio
AsyncOperation DoWithURL(string url, Action< StorageFile > callback)
Avaa tiedoston netistä (lukua varten) ja tekee sillä jotain.
void TriggerOnComplete(Action callback, TimeSpan timeout, params AsyncOperation[] actions)
Laukaisee aliohjelman kun annetut operaatiot on suoritettu.
SynchronousList< AsyncTrigger > triggers
virtual StorageFile Open(string fileName, bool write)
Avaa tiedoston.
AsyncOperation DoWithURL(string url, TimeSpan timeout, Action< StorageFile > callback)
Avaa tiedoston netistä (lukua varten) ja tekee sillä jotain.
AsyncOperation DoWith(string fileName, Action< StorageFile > callback)
Avaa tiedoston (lukua varten) ja tekee sillä jotain.
static Time Time
Peliaika. Sisältää tiedon siitä, kuinka kauan peliä on pelattu (Time.SinceStartOfGame) ja kuinka kaua...
Synkroninen lista, eli lista joka päivittyy vasta kun sen Update-metodia kutsutaan....
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
static readonly Time Zero
Nolla-aika