The "New Libraries" Update Thread #55
Replies: 3 comments 1 reply
-
Update for 8/2/2024
Next up:
|
Beta Was this translation helpful? Give feedback.
-
Update for 8/16/2024
Next up:
What can you do right now (after the open PR is merged):
When creating an OfflineDbContext, you need to implement OnDatasyncInitialization to set up the remote service. |
Beta Was this translation helpful? Give feedback.
-
Update for 8/23/2024
Next up:
Once I've done that (and end of next week is looking really good right now), I'll be code complete on the library. What's left to do?
I really want to get folks to sign up for helping with the bug bash. Can you commit to a few hours learning the new library and checking it out, with an intent to find the corner cases I didn't cover? On to the new PullAsync() code, which is currently in PR being built. There are two methods of pulling data. First, the tested version: public class MyDbContext : OfflineDbContext
{
// Whatever is necessary to set up the DbContext
// Don't forget to do what is necessary to store byte[] and DateTimeOffset for your situation
protected override void OnDatasyncInitialization(DatasyncOfflineOptionsBuilder builder)
{
HttpClientOptions options = new()
{
Endpoint = new Uri("https://myendpoint.azurewebsites.net"),
HttpPipeline = [ YourHandler ]
};
builder.UseHttpClientOptions(options);
}
} There is more you can do in the OnDatasyncInitialization - you can choose from a HttpClient, HttpClientFactory, or a basic endpoint, resulting in lots of ways to set up your HTTP pipeline. For each entity, you can add a relative URI (or an absolute URI) and a client name (used if you are using an IHttpClientFactory to generate clients). You can also specify a default query for each entity: options.Entity<Movie>(cfg =>
{
cfg.ClientName = "movies";
cfg.Endpoint = new Uri("/tables/movies", UriKind.Relative);
cfg.Query.Where(x => x.Rating != MovieRating.R);
}); Now the fun part: PullResult pullResult = await context.PullAsync([ typeof(Movie) ], new PullOptions()); Yes, there will be convenience methods, so you can just do PullAsync() and so on - I just haven't included them yet. This will use the default query and provide a default queryId for you - incrementally pulling records from the remote service. I've parallelized different types and split the storage in the database from the service request, so there is a good amount of parallelization going on here when you pull everything. If you want something move, you'll have to go to the configurator. I HAVE NOT TESTED THE CONFIGURATOR VERSION YET. However, it looks like this: PullResult result = await context.PullAsync(cfg => {
cfg.SetParallelOperations(8);
cfg.AddPullRequest<TEntity>(); // Use the defaults
cfg.AddPullRequest<TEntity>(e => {
e.Endpoint = new Uri("/tables/foo", UriKind.Relative);
e.HttpClient = new HttpClient();
e.Query.Where(x => x.Rating == MovieRating.G);
e.QueryId = "myQueryId";
});
}); This shows you both the basic version (where you use all the default) and the complex version (where you have absolute control over everything). There are reasonable defaults, so I believe this API gives you considerable flexibility - first, you can do basic "give me everything" pulls really easily. But you can break out of that and modify every bit of the pull configuration if you want to get complicated. Another thing I'm doing in the pull/push is getting rid of exceptions. In each case, there is a "FailedRequests" in the result object, together with an "IsSuccessful" flag. You can use these to generate your own exceptions if you desire, but you can also just handle the exceptions. Hope you all have a wonderful weekend! |
Beta Was this translation helpful? Give feedback.
-
Hey folks,
This is a chronological (and - hopefully - frequent) update on where I am with the new client re-design. Everything is a reply - if you want to ask a question on what was done, then please do so as a comment on the reply.
Beta Was this translation helpful? Give feedback.
All reactions