public virtual void Refresh(IBehaviorContext context, RefreshOptions options) { this.RefreshNext(context, options); // Note 1: We even revalidate if 'RefreshContainer' was called. 'RefreshContainer' // is used if items are added/removed in the source (e.g. domain model). // But these new items may be initially invalid, so we have to revalidate. // Note 2: We always transition to scope 'SelfAndLoadedDescendants'. Otherwise to // following unwanted scenario may occur: // 1. Revalidate with scope 'SelfAndAllDescendants' is called (e.g. for // a newly created record) for a parent VM. // 2. A new complex VM is added which has descendant which should never // be loaded in the context of the parent (e.g. the VM is also reused // in other places). // 3. Refresh is called on the parent. If we reuse the previous scope, // all descendants of the complex VM of step 2 would be loaded. // Anonther reason why we might not want to laod all new added descendants // is performance, especially if we used 'SelfAndAllDescendants' initially // for a new (and nearly empty) record to revalidate it once. State s = GetState(context); switch (s.Type) { case StateType.Validated: TransitionToValidated(context, ValidationScope.SelfAndLoadedDescendants); break; } }
public override void Refresh(IBehaviorContext context, RefreshOptions options) { DetectValidationResultChange( context, () => base.Refresh(context, options) ); }
public void Refresh(IBehaviorContext context, RefreshOptions options) { var collection = GetValue(context); Repopulate(context, collection, RefreshReason.Create(options.ExecuteRefreshDependencies)); this.RefreshNext(context, options); }
public void Refresh(IBehaviorContext context, RefreshOptions options) { // Call next behavior first, because a source accessor behavior may handle // it. this.RefreshNext(context, options); _collectionSourceCache.Clear(context); // ToArray so that (1) source is only enumerated once and (2) acess by index // (required by the equality check) is guaranteed to be fast. TItemSource[] newSourceItems = GetSourceItems(context).ToArray(); IVMCollection <TItemVM> vmCollection = GetValue(context); IEnumerable <TItemVM> itemsToRefresh = Enumerable.Empty <TItemVM>(); if (AreCollectionContentsEqual(vmCollection, newSourceItems)) { itemsToRefresh = vmCollection; } else { Dictionary <TItemSource, TItemVM> previousItemsBySource = vmCollection.ToDictionary( x => x.Source, _reusabilitySourceComparer ); List <TItemVM> newItems = new List <TItemVM>(); List <TItemVM> reusedItems = new List <TItemVM>(); foreach (TItemSource s in newSourceItems) { TItemVM item; bool isReusedItem = previousItemsBySource.TryGetValue(s, out item); if (isReusedItem) { reusedItems.Add(item); } else { item = CreateAndInitializeItem(context, s); } newItems.Add(item); } vmCollection.ReplaceItems(newItems, RefreshReason.Create(options.ExecuteRefreshDependencies)); itemsToRefresh = reusedItems; } if (options.Scope.HasFlag(RefreshScope.Content)) { itemsToRefresh .ForEach(x => x.Kernel.RefreshWithoutValidation(options.ExecuteRefreshDependencies)); } }
public void Refresh(IBehaviorContext context, RefreshOptions options) { var collection = GetValue(context); foreach (TItemVM item in collection) { item.Kernel.RefreshWithoutValidation(options.ExecuteRefreshDependencies); } this.RefreshNext(context, options); }
internal void RefreshInternal(IVMPropertyDescriptor property, RefreshOptions options) { _descriptor.Behaviors.ViewModelRefreshNext(this, property, options); // Refresh does not revalidate the property value itself. Descendants are // automatically validated by the appropriate behaviors. Revalidator.RevalidatePropertyValidations( _vm, property, ValidationScope.Self ); }
public void Refresh(IBehaviorContext context, RefreshOptions options) { RequireInitialized(); TSource source = this.GetValueNext <TSource>(context); TValue childVM = GetValue(context); // Note: We must not call 'SetValueNext' here because a Refresh would // try to set the source property which may fail if it is a readonly // property. if (source != null) { if (childVM != null) { bool sourceObjectHasChanged = !Object.ReferenceEquals(childVM.Source, source); bool alwaysRefreshChild = options.Scope.HasFlag(RefreshScope.Content); if (sourceObjectHasChanged || alwaysRefreshChild) { childVM.Source = source; childVM.Kernel.RefreshWithoutValidation(options.ExecuteRefreshDependencies); } } else { childVM = CreateViewModel(context); childVM.Source = source; UpdateCache(context, childVM); } } else { UpdateCache(context, default(TValue)); } this.RefreshNext(context, options); }
public void Refresh(IBehaviorContext context, RefreshOptions options) { RequireInitialized(); var previousValue = GetValue(context); RefreshCache(context); var newValue = GetValue(context); if (!Object.Equals(newValue, previousValue)) { var args = ChangeArgs.ViewModelPropertyChanged( _property, ValueStage.ValidatedValue, previousValue, newValue, RefreshReason.Create(options.ExecuteRefreshDependencies) ); context.NotifyChange(args); } this.RefreshNext(context, options); }
public void Refresh(IBehaviorContext context, IVMPropertyDescriptor property, RefreshOptions options) { RefreshTrace.BeginRefresh(property); RequireInitialized(); property.Behaviors.RefreshNext(context, options); this.ViewModelRefreshNext(context, property, options); RefreshTrace.EndLastRefresh(); }