private string GetFilename(TdApi.File file, long id, AvatarSize size) { var s = (int)size; var name = file == null ? _colorMapper[id] : id.ToString(); return($"avatar_{s}x{s}_{name}.jpg"); }
public IObservable <TdApi.File> LoadFile(TdApi.File file, int priority = 16) { bool downloadingNeeded = file.Local == null || !file.Local.IsDownloadingCompleted || file.Local.Path == null || !File.Exists(file.Local.Path); if (downloadingNeeded) { bool isNew = false; var subject = _files.GetOrAdd(file.Id, id => { isNew = true; return(new Subject <TdApi.File>()); }); return(isNew ? _agent.Execute(new TdApi.DownloadFile { FileId = file.Id, Priority = (int)priority }) .SelectMany(o => subject) : subject); } return(Observable.Return(file)); }
private bool IsDownloadingNeeded(TdApi.File file) { return(file.Local == null || !file.Local.IsDownloadingCompleted || file.Local.Path == null || !File.Exists(file.Local.Path)); }
public IObservable <TdApi.File> LoadFile(TdApi.File file, LoadPriority priority) { if (IsDownloadingNeeded(file)) { return(_agent.Execute(new TdApi.DownloadFile { FileId = file.Id, Priority = (int)priority }) .SelectSeq(downloading => { return _agent.Updates .OfType <TdApi.Update.UpdateFile>() .Select(u => u.File) .Where(f => f.Id == downloading.Id) .TakeWhile(f => IsDownloadingNeeded(f)); }) .Concat(Observable.Defer(() => _agent.Execute(new TdApi.GetFile { FileId = file.Id })))); } return(Observable.Return(file)); }
private IBitmap GetBitmap(TdApi.File file) { if (file?.Local?.Path != null && _cache.TryGetValue(file.Local.Path, out var bitmap)) { return((IBitmap)bitmap); } return(null); }
private IObservable <IBitmap> LoadBitmap(TdApi.File file) { if (file != null) { return(_fileLoader.LoadFile(file, LoadPriority.Max) .FirstAsync(f => f.Local != null && f.Local.IsDownloadingCompleted) .Select(f => GetBitmap(f.Local.Path))); } return(Observable.Return <Bitmap>(null)); }
private IBitmap GetBitmap(TdApi.File file, long id, AvatarSize size) { var filename = GetFilename(file, id, size); if (_cache.TryGetValue(filename, out var bitmap)) { return((IBitmap)bitmap); } return(null); }
private IBitmap GetBitmap(TdApi.File file, int size) { if (file?.Local?.Path != null) { var resizedFilePath = GetResizedPath(file.Local.Path, size); if (_cache.TryGetValue(resizedFilePath, out var bitmap)) { return((IBitmap)bitmap); } } return(null); }
private IObservable <IBitmap> LoadBitmap(TdApi.File file, long id, AvatarSize size) { var filename = GetFilename(file, id, size); if (file != null) { return(_fileLoader.LoadFile(file, LoadPriority.Max) .FirstAsync(f => f.Local != null && f.Local.IsDownloadingCompleted) .SelectMany(f => PrepareAvatar(f.Local.Path, (int)size, filename).ToObservable()) .SelectMany(path => CreateBitmap(path).ToObservable()) .Do(bitmap => { _cache.Set(filename, bitmap, new MemoryCacheEntryOptions { Size = 1 }); })); } return(Observable.Return <Bitmap>(null)); }
public IObservable <IBitmap> LoadFile(TdApi.File file, LoadPriority priority) { return(_fileLoader.LoadFile(file, priority) .FirstAsync(f => f.Local != null && f.Local.IsDownloadingCompleted) .Select(f => new Bitmap(f.Local.Path))); }