Aug 22, 2012 at 12:50 PM
Edited Aug 22, 2012 at 12:52 PM
You mention saving the contents of a PagedDataListSource<T> to disk on application suspesion. Whilst the Okra framework allows you to hook into application suspension events (via the ILifetimeManager and ILifetimeAware interfaces) you should remember
that you only have a limited period of time to save data upon suspension before your application is forcibly terminated. Hence the guidelines recomend that data is saved in the background whilst the app is running if possible rather than waiting for the suspension
My thoughts on this would be to save each page of data as it is retrieved - either in a seperate file for each page, or a single combined file that is updated each time. In your FetchPageAsync(...) method you could continue to use Json.Net (or any other
serialization technique) to save the resulting DataListPageResult<T> object to disk, then on subsequent calls you could retrieve the stored value if available, otherwise continue as normal.
In pseudo-code this would be,
protected override async Task<DataListPageResult<MyItem>> FetchPageAsync(int pageNumber)
DataListPageResult<MyItem> cachedPage = await GetPageFromDisk(pageNumber);
if (cachedPage != null)
DataListPageResult<MyItem> page = await GetPageFromDataSource(pageNumber);
Note that the SavePageToDisk(...) method should be marked as 'async' so that it would not block the thread until the data was saved.
How does this sound for your use-case? Let me know and I can adapt as required...