public LocalBillsService( IBillingUnitOfWorkFactory _billingUnitOfWorkFactory ) { this._billingUnitOfWorkFactory = _billingUnitOfWorkFactory ?? throw new ArgumentNullException(nameof(_billingUnitOfWorkFactory)); this._added_Subject = new Subject <BillDto>().DisposeWith(this._disposables); this._updated_Subject = new Subject <IReadOnlyCollection <BillDto> >().DisposeWith(this._disposables); this._removed_Subject = new Subject <IReadOnlyCollection <long> >().DisposeWith(this._disposables); //this._isBusy_BehaveiorSubject = new BehaviorSubject<bool>(false).DisposeWith(this._disposables); //this.IsBusyChanged = this._isBusy_BehaveiorSubject.DistinctUntilChanged(); this._billsChangesSubscription = new SerialDisposable().DisposeWith(this._disposables); }
public LocalSuppliersService( IBillingUnitOfWorkFactory _billingUnitOfWorkFactory ) { this._billingUnitOfWorkFactory = _billingUnitOfWorkFactory ?? throw new ArgumentNullException(nameof(_billingUnitOfWorkFactory)); this._added_Subject = new Subject <SupplierDto>().DisposeWith(this._disposables); this._updated_Subject = new Subject <IReadOnlyCollection <SupplierDto> >().DisposeWith(this._disposables); this._removed_Subject = new Subject <IReadOnlyCollection <long> >().DisposeWith(this._disposables); //this._isBusy_BehaveiorSubject = new BehaviorSubject<bool>(false).DisposeWith(this._disposables); //this.IsBusyChanged = this._isBusy_BehaveiorSubject.DistinctUntilChanged(); this._suppliersChangesSubscription = new SerialDisposable().DisposeWith(this._disposables); var supplierDtoChangeSets = ObservableChangeSet.Create <SupplierDto, long>( async cache => { //await Task.Delay(3_000); var supplierDTOs = await this.GetAllAsync().ConfigureAwait(false); cache.AddOrUpdate(supplierDTOs); var crudSubscriptions = new CompositeDisposable(); this.Added .Subscribe(supplierDto => cache.Edit(cacheUpdater => cacheUpdater.AddOrUpdate(supplierDto))) .DisposeWith(crudSubscriptions); this.Updated .Subscribe(e => { cache.Edit(cacheUpdater => { var updates = e .Select( updatedSupplierDto => { var oldVersion = cacheUpdater.Lookup(updatedSupplierDto.Id); return(new Change <SupplierDto, long>( ChangeReason.Update, updatedSupplierDto.Id, updatedSupplierDto, oldVersion)); }) .ToArray(); var changes = new ChangeSet <SupplierDto, long>(updates); cacheUpdater.Clone(changes); }); }) .DisposeWith(crudSubscriptions); this.Removed .Subscribe(e => cache.Edit(cacheUpdater => cacheUpdater.Remove(e))) .DisposeWith(crudSubscriptions); return(crudSubscriptions); }, x => x.Id) //this.SuppliersChanges = supplierDtoChangeSets // //.RefCount() // //.Transform(supplier => this._supplierViewModelFactoryMethod.Invoke(supplier), new ParallelisationOptions(ParallelType.Parallelise)) // //.DisposeMany() // .Sort(SortExpressionComparer<SupplierDto>.Ascending(vm => vm.Name)) //.Multicast(new ReplaySubject<IChangeSet<SupplierDto, int>>()) //.AutoConnect(1, subscription => this._suppliersChangesSubscription.Disposable = subscription) ; this.Suppliers = supplierDtoChangeSets //.Sort(SortExpressionComparer<SupplierDto>.Ascending(vm => vm.Name)) .RefCount() .AsObservableCache(); // applyLocking: false); }