Ejemplo n.º 1
0
        public void Test_Up_Working_Directory_Is_A_Noop_When_When_Initialised_With_No_Shares()
        {
            var virtualFolder = new VirtualFolder(new Dictionary<string, string>());

            virtualFolder.UpWorkingFolder(1);
            Assert.Equal(VirtualFolder.FolderRoot, virtualFolder.CurrentFolder);
        }
Ejemplo n.º 2
0
        private static bool TransformInternal(VirtualFolder root, VirtualFolder current)
        {
            foreach (var f in current.ChildFolders.ToList()) {
            var vf = f as VirtualFolder;
            if (TransformInternal(root, vf)) {
              current.ReleaseFolder(vf);
            }
              }

              if (current == root || current.ChildItems.Count() > 3) {
            return false;
              }
              var newParent = current.Parent as VirtualFolder;
              foreach (var c in current.ChildItems.ToList()) {
            current.RemoveResource(c);
            newParent.AddResource(c);
              }

              if (current.ChildCount != 0) {
            MergeFolders(current, newParent);
            foreach (var f in current.ChildFolders.ToList()) {
              newParent.AdoptFolder(f);
            }
            foreach (var f in current.ChildItems.ToList()) {
              current.RemoveResource(f);
              newParent.AddResource(f);
            }
              }
              return true;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NamespaceExtensionJunctionPointAttribute"/> class.
 /// </summary>
 /// <param name="availability">The availability.</param>
 /// <param name="location">The location.</param>
 /// <param name="name">The name.</param>
 public NamespaceExtensionJunctionPointAttribute(NamespaceExtensionAvailability availability, VirtualFolder location, string name)
 {
     //  Store the provided values.
     Availablity = availability;
     Location = location;
     Name = name;
 }
    public void Init()
    {
      rootDirectory = TestUtil.CreateTestDirectory();

      //init provider
      provider = new LocalFileSystemProvider(rootDirectory, true);
      root = VirtualFolder.CreateRootFolder(provider);
    }
Ejemplo n.º 5
0
 public override IMediaFolder Transform(IMediaFolder Root)
 {
   if (Root == null) {
     throw new ArgumentNullException("Root");
   }
   var rv = new VirtualFolder(null, Root.Title, Root.Id);
   EatAll(rv, Root);
   return rv;
 }
    private static void RecurseFS(VirtualFolder parent, Action<VirtualFolder, VirtualFile> fileTest, Action<VirtualFolder, VirtualFolder> folderTest)
    {
      var contents = parent.GetFolderContents();

      contents.Files.Do(vf => fileTest(parent, vf));
      contents.Folders.Do(vf => folderTest(parent, vf));

      contents.Folders.Do(vf => RecurseFS(vf, fileTest, folderTest));
    }
Ejemplo n.º 7
0
        private static void SortFolder(VirtualFolder folder, SimpleKeyedVirtualFolder titles)
        {
            foreach (var f in folder.ChildFolders.ToList()) {
            SortFolder(f as VirtualFolder, titles);
              }

              foreach (var c in folder.ChildItems.ToList()) {
            var pre = GetTitle(c);
            pre = pre[0].ToString().ToUpperInvariant();
            titles.GetFolder(pre).AddResource(c);
            folder.RemoveResource(c);
              }
        }
 private void CloneFolder(VirtualFolder parent, IMediaFolder folder)
 {
     foreach (var f in folder.ChildFolders) {
     var vf = new VirtualFolder(parent, f.Title, f.Id);
     parent.AdoptFolder(vf);
     CloneFolder(vf, f);
       }
       foreach (var i in folder.ChildItems) {
     if ((types & i.MediaType) == i.MediaType) {
       parent.AddResource(i);
     }
       }
 }
    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);
    }
    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");
    }
Ejemplo n.º 11
0
 private static void MergeFolders(VirtualFolder aFrom, VirtualFolder aTo)
 {
     var merges = from f in aFrom.ChildFolders
            join t in aTo.ChildFolders on f.Title equals t.Title
            where f != t
            select new { f = f as VirtualFolder, t = t as VirtualFolder };
       foreach (var m in merges.ToList()) {
     MergeFolders(m.f, m.t);
     foreach (var c in m.f.ChildFolders.ToList()) {
       m.t.AdoptFolder(c);
     }
     foreach (var c in m.f.ChildItems.ToList()) {
       m.t.AddResource(c);
       m.f.RemoveResource(c);
     }
     (m.f.Parent as VirtualFolder).ReleaseFolder(m.f);
       }
 }
Ejemplo n.º 12
0
 private void PartitionChildren(VirtualFolder folder, Prefixer prefixer, int startfrom = 1)
 {
     for (var wordcount = startfrom;;) {
     var curwc = wordcount;
     var groups = from i in folder.ChildItems.ToList()
              let prefix = prefixer.GetWordPrefix(GetTitle(i), curwc)
              where !string.IsNullOrWhiteSpace(prefix)
              group i by prefix.ToLowerInvariant()
              into g
              let gcount = g.LongCount()
              where gcount > 3
              orderby g.LongCount() descending
              select g;
     var longest = groups.FirstOrDefault();
     if (longest == null) {
       if (wordcount++ > 5) {
     return;
       }
       continue;
     }
     var newfolder = new VirtualFolder(folder, longest.Key);
     foreach (var item in longest) {
       folder.RemoveResource(item);
       newfolder.AddResource(item);
     }
     if (newfolder.ChildCount > 100) {
       PartitionChildren(newfolder, prefixer, wordcount + 1);
     }
     if (newfolder.ChildFolders.LongCount() == 1) {
       foreach (var f in newfolder.ChildFolders.ToList()) {
     folder.AdoptFolder(f);
       }
     }
     else {
       folder.AdoptFolder(newfolder);
     }
       }
 }
    private void BrowseFolder(VirtualFolder parentFolder, DirectoryInfo parentDir)
    {
      var contents = parentFolder.GetFolderContents();
      var folders = parentFolder.GetFolders();
      var files = parentFolder.GetFiles();

      Assert.AreEqual(contents.Folders.Count(), folders.Count());
      Assert.AreEqual(contents.Files.Count(), files.Count());


      Assert.AreEqual(parentDir.GetDirectories().Count(), contents.Folders.Count());
      Assert.AreEqual(parentDir.GetFiles().Count(), contents.Files.Count());

      foreach (var file in files)
      {
        //make sure contents matches the files collection
        VirtualFile virtualFile = file;
        Assert.AreEqual(contents.Files.Single(f => f.MetaData.FullName == virtualFile.MetaData.FullName).MetaData.Length, file.MetaData.Length);

        FileInfo fi = parentDir.GetFiles(file.MetaData.Name).Single();
        Assert.AreEqual(file.MetaData.Length, fi.Length);
      }

      foreach (var folder in contents.Folders)
      {
        //make sure contents matches the folders collection
        VirtualFolder virtualFolder = folder;
        Assert.AreEqual(contents.Folders.Single(f => f.MetaData.FullName == virtualFolder.MetaData.FullName).MetaData.Name, folder.MetaData.Name);


        DirectoryInfo dir = parentDir.GetDirectories(folder.MetaData.Name).Single();
        Assert.True(dir.Exists);

        //browse recursively
        BrowseFolder(folder, dir);
      }
    }
Ejemplo n.º 14
0
        public void Test_Returns_Correct_Folder_When_Initialised_With_No_Shares()
        {
            var virtualFolder = new VirtualFolder(new Dictionary<string, string>());

            Assert.Equal(VirtualFolder.FolderRoot, virtualFolder.CurrentFolder);
        }
Ejemplo n.º 15
0
 private void ReaddRoot(VirtualFolder master)
 {
     RegisterNewMaster(master);
     Changed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 16
0
 protected PlainFolder(FileServer server, DlnaMediaTypes types,
                       VirtualFolder parent, DirectoryInfo dir)
     : this(server, types, parent, dir, types.GetExtensions())
 {
 }
        private VirtualFolder IndexFiles(List <string> filePaths, Action <Color, string> consoleWrite)
        {
            consoleWrite(Color.Yellow, "Indexing Files...");

            //m3a, m3o, m3s, m3u
            var exileFiles = filePaths.Where(x => Path.GetExtension(x).ToLower().Contains("m3")).ToList();

            //var exileFiles = filePaths.Where(x => Path.GetExtension(x).ToLower() == _context.M3A_FileExtension).ToList();
            var revFiles = filePaths.Where(x => Path.GetExtension(x).ToLower() == _context.M4B_FileExtension).ToList();

            VirtualFolder exileFolder      = new VirtualFolder("Exile");
            VirtualFolder revelationFolder = new VirtualFolder("Revelation");

            var exileIndexer = new M3AFileIndexingService();
            var revIndexer   = new M4BFileIndexingService();

            Stopwatch eWatch = new Stopwatch();
            Stopwatch rWatch = new Stopwatch();

            bool[] exileFinished = new bool[exileFiles.Count()];
            bool[] revFinished   = new bool[revFiles.Count()];
            for (int i = 0; i < revFiles.Count(); i++)
            {
                var filePath      = revFiles[i];
                var fileName      = Path.GetFileName(filePath);
                var cacheFileName = fileName.Replace(M4B_FileExtension, ".index");

                if (_context.CacheDirectory.Contains(cacheFileName))
                {
                    // check for a cached copy so indexing only needs to be done the first time a file is loaded
                    consoleWrite(Color.Yellow, "Loading cached index for " + fileName);
                    var            cacheText   = File.ReadAllText(Path.Combine(_context.CacheDirectory, cacheFileName));
                    IVirtualFolder indexedFile = _context.CacheService.DeserializeIndexedFolder(cacheText);
                    revelationFolder.SubFolders.Add(indexedFile);
                }
                else
                {
                    var threadAccessibleIndex = i;
                    consoleWrite(Color.Yellow, "Indexing " + fileName);
                    rWatch.Reset(); rWatch.Start();
                    //var fileThread = new Thread(() =>
                    //{
                    IVirtualFolder indexedFile = revIndexer.IndexFile(filePath);
                    revelationFolder.SubFolders.Add(indexedFile);
                    revFinished[threadAccessibleIndex] = true;
                    rWatch.Stop();
                    consoleWrite(Color.Green, fileName + " Indexed in " + rWatch.ElapsedMilliseconds + "ms");
                    var serializedIndex = _context.CacheService.SerializeIndexedFolder(indexedFile as VirtualFolder);
                    //File.WriteAllText(Path.Combine(_context.CacheDirectory, ""),serializedIndex);
                    //});
                    //fileThread.Start();
                }
            }
            for (int i = 0; i < exileFiles.Count(); i++)
            {
                var fileName      = Path.GetFileName(exileFiles[i]);
                var cacheFileName = fileName.Replace(M3A_FileExtension, ".index");
                if (_context.CacheDirectory.Contains(cacheFileName))
                {
                    // check for a cached copy so indexing only needs to be done the first time a file is loaded
                    consoleWrite(Color.Yellow, "Loading cached index for " + fileName);
                    var            cacheText   = File.ReadAllText(Path.Combine(_context.CacheDirectory, cacheFileName));
                    IVirtualFolder indexedFile = _context.CacheService.DeserializeIndexedFolder(cacheText);
                    exileFolder.SubFolders.Add(indexedFile);
                }
                else
                {
                    var threadAccessibleIndex = i;
                    consoleWrite(Color.Yellow, "Indexing " + fileName);
                    eWatch.Reset(); eWatch.Start();
                    var fileThread = new Thread(() =>
                    {
                        IVirtualFolder indexedFile = exileIndexer.IndexFile(exileFiles[threadAccessibleIndex]);
                        exileFolder.SubFolders.Add(indexedFile);
                        exileFinished[threadAccessibleIndex] = true;
                        eWatch.Stop();
                        consoleWrite(Color.Green, fileName + " Indexed in " + eWatch.ElapsedMilliseconds + "ms");
                    });
                    fileThread.Start();
                }
            }

            bool notFinished = true;

            while (notFinished)
            {
                notFinished = !(exileFinished.All(x => x == true) && revFinished.All(x => x == true));
                Thread.Sleep(1000);
            }

            var rootFolder = new VirtualFolder("/");

            rootFolder.SubFolders.Add(exileFolder);
            rootFolder.SubFolders.Add(revelationFolder);
            return(rootFolder);
        }
Ejemplo n.º 18
0
        public void Test_FolderExists_returns_false_With_No_Shares_Defined()
        {
            var virtualFolder = new VirtualFolder(new Dictionary<string, string>());

            Assert.False(virtualFolder.FolderExists("folder"));
        }
Ejemplo n.º 19
0
        public override IMediaFolder Transform(IMediaFolder Root)
        {
            var root   = new VirtualClonedFolder(Root);
            var series = new SimpleKeyedVirtualFolder(root, "Series");
            var movies = new SimpleKeyedVirtualFolder(root, "Movies");

            //SortFolder(root, series);

            /*
             * foreach (var f in series.ChildFolders.ToList()) {
             * var fsmi = f as VirtualFolder;
             * root.AdoptFolder(fsmi);
             * }
             * if (!cascade) {
             * return root;
             * }
             *
             * var cascaded = new DoubleKeyedVirtualFolder(root, "Series"); */
            /*
             * foreach (var i in root.ChildFolders.ToList()) {
             *
             * //        var folder = cascaded.GetFolder(i.Title.StemCompareBase().Substring(0, 1).ToUpper());
             * //        folder.AdoptFolder(i);
             *
             * foreach (var c in i.ChildItems)
             * {
             *  var c0 = c as IMediaVideoResource;
             *  var folder = cascaded.GetFolder(c0 != null ? c0.MovieTitle : i.Title);
             *  folder.AddResource(c);
             * }
             * }
             * foreach (var i in root.ChildItems.ToList()) {
             * //        var folder = cascaded.GetFolder(i.Title.StemCompareBase().Substring(0, 1).ToUpper());
             * //        folder.AddResource(i);
             * //        cascaded.AddResource(i);
             * var c0 = i as IMediaVideoResource;
             * var folder = cascaded.GetFolder(c0 != null ? c0.MovieTitle : i.Title);
             * folder.AddResource(i);
             * }
             */
            /*
             * var items = (from i in root.AllItems.ToList()
             *            let d = (i as IMediaVideoResource).InfoDate
             *            orderby d
             *            select i).ToList();
             */
            foreach (var c in root.AllItems.ToList())
            {
                var c0     = c as IMediaVideoResource;
                var folder = (c0 != null && c0.IsSeries ? series : movies).GetFolder(c0 != null ? c0.MovieTitle : c.Title);
                //var folder = new DoubleKeyedVirtualFolder((c0 != null && c0.IsSeries ? series : movies),(c0 != null ? c0.MovieTitle : c.Title) );
                if (c0.Progress <= 85)
                {
                    folder.AddResource(c);
                }
                else
                {
                    var folder1 = folder.ChildFolders.ToList().Find(f => f.Title == "WATCHED");
                    if (folder1 == null)
                    {
                        folder1 = new VirtualFolder(folder, "WATCHED");
                    }

                    folder1.AddResource(c);
                    folder.AdoptFolder(folder1);
                }

                root.RemoveResource(c);
            }
            foreach (var f in root.ChildFolders.ToList())
            {
                root.ReleaseFolder(f);
            }

            root.AdoptFolder(series);
            root.AdoptFolder(movies);
            return(root);
        }
Ejemplo n.º 20
0
    /// <summary>
    /// Recursively browses the file system and performs tests on either
    /// files, folders, or both. The submitted parent folder is not tested.
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="fileTest"></param>
    /// <param name="folderTest"></param>
    protected static void RecurseFileSystem(VirtualFolder parent, Action<VirtualFolder, VirtualFile> fileTest, Action<VirtualFolder, VirtualFolder> folderTest)
    {
      var contents = parent.GetFolderContents();

      if (fileTest != null)
      {
        contents.Files.Do(vf => fileTest(parent, vf));
      }

      if (folderTest != null)
      {
        contents.Folders.Do(vf => folderTest(parent, vf));
      }

      contents.Folders.Do(vf => RecurseFileSystem(vf, fileTest, folderTest));
    }
Ejemplo n.º 21
0
 private bool CanDeleteFolder(VirtualFolder obj)
 {
     return(obj != null);
 }
Ejemplo n.º 22
0
 public VirtualFileSystem()
 {
     Root = new VirtualFolder("root");
 }
Ejemplo n.º 23
0
    private static void TraverseFolders(VirtualFolder clientFolder, VirtualFolder serviceFolder, TraverseAction assertAction)
    {
      assertAction(clientFolder, serviceFolder);

      //get child folders
      var cFolders = clientFolder.GetFolders().ToArray();
      var sFolders = serviceFolder.GetFolders().ToArray();
      Assert.AreEqual(sFolders.Count(), cFolders.Count());

      for (int i = 0; i < sFolders.Length; i++)
      {
        TraverseFolders(cFolders[i], sFolders[i], assertAction);
      }
    }
 public VirtualFolderViewModel(VirtualFolder folder) : base()
 {
     Folder         = folder;
     IsNameReadOnly = true;
 }
Ejemplo n.º 25
0
        public void Test_Set_Working_Directory_Throws_Exception_When_Initialised_With_No_Shares()
        {
            var virtualFolder = new VirtualFolder(new Dictionary<string, string>());

            Assert.Throws<FolderDoesNotExistException>(() => virtualFolder.SetWorkingFolder("blah"));
        }
Ejemplo n.º 26
0
 public override IMediaFolder Transform(IMediaFolder Root)
 {
     var rv = new VirtualFolder(null, Root.Title, Root.Id);
       EatAll(rv, Root);
       return rv;
 }
Ejemplo n.º 27
0
        private long ReadFileInfo(VirtualFolder parentFolder, FileStream fileStream, long fileStart, long startIndex)
        {
            long index = startIndex;

            var buffer = new byte[sizeof(uint)];

            fileStream.Seek(index, SeekOrigin.Begin);
            fileStream.Read(buffer, 0, buffer.Length);
            index += sizeof(uint);

            var fileNameSize = BitConverter.ToUInt32(buffer, 0);

            if (fileNameSize > 512)
            {
                throw new Exception("FileNameSize Too Big");
            }

            buffer = new byte[fileNameSize];
            fileStream.Seek(index, SeekOrigin.Begin);
            fileStream.Read(buffer, 0, buffer.Length);
            index += buffer.Length;

            var FileName = Encoding.ASCII.GetString(buffer);

            buffer = new byte[sizeof(uint)];
            fileStream.Seek(index, SeekOrigin.Begin);
            fileStream.Read(buffer, 0, buffer.Length);
            index += sizeof(uint);

            var FileSize = BitConverter.ToUInt32(buffer, 0);

            buffer = new byte[sizeof(uint)];
            fileStream.Seek(index, SeekOrigin.Begin);
            fileStream.Read(buffer, 0, buffer.Length);
            index += sizeof(uint);

            var FileOffset = BitConverter.ToUInt32(buffer, 0);

            var fileType          = FileType.Unknown;
            var fileNameLowercase = FileName.TrimEnd(new char[1] {
                '\0'
            }).ToLower();

            if (fileNameLowercase.EndsWith(".jpg"))
            {
                fileType = FileType.Jpg;
            }
            else if (fileNameLowercase.EndsWith(".zap"))
            {
                fileType = FileType.Zap;
            }
            else if (fileNameLowercase.EndsWith(".m4b"))
            {
                fileType = FileType.M4B;
            }
            else if (fileNameLowercase.EndsWith(".bik"))
            {
                fileType = FileType.Bink;
            }
            else if (fileNameLowercase.EndsWith(".bin"))
            {
                fileType = FileType.Binary;
            }
            else
            {
                fileType = FileType.Unknown;
            }

            if (fileType == FileType.M4B)
            {
                var folder = ReadM4BFileData(fileStream, fileNameLowercase, fileStart + FileOffset, FileOffset + FileSize);
                parentFolder.SubFolders.Add(folder);
            }
            else
            {
                var totalStartOffset = fileStart + FileOffset;
                var totalEndOffset   = fileStart + FileOffset + FileSize;
                var thisFile         = new VirtualFileEntry(fileNameLowercase, new VirtualFileDataInArchive(fileStream.Name, fileType, totalStartOffset, totalEndOffset));
                parentFolder.Files.Add(thisFile);
            }
            return(index);
        }
Ejemplo n.º 28
0
 private void SetupTest()
 {
     data = new VirtualFolder(GAME_NAME, SLOT_NAME, LEVEL_NAME);
     data.DeleteFolder();
 }