コード例 #1
0
        /// <summary>
        /// Reads the data from the tracked properties and saves it to the data store for the tracked object.
        /// </summary>
        public void Persist()
        {
            if (TargetReference.IsAlive)
            {
                if (TargetStore == null)
                {
                    TargetStore = InitStore();
                }

                foreach (string propertyName in TrackedProperties.Keys)
                {
                    var value = TrackedProperties[propertyName].Getter(TargetReference.Target);
                    try
                    {
                        var shouldPersist = OnPersistingState(propertyName, ref value);
                        if (shouldPersist)
                        {
                            TargetStore.Set(value, propertyName);
                        }
                        else
                        {
                            Trace.WriteLine(string.Format("Persisting cancelled, key='{0}', property='{1}'.", Key, propertyName));
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(string.Format("Persisting failed, property key = '{0}', message='{1}'.", propertyName, ex.Message));
                    }
                }

                TargetStore.CommitChanges();

                OnStatePersisted();
            }
        }
コード例 #2
0
        /// <summary>
        /// Reads the data from the tracked properties and saves it to the data store for the tracked object.
        /// </summary>
        public void Persist()
        {
            if (TargetReference.IsAlive)
            {
                foreach (string propertyName in TrackedProperties.Keys)
                {
                    var value = TrackedProperties[propertyName].Getter(TargetReference.Target);

                    try
                    {
                        value = OnPersistingState(propertyName, value);
                        TargetStore.Set(value, propertyName);
                    }
                    catch (OperationCanceledException ex)
                    {
                        Trace.WriteLine(string.Format("Persisting cancelled, property key = '{0}', message='{1}'.", propertyName, ex.Message));
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(string.Format("Persisting failed, property key = '{0}', message='{1}'.", propertyName, ex.Message));
                    }
                }

                TargetStore.CommitChanges();

                OnStatePersisted();
            }
        }