protected bool AsyncFetch <T>(Uri requestUri, Func <Uri, T> fetcher, out RemoteServerException remoteException) { if (null == requestUri) { remoteException = null; return(true); } lock (_lock) { RemoteResponse response; var key = new RequestKey(typeof(T), requestUri); if (_responses.TryGetValue(key, out response)) { remoteException = response.Exception; return(true); } remoteException = null; if (!_fetchRequests.Add(key)) { return(false); } } ActionUtil.RunAsync(() => FetchAndStore(requestUri, fetcher)); return(false); }
private void FetchAndStore <T>(Uri requestUri, Func <Uri, T> fetcher) { var key = new RequestKey(typeof(T), requestUri); try { var data = fetcher(requestUri); lock (_lock) { _responses[key] = new RemoteResponse(data, null); } } catch (Exception exception) { RemoteServerException remoteException = exception as RemoteServerException; // ReSharper disable once ConvertIfStatementToNullCoalescingExpression if (null == remoteException) { remoteException = new RemoteServerException( Resources.RemoteSession_FetchContents_There_was_an_error_communicating_with_the_server__ + exception.Message, exception); } lock (_lock) { _responses[key] = new RemoteResponse(null, remoteException); } } FireContentsAvailable(); }
public abstract bool AsyncFetchContents(RemoteUrl remoteUrl, out RemoteServerException remoteException);
public RemoteResponse(object data, RemoteServerException exception) { Data = data; Exception = exception; }