private void SaveResponseData(AsyncExecutionResponse response, int retryCount = 5)
        {
            Args.ThrowIfNull(response, "response");
            Args.ThrowIfNull(response.Request, "response.Request");
            response.ResultJson = response.Result?.ToJson() ?? "";
            string responseHash = response.ResultJson.Sha256();

            AsyncExecutionData executionData = AsyncCallbackRepository.OneAsyncExecutionDataWhere(c => c.RequestCuid == response.Request.Cuid);

            if (executionData == null)
            {
                Logger.Warning("Recieved response without corresponding ASYNCEXECUTIONDATA entry: \r\n{0}", response.PropertiesToString());
            }
            else
            {
                executionData.ResponseCuid = response.Cuid;
                executionData.Responded    = new Instant(DateTime.UtcNow);
                executionData.ResponseHash = responseHash;
                executionData.Success      = true;

                AsyncCallbackRepository.Save(executionData);
            }

            AsyncExecutionRequestData requestData = AsyncCallbackRepository.OneAsyncExecutionRequestDataWhere(c => c.Cuid == response.Request.Cuid);

            if (requestData == null)
            {
                Thread.Sleep(100);
                if (retryCount > 0)
                {
                    Logger.Warning("Received response without corresponding ASYNCEXECUTIONREQUESTDATA entry (retry count={0}): \r\n{1}", retryCount, response.PropertiesToString());
                    SaveResponseData(response, --retryCount);
                }
                return;
            }

            AsyncExecutionResponseData responseData = AsyncCallbackRepository.OneAsyncExecutionResponseDataWhere(c => c.Cuid == response.Cuid);

            if (responseData != null)
            {
                Logger.Warning("Received response that has already been recorded: {0}", response.PropertiesToString());
            }
            else
            {
                responseData = new AsyncExecutionResponseData
                {
                    RequestId    = requestData.Id,
                    ResultJson   = response.ResultJson,
                    ResponseHash = responseHash,
                    RequestHash  = requestData.RequestHash
                };

                AsyncCallbackRepository.Save(responseData);
            }
        }
        private void SaveExecutionRequestData(AsyncExecutionRequest request)
        {
            string             requestHash   = request.GetRequestHash();
            AsyncExecutionData executionData = AsyncCallbackRepository.OneAsyncExecutionDataWhere(c => c.RequestHash == requestHash);

            if (executionData == null)
            {
                executionData = new AsyncExecutionData
                {
                    RequestCuid = request.Cuid,
                    RequestHash = requestHash,
                    Requested   = new Instant(DateTime.UtcNow)
                };
                AsyncCallbackRepository.Save(executionData);
            }
            else
            {
                Logger.Warning("AsyncExecutionData was already persisted: Request.Cuid={0}, RequestHash={1}", executionData.RequestCuid, requestHash);
            }
            SaveRequestData(request, requestHash);
        }