public async Task <HttpResponseMessage> AlbumCover(int id) { var response = Request.CreateResponse(); var result = await _albumService.GetAlbumAsync(id, true); if (result.Type != ResultType.Ok) { return(null);// NotFound(); } var album = new Album { Id = result.Data.Id, Performer = new Performer { Name = result.Data.Performer.Name } }; response.Content = new PushStreamContent((stream, content, context) => { var path = FileLocator.GetAlbumImagePath(album); var image = new HttpFileStream(path); image.WriteToStream(stream, content, context); }, "image/jpeg"); return(response); }
public void LocateImagePath() { ImagePath = FileLocator.GetAlbumImagePath(Mapper.Map <Album>(this)); }
private async void MoveAlbum() { if (_albumToMove == null) { MessageBox.Show("Please select album to move"); return; } await _albumService.MoveAlbumToPerformerAsync(_albumToMove.Id, SelectedPerformer.Id); var album = Mapper.Map <Album>(_albumToMove); var performer = Mapper.Map <Performer>(_selectedPerformer); _albumToMovePerformer.Albums.Remove(_albumToMove); _albumToMovePerformer.UpdateAlbumCollectionRate(_rateCalculator); _albumToMove.Performer = performer; _albumToMove.LocateImagePath(); if (MessageBox.Show("Do you want to move all corresponding files as well?", "Confirmation", MessageBoxButton.YesNoCancel) != MessageBoxResult.Yes) { await InsertAlbumToCollectionAsync(_albumToMove); return; } var pathlist = FileLocator.MakePerformerImagePathlist(performer); var path = string.Empty; if (pathlist.Count == 1) { path = Path.GetDirectoryName(pathlist.First()); } else { var choice = new ChoiceWindow(); choice.SetChoiceList(pathlist.Select(p => Path.GetDirectoryName(p))); choice.ShowDialog(); path = choice.ChoiceResult; Directory.CreateDirectory(path); } // move album cover image file var albumPath = FileLocator.GetAlbumImagePath(album); if (albumPath != string.Empty) { File.Move(albumPath, $"{path}\\{Path.GetFileName(albumPath)}"); _albumToMove.LocateImagePath(); } // move folder with song files var albumFolder = FileLocator.FindAlbumPath(album); if (albumFolder != string.Empty) { var destinationFolder = $"{Path.GetDirectoryName(path)}\\{new DirectoryInfo(albumFolder).Name}"; if (Path.GetPathRoot(albumFolder) == Path.GetPathRoot(path)) { Directory.Move(albumFolder, destinationFolder); } // !!!!! .NET, are you kidding me? ((( else { Directory.CreateDirectory(destinationFolder); foreach (string dir in Directory.GetDirectories(albumFolder, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(Path.Combine(destinationFolder, dir.Substring(albumFolder.Length + 1))); } foreach (string file in Directory.GetFiles(albumFolder, "*", SearchOption.AllDirectories)) { File.Copy(file, Path.Combine(destinationFolder, file.Substring(albumFolder.Length + 1))); } Directory.Delete(albumFolder, true); } } await InsertAlbumToCollectionAsync(_albumToMove); _albumToMove = null; _albumToMovePerformer = null; }
public void LocateAlbumImagePath(Album album) { AlbumImagePath = FileLocator.GetAlbumImagePath(album); }
public void MoveAlbumFiles(PerformerViewModel performerNew) { var album = Mapper.Map <Album>(AlbumToMove); var performer = Mapper.Map <Performer>(performerNew); var initialAlbum = Mapper.Map <Album>(AlbumToMove); initialAlbum.Performer = Mapper.Map <Performer>(InitialPerformer); var pathlist = FileLocator.MakePerformerImagePathlist(performer); var path = string.Empty; if (pathlist.Count == 1) { path = Path.GetDirectoryName(pathlist.First()); } else { var parameters = new DialogParameters { { "options", pathlist.Select(p => Path.GetDirectoryName(p)) } }; _dialogService.ShowDialog("ChoiceWindow", parameters, r => { path = r.Parameters.GetValue <string>("choice"); }); Directory.CreateDirectory(path); } // move album cover image file var albumPath = FileLocator.GetAlbumImagePath(initialAlbum); if (albumPath != string.Empty) { File.Move(albumPath, $"{path}\\{Path.GetFileName(albumPath)}"); AlbumToMove.LocateImagePath(); } // move folder with song files var albumFolder = FileLocator.FindAlbumPath(initialAlbum); if (albumFolder != string.Empty) { var destinationFolder = $"{Path.GetDirectoryName(path)}\\{new DirectoryInfo(albumFolder).Name}"; if (Path.GetPathRoot(albumFolder) == Path.GetPathRoot(path)) { Directory.Move(albumFolder, destinationFolder); } // !!!!! .NET, are you kidding me? ((( else { Directory.CreateDirectory(destinationFolder); foreach (string dir in Directory.GetDirectories(albumFolder, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(Path.Combine(destinationFolder, dir.Substring(albumFolder.Length + 1))); } foreach (string file in Directory.GetFiles(albumFolder, "*", SearchOption.AllDirectories)) { File.Copy(file, Path.Combine(destinationFolder, file.Substring(albumFolder.Length + 1))); } Directory.Delete(albumFolder, true); } } }