BreezeJS and IndexedDB Offline Examples - breeze

Ok, I see where BreezeJS supports IndexedDB, at least based on an entry on their web page, but where can I find examples of how to architect an offline solution using BreezeJS and the IndexedDB local storage option?
How do I build this server side scheme in the local storage?
Also, are there examples syncing with Mysql also?
Thanks

Breeze can store any collection of entities exported from an EntityManager into any local storage mechanism available on the client BUT understand that you are storing the entire serialized collection of entities under a single key, i.e. you are not storing individual entities into a store by their key.
We do not have any examples yet using IndexedDb but there are several examples in the DocCode sample zip that use browser localStorage. The basic idea for indexedDb is much the same,
1) Export the entity or entities into a string via an EntityManager.exportEntities call. ( This returns a stringified json result).
2) Store the string into local storage (browser localStorage or IndexedDb) with some arbitrary key.
3) Later... retrieve the string from localStorage
4) Import the string into an EntityManager via an EntityManager.importEntities call.

Breeze does not provide a wrapper for IndexedDB. You have to write your own.
window.indexedDB is part of the browser's HTML5 DOM so when you see it listed in the Breeze documentation, it is only referencing what is available in the browser's DOM.
You will need to write your own customized IndexedDB function that handles request to save and retrieve from the database.

Here is a pull request which adds support to BreezeJS which will add more advanced support for exporting/importing with indexedDB. Please +1 if you would like this support added to Breeze.JS.
https://github.com/Breeze/breeze.js/pull/22

Related

What is the proper way to get private data from a MySQL database to an iOS app?

I am currently developing an app for a friend's business (so it's clear that I am not a professional developer and he's not going to get the perfect app). He needs the app to display and be able to interact with data from a MySQL database. I have already tried to find a way to do this but they mostly include a PHP script that just generates a json document which the app can then read. I cannot do that because the data includes customer information that can't just be accessible like that without some form of authentication from the app. The app will only be used by employees at work and on specific devices so storing the data locally is not a problem. Is there maybe a way to create a local cache of the database and then work with that? I would also be open to use other database software that can handle spreadsheet-like data.
Thanks in advance for any response!
Assuming your app going to get JSON data through PHP API. In that case, PHP API should encrypt the JSON data and your app will decrypt it. If you want to protect your data on users device, one of the option to use cipher SQLite.
You can any use symmetric or asymmetric encryption technique to encrypt the API response.
Here is good post to read.
https://www.ssl2buy.com/wiki/symmetric-vs-asymmetric-encryption-what-are-differences

How to read the localstorage values at server side

I am using localstorage to maintain the data at client side in MVC.
I need to read the localstorage data in MVC controller. Is this possible?
If it is, please give me the solution how to do it.
The server doesn't have access to the client browser which is where the local data is stored . You will need to send the data to the server using javascript.
If you can give us some more information then i can give you an example that would solve your problem.
What version of MVC are you using (MVC2/3/4, WEB API, etc)?
What is the reason you need this data visible to the server?
Do you want the controller to do something with this data before it returns a new view?
etc.

How to create forms in dart?

What is the best way to create forms (textfields, checkboxes, radio buttons, ...) and handle the data after the user's input?
Just use web components as dart's web ui?
http://www.dartlang.org/articles/web-ui/
http://www.dartlang.org/docs/tutorials/web-ui/
edit: Lets imagine the following example application: I would like to create an online quiz/test.
First the user has to register
Data will be stored in a textfile or in a database
User can log in and play an online quiz or do an online test.
For that quiz/test i need to evaluate the input with the predefined correct answers
Here's a high-level answer to your question.
To handle data on the server side you can use the HttpServer class to start a web server. See this article.
To store data in a flat file you'll need to use the dart:io package to open a file and write to it. See the documentation for File.openWrite().
To store data in a database there are packages available on pub for mysql and postgresql.
There are two different ways to implement the client side. The traditional way is to use templating to generate html with the data in input elements within a form tag, and then handle the form submission in your webserver.
The modern way, that is the focus within the Dart community, is to write a single page app, which uses HttpRequest to read data from and send data to the server (usually using json).
On the client side, you could retrieve data from server (e.g. as JSON) and use that to build a form. This seems like a good fit for a web component as elements can be dynamically added based on received data.
The component would be bound to the model so you can serialize the model object to JSON on submit and send it to server on submit or just send it as standard HTML form.
The server side of the story is less clear, there are no production quality web server libraries that I am aware of, but you could take a look at DartExpress as an example, or Stream, and there are others, more or less complete. Anyway, you would have to extract the POST payload from HttpRequest (if sent as JSON) or use the form data which is also accessible via queryParameters property - please note that this is Dart:io.HttpRequest class, not Dart:html.HttpRequest, and it is available only on server side.
The mentioned server frameworks simplify this part a bit.
Using Web-UI would be a good choice. The todomvc application illustrates nicely how to dynamically capture the input from a user. Processing on the server side is wide open as far as choices go. Dart does have server side capabilities, and you could use some of the existing libraries to accomplish what you want.
Another way that you can process the information server side is to comunicate with the DB directly using a REST based web service like CouchDB. Cloudant offers such a service and allows you to communicate directly to the DB from the client, providing you can overcome the Same-Origin-Policy. There are 2 ways to do this. Enable CORS on the CouchDB instance, or host your application on the server that has the DB, which is also possible with CouchDB.
Dart serverside also supports websockets, so you can easily deliver the user provided data to the server with web sockets, and then do whatever processing you like on the serverside.
One other option I can think of would be to have the information processed and saved in the local browser. You can access the local DB or local browser file system from the Dart client, and keep everything local. For statistics, you can have the client update a web service of your choice.

Accessing an external SQL database in iOS

I am writing an iOS application that needs to access data from an external SQL Server 2005 database. I already have a website that accesses the same data.
I usually access the SQL server database using .NET along with stored procedures for security reasons.
I need to populate an array that will itself populate another TableViewController.
As I'm fairly new to the whole iOS thing, kindly let me know how I can do this. If it's possible, please suggest the syntax or Google keywords for this.
I'd recommend making a simple WCF .NET REST Service that queries your database and returns what you need.
I'm pretty sure your iOS app will not be able to connect to it directly.
Check out the following;
http://msdn.microsoft.com/en-us/library/bb412178.aspx
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
The code project tutorial is very easy to follow. And you can download the project code.
It sounds like you will want to make an API to access your database and you can access it through web requests. Essentially you will be performing web requests and respond from your site in json or xml where within your iOS client side code you can parse that and do what you need with it.

is it possible to share session data from a asp.net mvc application and a python application?

I would like to be able to share some data between an asp.net mvc application and a python/django application . The type of data I would like to share are authentification or session data.
This is of course possible as long as you access some shared resources between both frameworks. There are likely several ways of doing it but one of the most obvious would be using some shared backing store ie. database or maybe even memcached which would be faster. I'm not a Django user but as far as I know memcached is supported in it...
There is of course a more complex scenario related to this and that is data compatibility. You will likely have to use some interchangable format that both frameworks understand ie. XML, JSON, BSON or similar. So even when using memcached you will have to do this translation.
How I would share session...
Make the Session Cookie sub-domain agnostic
<httpCookies domain=".mydomain.tld" />
Have my two sub-domains that I want to share session between
www.mydomain.tld [ASP.net MVC app]
extra.mydomain.tld [Python app]
Create a simple web service or generic handler in ASP.net that returns the user's session serialized in JSON or XML.
If you use generic handler remember to use the IReadOnlySessionState or IRequiresSessionState interfaces on the class.
Now from extra.mydomain.tld you can call your www.mydomain.tld/[Get/Set]SessionValue handler or service. It will pick up on your ".mydomain.tld" cookie and allow sharing modifying values.
I would recommend the following approach using a shared database (could be a shared cache or any other datastore):
When a user accesses one of your applications at your domain, you create a cookie with the key "_shared_session" and with the value of a random string generated by your application;
Save the value of this cookie into the database and relate it to a JSON object holding the data you want to share between applications;
When the user accesses the other application, you verify if the cookie with the key "_shared_session" exists and read its value;
With the value of the cookie, you can retrieve the shared JSON object.
Quick answer: there should be a filter that look for a shared cookie before creating a new session
There is an option for storing Session state in MS SQL Server database which is available out of the box. Use the steps from the next kb http://support.microsoft.com/kb/317604
It's more about configuration, not implementation.
You can write your own custom storage provider but is there any reason for that?
I'm not familiar with python, but there are at least ODBC drivers for it
http://wiki.python.org/moin/SQL%20Server

Resources