private IMediaFolder Randomizer() { var result = new VirtualFolder() { Name = "Randomizer", Id = "vf:randomizer" }; var randomTracks = new VirtualFolder() { Name = "Random Tracks", Id = "vf:randomtracks" }; for (var i = 0; i < RandomTrackLimit; i++) { randomTracks.AddFolder(new VirtualFolder()); } result.AddFolder(randomTracks); var randomRatedTracks = new VirtualFolder() { Name = "Random Rated Tracks", Id = "vf:randomratedtracks" }; for (var i = 0; i < RandomTrackLimit; i++) { randomRatedTracks.AddFolder(new VirtualFolder()); } result.AddFolder(randomRatedTracks); return(result); }
/// <summary> /// Returns items to display at top level (level 1) /// </summary> /// <returns></returns> private IMediaFolder RootFolder() { var result = new VirtualFolder(); result.AddFolder(Artists()); result.AddFolder(Collections()); result.AddFolder(Playlists()); result.AddFolder(Randomizer()); result.AddFolder(Releases()); return(result); }
protected override void InitInternal() { base.InitInternal(); testFolder = Context.EmptyFolder; folderA = testFolder.AddFolder("a"); folderB = testFolder.AddFolder("b"); folderC = testFolder.AddFolder("c"); testFolder.AddFile(Context.DownloadFile0Template.FullName, "file0.doc", false); testFolder.AddFile(Context.DownloadFile0Template.FullName, "file0.txt", false); testFolder.AddFile(Context.DownloadFile1Template.FullName, "file1.doc", false); testFolder.AddFile(Context.DownloadFile1Template.FullName, "file1.txt", false); }
public void Creating_A_Folder_And_Adding_A_File_Should_Create_Items_On_File_System() { var foo = root.AddFolder("foo"); var bar = foo.AddFolder("bar"); FileInfo sourceFile = rootDirectory.GetFiles().First(); using(Stream stream = sourceFile.OpenRead()) { var foobar = bar.AddFile("foobar.bin", stream, false, sourceFile.Length, ContentUtil.UnknownContentType); Assert.AreEqual("foobar.bin", foobar.MetaData.Name); } var fooDir = rootDirectory.GetDirectories("foo").Single(); var barDir = fooDir.GetDirectories("bar").Single(); Assert.AreEqual(1, barDir.GetFiles().Count()); //create a file on root level sourceFile = rootDirectory.GetFiles().First(); using (Stream stream = sourceFile.OpenRead()) { var rootFile = root.AddFile("rootFile.bin", stream, false, sourceFile.Length, ContentUtil.UnknownContentType); Assert.AreEqual("rootFile.bin", rootFile.MetaData.Name); Assert.True(File.Exists(Path.Combine(rootDirectory.FullName, rootFile.MetaData.Name))); } }
/// <summary> /// Returns groups of artists for level 2 /// </summary> /// <returns></returns> private IMediaFolder Artists() { try { var result = new VirtualFolder() { Name = "Artists", Id = "vf:artists" }; foreach (var groupKey in ArtistGroupKeys()) { var f = new VirtualFolder(result, groupKey, $"vf:artistsforfolder:{ groupKey }"); foreach (var artistForGroup in ArtistsForGroup(groupKey)) { var af = new VirtualFolder(f, artistForGroup.RoadieId.ToString(), $"vf:artist:{ artistForGroup.Id }"); f.AddFolder(af); } result.AddFolder(f); } return(result); } catch (Exception ex) { Logger.LogError(ex, "Artists Root"); } return(null); }
protected override void InitInternal() { base.InitInternal(); //create source and add two files source = Context.EmptyFolder.AddFolder("Source"); //sub folders source.AddFolder("folder0"); source.AddFolder("folder1"); //sub files source.AddFile(Context.DownloadFile0Template.FullName, "file0.bin", false); source.AddFile(Context.DownloadFile1Template.FullName, "file1.txt", false); targetPath = FileSystem.CreateFolderPath(Context.EmptyFolder.MetaData.FullName, "Target"); }
protected override void InitInternal() { base.InitInternal(); testFolder = Context.EmptyFolder; testFolder.AddFolder("dir_foo"); testFolder.AddFolder("dir_bar"); testFolder.AddFolder("dir_foobar"); testFolder.AddFolder("dir_barfoo"); testFolder.AddFile(Context.DownloadFile0Template.FullName, "foo.txt", false); testFolder.AddFile(Context.DownloadFile0Template.FullName, "bar.txt", false); testFolder.AddFile(Context.DownloadFile1Template.FullName, "foobar.txt", false); testFolder.AddFile(Context.DownloadFile1Template.FullName, "barfoo.txt", false); }
/// <summary> /// Creates the test directory. /// </summary> /// <param name="root"></param> /// <param name="recreateLocalFiles">Whether to recreate the local test /// files that are used for up/downloads before uploding them to the /// virtual FS.</param> public virtual void InitFileSystemUnderTest(bool recreateLocalFiles) { VirtualFolder root = VirtualFolder.CreateRootFolder(FileSystem); //create two top level folders var f0 = root.AddFolder(ChildFolder0Name); root.AddFolder(ChildFolder1Name); //create upload/download folders f0.AddFolder(UploadFolderName); var download = f0.AddFolder(DownloadFolderName); if (recreateLocalFiles) { //overwrite local files CreateLocalTestFiles(); } //upload files and and empty folder to download folder download.AddFile(DownloadFile0Template.FullName, DownloadFile0Name, false); download.AddFile(DownloadFile1Template.FullName, DownloadFile1Name, false); download.AddFolder(EmptyFolderName); }
public void Folders_Should_Indicate_Whether_They_Are_Empty_Or_Not() { //the test folder is not empty, but contains not sub folders and files testFolder.RefreshMetaData(); Assert.IsFalse(testFolder.MetaData.IsEmpty); //add sub folder to folder a folderA.AddFolder("x"); folderA.RefreshMetaData(); Assert.IsFalse(folderA.MetaData.IsEmpty); //add sub files to folder b folderA.AddFile(Context.DownloadFile0Template.FullName, "xxx.bin", false); folderA.RefreshMetaData(); Assert.IsFalse(folderA.MetaData.IsEmpty); //folder c is still empty folderC.RefreshMetaData(); Assert.IsTrue(folderC.MetaData.IsEmpty); }
private IMediaFolder Collections() { var result = new VirtualFolder() { Name = "Collections", Id = "vf:collections" }; foreach (var cg in CollectionGroups()) { var f = new VirtualFolder(result, cg.SortName ?? cg.Name, $"vf:releasesforcollection:{ cg.Id }"); foreach (var releaseForCollection in ReleasesForCollection(cg.Id)) { var af = new VirtualFolder(f, releaseForCollection.RoadieId.ToString(), $"vf:release:{ releaseForCollection.Id }"); f.AddFolder(af); } result.AddFolder(f); } return(result); }
private IMediaFolder Playlists() { var result = new VirtualFolder() { Name = "Playlists", Id = "vf:playlists" }; foreach (var pl in PlaylistGroups()) { var f = new VirtualFolder(result, pl.Name, $"vf:tracksforplaylist:{ pl.Id }"); foreach (var track in TracksForPlaylist(pl.Id)) { var t = new VirtualFolder(result, pl.Name, $"t:tk:{track.Id}::{Guid.NewGuid()}"); f.AddFolder(t); } result.AddFolder(f); } return(result); }
private IMediaFolder Releases() { var result = new VirtualFolder() { Name = "Releases", Id = "vf:releases" }; foreach (var groupKey in ReleaseGroupKeys()) { var f = new VirtualFolder(result, groupKey, $"vf:releasesforfolder:{ groupKey}"); foreach (var releaseForGroup in ReleasesForGroup(groupKey)) { var af = new VirtualFolder(f, releaseForGroup.RoadieId.ToString(), $"vf:release:{ releaseForGroup.Id }"); f.AddFolder(af); } result.AddFolder(f); } return(result); }
/// <summary> /// Returns releases for group letter (level 3) /// </summary> private IMediaItem ReleasesForFolder(string id) { var artistsForFolderKey = id.Replace("vf:releasesforfolder:", ""); var result = new VirtualFolder() { Name = artistsForFolderKey, Id = id }; foreach (var releaseForGroup in ReleasesForGroup(artistsForFolderKey)) { var af = new VirtualFolder(result, releaseForGroup.Title, $"vf:release:{ releaseForGroup.Id }"); foreach (var artistRelease in TracksForRelease(releaseForGroup.Id)) { var fr = new VirtualFolder(af, artistRelease.RoadieId.ToString(), $"vf:release:{ artistRelease.Id }"); af.AddFolder(fr); } result.AddFolder(af); } return(result); }
public void Moving_Into_New_Folder_Should_Adjust_File() { VirtualFolder root = VirtualFolder.CreateRootFolder(Provider); var movedFolder = root.GetFolders().First(); foreach (var virtualFile in movedFolder.GetFiles()) { Console.Out.WriteLine("File: " + virtualFile.MetaData.Name + ", " + virtualFile.MetaData.FullName); } var testFolder = root.AddFolder("Test"); string targetPath = Provider.CreateFolderPath("/", "Nested"); movedFolder.Move(targetPath); Console.Out.WriteLine("movedFolder = {0}", movedFolder.MetaData.FullName); foreach (var virtualFile in movedFolder.GetFiles()) { Console.Out.WriteLine("File: " + virtualFile.MetaData.Name + ", " + virtualFile.MetaData.FullName); } }
private IMediaItem ReleasesForCollectionFolder(string id) { var collectionId = SafeParser.ToNumber <int>(id.Replace("vf:releasesforcollection:", "")); var collection = DbContext.Collections.FirstOrDefault(x => x.Id == collectionId); var result = new VirtualFolder() { Name = collection.Name, Id = id }; foreach (var collectionRelease in ReleasesForCollection(collection.Id)) { var fr = new VirtualFolder(result, collectionRelease.Title, $"vf:release:{ collectionRelease.Id }"); foreach (var releaseTrack in TracksForRelease(collectionRelease.Id)) { var t = new Track(releaseTrack.RoadieId.ToString(), releaseTrack.ReleaseMedia.Release.Artist.Name, releaseTrack.ReleaseMedia.Release.Title, releaseTrack.ReleaseMedia.MediaNumber, releaseTrack.Title, releaseTrack.ReleaseMedia.Release.Genres.Select(x => x.Genre.Name).ToCSV(), releaseTrack.TrackArtist?.Name, releaseTrack.TrackNumber, releaseTrack.ReleaseMedia.Release.ReleaseYear, TimeSpan.FromMilliseconds(SafeParser.ToNumber <double>(releaseTrack.Duration)), releaseTrack.PartTitles, releaseTrack.LastUpdated ?? releaseTrack.CreatedDate, null); fr.AddResource(t); } result.AddFolder(fr); } return(result); }