private async void NotifyGlobalProgress(NotifyGlobalProgress notify) { Console.WriteLine("[ProgressManager] NotifyGlobalProgress"); long total = 100; long written = 100; foreach (var item in _repository.All()) { long itotal = item.State == State.Finished ? 100 : item.State == State.Error ? 100 : item.State == State.Waiting ? 100 : item.State == State.Downloading ? (item.Total == 0 ? 100 : item.Total) : 100; long iwritten = item.State == State.Finished ? 100 : item.State == State.Error ? 100 : item.State == State.Waiting ? 0 : item.State == State.Downloading ? item.Written : 0; itotal = Math.Max(itotal, iwritten); int percent = (int)((iwritten / (float)itotal) * 100); written += percent; total += 100; } await _bus.SendAsync <GlobalProgress> (new GlobalProgress { Total = total, Written = written }); }