/// <summary> /// Notifies the user that a Add Event request has failed. /// </summary> /// /// <param name="serverResponse">A container for information on the response from the server. Only /// failed responses can be passed into this method.</param> /// <param name="request"> The request that was sent to the server.</param> /// <param name="callback">The error callback.</param> private void NotifyAddEventError(ServerResponse serverResponse, AddEventRequest request, Action <AddEventRequest, AddEventError> errorCallback) { ReleaseAssert.IsTrue(serverResponse.Result != HttpResult.Success || serverResponse.HttpResponseCode != SuccessHttpResponseCode, "Input server request must describe an error."); switch (serverResponse.Result) { case HttpResult.Success: m_logging.LogVerboseMessage("Add Event request failed with http response code: " + serverResponse.HttpResponseCode); break; case HttpResult.CouldNotConnect: m_logging.LogVerboseMessage("Add Event request failed becuase a connection could be established."); break; default: m_logging.LogVerboseMessage("Add Event request failed for an unknown reason."); throw new ArgumentException("Invalid value for server response result."); } AddEventError error = new AddEventError(serverResponse); m_taskScheduler.ScheduleMainThreadTask(() => { errorCallback(request, error); }); }
/// <summary> /// Notifies the user that a Add Event request was successful. /// </summary> /// /// <param name="serverResponse">A container for information on the response from the server. Only /// successful responses can be passed into this method.</param> /// <param name="request"> The request that was sent to the server.</param> /// <param name="callback">The success callback.</param> private void NotifyAddEventSuccess(ServerResponse serverResponse, AddEventRequest request, Action <AddEventRequest> successCallback) { ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode, "Input server request must describe a success."); m_logging.LogVerboseMessage("AddEvent request succeeded."); m_taskScheduler.ScheduleMainThreadTask(() => { successCallback(request); }); }
/// <summary> /// Records a custom metrics event that occured within the context of a session. The /// behaviour of this method is identical to AddEvents method, with the exception /// that the request format accepts a single Event json object rather than an array. /// </summary> /// /// <param name="desc">The request description.</param> /// <param name="successCallback">The delegate which is called if the request was successful.</param> /// <param name="errorCallback">The delegate which is called if the request was unsuccessful. Provides /// a container with information on what went wrong.</param> public void AddEvent(AddEventRequestDesc desc, Action <AddEventRequest> successCallback, Action <AddEventRequest, AddEventError> errorCallback) { m_logging.LogVerboseMessage("Sending Add Event request."); var metricsAccessToken = m_dataStore.GetString("MetricsAccessToken"); var request = new AddEventRequest(desc, metricsAccessToken); m_serverRequestSystem.SendImmediateRequest(request, (IImmediateServerRequest sentRequest, ServerResponse serverResponse) => { ReleaseAssert.IsTrue(request == sentRequest, "Received request is not the same as the one sent!"); if (serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode) { NotifyAddEventSuccess(serverResponse, request, successCallback); } else { NotifyAddEventError(serverResponse, request, errorCallback); } }); }