示例#1
0
        private void GetPropertiesFromStorage()
        {
            // Get properties from storage
            _rehydratedProperties = PersistenceStorage.GetObjectFromIsolated <List <PersistenceProperties> >(_persistenceProperties);

            LoadProperties();
        }
示例#2
0
        private void DehydrateObjects()
        {
            List <PersistenceProperties> dehydrated = new List <PersistenceProperties>();

            // Examine each object
            foreach (KeyValuePair <string, object> obj in _persistentObjects)
            {
                if (obj.Value != null)
                {
                    // Notify object that it is about to be dehydrated
                    if (obj.Value is IPersistent && ApplicationMode == ApplicationMode.Deactivated)
                    {
                        (obj.Value as IPersistent).OnDeactivated();
                    }
                    else if (obj.Value is IPersistent && ApplicationMode == ApplicationMode.Closing)
                    {
                        (obj.Value as IPersistent).OnClosing();
                    }

                    IEnumerable <PropertyInfo> pi = null;

                    pi = obj.Value.GetType().GetProperties();


                    // Examine each property
                    foreach (PropertyInfo p in pi)
                    {
                        // Add any properties with Persist attribute
                        object[] atts = null;

                        atts = p.GetCustomAttributes(typeof(Persist), true);


                        if (atts != null && atts.Length > 0)
                        {
                            PersistMode mode = (atts[0] as Persist).PersistMode;
                            if ((this.ApplicationMode == ApplicationMode.Deactivated &&
                                 (mode == PersistMode.TombstonedOnly || mode == PersistMode.Both)) ||
                                (this.ApplicationMode == ApplicationMode.Closing &&
                                 (mode == PersistMode.ClosedOnly || mode == PersistMode.Both)))
                            {
                                var tsp = new PersistenceProperties(obj.Key, obj.Value.GetType().Name, p.Name, p.GetValue(obj.Value, null));

                                dehydrated.Add(tsp);
                            }
                        }
                    }
                }
            }

            dehydrated.TrimExcess();


            PersistenceStorage.StoreObjectToIsolated <List <PersistenceProperties> >(_persistenceProperties, dehydrated, true);
        }