public void Stop() { if (State == TournamentProxyState.Stopped) { return; } try { State = TournamentProxyState.Stopping; //Stop the get requests thread getRequestsThreadShouldPause = true; if (getRequestsThread != null) { getRequestsThread.Abort(); } getRequestsThread = null; //End all process request threads foreach (System.Threading.Thread requestThread in processRequestThreads) { requestThread.Abort(); } processRequestThreads.Clear(); //Clear static files ClearProxyStaticFiles(); } catch { State = TournamentProxyState.Stopped; throw; } State = TournamentProxyState.Stopped; }
public void Pause() { if (State == TournamentProxyState.Started) { getRequestsThreadShouldPause = true; State = TournamentProxyState.Paused; } }
public void Resume() { if (State == TournamentProxyState.Paused) { getRequestsThreadShouldPause = false; lock (getRequestsThreadLock) { System.Threading.Monitor.PulseAll(getRequestsThreadLock); } State = TournamentProxyState.Started; } }
protected void getRequests() { bool continueGettingRequests = true; while (continueGettingRequests) { if (getRequestsThreadShouldPause) { lock (getRequestsThreadLock) { System.Threading.Monitor.Wait(getRequestsThreadLock); } } try { string result = new WebClient().DownloadString(ProxyUrl + proxyGetRequestsPath + "?sharedkey=" + _sharedKeyUrlEncoded); object[] requests = (object[])jsonSerializer.DeserializeObject(result); if (requests != null) { foreach (object request in requests) { if (request == null) { continue; } try { System.Threading.ThreadStart threadStart = new System.Threading.ThreadStart(() => handleRequest((Dictionary <string, Object>)request)); System.Threading.Thread thread = new System.Threading.Thread(threadStart); thread.Start(); } catch (Exception ex) { Program.logException(ex, String.Format(Resources.ProxyProcessRequestsFailed, request.ToString())); } } } State = TournamentProxyState.Started; } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { State = TournamentProxyState.Error; Program.logException(ex, getRequestsThreadShouldPause ? Resources.ProxyGetRequestsFailedPossibleThreadPause : Resources.ProxyGetRequestsFailed); } } }
protected void reply(object data) { try { if (data == null) { return; } object replyData = (data is object[]) ? data : new object[] { data }; string replyStr = jsonSerializer.Serialize(replyData); string result = new WebClient().UploadString(ProxyUrl.ToString() + proxyReplyPath + "?sharedkey=" + _sharedKeyUrlEncoded, replyStr); } catch (Exception ex) { State = TournamentProxyState.Error; Program.logException(ex, Resources.ProxyReplyFailed); } }
public void Start() { if (State != TournamentProxyState.Stopped) { return; } try { State = TournamentProxyState.Starting; ClearProxyStaticFiles(); UploadProxyStaticFiles(); startGettingRequests(); State = TournamentProxyState.Started; } catch { State = TournamentProxyState.Stopped; throw; } }