/// <summary> /// The process request async. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public override CefReturnValue ProcessRequestAsync(CefRequest request, CefCallback callback) { var scheme = _requestSchemeProvider?.GetScheme(request.Url); if (scheme is not null && scheme.UrlSchemeType == UrlSchemeType.LocalRequest) { _stream = Stream.Null; var uri = new Uri(request.Url); var path = uri.LocalPath; _mimeType = "application/json"; bool isRequestAsync = _routeProvider.IsRouteAsync(path); if (isRequestAsync) { ProcessRequestAsync(path); } else { ProcessRequest(path); } } return(CefReturnValue.ContinueAsync); #region Process Request void ProcessRequest(string path) { Task.Run(() => { using (callback) { try { var response = new ChromelyResponse(); if (string.IsNullOrEmpty(path)) { _chromelyResponse = _chromelyErrorHandler.HandleRouteNotFound(request.Identifier.ToString(), path); } else { var parameters = request.Url.GetParameters(); var postData = GetPostData(request); var jsonRequest = _dataTransferOptions.ConvertObjectToJson(request); _chromelyResponse = _requestHandler.Execute(request.Identifier.ToString(), path, parameters, postData, jsonRequest); string?jsonData = _dataTransferOptions.ConvertResponseToJson(_chromelyResponse.Data); if (jsonData is not null) { var content = Encoding.UTF8.GetBytes(jsonData); _stream = new MemoryStream(); _stream.Write(content, 0, content.Length); } } } catch (Exception exception) { _stream = Stream.Null; var chromelyRequest = new ChromelyRequest() { Id = request.Identifier.ToString(), RouteUrl = request.Url }; _chromelyResponse = _chromelyErrorHandler.HandleError(chromelyRequest, exception); } if (_stream is null) { callback.Cancel(); } else { SetResponseInfoOnSuccess(); callback.Continue(); } } }); } #endregion #region Process Request Async void ProcessRequestAsync(string path) { Task.Run(async() => { using (callback) { try { var response = new ChromelyResponse(); if (string.IsNullOrEmpty(path)) { _chromelyResponse = _chromelyErrorHandler.HandleRouteNotFound(request.Identifier.ToString(), path); } else { var parameters = request.Url.GetParameters(request.ReferrerURL); var postData = GetPostData(request); var jsonRequest = _dataTransferOptions.ConvertObjectToJson(request); _chromelyResponse = await _requestHandler.ExecuteAsync(request.Identifier.ToString(), path, parameters, postData, jsonRequest); string?jsonData = _dataTransferOptions.ConvertResponseToJson(_chromelyResponse.Data); if (jsonData is not null) { var content = Encoding.UTF8.GetBytes(jsonData); _stream = new MemoryStream(); _stream.Write(content, 0, content.Length); } } } catch (Exception exception) { _stream = Stream.Null; var chromelyRequest = new ChromelyRequest() { Id = request.Identifier.ToString(), RouteUrl = request.Url }; _chromelyResponse = _chromelyErrorHandler.HandleError(chromelyRequest, exception); } if (_stream is null) { callback.Cancel(); } else { SetResponseInfoOnSuccess(); callback.Continue(); } } }); } #endregion }