asp.net mvc 4 - Store and Sync local Data using Breezejs and MVC Web API -


i want use breezejs api storing data in local storage (indexdb or websql) , want sync local data sql server.

but failed achieve , not able find sample app of type of application using breezejs, knockout , mvc api.

my requirement is:

1) if internet available, data come sql server using mvc web api.

2) if internet shutdown, application retrieve data cached local storage (indexdb or websql).

3) internet on, local data sync sql server.

please let me know can achieve requirement using breezejs api or not?

if yes, please provide me , links , sample.

if no, other can use achieving type of requirement?

thanks.

please me meet requirement.

you can this, suggest using localstorage. basically, every time read server or save server, export entities , save local storage. then, when need read in data, if server unreachable, read data localstorage , use importentities manager , query locally.

function getdata() {     var query = breeze.entityquery                .from("{yourapi}");      manager.executequery.then(savelocallyandreturnpromise)         .fail(trylocalrestoreandreturnpromise)      // if query successful remotely, save data in case connection      // lost     function savelocallyandreturnpromise(data) {         // should add error handling here.  code         // assumes tis local processing successful.         var cachedata = manager.exportentities()         window.localstorage.setitem('savedcache',cachedata);          // return queried data promise detour         // transparent viewmodel         return q(data);     }     function trylocalrestoreandreturnpromise(error) {         // assume error means server inaccessible.         // simplified example, more robust error handling         // warranted         var cachedata = window.localstorage.getitem('savedcache');         // note: should handle empty saved cache here throwing error;         manager.importentities(cachedata); // restore saved cache         var query = query.using(breeze.fetchstrategy.fromlocalcache);         return manager.executequery(query); // promise     } } 

this code skeleton simplicity. should check catch , handle errors, add isconnected function determine connectivity, etc.

if doing editing locally, there few more hoops jump through. every time make change cache, need export either whole cache or changes (probably depending on size of cache). when there connection, need test local changes first and, if found, save them server before requerying server. in addition, schema changes made while offline complicate matters tremendously, aware of that.

hope helps. robust implementation bit more complex, should give starting point.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -