Exemplo n.º 1
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Ensure that the given property is present in the in-memory cache - if not, the
        /// property is populated with its initial value from the backing store (or with a
        /// default empty value if the item is not a persisted type).
        /// </summary>
        //------------------------------------------------------------------------------------
        private ItemProperty EnsureItemProperty(string dsPropName, string publicPropName, PropType type)
        {
            if (publicPropName == null)
            {
                throw new ApplicationException();
            }

            ItemProperty itemProperty = null;

            lock (SyncLockItemProperties)
            {
                if (!ItemProperties.TryGetValue(publicPropName, out itemProperty))
                {
                    itemProperty = new ItemProperty(this, dsPropName, publicPropName, type);
                    if (IsPersisted)
                    {
                        itemProperty.ReadFromStore();
                    }

                    ItemProperties.Add(publicPropName, itemProperty);
                }
            }

            return(itemProperty);
        }
Exemplo n.º 2
0
        public object GetRefreshedBackingValue <T>(Expression <Func <T> > expression)
        {
            string publicPropName = StringUtils.GetExpressionName(expression);

            if (ItemProperties.ContainsKey(publicPropName))
            {
                ItemProperty itemProperty = ItemProperties[publicPropName];
                itemProperty.ReadFromStore();
                return(itemProperty.BackingValue);
            }

            return(null);
        }
Exemplo n.º 3
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Reads the latest value of the given property from the backing store, and if the
        /// value is different what's currently in memory, sets the value of the given
        /// property to the new value.
        /// </summary>
        //------------------------------------------------------------------------------------
        public void SyncPropertyFromStore(ItemProperty itemProperty)
        {
            // Read the latest value from the backing store
            ItemProperty propertyFromStore = new ItemProperty(this, itemProperty.DSPropName, itemProperty.PublicPropName, itemProperty.PropertyType);

            propertyFromStore.ReadFromStore();

            // If the backing store value doesn't match in the in-memory cached value, update
            // the object model with the new value.
            if (!propertyFromStore.IsEqual(itemProperty))
            {
                // First set the backing value of our in-memory property to the value from the store
                itemProperty.BackingValue = propertyFromStore.BackingValue;

                // Use the same value to set the current value (via the object model) so that
                // backing and current values are sync'd, and all UI side-effects are enacted.
                SetPublicProperty(itemProperty.PublicPropName, propertyFromStore.BackingValue);
            }
        }