public Warp(IOutputWrite output) { this.Write = output; if (this.Write == null) { throw new GameException("Property Write is not set for Warp. "); } }
public Impulse(IOutputWrite output) { this.Write = output; if (this.Write == null) { throw new GameException("Property Write is not set for Impulse. "); } }
public Map(SetupOptions setupOptions, IOutputWrite write, IStarTrekKGSettings config, FactionName defaultHostile = null) { this.Config = config; this.Write = write; this.DefaultHostile = defaultHostile ?? FactionName.Klingon; this.Initialize(setupOptions); }
public async Task MultipleTasks(IReader[] readers, IOutputWrite <string, int> output, CancellationToken cancellationToken) { IReader reader = null; _asyncWaiters = new HashSet <Task>(); Predicate <Task> p = delegate(Task t) { return(t.IsCompleted == true || t.IsFaulted || t.IsCanceled); }; for (int i = 0; i < readers.Length; i++) { reader = readers[i]; _asyncWaiters.Add(Task.Factory.StartNew(async delegate(Object obj) { CustomData data = obj as CustomData; if (data == null) { return; } await SingularTask(data.r, output, CancellationToken.None); }, new CustomData { r = reader }).Unwrap()); } try { await Task.WhenAll(_asyncWaiters); } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { Debug.WriteLine("{0}:\n {1}", e.GetType().Name, e.Message); } } finally { while (_asyncWaiters.Count > 0) { _asyncWaiters.RemoveWhere(p); } } try { await OutputWriting(output, CancellationToken.None); } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { Debug.WriteLine("{0}:\n {1}", e.GetType().Name, e.Message); } } }
private async Task OutputWriting(IOutputWrite <string, int> output, CancellationToken cancellationToken) { _list = _cdic.OrderByDescending(i => i.Value).ThenBy(k => k.Key).ToList(); for (int i = 0; i < _list.Count; i++) { var item = _list.ElementAt(i); { output.Add(item.Key, item.Value); } } await Task.Yield(); }
public async Task SingularTask(IReader reader, IOutputWrite <string, int> output, CancellationToken cancellationToken) { char ch = '\0', prev = '\0'; string word = ""; IReader r = reader; bool error = true; bool asyncThread = _asyncWaiters != null ? true : false; while (error) { try { ch = asyncThread ? await r.awaitNext() : r.Next(); error = true; } catch (IndexOutOfRangeException) { error = false; } if (ch == '\t') { continue; } if (Char.IsLetter(ch)) { word += Char.ToLowerInvariant(ch); } if ((ch == ' ' && prev != '\0')) { if (!_cdic.ContainsKey(word)) { _cdic.AddOrUpdate(word, 1, (key, oldValue) => 1); } else { _cdic.AddOrUpdate(word, 0, (key, oldValue) => oldValue + 1); } word = ""; } prev = ch; } if (!asyncThread) { await OutputWriting(output, CancellationToken.None); } }
public Render(IOutputWrite write, IStarTrekKGSettings config) { this.Config = config; this.Write = write; this.Write.Config = config; }
public Regions(IMap map, IOutputWrite write) { this.Write = write; this.Map = map; }
public BlobEngine(IDatabase db, IInputReader reader, IOutputWrite writer) { this.db = db; this.reader = reader; this.writer = writer; }