// 20141020 squeezing a task to its proxy public virtual bool UpdateTask(ITestTask task) // public virtual bool UpdateTask(ITestTaskStatusProxy task) { // TODO: try several times try { // 20141211 // TODO: AOP Trace.TraceInformation("UpdateTask(ITestTask task).1: task id = {0}, task name = {1}, url = {2}", task.Id, task.Name, UrlList.TestTasks_Root + "/" + task.Id); // 20141215 // _restTemplate.Put(UrlList.TestTasks_Root + "/" + task.Id, task); var updatingTaskResponse = _restTemplate.Exchange(UrlList.TestTasks_Root + "/" + task.Id, HttpMethod.PUT, new HttpEntity(task)); Trace.TraceInformation("UpdateTask(ITestTask task).2"); if (HttpStatusCode.OK == updatingTaskResponse.StatusCode) { return(true); } throw new UpdateTaskException("Failed to update task '" + task.Name + "'"); // 20141215 // return true; } catch (Exception eOnUpdatingTask) { // TODO: AOP Trace.TraceError("UpdateTask(ITestTask task)"); Trace.TraceError(eOnUpdatingTask.Message); throw new UpdateTaskException("Failed to update task '" + task.Name + "'"); } }
public virtual void Send(string status) { // TODO: add an error handler (??) try { Trace.TraceInformation("Send(string status).1"); // 20141215 // _restTemplate.Put(UrlList.TestClients_Root + "/" + ClientSettings.Instance.ClientId + "/status", new DetailedStatus(status)); var detailedStatusSendingResponse = _restTemplate.Exchange(UrlList.TestClients_Root + "/" + ClientSettings.Instance.ClientId + "/status", HttpMethod.PUT, new HttpEntity(new DetailedStatus(status))); if (HttpStatusCode.OK == detailedStatusSendingResponse.StatusCode) { return; } Trace.TraceInformation("Send(string status).2 HttpStatusCode.Created != detailedStatusSendingResponse.StatusCode"); throw new SendingDetailedStatusException("Failed to send detailed status. " + detailedStatusSendingResponse.StatusCode); } catch (RestClientException eSendingDetialedStatus) { // TODO: AOP Trace.TraceError("Send(string status)"); Trace.TraceError(eSendingDetialedStatus.Message); throw new SendingDetailedStatusException("Failed to send detailed status. " + eSendingDetialedStatus.Message); } }
public virtual void UnregisterClient() { CloseCurrentTaskIfAny(); try { // 20141211 // TODO: AOP Trace.TraceInformation("UnregisterClient().1: client id = {0}, url = {1}", ClientSettings.Instance.ClientId, UrlList.TestClients_Root + "/" + ClientSettings.Instance.ClientId); // 20141216 // _restTemplate.Delete(UrlList.TestClients_Root + "/" + ClientSettings.Instance.ClientId); var unregisteringClientResponse = _restTemplate.Exchange(UrlList.TestClients_Root + "/" + ClientSettings.Instance.ClientId, HttpMethod.DELETE, null); if (HttpStatusCode.NoContent != unregisteringClientResponse.StatusCode) { throw new ClientDeregistrationException("Failed to unregister the client"); } ClientSettings.Instance.ResetData(); Trace.TraceInformation("UnregisterClient().2"); } catch (RestClientException eUnregisteringClient) { // TODO: AOP Trace.TraceError("UnregisterClient()"); Trace.TraceError(eUnregisteringClient.Message); throw new ClientDeregistrationException("Failed to unregister the client. " + eUnregisteringClient.Message); } }
// 20141020 squeezing a task to its proxy ITestTask AcceptCurrentTask(ITestTask task) // ITestTaskProxy acceptCurrentTask(ITestTaskCodeProxy task) { Trace.TraceInformation("acceptCurrentTask(ITestTask task).1"); if (null == task) { throw new AcceptTaskException("Failed to accept task."); } // 20141211 // TODO: AOP Trace.TraceInformation("acceptCurrentTask(ITestTask task).2: task id = {0}", task.Id); task.TaskStatus = TestTaskStatuses.Running; task.StartTimer(); try { // 20141211 // TODO: AOP Trace.TraceInformation("acceptCurrentTask(ITestTask task).3: task id = {0}, url = {1}", task.Id, UrlList.TestTasks_Root + "/" + task.Id); // 20141215 // _restTemplate.Put(UrlList.TestTasks_Root + "/" + task.Id, task); var acceptingTaskResponse = _restTemplate.Exchange(UrlList.TestTasks_Root + "/" + task.Id, HttpMethod.PUT, new HttpEntity(task)); Trace.TraceInformation("acceptCurrentTask(ITestTask task).4"); if (HttpStatusCode.OK == acceptingTaskResponse.StatusCode) { return(task); } throw new AcceptTaskException("Failed to accept task '" + task.Name + "'"); // 20141215 // return task; } catch (RestClientException eAcceptingTask) { // TODO: AOP Trace.TraceError("acceptCurrentTask(ITestTask task)"); Trace.TraceError(eAcceptingTask.Message); throw new AcceptTaskException("Failed to accept task '" + task.Name + "'. " + eAcceptingTask.Message); } }