private Transaction(AnnotationRecordCachePersistentProvider provider) { _provider = provider; _db = provider._db; _size = provider._size; _writeOptions = provider._writeOptions; _batch = new WriteBatch(); }
public AnnotationRecordDataAccessor(string sequencePath) { _sequencePath = sequencePath; _name = Path.GetFileName(sequencePath); if (_name != null && _name.Length == 0) { throw new ArgumentException(string.Format(MultiLanguageResources.InvalidPath, sequencePath)); } string initialRecordPath = Path.Combine(sequencePath, "res.txt"); string matFilePath = Path.Combine(sequencePath, "res.mat"); string cacheFilePath = Path.Combine(sequencePath, "cache.db"); bool existsInitialRecordFile = File.Exists(initialRecordPath); bool existsMatFile = File.Exists(matFilePath); var imageFileNameList = GetImageFileList(sequencePath); if (imageFileNameList.Count == 0) { throw new Exception(MultiLanguageResources.NoValidImageFilesInDirectory); } IList <int[]> initialRecords = null; IList <AnnotationRecord> matFileRecords = null; IList <bool> matFileRecordValidity = null; if (existsInitialRecordFile) { initialRecords = LoadInitialRecordsFromTxt(initialRecordPath); } if (existsMatFile) { (matFileRecords, matFileRecordValidity) = LoadRecordsFromMatFile(matFilePath); } var(cachePersistentProvider, cacheRecords) = InitializeAnnotationCache(cacheFilePath); if (matFileRecords == null) { matFileRecords = new List <AnnotationRecord>(); matFileRecordValidity = new List <bool>(); } var(mergedRecords, cacheUpdateToDoList, isMatFileUpdateRequired) = MergeMatFileRecordsAndCacheRecords(matFileRecords, matFileRecordValidity, cacheRecords, imageFileNameList); if (initialRecords != null) { isMatFileUpdateRequired |= MergeAnnotationRecordsWithInitialRecords(mergedRecords, initialRecords, imageFileNameList.Count, cacheUpdateToDoList); } if (IsEmptyRecord(mergedRecords[0])) { throw new Exception("No valid first frame annotation"); } if (isMatFileUpdateRequired) { GenerateMatlabFile(mergedRecords, matFilePath); } cachePersistentProvider.Resize(imageFileNameList.Count); foreach (var keyValuePair in cacheUpdateToDoList) { cachePersistentProvider.Set(keyValuePair.Key, keyValuePair.Value); } _cachePersistentProvider = cachePersistentProvider; _annotationRecords = mergedRecords; }
private static (AnnotationRecordCachePersistentProvider, IList <AnnotationRecordCache>) InitializeAnnotationCache(string cachePath) { var cachePersistentProvider = new AnnotationRecordCachePersistentProvider(cachePath); return(cachePersistentProvider, cachePersistentProvider.AsList()); }