private Record GetRecordFromUri(string recordFileUri) { var encryptedBytes = DataGateway.GetBytes(recordFileUri); var record = Cryptor.GetDecryptedContent <Record>(encryptedBytes, _password); return(record); }
public List <RecordHeader> GetRecordHeaders(string searchText) { var files = DataGateway.GetFileNames(GetEffectiveWorkingDirectory(), "*.rcd"); var recordHeaders = files.Select(f => GetRecordFromUri(f).Header).ToList(); return(Searcher.Search(recordHeaders, searchText)); }
public Safe(string password) { _password = password; Cryptor = new Cryptor(); DataGateway = new DataGateway(); Searcher = new Searcher(); }
public void UpsertRecord(Record record) { var recordFileUri = GetRecordFileUri(record.Header.Id); var encryptedRecordBytes = Cryptor.GetEncryptedBytes(record, _password); DataGateway.DeleteFileIfAvailable(recordFileUri); DataGateway.PutBytes(recordFileUri, encryptedRecordBytes); }
public void RetreiveFile(string recordId, string fileId, string fileUri) { var encryptedFileUri = GetEncryptedFileUri(recordId, fileId); var encryptedBytes = DataGateway.GetBytes(encryptedFileUri); var fileByes = Cryptor.GetDecryptedContent <byte[]>(encryptedBytes, _password); DataGateway.PutBytes(fileUri, fileByes); }
public void StoreFile(string recordId, string fileId, string fileUri) { var effectiveFile = GetEncryptedFileUri(recordId, fileId); var fileBytes = DataGateway.GetBytes(fileUri); var encryptedBytes = Cryptor.GetEncryptedBytes(fileBytes, _password); DataGateway.PutBytes(effectiveFile, encryptedBytes); }
public void ReorganizeFiles(string recordId) { var validFiles = new List <string>(); var recordFiles = DataGateway.GetFileNames(GetEffectiveWorkingDirectory(), recordId + ".rcd"); if (recordFiles.Count != 0) { var record = GetRecord(recordId); validFiles.AddRange(record.FileRecords.Select(x => x.AssociatedRecordId + "_" + x.FileId).ToList()); } var pattern = recordId + "_*.encfile"; var files = DataGateway.GetFileNames(GetEffectiveWorkingDirectory(), pattern); foreach (var file in files) { var fileWithOutPath = Path.GetFileName(file); var fileNameWithoutExtention = Path.GetFileNameWithoutExtension(fileWithOutPath); if (!validFiles.Contains(fileNameWithoutExtention)) { DataGateway.DeleteFileIfAvailable(file); } } }
public void DeleteRecord(string recordId) { var recordFile = GetRecordFileUri(recordId); DataGateway.DeleteFileIfAvailable(recordFile); }