Page 39 - MSDN Magazine, June 2017
P. 39

• Microsoft.Azure.Mobile.Crashes: Enables an app to share crash information with the Mobile Center. It has a dependency on the Microsoft.Azure.Mobile package, which is also installed.
• Microsoft.Azure.Mobile.Analytics: Enables an app to share usage information with the Mobile Center and has the same dependency on Microsoft.Azure.Mobile.
• Microsoft.Azure.Mobile.Client: Installs the Azure Mobile Client SDK and lets a Windows or Xamarin app work with the Azure Mobile Apps service.
Figure 7 Defining the Data Model
The next step is modeling objects that map tables in the back-end service.
Defining a Data Model
For better code reuse, you can create a base class that maps the basic structure of a table, and then write derived classes that extend the base object with specific columns. The base class must also implement the INotifyPropertyChanged interface to raise change notification with data binding to the UI. Having said that,
// Requires the following directives:
// using System.ComponentModel and System.Runtime.CompilerServices public abstract class TableBase : INotifyPropertyChanged
{
private string id; public string Id
{ get
{
return id;
}
set {
id = value; OnPropertyChanged(); }
}
private string userId; public string UserId {
get {
return userId; }
set {
userId = value; OnPropertyChanged(); }
}
private DateTimeOffset createdAt; public DateTimeOffset CreatedAt {
get {
return createdAt; }
set {
createdAt = value; OnPropertyChanged(); }
}
private DateTimeOffset updatedAt; public DateTimeOffset UpdatedAt {
get {
return updatedAt; }
set {
updatedAt = value; OnPropertyChanged(); }
}
private string version; public string Version {
get {
return version;
}
set {
version = value; OnPropertyChanged(); }
}
private bool deleted; public bool Deleted {
get {
return deleted; }
set {
deleted = value; OnPropertyChanged(); }
}
public TableBase() {
this.CreatedAt = DateTimeOffset.Now;
this.UpdatedAt = DateTimeOffset.Now; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
PropertyChanged?.Invoke(this,
new PropertyChangedEventArgs(propertyName));
} }
public class Book: TableBase {
private string author; public string Author {
get {
return author; }
set {
author = value; OnPropertyChanged(); }
}
private string title; public string Title {
get {
return title; }
set {
title = value; OnPropertyChanged(); }
} }
msdnmagazine.com
June 2017 35



























   37   38   39   40   41