public void TestDatabaseMetaTableSerialization()
        {
            var entry = new VideoFingerPrintDatabaseMetaTableEntryWrapper
            {
                FileName = "test",
                FileSize = 1,
            };

            var entry2 = new VideoFingerPrintDatabaseMetaTableEntryWrapper
            {
                FileName = "test 2",
                FileSize = 2,
            };

            var database = new VideoFingerPrintDatabaseMetaTableWrapper
            {
                DatabaseMetaTableEntries = new[] { entry, entry2 },
            };

            using (var memoryStream = new MemoryStream())
            {
                VideoFingerPrintDatabaseMetaTableSaver.Save(database, memoryStream);
                byte[] savedDatabase = memoryStream.ToArray();
                VideoFingerPrintDatabaseMetaTableWrapper reloadedDatabase = VideoFingerPrintDatabaseMetaTableLoader.Load(savedDatabase);

                Assert.AreEqual(database, reloadedDatabase);
            }
        }
Exemplo n.º 2
0
        private void UpdateMetatable(string databasePath, ulong fileSize)
        {
            VideoFingerPrintDatabaseMetaTableWrapper metatable = CreateOrLoadMetatable(_metatablePath);

            // Get matching database entry
            VideoFingerPrintDatabaseMetaTableEntryWrapper databaseEntry = (from entry in metatable.DatabaseMetaTableEntries
                                                                           where string.Equals(entry.FileName, databasePath, StringComparison.Ordinal)
                                                                           select entry).SingleOrDefault();

            databaseEntry.FileSize = fileSize;

            VideoFingerPrintDatabaseMetaTableSaver.Save(metatable, _metatablePath);
        }
Exemplo n.º 3
0
        public static VideoFingerPrintDatabaseMetaTableWrapper Coalesce(
            string pathToMetatable
            )
        {
            VideoFingerPrintDatabaseMetaTableWrapper oldMetatable = VideoFingerPrintDatabaseMetaTableLoader.Load(pathToMetatable);
            IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> databasesSelectedForCoalescing = GetDatabasesThatNeedCoalescing(oldMetatable);
            IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> remainingDatabases             = oldMetatable.DatabaseMetaTableEntries.Except(databasesSelectedForCoalescing);
            IEnumerable <IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> > groupedEntries  = DetermineGroups(databasesSelectedForCoalescing);
            IEnumerable <VideoFingerPrintDatabaseMetaTableEntryWrapper> coalescedDatabaseGroups        = CoalesceDatabaseGroups(groupedEntries);

            VideoFingerPrintDatabaseMetaTableWrapper newMetaTable = new VideoFingerPrintDatabaseMetaTableWrapper
            {
                DatabaseMetaTableEntries = coalescedDatabaseGroups.Concat(remainingDatabases).ToArray(),
            };

            VideoFingerPrintDatabaseMetaTableSaver.Save(newMetaTable, pathToMetatable);

            // Delete old databases
            DeleteOldDatabases(databasesSelectedForCoalescing);

            return(newMetaTable);
        }
Exemplo n.º 4
0
        private Tuple <VideoFingerPrintDatabaseWrapper, string> CreateNewDatabaseAndAddToMetatable()
        {
            VideoFingerPrintDatabaseMetaTableWrapper metatable = CreateOrLoadMetatable(_metatablePath);
            string emptyDatabaseFileName = Path.GetRandomFileName() + ".bin";
            VideoFingerPrintDatabaseWrapper emptyDatabase = new VideoFingerPrintDatabaseWrapper();

            VideoFingerPrintDatabaseSaver.Save(emptyDatabase, emptyDatabaseFileName);

            // Add to the metatable
            var databaseEntries = new List <VideoFingerPrintDatabaseMetaTableEntryWrapper>(metatable.DatabaseMetaTableEntries);

            databaseEntries.Add(new VideoFingerPrintDatabaseMetaTableEntryWrapper
            {
                FileName = emptyDatabaseFileName,
                FileSize = 0ul,
            });

            metatable.DatabaseMetaTableEntries = databaseEntries.ToArray();

            VideoFingerPrintDatabaseMetaTableSaver.Save(metatable, _metatablePath);

            return(Tuple.Create(emptyDatabase, emptyDatabaseFileName));
        }