/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>The result of request execution.</returns> public ApiResponse Handle([NotNull] ApiRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrWhiteSpace(request.SourceType)) { throw new ArgumentException(Resources.ApiService_Handle_SourceTypeNotSpecified); } if (string.IsNullOrWhiteSpace(request.RequestMethod)) { throw new ArgumentException(Resources.ApiService_Handle_RequestMethodNotSpecified); } var executor = _requestExecutorProvider.Get(request.SourceType); if (!executor.CanHandleAsync(request)) { return(executor.Execute(request)); } _eventProvider.Publish( new Event { Key = EventKeys.ExternalSystemAction, Data = new Dictionary <string, string> { { "Data", JsonConvert.SerializeObject(request) } } }); _unitOfWork.Commit(); return(new ApiResponse { Success = true }); }
/// <summary> /// Handles the specified event to handle. /// </summary> /// <param name="eventToHandle">The event to handle.</param> public void Handle(Event eventToHandle) { var request = JsonConvert.DeserializeObject <ApiRequest>(eventToHandle.Data.GetOrNull("Data")); if (request == null) { return; } var executor = _requestExecutorProvider.Get(request.SourceType); try { executor.Execute(request); } catch (Exception exception) { _log.Fatal(Resources.ErrorWhileProcessingRequest, exception); } }