Пример #1
0
        public async Task InsertScannedFileAsync_IgnoresDuplicateFile()
        {
            // ARRANGE
            var files           = new Mock <IDataCache <ScannedFile> >();
            var locations       = new Mock <IDataCache <ScannedLocation> >();
            var mockScannedFile = new ScannedFile()
            {
                Name = "foo",
                Path = "bar",
                Hash = new byte[32]
            };
            FileHashService service = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData()).Returns(() => new List <ScannedFile>()
            {
                new ScannedFile()
                {
                    Name = "foo",
                    Path = "bar",
                    Hash = new byte[32]
                }
            }.AsQueryable());

            // ACT
            await service.InsertScannedFileAsync(mockScannedFile);

            // ASSERT
            files.Verify(t => t.InsertData(It.IsAny <ScannedFile>()), Times.Never());
        }
Пример #2
0
        public void Equals_UnEqualPath_ReturnFalse()
        {
            // ARRANGE
            ScannedFile one = new ScannedFile()
            {
                Name = "foo",
                Path = "bar",
                Hash = new byte[32]
            };
            ScannedFile two = new ScannedFile()
            {
                Name = "foo",
                Path = "bar2",
                Hash = new byte[32]
            };

            one.Hash[0] = 0x99;
            two.Hash[0] = 0x99;

            // ACT
            bool result = one.Equals(two);

            // ASSERT
            Assert.IsFalse(result);
        }
Пример #3
0
        private static ScannedFile Convert(ScannedFileInfo info)
        {
            ScannedFile sf = new ScannedFile();

            sf.OriginalName = info.origFile;
            sf.NewName      = info.newFile;
            sf.Type         = info.type;
            return(sf);
        }
Пример #4
0
        public async Task ReturnDuplicatesAsync_ManyDuplicateHash_ReturnsSortedList()
        {
            // ARRANGE
            var             files     = new Mock <IDataCache <ScannedFile> >();
            var             locations = new Mock <IDataCache <ScannedLocation> >();
            FileHashService service   = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData())
            .Returns(() =>
            {
                byte[] uniqueBytesOne           = new byte[32];
                byte[] uniqueBytesTwo           = new byte[32];
                uniqueBytesOne[1]               = 0x01;
                uniqueBytesTwo[2]               = 0x02;
                List <ScannedFile> scannedFiles = new List <ScannedFile>();
                for (int i = 1; i <= 10; i++)
                {
                    ScannedFile file = new ScannedFile()
                    {
                        Hash = new byte[32]
                    };
                    switch (i)
                    {
                    case 1:
                        file.Name = "foo1";
                        Array.Copy(uniqueBytesOne, file.Hash, 32);
                        break;

                    case 2:
                        file.Name = "bar1";
                        Array.Copy(uniqueBytesTwo, file.Hash, 32);
                        break;

                    case 3:
                        file.Name = "bar2";
                        Array.Copy(uniqueBytesTwo, file.Hash, 32);
                        break;

                    case 4:
                        file.Name = "foo2";
                        Array.Copy(uniqueBytesOne, file.Hash, 32);
                        break;
                    }
                    scannedFiles.Add(file);
                }
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <ScannedFile> results = await service.ReturnDuplicatesAsync();

            // ASSERT
            Assert.AreEqual("foo2", results[1].Name, "The collection was not sorted as expected.");
        }
Пример #5
0
        public async Task ReturnDuplicatesAsync_ManyDuplicateHash_ReturnsManyScannedFiles()
        {
            // ARRANGE
            var             files     = new Mock <IDataCache <ScannedFile> >();
            var             locations = new Mock <IDataCache <ScannedLocation> >();
            FileHashService service   = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData())
            .Returns(() =>
            {
                byte[] uniqueBytesOne           = new byte[32];
                byte[] uniqueBytesTwo           = new byte[32];
                uniqueBytesOne[1]               = 0x01;
                uniqueBytesTwo[2]               = 0x02;
                List <ScannedFile> scannedFiles = new List <ScannedFile>();
                for (int i = 1; i <= 10; i++)
                {
                    ScannedFile file = new ScannedFile()
                    {
                        Hash = new byte[32]
                    };
                    switch (i)
                    {
                    case 1:
                    case 2:
                        Array.Copy(uniqueBytesOne, file.Hash, 32);
                        break;

                    case 3:
                    case 4:
                        Array.Copy(uniqueBytesTwo, file.Hash, 32);
                        break;

                    default:
                        file.Hash[31] = (byte)i;
                        break;
                    }
                    scannedFiles.Add(file);
                }
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <ScannedFile> results = await service.ReturnDuplicatesAsync();

            // ASSERT
            Assert.AreEqual(4, results.Count, "The number of found scanned files does not match what was expected");
        }
Пример #6
0
        private async void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            scannedFile = await GetFile(episode);

            LoadSidebar();
            Helper.DisableScreenSaver();
            MainWindow.HideContent();
            MainWindow.videoPlayback = true;
            PlayerPage.Focus();
            VolumeSlider.Value         = Player.Volume = Properties.Settings.Default.Volume;
            VolumeSlider.ValueChanged += VolumeSlider_ValueChanged;
            Player.MediaFailed        += (s, ev) => MediaFailedEvent();
            Player.MediaEnded         += (s, ev) => MediaFinishedEvent();
            Player.MediaOpened        += (s, ev) => MediaOpenedEvent();
            Player.Source              = new Uri(scannedFile.NewName);
        }
Пример #7
0
        public async static Task <bool> EpisodeViewMouseLeftUp(Series series, Episode episode)
        {
            List <Episode.ScannedFile> list = new List <Episode.ScannedFile>();

            foreach (var item in episode.files)
            {
                if (item.Type == Episode.ScannedFile.FileType.Video)
                {
                    list.Add(item);
                }
            }
            List <FileInfo> infoList = new List <FileInfo>();

            foreach (var item in list)
            {
                infoList.Add(new FileInfo(item.NewName));
            }
            FileInfo info = infoList.OrderByDescending(ex => ex.Length).FirstOrDefault();

            if (info != null)
            {
                ScannedFile sf = list.Where(x => x.NewName == info.FullName).FirstOrDefault();
                if (!Settings.UseWinDefaultPlayer)
                {
                    //Used to release as many resources as possible to give all rendering power to video playback
                    GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                    await Task.Run(() => {
                        Thread.Sleep(500);
                    });

                    MainWindow.AddPage(new LocalPlayer(series, episode));
                }
                else
                {
                    Process.Start(sf.NewName);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private async void Play_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            List <Episode.ScannedFile> list = new List <Episode.ScannedFile>();

            foreach (var item in episode.files)
            {
                if (item.Type == ScannedFile.FileType.Video)
                {
                    list.Add(item);
                }
            }
            List <FileInfo> infoList = new List <FileInfo>();

            foreach (var item in list)
            {
                infoList.Add(new FileInfo(item.NewName));
            }
            FileInfo info = infoList.OrderByDescending(ex => ex.Length).FirstOrDefault();

            if (info != null)
            {
                ScannedFile sf = list.Where(x => x.NewName == info.FullName).FirstOrDefault();
                if (!Settings.UseWinDefaultPlayer)
                {
                    //Used to release as many resources as possible to give all rendering power to video playback
                    GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                    await Task.Run(() => {
                        Thread.Sleep(500);
                    });

                    MainWindow.AddPage(new LocalPlayer(Database.GetSeries((int)episode.seriesId), episode));
                }
                else
                {
                    Process.Start(sf.NewName);
                }
            }
            else
            {
                await MessageBox.Show("No files found...", "Error");
            }
        }
Пример #9
0
        private async void PlayFile(Series series, Episode episode)
        {
            List <Episode.ScannedFile> list = new List <Episode.ScannedFile>();

            episode = Database.GetEpisode(series.id, episode.id);
            foreach (var item in episode.files)
            {
                if (item.Type == Episode.ScannedFile.FileType.Video)
                {
                    list.Add(item);
                }
            }
            List <FileInfo> infoList = new List <FileInfo>();

            foreach (var item in list)
            {
                infoList.Add(new FileInfo(item.NewName));
            }
            FileInfo info = infoList.OrderByDescending(ex => ex.Length).FirstOrDefault();

            if (info != null)
            {
                ScannedFile sf = list.Where(x => x.NewName == info.FullName).FirstOrDefault();
                if (!Settings.UseWinDefaultPlayer)
                {
                    //Used to release as many resources as possible to give all rendering power to video playback
                    MainWindow.RemoveAllPages();
                    GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                    MainWindow.AddPage(new LocalPlayer(series, episode));
                }
                else
                {
                    Process.Start(sf.NewName);
                }
            }
        }