private PropertyTask<ReadOnlyCollectionShortcut<SavedListConfigViewModel>> EnsureConfigsTask() { if (_configsTask != null) return _configsTask; return _configsTask = new PropertyTask<ReadOnlyCollectionShortcut<SavedListConfigViewModel>>( notifier: () => { OnPropertyChanged("Configs"); OnPropertyChanged("ConfigsAsync"); }, createTask: () => { var ctx = ViewModelFactory.CreateNewContext(); var qryTask = ctx.GetQuery<SavedListConfiguration>() .Where(i => i.Type.ExportGuid == Parent.DataType.ExportGuid) // Parent.DataType might be from FrozenContext .Where(i => i.Owner == null || i.Owner.ID == this.CurrentPrincipal.ID) .ToListAsync(); var result = new ZbTask<ReadOnlyCollectionShortcut<SavedListConfigViewModel>>(qryTask); result .OnResult(t => { t.Result = new ReadOnlyCollectionShortcut<SavedListConfigViewModel>(); foreach (var cfg in qryTask.Result) { var obj = cfg.Configuration.FromXmlString<SavedListConfigurationList>(); foreach (var item in obj.Configs) { t.Result.Rw.Add(ViewModelFactory.CreateViewModel<SavedListConfigViewModel.Factory>().Invoke(DataContext, this, item, cfg.Owner != null)); } } }) .Finally(() => ctx.Dispose()); return result; }, set: null); }
private void TriggerPossibleValuesROAsync() { if (_getPossibleValuesROTask == null) { var task = GetPossibleValuesAsync(); _getPossibleValuesROTask = new ZbTask<ReadOnlyObservableCollection<TagEntryViewModel>>(task); _getPossibleValuesROTask.OnResult(t => { _possibleValues = new ObservableCollection<TagEntryViewModel>(task.Result); _possibleValuesRO = new ReadOnlyObservableCollection<TagEntryViewModel>(_possibleValues); EnsureValuePossible(Value); OnPropertyChanged("PossibleValuesAsync"); OnPropertyChanged("FilteredPossibleValuesAsync"); }); } }