1. Marco Meoni
  2. .NET DataStore
  3. Sunday, 16 October 2022 18:14 PM UTC

Hello,

common use case when performing .NET datastore update in API Service is 

1) send restclient.Submit( ... dw_1) or restclient.sendPostRequest( ... dw_1.exportJson(True) ) from PB client
2) perform restclient.Retrieve(dw_1 ...) from PB client to refresh DW buffers

I was wondering if can avoid 2nd server call, since the API can return the datastore instead of the ds.update() return code

But the PB client seems unable to perform a new update and have its update flags in sync with API datastore

For example, Service's UpdateAsync below from Snapdevelop scaffolding is modified to return IDataStore<Department> instead of int.

public async Task<IDataStore<Department>> RetrieveAsync(CancellationToken cancellationToken)
{
  var dataStore = new DataStore<Department>(_dataContext);
  await dataStore.RetrieveAsync(new object[] { }, cancellationToken);
  return dataStore;
}

public async Task<IDataStore<Department>> UpdateAsync(IDataStore<Department> department, CancellationToken cancellationToken)
{
  department.DataContext = _dataContext;
  await department.UpdateAsync(cancellationToken); 
  return department;     // not working. UpdateAsync(true, cancellationToken) not working either
  //return await RetrieveAsync(cancellationToken);    // not working either
}

PB client is sending update and then refreshing the DW with API response, but a subsequent second update fails (in e.g. duplicate key and http 500 return code).

restclient.setRequestheader( "Content-type", "application/json" )
restclient.Submit( ls_endpoint, ls_response, dw_1)

dw_1.Reset()
// Attempt to refesh DW state on the client, and avoid new retrieve
dw_1.importJson(ls_response)

I would like to avoid this new server call to have proper refresh on PB DW 

restclient.Retrieve(dw_1, ls_response)

Thanks for sharing any idea.

.m

 

Marco Meoni Accepted Answer Pending Moderation
  1. Monday, 24 October 2022 09:30 AM UTC
  2. .NET DataStore
  3. # 1

Thank you Logan

indeed I can return DW JSON from the controller and have one server call to perform both update+refresh.

var result = await _iservice.UpdateAsync(mymodel, default);

return Ok(result.ExportJson());

 

Best,

.m

Comment
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 18 October 2022 10:20 AM UTC
  2. .NET DataStore
  3. # 2

Hi Marco,

Can you use the DwControl.ResetUpdate() method to solve the update the second update fails issue? 

Have you ever tried to return DataWindow format JSON (contains row status) instead of Plain JSON for the REST API response? This is not a good practice but can reduce call times as you required. Refer to the ExportJson method of .NET DataStore.

Regards, Logan

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.