/// <summary> /// Add a property to the object. /// </summary> /// <param name="propertyName">Name of the object</param> /// <param name="type">Property type</param> /// <param name="subscribe">True to cause the property to be subscribed to</param> /// <returns></returns> public async Task AddPropertyAsync(string propertyName, PremiseProperty.PremiseType type = PremiseProperty.PremiseType.TypeText, bool subscribe = false) { try { _properties[propertyName] = new PremiseProperty(propertyName, type); Debug.WriteLine("getting {0} {1}", Location, propertyName); this.SetMember(propertyName, await PremiseServer.Instance.GetValueTaskAsync(Location, propertyName), false); if (subscribe) // Do we really want to await here? await PremiseServer.Instance.Subscribe(this, propertyName); } catch (Exception ex) { throw ex; } }
public void SetMember(String propertyName, object value, bool fromUI = true) { PremiseProperty current = null; if (!_properties.TryGetValue(propertyName, out current)) { current = new PremiseProperty(propertyName, PremiseProperty.PremiseType.TypeText); } // Only update value if it changed if (current.Value == value) return; current.Value = value; _properties[propertyName] = current; OnPropertyChanged(propertyName); if (fromUI) { Debug.WriteLine("Updating server: {0}: {1}", propertyName, value); SendPropertyChangeToServer(propertyName, value); } }