private byte[] ReadFromDbFile(DbFileResource dbFile, int capacity, long position) { byte[] data, hash; lock (dbFile) ReadFromDbFile(dbFile, capacity, position, out data, out hash); var control = new MD5CryptoServiceProvider().ComputeHash(data); if (!control.SequenceEqual(hash)) { return(null); } return(data); }
/// <summary> /// Test the connection with a nq file /// </summary> private void TestConnection() { try { if (!Directory.Exists(FilesDirectory)) { Directory.CreateDirectory(FilesDirectory); } string testFilePath = $"{FilesDirectory}/test.nq"; string downloadedTestFilePath = $"{FilesDirectory}/downloadedtest.nq"; //nq file creation File.WriteAllText(testFilePath, $"Testing file... {DateTime.Now.Ticks}"); //summarie of nq file byte[] fileHash = new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(testFilePath)); //download nq file WebClient client = new WebClient(); client.DownloadFile($"{Uri}/test.nq", downloadedTestFilePath); //summarie of downloaded nq file byte[] downloadedFileHash = new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(downloadedTestFilePath)); //if the summaries are different, something is wrong if (!fileHash.SequenceEqual(downloadedFileHash)) { Console.Error.Write("The connection to the server could not be established or nq files are not supported."); throw new WebException("The connection to the server could not be established or nq files are not supported."); } //Test resource api string url = $"{ApiUrl}/resource/test-massive-load"; MassiveDataLoadTestResource resource = new MassiveDataLoadTestResource() { fileHash = fileHash, url = $"{Uri}/test.nq" }; WebRequestPostWithJsonObject(url, resource); } catch (Exception) { throw new WebException($"The connection to the server could not be established or nq files are not supported. {Uri}"); } }