Пример #1
0
 /// <summary>
 /// Called to end an edit operation
 /// </summary>
 /// <param name="vm"></param>
 /// <param name="success">True for persist, False to cancel edits</param>
 public void OnEndEdit(ValidatingViewModel vm, bool success)
 {
     if (!success)
     {
         RestoreFieldValues(vm, _savedState);
     }
     _savedState = null;
 }
Пример #2
0
        /// <summary>
        /// Returns the fields to capture
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        private IEnumerable <FieldInfo> GetFieldsToSerialize(ValidatingViewModel target)
        {
            EditingViewModel      evm       = target as EditingViewModel;
            Predicate <FieldInfo> testField = (evm != null && evm.FieldPredicate != null) ? evm.FieldPredicate : f => true;

            return(target.GetType()
                   .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                   .Where(f => f.GetType() != typeof(ShallowCopyEditableObject) && testField(f)));
        }
Пример #3
0
            public void ReturnsTrueForOutdatedValidationContext()
            {
                var vm = new ValidatingViewModel();

                vm.FirstName = "some value";

                var lastUpdated = vm.ValidationContext.LastModifiedTicks;

                vm.FirstName = null;

                Assert.IsTrue(vm.IsValidationSummaryOutdated(lastUpdated, true));
            }
Пример #4
0
            public void ReturnsTrueForOutdatedValidationContext()
            {
                var vm = new ValidatingViewModel();

                vm.FirstName = "some value";

                var lastUpdated = vm.ValidationContext.LastModifiedTicks;

                vm.FirstName = null;

                Assert.IsTrue(vm.IsValidationSummaryOutdated(lastUpdated, true));
            }
Пример #5
0
        private List <string> CaptureErrorChanges(ValidatingViewModel obj, Action action)
        {
            var changes = new List <string>();

            obj.ErrorsChanged += (sender, e) =>
            {
                changes.Add(e.PropertyName);
            };

            action();

            return(changes);
        }
Пример #6
0
            public void ReturnsFalseForNotOutdatedValidationContext()
            {
                var vm = new ValidatingViewModel();

                vm.FirstName = "some value";

                var lastUpdated = DateTime.Now.Ticks + 1;

                // Only full .NET supports reliable stopwatch, all other frameworks always assume outdated
#if NET
                Assert.IsFalse(vm.IsValidationSummaryOutdated(lastUpdated, true));
#else
                Assert.IsTrue(vm.IsValidationSummaryOutdated(lastUpdated, true));
#endif
            }
Пример #7
0
            public void ReturnsFalseForNotOutdatedValidationContext()
            {
                var vm = new ValidatingViewModel();

                vm.FirstName = "some value";

                var lastUpdated = DateTime.Now.Ticks + 1;

                // Only full .NET supports reliable stopwatch, all other frameworks always assume outdated
#if NET
                Assert.IsFalse(vm.IsValidationSummaryOutdated(lastUpdated, true));
#else
                Assert.IsTrue(vm.IsValidationSummaryOutdated(lastUpdated, true));
#endif
            }
Пример #8
0
 /// <summary>
 /// This restores the state of the current object from the passed clone object.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="fieldValues">Object to restore state from</param>
 private void RestoreFieldValues(ValidatingViewModel target, Dictionary <string, object> fieldValues)
 {
     foreach (FieldInfo fi in GetFieldsToSerialize(target))
     {
         object value;
         if (fieldValues.TryGetValue(fi.Name, out value))
         {
             fi.SetValue(target, value);
         }
         else
         {
             Debug.WriteLine("Failed to restore field " + fi.Name + " from cloned values, field not found in Dictionary.");
         }
     }
 }
        private void DialogHost_Closing(object sender, CancelEventArgs e)
        {
            string errorIfInvalidIdentifier = this.Model.GetErrorIfInvalidIdentifier(this.AreaName);

            if (!string.IsNullOrEmpty(errorIfInvalidIdentifier))
            {
                ValidatingViewModel.DisplayErrorMessage(this.DialogHost, errorIfInvalidIdentifier);
                e.Cancel = true;
                return;
            }
            if (this.Model.AreaExists(this.AreaName))
            {
                ValidatingViewModel.DisplayErrorMessage(this.DialogHost, Resources.AreaExistsMessage);
                e.Cancel = true;
            }
        }
Пример #10
0
 /// <summary>
 /// This is used to clone the object.  Override the method to provide a more efficient clone.  The
 /// default implementation simply reflects across the object copying every field.
 /// </summary>
 /// <returns>Clone of current object</returns>
 private Dictionary <string, object> GetFieldValues(ValidatingViewModel target)
 {
     return(GetFieldsToSerialize(target)
            .Select(fi => new { Key = fi.Name, Value = fi.GetValue(target) })
            .ToDictionary(k => k.Key, k => k.Value));
 }
Пример #11
0
 /// <summary>
 /// Called to begin an edit operation
 /// </summary>
 public void OnBeginEdit(ValidatingViewModel vm)
 {
     _savedState = GetFieldValues(vm);
 }