/// <summary> /// Stores the value into the store and returns a <see cref="StoreBackedProperty{T}" /> with the Id for retrieval /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value">The property to store</param> /// <returns>The link to retrieve he object from the store</returns> /// <exception cref="InvalidOperationException"> /// When there is no encoder set for <typeparamref name="T"/> and <see cref="FallbackToBsonEncoder"/> is false /// </exception> public virtual async Task <StoreBackedProperty <T> > StoreValueAsync <T>(T value) { ThrowIfDisposed(); ThrowIfNoDataCommunicator(); var property = new StoreBackedProperty <T>(Guid.NewGuid().ToString()); var encoder = GetEncoder <T>(); var bytes = encoder.Encode(value); await DataCommunicator.StoreDataAsync(property.Id, bytes).ConfigureAwait(false); return(property); }
/// <summary> /// Retrieves the value from the store using the <see cref="DataCommunicator"/> and the appropriate <see cref="IStoreBackedPropertyEncoder{T}"/> /// </summary> /// <typeparam name="T">The type of value to retrieve</typeparam> /// <param name="property">The property that is being pulled. The <see cref="StoreBackedProperty{T}.Id"/> should be set properly</param> /// <returns>The deserialized property from the store</returns> public virtual async Task <T> GetValueAsync <T>(StoreBackedProperty <T> property) { ThrowIfDisposed(); ThrowIfNoDataCommunicator(); if (property == null) { throw new ArgumentNullException(nameof(property)); } var encoder = GetEncoder <T>(); var data = await DataCommunicator.GetDataAsync(property.Id) .ConfigureAwait(false); return(encoder.Decode(data)); }