internal static PersistentBlob ToBlob <T>(this T value) { var bytes = value.ToJson().ToZipBytes(); var blob = new PersistentBlob(bytes); return(blob); }
internal static T FromBlob <T>(this PersistentBlob value) { var bytes = value.GetBytes(); var json = bytes.FromZipBytes(); return(json.FromJson <T>()); }
/// <summary> /// Retrieve all string records in the table. /// </summary> public void RetrieveAllStringRecords() { foreach (var entry in this.stringDictionary.Keys) { PersistentBlob value = this.stringDictionary[entry]; } }
/// <summary> /// Retrieve the current record multiple times using string keys. /// </summary> /// <param name="numRetrieves">The number of times to retrieve the record.</param> public void RepeatedlyRetrieveOneStringRecord(int numRetrieves) { for (int i = 0; i < numRetrieves; ++i) { PersistentBlob value = this.stringDictionary[this.lastStringKey]; } }
public void TestGenericStructAndPersistenBlobDictionary() { try { using (var dictionary = new PersistentDictionary <int, ContainingStruct>(DictionaryPath)) { var blob = new PersistentBlob(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); var nestedBlob = new ContainingStruct() { Key = 3, Blob = blob, }; RunDictionaryTests(dictionary, 1, nestedBlob); RunDictionaryTests(dictionary, 2, new ContainingStruct()); RunDictionaryTests(dictionary, 3, new ContainingStruct() { Key = 4, Blob = new PersistentBlob(new byte[0]) }); } } catch (ArgumentOutOfRangeException ex) { var expectedMessage = (new ArgumentOutOfRangeException("TColumn", typeof(ContainingStruct), "Not supported for SetColumn")).Message; Assert.AreEqual(expectedMessage, ex.Message); } }
public void TestGenericStructAndPersistenBlobDictionary() { try { using (var dictionary = new PersistentDictionary <int, ContainingStruct>(DictionaryPath)) { var blob = new PersistentBlob(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); var nestedBlob = new ContainingStruct() { Key = 3, Blob = blob, }; RunDictionaryTests(dictionary, 1, nestedBlob); RunDictionaryTests(dictionary, 2, new ContainingStruct()); RunDictionaryTests(dictionary, 3, new ContainingStruct() { Key = 4, Blob = new PersistentBlob(new byte[0]) }); } } catch (ArgumentOutOfRangeException ex) { #if NETCOREAPP3_0 Assert.AreEqual("Not supported for SetColumn (Parameter 'TColumn')\r\nActual value was EsentCollectionsTests.GenericDictionaryTests+ContainingStruct.", ex.Message); #else Assert.AreEqual("Not supported for SetColumn\r\nParameter name: TColumn\r\nActual value was EsentCollectionsTests.GenericDictionaryTests+ContainingStruct.", ex.Message); #endif } }
/// <summary> /// Initializes a new instance of the <see cref="PerfTestWorker"/> class. /// </summary> public PerfTestWorker() { EseInteropTestHelper.ThreadBeginThreadAffinity(); this.data = new byte[DictionaryOpenCloseTest.DataSize]; this.persistentBlob = new PersistentBlob(this.data); this.RandomGenerator = new Random(); }
public void TestGenericStringPersistenBlobDictionary() { using (var dictionary = new PersistentDictionary <string, PersistentBlob>(DictionaryPath)) { var blob = new PersistentBlob(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); RunDictionaryTests(dictionary, "blob0", blob); RunDictionaryTests(dictionary, "blob1", new PersistentBlob(null)); RunDictionaryTests(dictionary, "blob2", new PersistentBlob(new byte[0])); } }
/// <summary> /// Retrieve the current record multiple times. /// </summary> /// <param name="numRetrieves">The number of times to retrieve the record.</param> public void RepeatedlyRetrieveOneRecord(int numRetrieves) { for (int i = 0; i < numRetrieves; ++i) { try { RetryIfDisposed(() => { PersistentBlob value = PerfDictionary[this.lastKey]; }); } catch (KeyNotFoundException) { // Maybe we switched to a new database? } } }
/// <summary> /// Initializes a new instance of the <see cref="PerfTestWorker"/> class. /// </summary> /// <param name="longDictionary"> /// The dictionary to use for integer lookups. /// </param> /// <param name="longDatabase"> /// Path to the integer-lookup database. The database should already be created. /// </param> /// <param name="stringDictionary"> /// The dictionary to use for string lookups. /// </param> /// <param name="stringDatabase"> /// Path to the string-lookup database. The database should already be created. /// </param> public PerfTestWorker( PersistentDictionary <long, PersistentBlob> longDictionary, string longDatabase, PersistentDictionary <string, PersistentBlob> stringDictionary, string stringDatabase) { EseInteropTestHelper.ThreadBeginThreadAffinity(); this.longDictionary = longDictionary; this.longDatabase = longDatabase; this.stringDictionary = stringDictionary; this.stringDatabase = stringDatabase; this.data = new byte[SimpleDictionaryPerfTest.DataSize]; this.persistentBlob = new PersistentBlob(this.data); }
private TValue DecodeValue(PersistentBlob value) { return(valueDecoder(value.GetBytes())); }