private void UpdateStatus() { ErrorInformation error = null; var waiting = false; var loading = false; var background = false; foreach (var source in _sources) { switch (source.Status) { case OnlineManagerStatus.Loading: if (source.BackgroundLoading) { background = true; } else { loading = true; } break; case OnlineManagerStatus.Error: error = source.Error; break; case OnlineManagerStatus.Waiting: waiting = true; break; } } if (loading) { Status = OnlineManagerStatus.Loading; BackgroundLoading = false; } else { Status = error != null ? OnlineManagerStatus.Error : waiting ? OnlineManagerStatus.Waiting : OnlineManagerStatus.Ready; BackgroundLoading = background; } Error = error; }
private async Task LoadAsyncInner() { _reloadAfterwards = false; Status = OnlineManagerStatus.Loading; var cancellationSource = new CancellationTokenSource(); _cancellationSource = cancellationSource; try { var ready = await GetSourceLoadTask(cancellationSource.Token); while (_reloadAfterwards && !cancellationSource.IsCancellationRequested) { _reloadAfterwards = false; ready = await GetSourceLoadTask(cancellationSource.Token); } // new LoadAsyncInner() might be started, if this one is cancelled if (_cancellationSource == cancellationSource) { // GetLoadInnerTask() returns “false”, if loading was cancelled before all servers // were loaded and ready to be added to the list. In this case, we need to revert state // to Waiting so source will be properly loaded later. Status = ready ? OnlineManagerStatus.Ready : OnlineManagerStatus.Waiting; } } catch (InformativeException e) { Error = new ErrorInformation(e); } catch (Exception e) { Logging.Error(e); Error = new ErrorInformation(e); } finally { if (_cancellationSource == cancellationSource) { _cancellationSource = null; _loadingTask = null; _customers.Clear(); } cancellationSource.Dispose(); } }
protected bool Equals(ErrorInformation other) { return(string.Equals(Message, other.Message) && string.Equals(Commentary, other.Commentary) && IsFatal == other.IsFatal); }