Example #1
0
        /// <summary>
        ///     Add a property to the object. Makes a call to the server to get the value.
        /// </summary>
        /// <param name="propertyName">Name of the property (e.g. foo["propertyname"])</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 {
                PremiseProperty prop;
                if (!_properties.TryGetValue(propertyName, out prop)) {
                    _properties[propertyName] = new PremiseProperty(propertyName) { PropertyType = type };
                }

                if (subscribe) {
                    await PremiseServer.Instance.Subscribe(this, propertyName);
                }

                // Sadly, premise does not automatically send a update notification upon
                // a subscription. Thus even for properites where we are using a subscription
                // we have to block waiting for the initial value. 
                string val = await PremiseServer.Instance.GetValueTaskAsync(Location, propertyName);
                Debug.WriteLine("got {0} {1} = {2}", Location, propertyName, val);

                SetMember(propertyName, val, false);
                HasServerData = true;
            } catch (Exception) {
                throw;
            }
        }
Example #2
0
        /// <summary>
        ///     Add a property to the object. Makes a call to the server to get the value.
        /// </summary>
        /// <param name="propertyName">Name of the property (e.g. foo["propertyname"])</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 {
                PremiseProperty prop = null;
                if (!_properties.TryGetValue(propertyName, out prop)) {
                    _properties[propertyName] = new PremiseProperty(propertyName) { PropertyType = type };
                }

                //Debug.WriteLine("getting {0} {1}", Location, propertyName);
                string val = await PremiseServer.Instance.GetValueTaskAsync(Location, propertyName);
                Debug.WriteLine("got {0} {1} = {2}", Location, propertyName, val.ToString());

                this.SetMember(propertyName, val, false);
                if (subscribe)
                    // BUGBUG: Should we await here? 
                    PremiseServer.Instance.Subscribe(this, propertyName);

                HasServerData = true;
            } catch (Exception ex) {
                throw ex;
            }
        }
Example #3
0
 /// <summary>
 ///     Add a property to the object. Makes a call to the server to get the value.
 /// </summary>
 /// <param name="propertyName">Name of the property (e.g. foo["propertyname"])</param>
 /// <param name="initalValue">Initial value for the property (enables reducing UI churn on first load)</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,
                                    object initalValue,
                                    PremiseProperty.PremiseType type = PremiseProperty.PremiseType.TypeText,
                                    bool subscribe = false) {
     try {
         PremiseProperty prop = null;
         if (!_properties.TryGetValue(propertyName, out prop)) {
             _properties[propertyName] = new PremiseProperty(propertyName) {PropertyType = type, Value = initalValue};
         }
         AddPropertyAsync(propertyName, type, subscribe);
     } catch (Exception ex) {
         throw ex;
     }
 }
Example #4
0
        //public async void SetMemberAsync(String propertyName, object value, bool sendToServer = true) {
        //    PremiseProperty current = null;
        //    if (!_properties.TryGetValue(propertyName, out current)) {
        //        current = new PremiseProperty(propertyName);
        //    }
        //    // Only update value if it changed
        //    if (current.Value == value) return;

        //    current.Value = value;
        //    _properties[propertyName] = current;
        //    OnPropertyChanged(propertyName);
        //    if (sendToServer) {
        //        var server = PremiseServer.Instance;
        //        if (server != null && !String.IsNullOrEmpty(Location)) {
        //            // Spin up a new thread for this to get it off the UI thread (not really needed, probably)
        //            server.SetValueAsync(Location, propertyName, value.ToString());
        //        }
        //    }
        //}

        public void SetMember(String propertyName, object value, bool sendToServer = true) {
            PremiseProperty current = null;
            if (!_properties.TryGetValue(propertyName, out current)) {
                current = new PremiseProperty(propertyName);
            }
            // Only update value if it changed
            if (current.Value == value) return;

            current.Value = value;
            _properties[propertyName] = current;
            OnPropertyChanged(propertyName);
            if (sendToServer) {
                Debug.WriteLine("Updating server: {0}: {1}", propertyName, value);
                SendPropertyChangeToServer(propertyName, value);
            }
        }
Example #5
0
        /// <summary>
        ///     Add a command property to the object. Commands are boolean toggles, so there is
        ///     no need to request the state from the server.
        /// </summary>
        /// <param name="commandName">Name of the command (e.g. foo["trigger"])</param>
        /// <returns></returns>
        public void AddCommand(string commandName) {
            try {
                _properties[commandName] = new PremiseProperty(commandName, PremiseProperty.PremiseType.TypeBoolean);

                // Make sure any subscribers get notified with the correct property name
                OnPropertyChanged(commandName + "Command");

            } catch (Exception ex) {
                throw ex;
            }
        }
Example #6
0
        /// <summary>
        ///     Add a property to the object. Makes a call to the server to get the value if
        ///     initialValue is not specified or subscribe is set to true.
        /// </summary>
        /// <param name="propertyName">Name of the property (e.g. foo["propertyname"])</param>
        /// <param name="initalValue">Initial value for the property (enables reducing UI churn on first load)</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,
                                           object initalValue,
                                           PremiseProperty.PremiseType type = PremiseProperty.PremiseType.TypeText,
                                           bool subscribe = false) {
            PremiseProperty prop;
            if (!_properties.TryGetValue(propertyName, out prop)) {
                _properties[propertyName] = new PremiseProperty(propertyName) {PropertyType = type, Value = initalValue};
            }

            // Ignore server
            if (initalValue != null && subscribe == false) return;

            await AddPropertyAsync(propertyName, type, subscribe);
        }