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;
38 private class AsyncTrigger
40 public List<AsyncOperation> ops;
41 public Action onCompleted;
42 public int triggered = 0;
43 public int failed = 0;
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;
63 get {
return triggers.
Count > 0; }
70 foreach ( var trig
in triggers )
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 )
86 triggers.Remove( trig );
109 using ( var f =
Open( fileName,
false ) )
134 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );
136 IAsyncResult result = request.BeginGetResponse( DoWithCallback, op );
158 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );
160 IAsyncResult result = request.BeginGetResponse( DoWithCallback, op );
165 private void DoWithCallback(IAsyncResult ar)
170 WebResponse response = op.
Request.EndGetResponse( ar );
171 Stream resStream = response.GetResponseStream();
172 MemoryStream memStream =
new MemoryStream();
173 resStream.CopyStreamTo( memStream );
177 memStream.Seek( 0, SeekOrigin.Begin );
181 foreach ( var trig
in triggers.
FindAll( t => t.ops.Any( o => o.Result == ar ) ) )
185 catch ( WebException we )
199 triggers.
Add(
new AsyncTrigger( actions.ToList().FindAll( o => !o.IsCompleted ), callback ) );
216 triggers.
Add(
new AsyncTrigger( actions.ToList().FindAll( o => !o.IsCompleted ), timeout, callback ) );
Action< StorageFile > Callback
void TriggerOnComplete(Action callback, params AsyncOperation[] actions)
Laukaisee aliohjelman kun annetut operaatiot on suoritettu.
void Update(Time time)
Lisää ja poistaa jonossa olevat elementit sekä kutsuu niiden Update-metodia.
abstract StorageFile Open(string fileName, bool write)
AsyncOperation(HttpWebRequest req, Action< StorageFile > callback)
void TriggerOnComplete(Action callback, TimeSpan timeout, params AsyncOperation[] actions)
Laukaisee aliohjelman kun annetut operaatiot on suoritettu.
AsyncOperation DoWithURL(string url, Action< StorageFile > callback)
Avaa tiedoston netistä (lukua varten) ja tekee sillä jotain.
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Peliluokka reaaliaikaisille peleille.
AsyncOperation DoWithURL(string url, TimeSpan timeout, Action< StorageFile > callback)
Avaa tiedoston netistä (lukua varten) ja tekee sillä jotain.
int Count
Kuinka monta elementtiä listassa nyt on. Ei laske mukaan samalla päivityskierroksella tehtyjä muutoks...
static Time Time
Peliaika. Sisältää tiedon siitä, kuinka kauan peliä on pelattu (Time.SinceStartOfGame) ja kuinka kaua...
List< T > FindAll(Predicate< T > pred)
AsyncOperation(HttpWebRequest req, Action< StorageFile > callback, TimeSpan timeout)
AsyncOperation DoWith(string fileName, Action< StorageFile > callback)
Avaa tiedoston (lukua varten) ja tekee sillä jotain.
static readonly Time Zero