/// <summary> /// Initializes a new instance of the <see cref="PaginationManager{T}" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="reclaimer">The reclaimer.</param> /// <param name="expiryComparer">The expiry comparer.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="maxPages">The maximum pages.</param> /// <param name="maxDeltas">The maximum deltas.</param> /// <param name="maxDistance">The maximum distance.</param> /// <param name="sectionContext">The section context.</param> public PaginationManager( IPagedSourceProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1, string sectionContext = "") { this.PageSize = pageSize; this.MaxPages = maxPages; this.MaxDeltas = maxDeltas; this.MaxDistance = maxDistance; if (provider is IPagedSourceProviderAsync <T> async) { this.ProviderAsync = async; } else { this.Provider = provider; } this._reclaimer = reclaimer ?? new PageReclaimOnTouched <T>(); this.ExpiryComparer = expiryComparer; VirtualizationManager.Instance.AddAction(new ReclaimPagesWA(this, sectionContext)); }
/// <summary> /// Replaces at. /// </summary> /// <param name="offset">The offset.</param> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> /// <param name="updatedAt">The updated at.</param> public void ReplaceAt(int offset, T oldValue, T newValue, object updatedAt, IPageExpiryComparer comparer) { if (IsSafeToUpdate(comparer, updatedAt)) { _Items[offset] = newValue; } }
/// <summary> /// Appends the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public int Append(T item, object updatedAt, IPageExpiryComparer comparer) { _Items.Add(item); LastTouch = DateTime.Now; return(_Items.IndexOf(item)); }
/// <summary> /// Appends the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public int Append(T item, object updatedAt, IPageExpiryComparer comparer) { this.Items.Add(item); this.LastTouch = DateTime.Now; //return this.Items.IndexOf(item); return(this.Items.Count); }
/// <summary> /// Removes at. /// </summary> /// <param name="offset">The offset.</param> /// <param name="updatedAt">The updated at.</param> /// <param name="comparer"></param> /// <returns></returns> public bool RemoveAt(int offset, object updatedAt, IPageExpiryComparer comparer) { if (this.IsSafeToUpdate(comparer, updatedAt)) { this.Items.RemoveAt(offset); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="VirtualizingObservableCollection{T}" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="reclaimer">The optional reclaimer.</param> /// <param name="expiryComparer">The optional expiry comparer.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="maxPages">The maximum pages.</param> /// <param name="maxDeltas">The maximum deltas.</param> /// <param name="maxDistance">The maximum distance.</param> public VirtualizingObservableReactiveCollection( IPagedSourceProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1) : base(provider, reclaimer, pageSize, maxPages, maxDeltas, maxDistance) { }
/// <summary> /// Determines whether it is safe to update into a page where the pending update was generated at a given time. /// </summary> /// <param name="updatedAt">The updated happened at this datetime.</param> /// <returns></returns> public bool IsSafeToUpdate(IPageExpiryComparer comparer, object updatedAt) { var ret = true; if (comparer != null) { ret = comparer.IsUpdateValid(this.WiredDateTime, updatedAt); } return(ret); }
/// <summary> /// Replaces at. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> /// <param name="updatedAt">The updated at.</param> public T ReplaceAt(T oldValue, T newValue, object updatedAt, IPageExpiryComparer comparer) { if (!this.IsSafeToUpdate(comparer, updatedAt)) { return(oldValue); } var offset = this.Items.IndexOf(oldValue); this.Items[offset] = newValue; return(oldValue); }
public ConcurrentIObservableVirtualizingObservableCollection( IPagedSourceProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1) : base(provider, reclaimer, expiryComparer, pageSize, maxPages, maxDeltas, maxDistance) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="VirtualizingObservableCollection{T}" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="reclaimer">The optional reclaimer.</param> /// <param name="expiryComparer">The optional expiry comparer.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="maxPages">The maximum pages.</param> /// <param name="maxDeltas">The maximum deltas.</param> /// <param name="maxDistance">The maximum distance.</param> public VirtualizingObservableCollection( IPagedSourceProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1) : this() { this.Provider = new PaginationManager <T>(provider, reclaimer, expiryComparer, pageSize, maxPages, maxDeltas, maxDistance); }
/// <summary> /// Removes at. /// </summary> /// <param name="offset">The offset.</param> /// <param name="updatedAt">The updated at.</param> /// <returns></returns> public bool RemoveAt(int offset, object updatedAt, IPageExpiryComparer comparer) { bool removed = true; if (IsSafeToUpdate(comparer, updatedAt)) { _Items.RemoveAt(offset); } return(removed); }
/// <summary> /// Initializes a new instance of the <see cref="VirtualizingObservableCollection{T}" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="reclaimer">The optional reclaimer.</param> /// <param name="expiryComparer">The optional expiry comparer.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="maxPages">The maximum pages.</param> /// <param name="maxDeltas">The maximum deltas.</param> /// <param name="maxDistance">The maximum distance.</param> /// //TODO Check implementation public VirtualizingObservableReactiveCollection( IPagedSourceObservableProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1) : base(provider, reclaimer, pageSize, maxPages, maxDeltas, maxDistance) { (this.Provider as PaginationManager <T>).CollectionChanged += this.VirtualizingObservableCollection_CollectionChanged; this.IsSourceObservable = true; }
/// <summary> /// Initializes a new instance of the <see cref="PaginationManager{T}" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="reclaimer">The reclaimer.</param> /// <param name="expiryComparer">The expiry comparer.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="maxPages">The maximum pages.</param> /// <param name="maxDeltas">The maximum deltas.</param> /// <param name="maxDistance">The maximum distance.</param> /// <param name="sectionContext">The section context.</param> public PaginationManager( IPagedSourceObservableProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1, string sectionContext = "") : this(provider as IPagedSourceProvider <T>, reclaimer, expiryComparer, pageSize, maxPages, maxDeltas, maxDistance, sectionContext) { provider.CollectionChanged += this.OnProviderCollectionChanged; }
/// <summary> /// Inserts at. /// </summary> /// <param name="offset">The offset.</param> /// <param name="item">The item.</param> /// <param name="updatedAt">The updated at.</param> public void InsertAt(int offset, T item, object updatedAt, IPageExpiryComparer comparer) { if (IsSafeToUpdate(comparer, updatedAt)) { if (_Items.Count > offset) { _Items.Insert(offset, item); } else { _Items.Add(item); } } }
/// <summary> /// Replaces at. /// </summary> /// <param name="offset">The offset.</param> /// <param name="newValue">The new value.</param> /// <param name="updatedAt">The updated at.</param> public T ReplaceAt(int offset, T newValue, object updatedAt, IPageExpiryComparer comparer) { var oldValue = this.Items[offset]; if (!this.IsSafeToUpdate(comparer, updatedAt)) { if (this.Items.Count > offset) { this.Items[offset] = newValue; } return(oldValue); } this.Items[offset] = newValue; return(oldValue); }
/// <summary> /// Determines whether it is safe to update into a page where the pending update was generated at a given time. /// </summary> /// <param name="updatedAt">The updated happened at this datetime.</param> /// <returns></returns> public bool IsSafeToUpdate(IPageExpiryComparer comparer, object updatedAt) { bool ret = true; if (comparer != null) { ret = comparer.IsUpdateValid(this.WiredDateTime, updatedAt); } //if(updatedAt.HasValue && updatedAt.Value != DateTime.MinValue) //{ // if(updatedAt.Value< this.WiredDateTime) // { // ret = false; // } //} return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="PaginationManager{T}" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="reclaimer">The reclaimer.</param> /// <param name="expiryComparer">The expiry comparer.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="maxPages">The maximum pages.</param> /// <param name="maxDeltas">The maximum deltas.</param> /// <param name="maxDistance">The maximum distance.</param> /// <param name="sectionContext">The section context.</param> public PaginationManager(IPagedSourceProvider <T> provider, IPageReclaimer <T> reclaimer = null, IPageExpiryComparer expiryComparer = null, int pageSize = 100, int maxPages = 100, int maxDeltas = -1, int maxDistance = -1, string sectionContext = "", TimeSpan?delayBetweenReclaims = null) { this.PageSize = pageSize; this.MaxPages = maxPages; this.MaxDeltas = maxDeltas; this.MaxDistance = maxDistance; if (provider is IPagedSourceProviderAsync <T> ) { this.ProviderAsync = (IPagedSourceProviderAsync <T>)provider; } else { this.Provider = provider; } if (reclaimer != null) { _Reclaimer = reclaimer; } else { _Reclaimer = new PageReclaimOnTouched <T>(); } this.ExpiryComparer = expiryComparer; VirtualizationManager.Instance.AddAction(new ReclaimPagesWA(this, sectionContext, delayBetweenReclaims)); }
/// <summary> /// Determines whether it is safe to update into a page where the pending update was generated at a given time. /// </summary> /// <param name="comparer"></param> /// <param name="updatedAt">The updated happened at this datetime.</param> /// <returns></returns> public bool IsSafeToUpdate(IPageExpiryComparer comparer, object updatedAt) { return(comparer == null || comparer.IsUpdateValid(this.WiredDateTime, updatedAt)); }