/// <summary> /// Shutdowns the specified world identifier. /// </summary> /// <param name="worldId">The world identifier.</param> /// <param name="cancelToken">The cancel token.</param> /// <param name="stream">The stream.</param> private void Shutdown(string worldId, CancellationToken cancelToken, EeStream stream) { Console.WriteLine("Received signal to cancel for " + worldId); GlobalConnection.Disconnect(); stream.Shutdown(); Core.pool.PutObject(GlobalConnect); Console.WriteLine(worldId + " cleaned up. Bye!"); cancelToken.ThrowIfCancellationRequested(); }
/// <summary> /// Crawls the specified world identifier. /// </summary> /// <param name="worldId">The world identifier.</param> /// <param name="cancelToken">The cancel token.</param> public void Crawl(string worldId, CancellationToken cancelToken) { TheWorldId = worldId; var eeEvent = new EeStream(worldId); Client.Multiplayer.JoinRoom(worldId, null, // never create a new room. Ever! delegate(Connection connection) { GlobalConnection = connection; _stopwatch = new Stopwatch(); _stopwatch.Start(); Console.WriteLine(Client.ConnectUserId + " is connected to " + worldId); GlobalConnection.Send("init"); GlobalConnection.Send("init2"); GlobalConnection.OnMessage += delegate(object sender, Message m) { eeEvent.Write(m, _stopwatch.Elapsed.TotalSeconds); }; GlobalConnection.OnDisconnect += delegate(object sender, string message) { if (message == "receivedBytes == 0") { Console.WriteLine("Disconnected because of immediate kick"); } else { Console.WriteLine("Connection disconnected for " + worldId); } if (!cancelToken.IsCancellationRequested) { Shutdown(worldId, cancelToken, eeEvent); } }; }); //http://msdn.microsoft.com/en-us/library/system.timers.timer%28v=vs.110%29.aspx // Create a timer with a two second interval. // Hook up the Elapsed event for the timer. Core.ATimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { //Console.WriteLine("Timer fired for " + worldId); if (cancelToken.IsCancellationRequested) { Shutdown(worldId, cancelToken, eeEvent); } }; Console.WriteLine("Got to end of function."); }