3. “This weighty book gives clear guidance that will help
you build quality apps, starting with architectural
considerations, and then jumping into practical code
strategies.”
- Bryan Costanich, Vice President, Xamarin
“Dan Hermes’ extraordinary book is the most intelligent
work on cross-platform mobile development I’ve seen.”
– Jesse Liberty, Director of New Technology
Development, Falafel Software, Xamarin Certified
Developer / Xamarin MVP
27. • Easy Tables
• Entity Framework
For the demo just click Create ToDoItem Table:
Create your Tables
28. • Create a new Azure Mobile App backend
• Build, upload, and test the server project
• Create a client mobile application
or Just Use Azure’s Built-in Table API
Create a Table API using C#
Extremely powerful
You can do almost anything your backend would ever need to do with Azure. Data storage, authentication/authorization, push notifications, custom APIs, blob storage, etc.
Flexible
Need something lightweight? Azure is there.
Need something robust and powerful? Azure is there.
C# clients
I’m a frontend developer, I care a lot about how easy this makes MY job (selfish)
Many C# clients are written by Java developers, etc.
Easy to use C# client
Abstracts away much of pain of using a RESTful API
C# Features
Async / Await / TPL
Uses C# idioms
Properties, Fluent API
Seems obvious, but not always true (first class citizen)
Notes:
App Service aims to automate the creation of very common line-of-business mobile and web functionality
The developers can focus on developing the parts of the app that are unique as opposed to the boilerplate, typical scenarios that must be re-created for each application
Notes:
Azure Mobile Apps is an app type of Azure App Service (others types include Web Apps, API Apps, and Logic Apps)
Users don’t really care (and usually don’t know) what a mobile app is using for it’s backend
Users care most about enjoying the app experience
Devs should therefore spend most of their time building the best client experience they can
Azure Mobile Apps helps devs by providing common mobile app backend features in a turnkey manner
Data storage powered by SQL Database (but you don’t have to be a Database Admin to use it)
User Authentication and Data Authorization
Push Notifications (using services built into Android, iOS, Windows, and more)
Other topics not covered in this lesson:
Backend job processing using the scheduler
Backend Logic
Image and text courtesy of Microsoft
References:
Image courtesy of Microsoft
Notes:
By following the step-by-step wizard-like process in App Service in the browser, you can add common functionality that’s pre-configured to work with your Azure instance and other apps and services you’ve built in your Azure instance
Notes:
Select New > Web + Mobile > Mobile App
Notes:
Select New > Web + Mobile > Mobile App
1 Connect to a Database (create a DB connection)
2 Create a table API (C# or Node.js)
3 Configure your client application
What if a GetAll should only return favorites for that user.
What if a GetAll should only return favorites for that user.
Notes:
You can download the solution to a Mac and open it in Xamarin Studio, or you can download the solution to a Windows computer and open it in Visual Studio using a networked Mac for building the iOS app.
Extract the project that you downloaded, and then open it in Xamarin Studio or Visual Studio.
Add Azure Nuget
What if a GetAll should only return favorites for that user.
What if a GetAll should only return favorites for that user.
Notes:
Calls to the data store can be made in the app directly from the places in the app that need data.
This is a functional approach, but eventually can lead to unmaintainable, spaghetti code.
In professional grade apps this is considered an anti-pattern, a programming practice to avoid.
In formal terms this hard-coded approach violates Separation of Concerns (SOC)
Notes:
CRUD is the standard set of database transactions needed as an interface for most projects.
Item is an object of type TodoItem. It must have an ID property for many of these transactions.
Tip: When executing a query using an untyped table object, you must explicitly specify the OData query string by calling ReadAsync.
Notes:
Create and Read are good academic terms but a bit stodgy for method names. Let’s use New and Get instead.
Initialization is done in the service’s constructor, AzureDataService (), or in an explicitly called initializer like Initialize().
Notes:
Create and Read are good academic terms but perhaps a bit stodgy for method names. Let’s use New and Get instead.
Notes:
Notes:
Sync local SQLite database with Azure cloud data store (SQL Database). These are the ways:
PushAsync - takes local changes to all tables and applies them to Azure cloud data store
Push is executed on the whole context, not on particular tables. It’s implemented this way to maintain the relationships between rows in different tables, i.e. foreign keys.
PullAsync - grab data from Azure and bring it local to the device – automatically pushes first
This is the most commonly-used offline sync function.
PurgeAsync - deletes items in local table that match the query param – automatically pushes first
Generally used when ‘soft deletes’ not enabled on server.
Notes:
Azure Mobile Client SDK 3.0 brought some changes
The SQLite Batteries initialization is now required for all Oses.
For Android, the path folder for the MobileServiceClient call is not supplied. This must be determined manually. Generally this is done in the Android project and injected back into the Xamarin.Forms PCL.
Define a SQLitePath class in the Xamarin.Forms project with a property called PathName.
public class SQLitePath
{
public static string PathName { get; set; } = "localstore.db";
}
In the AzureDataServicesSync contructor shown in the slide, replace the ‘store’ assignment with this code:
var path = "localstore.db";
path = SQLitePath.PathName;
var store = new MobileServiceSQLiteStore(path);
In Android activity (such as MainActivity.cs)
SQLitePath.PathName = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), SQLitePath.PathName);
if (!File.Exists(SQLitePath.PathName))
{
File.Create(SQLitePath.PathName).Dispose();
}
See detail in Lab 5.
Notes:
First PullSync parameter “allTasks” is a name given to the query generated by the next parameter.
Second parameter creates query to select all rows in the TodoTable.
Notes:
PushAsync, PullAsync, PurgeAsync are the ways to sync data using the Azure Mobile Client API. More in the next slide.
All writes go to the local SQLite database. Nothing goes to Azure unless we sync explicitly using PushAsync, PullAsync, or PurgeAsync.
Sync errors throw MobileServicePushFailedException
Notes:
What if a GetAll should only return favorites for that user.
Notes:
There are two forms of auth and the first we’ll talk about is server auth
This is a basic Oauth flow
The client device calls a method in the SDK which opens a webview which goes to a specific auth provider
The user authenticates
The provider hands back information to the Mobile Service
The Mobile Service creates an identity which it hands back to the client
Future requests from the client contain that identity (though it needs to be cached locally for app restarts)
The Mobile Service now has Graph access to the provider
SO Hard!
Azure makes it easy
Huge value in having this integrated with data... you can just say fire a push IF
Notes:
Some of the items in the store are free and some are available for a fee. The fees charged can also be based on the level of service, frequently revolving around volume of use
The items in the store are pieces of a larger or enterprise-level app that may be helpful
Email sending/management with SendGrid or Office365
Enterprise-level third-party integration with services like SharePoint, SalesForce and QuickBooks
API access for enterprise-level data services like Bing Search or Global Address Validation
Some items are entire Azure-configured applications or content management systems (CMSes) like WordPress, Umbraco, Drupal, etc.
This can speed up the application development process and save time and money
Most of the items in the Azure Marketplace are built with cloud-computing and Azure in mind, removing some of the common Azure-related development tasks
Azure Active Directory is Microsoft’s multi-tenant, cloud-based directory and identity management service. It provides single sign on access to all integrated apps and services. It includes identity management functionality such as multi-factor authentication, password management, role based access control, auditing and security monitoring and alerting
More on the Azure Marketplace: https://azure.microsoft.com/en-us/marketplace/
Notes:
Azure Mobile Apps is an app type of Azure App Service (others types include Web Apps, API Apps, and Logic Apps)
Users don’t really care (and usually don’t know) what a mobile app is using for it’s backend
Users care most about enjoying the app experience
Devs should therefore spend most of their time building the best client experience they can
Azure Mobile Apps helps devs by providing common mobile app backend features in a turnkey manner
Data storage powered by SQL Database (but you don’t have to be a Database Admin to use it)
User Authentication and Data Authorization
Push Notifications (using services built into Android, iOS, Windows, and more)
Other topics not covered in this lesson:
Backend job processing using the scheduler
Backend Logic
Image and text courtesy of Microsoft