public async Task SessionStateSeralizationTest() { var sessionState = new SessionState(false); sessionState.AddOrUpdateSubscription(MethodPostTopicPrefix, QualityOfService.AtLeastOnce); sessionState.RemoveSubscription(TwinSubscriptionTopicPrefix); Assert.True(sessionState.SubscriptionRegistrations.ContainsKey(MethodPostTopicPrefix)); Assert.True(sessionState.SubscriptionRegistrations.ContainsKey(TwinSubscriptionTopicPrefix)); Assert.True(sessionState.SubscriptionRegistrations[MethodPostTopicPrefix]); Assert.False(sessionState.SubscriptionRegistrations[TwinSubscriptionTopicPrefix]); IEntityStore <string, SessionState> entityStore = new StoreProvider(new InMemoryDbStoreProvider()).GetEntityStore <string, SessionState>(Constants.SessionStorePartitionKey); string key = Guid.NewGuid().ToString(); await entityStore.Put(key, sessionState); Option <SessionState> retrievedSessionStateOption = await entityStore.Get(key); Assert.True(retrievedSessionStateOption.HasValue); SessionState retrievedSessionState = retrievedSessionStateOption.OrDefault(); Assert.NotNull(retrievedSessionState); Assert.NotNull(retrievedSessionState.Subscriptions); Assert.NotNull(retrievedSessionState.Subscriptions.FirstOrDefault(s => s.TopicFilter == MethodPostTopicPrefix)); Assert.True(retrievedSessionState.SubscriptionRegistrations.ContainsKey(MethodPostTopicPrefix)); Assert.True(retrievedSessionState.SubscriptionRegistrations.ContainsKey(TwinSubscriptionTopicPrefix)); Assert.True(retrievedSessionState.SubscriptionRegistrations[MethodPostTopicPrefix]); Assert.False(retrievedSessionState.SubscriptionRegistrations[TwinSubscriptionTopicPrefix]); }
public IEnumerable <T> GetCollection <T>(Key key) { return(_retryStrategy.ExecuteFuncWithRetry( () => Helpers.SeparateJsonArray(StoreProvider.Get(key)).Select(s => Serializer.Deserialize <T>(s)).ToList() )); }
public T Get <T>(Key key, out ulong cas) { //horrendous hack for accomodating out params! ulong casOut = 0; var outerResult = _retryStrategy.ExecuteFuncWithRetry( () => { ulong cas2; var innerResult = Serializer.Deserialize <T>(StoreProvider.Get(key, out cas2)); casOut = cas2; return(innerResult); }); cas = casOut; return(outerResult); }
public IEnumerable <T> GetCollection <T>(Key key, out ulong cas) { // nasty hack for out params ulong casOut = 0; var outerResult = _retryStrategy.ExecuteFuncWithRetry( () => { ulong cas2; var innerResult = Helpers.SeparateJsonArray(StoreProvider.Get(key, out cas2)).Select( s => Serializer.Deserialize <T>(s)).ToList(); casOut = cas2; return(innerResult); }); cas = casOut; return(outerResult); }
public T Get <T>(Key key) { return(_retryStrategy.ExecuteFuncWithRetry( () => Serializer.Deserialize <T>(StoreProvider.Get(key)))); }