Пример #1
0
        private Record GetRecordFromUri(string recordFileUri)
        {
            var encryptedBytes = DataGateway.GetBytes(recordFileUri);
            var record         = Cryptor.GetDecryptedContent <Record>(encryptedBytes, _password);

            return(record);
        }
Пример #2
0
        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));
        }
Пример #3
0
 public Safe(string password)
 {
     _password   = password;
     Cryptor     = new Cryptor();
     DataGateway = new DataGateway();
     Searcher    = new Searcher();
 }
Пример #4
0
        public void UpsertRecord(Record record)
        {
            var recordFileUri        = GetRecordFileUri(record.Header.Id);
            var encryptedRecordBytes = Cryptor.GetEncryptedBytes(record, _password);

            DataGateway.DeleteFileIfAvailable(recordFileUri);
            DataGateway.PutBytes(recordFileUri, encryptedRecordBytes);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
                }
            }
        }
Пример #8
0
        public void DeleteRecord(string recordId)
        {
            var recordFile = GetRecordFileUri(recordId);

            DataGateway.DeleteFileIfAvailable(recordFile);
        }