public bool IsFileCached(string key, string path = null) { string fileName = GetFileNameForKey(key); string filePath = Path.Combine(path ?? string.Empty, fileName); return(FileStorageHelper.IsFileExists(filePath)); }
/// <summary> /// Load state /// </summary> public async Task LoadState() { try { if (!FileStorageHelper.IsFileExists("currentPlaylist.js")) { return; } var json = await FileStorageHelper.ReadText("currentPlaylist.js"); if (!string.IsNullOrEmpty(json)) { _currentPlaylist.Deserialize(json); if (_currentPlaylist.CurrentItem != null) { UpdateTransportControl(); CurrentAudioChanged?.Invoke(this, EventArgs.Empty); } } } catch (Exception ex) { Logger.Error(ex, "Unable to load AudioService state"); } }
public async Task <Stream> GetCachedImageStream(string key) { if (!IsFileCached(key, ImageCachePath)) { return(null); } try { var fileName = GetFileNameForKey(key); var filePath = Path.Combine(ImageCachePath, fileName); if (!FileStorageHelper.IsFileExists(filePath)) { return(null); } var ms = new MemoryStream(); using (var fileStream = await FileStorageHelper.OpenFileRead(filePath)) { await fileStream.CopyToAsync(ms); } await ms.FlushAsync(); ms.Seek(0, SeekOrigin.Begin); return(ms); } catch (Exception ex) { Logger.Error(ex, "Unable to get cached image stream"); } return(null); }