public async Task <SubscriptionOnStateValue> Subscribe(string sentinelHost, string packageHost, string stateValueName) { using (var client = new HomeConnectionClient(HomeHubConnection)) { var stateValueKey = new StateValueKey(sentinelHost, packageHost, stateValueName); await SubscribeOnValueChanged(stateValueKey); var subscriptionKeyValue = await client.PostAsJson <string>("subscription", new Subscription(SentinelHost.GetName(), sentinelHost, packageHost, stateValueName)); if (!string.IsNullOrEmpty(subscriptionKeyValue)) { var subscriptionKey = new SubscriptionKey(subscriptionKeyValue); if (subscriptionKey.IsValid()) { var subscriptionOnStateValue = new SubscriptionOnStateValue(subscriptionKey, stateValueKey); AddSubscriptionInStore(stateValueKey, subscriptionOnStateValue); return(subscriptionOnStateValue); } } else { await UnSubscribeOnValueChanged(new StateValueKey(sentinelHost, packageHost, stateValueName)); } } return(null); }
public void return_true_when_subscription_key_is_not_empty() { var subscriptionKey = new SubscriptionKey(Guid.NewGuid().ToString()); Check.That(subscriptionKey.IsValid()).IsEqualTo(true); }