Consultation on database [closed]

-1

I have a question that I need to get out of. I have to do a project with .Net (a desktop application with C #). It must connect to an API. But here is my doubt, you should also be able to work in an 'offline' manner, that is, when you do not have an Internet connection to communicate with the API, you should be able to work locally until you resume the connection and update the information through the API. I do not know if this is possible. Thank you very much already.

    
asked by Agu Décima 07.03.2018 в 02:03
source

2 answers

1

You can save the data in the browser, using for example:

  • localStorage : it's just a set of keys and values. Easy to use and almost no learning curve, but somewhat limited as a solution for structured data. To store a structure with several fields you have to save them with JSON.stringify and recover them with JSON.parse.
  • IndexedDB : has a steeper learning curve but allows for more complex operations. There are wrappers like dexie and db.js that simplify its use.
  • Web SQL : (semi-discontinued) provides a relational database, basically a SQLite implementation in the browser. At this point I think only Chrome and Safari support it and is being deprecated .

The important thing is that you manage the change in the state of the connection to know if the user is offline (save locally) and when it goes online (you synchronize what was stored locally to the API).

For example you can check the value of navigator.onLine

function persist(...argumentos...) {
  if(navigator.onLine) {
    // guardas mediante el API
  } else {
    // guardas localmente en el browser
  }
}

But you will need to detect the change of state to trigger the synchronization of what you saved while offline:

window.addEventListener(‘online’, function(event){
    // sincronizas el local con el API
});

You can be guided by this article

    
answered by 07.03.2018 в 11:42
1

You would need to create an intermediate bd that is hosted on the local network server of the desktop application, and then a service that is responsible for taking the data from the intermediate bd to the API.

    
answered by 07.03.2018 в 03:25