コード例 #1
0
ファイル: SessionStateTest.cs プロジェクト: darobs/iotedge-HA
        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]);
        }
コード例 #2
0
 public IEnumerable <T> GetCollection <T>(Key key)
 {
     return(_retryStrategy.ExecuteFuncWithRetry(
                () =>
                Helpers.SeparateJsonArray(StoreProvider.Get(key)).Select(s => Serializer.Deserialize <T>(s)).ToList()
                ));
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public T Get <T>(Key key)
 {
     return(_retryStrategy.ExecuteFuncWithRetry(
                () => Serializer.Deserialize <T>(StoreProvider.Get(key))));
 }