Occasionally Connected LightSwitch HTML Apps Using JayData

JayData, as many are probably aware from prior blog posts and discussions on this forum, is a powerful JavaScript utility library for OData providers, including LightSwitch. 
Recently, the JayData developers have expanded the
provider offerings to include many other database programmatic interfaces. 
Their latest release, JayData 1.3.6, codenamed “Advanced Sync Edition,” aims to support occasionally connected apps by exploiting the local storage capability of the browser (Web SQL. sqLite, IndexedDb, etc.). 
Development is simplified when using the same data model and API for writing to both local storage and the OData endpoint.
An example of this is shown at How to Create a Synchronized Online-Offline Data App with JavaScript and JayData. 
This model, the “To Does” project, was successfully adapted to a LightSwitch HTML app without difficulty. 
Although “To Does” projects like this serve as a nice proof-of-concept, they are excessively simple compared to real world business applications. 
Fortunately, JayData 1.3.6 also includes support for configurable foreign keys. 
With this, more complex object-relational mapping that would typically be used with Entity Framework and similar RDBMS may be approximated.
To illustrate, the To Does project was expanded to include entity relationships. 
Specifically, a To Do must be assigned to a single individual Project, and any single Project can have many To Does. 
A Project can be assigned to an Employee or to multiple Employees, while an Employee can have a single Project or many Projects, thus defining a many-to-many relationship between Employee and Project.
So how might and online-offline LightSwitch HTML application work in practice? 
Ideally in my opinion, the transition from online to offline and back should be seamless and transparent to the user, allowing for both UX and UI to be unperturbed. 
This approach turned out to be too difficult for me as a developer, as I experienced problems with the closed-end nature of LightSwitch’s Visual Collection object, for instance. Separation of concerns is a real challenge with this approach.
 There is also the separate UI approach for both offline and online data entry, which have been nicely illustrated by Michael Washington and Paul van Bladel on their blogs using JayData and BreezeJS with AngularJS alongside a LightSwitch HTML
app.  This approach is valid, and from the viewpoint of the developer has its advantages. From a design standpoint, it is likely to be frustrating for an end-user who must deal with “spotty” network coverage, necessitating changing back-and-forth
from one UI to another.
I opted for a hybrid approach, staying entirely inside the LightSwitch HTML app environment but having individual menu options to select depending on the user’s online status, which is constantly displayed with a status icon (see Main Menu figure). 
In many cases, the native LightSwitch screen and menu buttons are fully functional in the offline state. 
When they are not, most often with regard to a “Browse” screen or involving a Visual Collection, I have substituted the updated WinJS library (now at
version 4.0, capable of replacing LightSwitch’s v1.0 with no breaking changes) to create a custom control that resembles the LightSwitch listview.
To use the app, you can use any of the online Menu buttons to enter Employee, Project, or To Do data in the usual way while connected.
  The Offline menu buttons are functional in either a connected or disconnected status, which can be tested by disabling your devices WiFi, for example. 
This LightSwitch app does not work with all browsers, however. 
Because the local database is stored using the Web SQL/sqLite JayData API, it is not supported by either IE or FireFox. 
It is supported by Chrome, Safari, Opera, Android browsers, Kindle Fire, and iPad browsers
(see link). 
To see the local data stored in Web SQL while using Chrome, you can press F12, select Resources, and expand Web SQL to see the Table data updated with each transaction (see figure).
After entering data using the Offline menu selections, you will want to synchronize your local data with the remote LightSwitch database, which is performed by clicking “Synchronize Offline to Online” on the Main Menu. 
A success or error dialog message should follow, depending on the result of the sync. 
The dates and times of the last synchronizations are displayed on the Main Menu. 
With each online database transaction, including offline to online syncs, the offline database is updated to reflect the very latest LightSwitch application data. 
This method attempts to have the LightSwitch online database as the “single source of truth” as much as possible while the user is online.
Lastly (if anyone is still reading this far), note that by design there is no business logic programmed into this application; business logic is a separate issue to be addressed. 
There can be as many incomplete To Does as you want, an Employee can be assigned the same Project many times, etc. 
If your application requires business logic, you will have to program it into the client-side in order for the user to be prompted to follow it while offline.
To experiment with LightSwitch OfflineToDoes app, go to:
http://offlinetodoes.azurewebsites.net/htmlclient
…and log in with username “testuser” and password “Testuser1!” 
In a few days I will try to load the sample project code to MSDN for anyone to download and review if desired.
TL;DR:
JayData provides an attractive solution for creating online-offline LightSwitch HTML apps by automating a single codebase to carry out CRUD operations on both a local datasource and the remote LightSwitch database. 
Integrating the offline portion of the app into the LightSwitch UI requires an individualized solution and is code-intensive, however.

Thank you both for the input. Zardoz, I tried making a couple of updates to address items you mentioned.  I left unfixed the problem that occurs when editing an offline Project's budget item..this still does not work.  LightSwitch identifies this
entity as a decimal, WebSql expects a plain number, but LightSwitch's post-processing business type formats it to currency (I see USD, you may see NZD, AUD, etc.)  In the console there is a "getModel() is undefined" in msls.js.  If I take
out the Money business type to regular Text on the View, it works fine.
I'm not sure if I understood your last item just right, but I tweaked the Add Edit Offline Project screen to prevent the Project from being null if the user only enters a new To Do. Not sure why the screen validation wasn't firing before.
Regarding navigation, I don't wish to use the browser's back or forward buttons at all for the app, especially the Offline portion, only the LightSwitch menu navigation and command buttons. I know Xpert360 has shown how to put the former LightSwitch back
button in the app which is useful too. Navigation, cacheing and disposing were some of the tricky parts getting to integrate between LightSwitch UI and offline custom controls.  Occasionally I felt like I was having to be "clever" at solutions,
except that when it comes to programming, I'm not a fan of cleverness.
The project is published
here. Hopefully this serves as a good starting point for someone, and I look forward to seeing how it can be improved upon and used in practice.

Similar Messages

  • Set connection timeout in LightSwitch HTML

    Hi.
    I am creating Lightswitch HTML application and implementing export functionality using ServerApplicationContext.
    I am trying to export a lot of data and i when i call for DB objects I get connection error. I have tried to set ;Connection Timeout=300 in connection string in web.config but it seams like not functioning, and still failing after 30sec. 
    Can you please guide me where can I set a connection timeout in order to change it's default value from 30 sec to something bigger?

    Igor,
    I think what you are looking for is "CommandTimeout" and not connection timeout. The connection timeout is how long the SQL Client will wait while establishing a connection. A command timeout is how long the SQL Client will wait for a command to complete.
    So if you are executing a long running command, you will run into command timeout issues.
    In order to set the command timeout for your SQL data source, add a "key" to your web.config's <appSettings> node of the following form:
    <appSettings>
    <add key="DataSourceName_CommandTimeout" value="60" />
    </appSettings>
    Replace DataSourceName with the name of your data source.  So if you are using the ApplicationData data source, the key would be named "ApplicationData_CommandTimeout". Look in your Solution Explorer under "Data Sources" for the name of your
    data source.
    The value is the number in seconds for the timeout.
    Eric
    http://blogs.msdn.com/b/eric_erhardt/

  • Lightswitch HTML Sharepoint App: Access Control Methods

    I have a Lightswitch HTML SharePoint App. Which is working well.
    I have implemented user access security on the entities using SharePoint groups.
    partial void UserAccessGroups_CanUpdate(ref bool result)
    result = false;
    var clientContext = Application.SharePoint.GetHostWebClientContext();
    Microsoft.SharePoint.Client.Web web = clientContext.Web;
    Microsoft.SharePoint.Client.GroupCollection UserGroups = web.CurrentUser.Groups;
    clientContext.Load<Microsoft.SharePoint.Client.GroupCollection>(UserGroups);
    clientContext.ExecuteQuery();
    foreach (var item in UserGroups)
    var permission = "UserAccessGroupAdmin";
    if (item.Title == permission)
    result = true;
    break;
    This works fine when I am debugging the application and it is running on localhost.
    However when I publish theapp and it is running in an Azure site it doesn't work and I am un able to edit the entitiy.
    I have set up the SharePoint Group on the site that is running the appp and assigned the user to the group.
    Has anyone else had a similar experience or have any suggestions.
    Thank you,
    Andrew

    This may help:
    An End-To-End LightSwitch SharePoint Workflow Application
    I have SharePoint permissions in that example and I tested it in production and it definitely works.
    bool isMemberOfVacationApprovers = false;
    var clientContext = this.Application.SharePoint.GetHostWebClientContext();
    //Load the properties for the web object.
    Microsoft.SharePoint.Client.Web web = clientContext.Web;
    // Get the current web
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    // Groups for current User
    Microsoft.SharePoint.Client.GroupCollection UserGroups = web.CurrentUser.Groups;
    clientContext.Load<Microsoft.SharePoint.Client.GroupCollection>(UserGroups);
    clientContext.ExecuteQuery();
    foreach (var item in UserGroups)
    if (item.Title == "Vacation Approvers")
    isMemberOfVacationApprovers = true;
    if (!isMemberOfVacationApprovers)
    results.AddEntityError
    ("Only members of Vacation Approvers can edit this record.");
    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book
    http://LightSwitchHelpWebsite.com

  • Whenever i try and open a social network app it comes up with an error message sayinng "Connect to itunes to use Push Notifications" I have successfully conntected to itunes via phone and computer however this message is still appearing and will not go?

    Whenever i try and open a social network app it comes up with an error message sayinng "Connect to itunes to use Push Notifications" I have successfully conntected to itunes via phone and computer however this message is still appearing and will not go, therefore i cannot use the apps?HELP PLEASE

    http://support.apple.com/kb/TS3281

  • Since update to iOS 7, every time I open an app a pop up message telling me to connect to iTunes to use push notifications comes up. EVERY TIME! How do I make it stop???

    Since update to iOS 7, every time I open an app a pop up message telling me to connect to iTunes to use push notifications comes up. EVERY TIME! How do I make it stop???

    Do you use iTunes with your iPad and if so, have you tried syncing your iPad with iTunes since you updated the iOS?

  • Apps in iTunes disappear; 'Connect to iTunes to Use Push Notifications'

    Right, I synced my iphone up a while back to add a song to my phone.
    Since then, I've had several problems I have yet to resolve:
    1) I keep getting 'Connect to iTunes to Use Push Notifications.'
         I searched through the forums and have yet to find a solution, nothing seems to work. Tried changing sims, rebooting/resyncing, messing with the notifications, etc., etc., etc. Nothing has worked.
    2) I keep getting a notification when I try to do anything from my Macbook to my iphone that says my phone is not synced to my library, would I like to sync to my library now' or something to that effect. It doesn't matter how many times I add it, it will not recognise it.
    3) All the apps I had downloaded that are associated with my iPhone, my iTouch, and my iPad have deleted themselves. I plug in the iPhone, all it recognises is the apps it came with, nothing else.
    The iPad and iTouch are not giving the pop up for the Push Notifications because I have not synced them in a while.
    Phone is a 3gs, running 5.1.1. I would prefer not to upgrade to the 6.0 if possible, I have heard terrible things about the upgrade from friends and would really prefer not to upgrade until all the bugs are fixed. Also, I'm reading other posts online that say they're still having the problem after upgrading to 6.0, and I don't want extra frustrations with the upgrade as well as all this. iPhone is NOT jailbroken, has never been jailbroken.
    Macbook Pro is running 10.6.8.
    iTunes is running the newest version 10.7
    Some of you must have had this problem, any help would be appreciated, that pop-up for Push Notifications is really driving me insane.
    Help!
    thanks

    Did you get any help on this? From what I can see from surfing this site, it's a BUG that no one has offered a solution to. It sometimes happens after a 'reset' and going to ITunes does not offer a way to 'set up push notifications'.

  • Since i have updated my iphone everytime i open an app it comes up with a message 'connect to itunes to use push notifications, may include alerts, sounds and icon badges, i have backed up my phone on itunes and restored phone but its still doing it, :(

    since i have updated my iphone everytime i open an app it comes up with a message 'connect to itunes to use push notifications, may include alerts, sounds and icon badges, i have backed up my phone on itunes and restored phone but its still doing it  can anyone help?
    Em

    Return the iPhone and get your money back. It has been
    hacked/modified/jailbroken and likely cannot be made
    operative.

  • "Connect to iTunes to Use Push Notifications" comes almost in every app that I open and it does not notify me when I got message in Whatsapp and Viber. Please help me to overcome it, it is becoming quite annoying!

    "Connect to iTunes to Use Push Notifications" comes almost in every app that I open and it does not notify me when I got message in Whatsapp and Viber. Please help me to overcome it, it is becoming quite annoying!

    Did you get any help on this? From what I can see from surfing this site, it's a BUG that no one has offered a solution to. It sometimes happens after a 'reset' and going to ITunes does not offer a way to 'set up push notifications'.

  • HT3576 How can I get rid of "Connect to itunes to use push notifications" pop-ups.  I just had to replace my iPhone 5 and when I did a restore from backup, most of my apps will not let me in becuase I cannot get past the"connect to itunes..." message.

    My iPhone 5 was distroyed so I replaced it with a new iPhone 5 yesterday.  I did a restore from a backup that i had performed a week ago.  When I tried to use the phone several of my apps would not let me in becuase they continually gave me a popup message "Connect to Itunes to use push notifications".  I click ok and the popup comes back.  I have shut my phone off several times.  I have complete closed the apps several times.  I have even deleted the apps from my phone and reinstalled.  All to no avail.  Please help - does anyone know how to fix this?

    Yes - I connected my phone to my computer / Itunes and went into the apps section, but from there I have no idea how to manage the push notifications.  I even tryied going into itunes that is installed on my phone.  I still cannot find anyplace to manage these popups.  I have also gone into settings - notifiations - and tried turning all notifications for these apps all off but that didnt work either.  Any guidance is MUCH appreciated - Im not sure where to go from here.

  • I am getting error while connecting to sqlplus by using apps account in 11i

    i am getting error while connecting to sqlplus by using apps account in 11i. Does anyone has similar error.
    [applmgr@appsc05t01 admin]$ sqlplus
    SQL*Plus: Release 8.0.6.0.0 - Production on Mon Sep 13 14:34:52 2010
    (c) Copyright 1999 Oracle Corporation. All rights reserved.
    Enter user-name: apps
    ERROR:
    ORA-12514: Message 12514 not found; product=RDBMS; facility=ORA
    Enter user-name:
    Thanks
    Rao

    yes.
    login as: gorantla
    [email protected]'s password:
    Last login: Mon Sep 13 14:39:23 2010 from glng3wy9g1.actuant.pri
    [gorantla@appsc05t01 ~]$ sudo su - applmgr
    [applmgr@appsc05t01 ~]$ ora_setup
    Available databases:
    x = ATUXX
    y = ATUYY
    z = ATUZZ
    Select database: \c
    y
    ORACLE_SID=ATUYY
    IAS_ORACLE_HOME=/apps/ATUYY/atuyyora/iAS
    ORACLE_HOME=/apps/ATUYY/atuyyora/8.0.6
    APPL_TOP=/apps/ATUYY/atuyyappl
    [applmgr@appsc05t01 ~]$
    [applmgr@appsc05t01 ~]$
    [applmgr@appsc05t01 ~]$
    [applmgr@appsc05t01 ~]$ tnsping ATUYY
    TNS Ping Utility for Linux: Version 8.0.6.3.0 - Production on 13-SEP-2010 15:42:32
    (c) Copyright 1997 Oracle Corporation. All rights reserved.
    Attempting to contact (ADDRESS=(PROTOCOL=tcp)(HOST=dbrac05t01-vip.actuant.pri)(PORT=1611))
    OK (0 msec)
    [applmgr@appsc05t01 ~]$ sqlplus
    SQL*Plus: Release 8.0.6.0.0 - Production on Mon Sep 13 15:42:40 2010
    (c) Copyright 1999 Oracle Corporation. All rights reserved.
    Enter user-name: apps
    ERROR:
    ORA-12514: Message 12514 not found; product=RDBMS; facility=ORA
    Enter user-name:
    Thanks
    Rao

  • TS1424 everytime i try to download an app from itunes, or to 'view all' the apps listed, the error says; 'We could not complete your iTunes Store reuest. The network connection was reset' I used both my desktop and laptop both on Windows 7 Pro, & net is f

    everytime i try to download an app from itunes, or to 'view all' the apps listed, the error says; 'We could not complete your iTunes Store reuest. The network connection was reset' I used both my desktop and laptop both on Windows 7 Pro, & net is fine. please help. is there soemthing wrong with apple store temporarily?

    The latest message is: 'We could not complete your iTunes Store request. The network connection was reset.'
    In between, I got a messge about verifying my payment method. When I tried to submit the details, I kept getting a mmessage stating that my payment method was declined (my card is not near it's expiration date, and works fine).
    Argh!

  • HT201274 every time i open an app it says to connect to itunes to use push notifications

    Anytime I open an app, it always tells me to "Connect to itunes to use push notifications."  How do I fix that.
    Also, when i open youtube, it tells me i cannot connect to youtube.

    Did you already try to reset the iPad by holding the sleep and home button for about 10sec, until the Apple logo comes back again?

  • I have 2 games Words with Friends and Cityville that receives a Pop-up message form iTunes...  "Connect to iTunes to use Push Notifications" and will not allow me to exit out of the app or play.  How can I get this message to STOP?

    I have 2 games Words with Friends and Cityville that receives a Pop-up message form iTunes...  "Connect to iTunes to use Push Notifications" and will not allow me to exit out of the app or play.  How can I get this message to STOP?

    Yes - I connected my phone to my computer / Itunes and went into the apps section, but from there I have no idea how to manage the push notifications.  I even tryied going into itunes that is installed on my phone.  I still cannot find anyplace to manage these popups.  I have also gone into settings - notifiations - and tried turning all notifications for these apps all off but that didnt work either.  Any guidance is MUCH appreciated - Im not sure where to go from here.

  • IPhone 5 unable to connect to internet or use web-based apps like Facebook or Tumblr

    About two days ago, shortly after using my iPhone 5 to upload a picture of my son eating a donut to Facebook, I seem to have lost all ability to connect to the internet or update content on web-based apps like Facebook or Tumblr.  I tried to restore my iPhone in iTunes on my computer but could not do that without first turning of "Find My iPhone," in the iCloud section of my settings.  When asked to enter my password to turn off this feature the phone is "unable to connect to iCloud."  It doesn't seem to matter if I'm connected to WiFi or using my cell data - I'm getting a strong signal in either case, but the phone is unable to connect to anything.  I CAN make phone calls and send texts but that's just about it.
    I recently updated to IOS 8.1.1 but it worked fine for several days before this problem started.  Any ideas?

    I reset my network settings (Settings > General > Reset > Reset Network Settings) and rejoined my network, and that seemed to fix it. Apps are working on wifi and on data, and I can once again send imessages. Since I couldn't find a similar post very easily, I wanted to post this for whoever needs help with this problem ;D

  • TS3297 Anybody else having issues connecting to the App Store after iOS 6.0 update?  I am using an iPod 4th gen and am having issues with a blank screen on the App Store.

    My 4th gen ipod touch won't connect to the App Store after I updated to ios6.0.  It just gives me a blank screen no message or anything.

    hi! im using an ipad2 and updated to ios6 last 3days ago. since then my app store is blank and is prompting an error saying cannot connect to itunes.

Maybe you are looking for