示例#1
0
        public AudioBooksDbContainerSqLite()
        {
            ExecuteWithLock executeWithLockDelegate = AudioBooksDbContainerSQLiteConfig.ExecuteWithLockDelegate;

            _audioBooks = new Lazy <AudioBookSet>(() =>
            {
                var needVacuum = _config.LastAudioBooksVacuum.AddDays(3) < DateTime.Now;
                var result     = new AudioBookSet(_config.AudioBooksFilePath, executeWithLockDelegate,
                                                  needVacuum);
                if (needVacuum)
                {
                    executeWithLockDelegate(() =>
                    {
                        _config.LastAudioBooksVacuum = DateTime.Now;
                        _config.Save();
                    });
                }

                return(result);
            }, true);
            _replacementStringSet =
                new Lazy <ReplacementStringSet>(
                    () =>
                    new ReplacementStringSet(_config.ProcessingSettingsFilePath,
                                             executeWithLockDelegate), true);
            _userDataSet =
                new Lazy <UserDataSet>(
                    () => new UserDataSet(_config.UserDataFilePath, executeWithLockDelegate),
                    true);
            _binaryDataSet =
                new Lazy <BinaryDataSet>(
                    () => new BinaryDataSet(_config.BinaryDataFilePath, executeWithLockDelegate),
                    true);
        }
示例#2
0
        public void Import(string dbFilePath)
        {
            using (var audioBookSet = new AudioBookSet(dbFilePath, ExecuteWithLockDelegate, true))
            {
                var groups  = audioBookSet.GetRecordGroupsAll();
                var records = audioBookSet.GetRecordsAll();

                var existedGroups  = new HashSet <string>(GetRecordGroupsAll().Select(item => item.Key));
                var existedRecords = new HashSet <string>(GetRecordsAll().Select(item => item.Key));

                var newGroups  = groups.Where(group => !existedGroups.Contains(group.Key));
                var newRecords = records.Where(record => !existedRecords.Contains(record.Key));

                foreach (var audioBookGroup in newGroups)
                {
                    AddRecordGroup(audioBookGroup);
                }

                foreach (var newRecord in newRecords)
                {
                    AddRecord(newRecord);
                }
            }
        }
示例#3
0
 public void SaveChanges()
 {
     AudioBookSet.SaveAudioBooks();
     AudioBookGroupSet.SaveAudioBookGroups();
     BinaryDataSet.SaveBinaryData();
 }