void SendSettings() { try { string sSettings = Newtonsoft.Json.JsonConvert.SerializeObject(_process.Settings, Formatting.None, new JsonSerializerSettings { ContractResolver = new ezPrivateContractResolver() }); string url = ServerUrl(ezBuildRequestMessageType.POSTConfiguration); HttpHelper.ResponseResult response = HttpHelper.POST(url, sSettings); if (response == null) { Console.WriteLine("SendSettings: Server not responding at URL '{0}'.", url); return; } if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine("SendSettings: Server returned statusCode '{0}'.", response.StatusCode); return; } lock (_Lock) { _sID = response.Message; } Console.WriteLine("SendSettings: New BuidMachine ID is '{0}'.", _sID); } catch (Exception ex) { Console.WriteLine("SendSettings Failed: {0}.", ex.Message); } }
void HandleRunRequest(int iRevision, bool bClean = false) { lock (_Lock) { _bIsBuilding = true; } string sFilename = _process.GetResultFilename(iRevision); string sResults = null; // Check whether we have already run this build before. try { string sResultPath = System.IO.Path.Combine(_process.Settings.AbsOutputFolder, sFilename); if (System.IO.File.Exists(sResultPath)) { sResults = System.IO.File.ReadAllText(sResultPath, Encoding.UTF8); } } catch (Exception) { } // Run build process as we don't have the result for this revision. if (sResults == null) { bool bRes = _process.Run(iRevision, bClean); sResults = _process.GetJSON(); } // Send result to server. try { string url = ServerUrl(ezBuildRequestMessageType.POSTBuildResult) + string.Format("&File={0}", sFilename); HttpHelper.ResponseResult response = HttpHelper.POST(url, sResults); if (response == null) { Console.WriteLine("HandleRunRequest: Server not responding at URL '{0}'.", url); } else if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine("HandleRunRequest: Server returned statusCode '{0}'.", response.StatusCode); } else { Console.WriteLine("HandleRunRequest: Build results for rev. '{0}' sent successfully.", iRevision); } } catch (Exception ex) { Console.WriteLine("HandleRunRequest Failed: {0}.", ex.Message); } lock (_Lock) { _bIsBuilding = false; } }
void PostToAddress(string sData, string sAddress) { HttpHelper.ResponseResult response = HttpHelper.POST(sAddress, sData); if (response == null) { throw new System.Exception(String.Format("Server not responding at URL '{0}'", sAddress)); } if (response.StatusCode != HttpStatusCode.OK) { throw new System.Exception(String.Format("Server '{0}' returned statusCode '{1}'", sAddress, response.StatusCode)); } }
void PingServer() { string url = ServerUrl(ezBuildRequestMessageType.GETPing); HttpHelper.ResponseResult response = HttpHelper.GET(url); if (response == null) { Console.WriteLine("PingServer: Server not responding at URL '{0}'.", url); return; } if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine("PingServer: Server returned statusCode '{0}'.", response.StatusCode); return; } }
void RequestWork() { string url = ServerUrl(ezBuildRequestMessageType.GETWork); HttpHelper.ResponseResult response = HttpHelper.GET(url); if (response == null) { Console.WriteLine("RequestWork: Server not responding at URL '{0}'.", url); return; } if (response.StatusCode == HttpStatusCode.BadRequest) { SendSettings(); return; } if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine("RequestWork: Server returned StatusCode '{0}'.", response.StatusCode); return; } try { ezGETWorkResponse workResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <ezGETWorkResponse>(response.Message); if (workResponse.Response == ezGETWorkResponse.WorkResponse.RunBuild) { HandleRunRequest(workResponse.Revision); return; } else if (workResponse.Response == ezGETWorkResponse.WorkResponse.RunBuildAndClean) { HandleRunRequest(workResponse.Revision, true); return; } } catch (Exception ex) { Console.WriteLine("RequestWork Failed: {0}.", ex.Message); } }