Click or drag to resize

Introduction


Intro

The .Net SDK provided by built.io is available for Xamarin, Windows Phone and legacy .Net applications. Let us quickly understand the process to install and initialize this SDK, as well as the other features it provides.

Installation

For Xamarin installation

To use this SDK in Xamarin, follow the steps given below:

  • Create new MonoDroid or MonoTouch project.
  • Expand project under "Solution Explorer".
  • Now Right click on "Components" directory.
  • And select "Get More Components" option.
  • In "Search Component", search for "built.io".
  • Select "built.io" component from search list.
  • Now click on "Add to App" button, it will add "built.io" component to project.
  • Alternatively, you can download component from following location-
    http://components.xamarin.com/view/built.io

Including into class

  • Add following line into C# source file.

    using BuiltSDK;

Basic structure

The structure followed by SDK logically resembles the application structure on built.io. Once you have done the basic setup explained in the Installation section, you get a Built object, which can be used to initialize different modules.

The initialization process for each module is explained below.

  • Application

    To initialize an app, use the App static method from Built class and provide the application's api key.

    var app = Built.App("api_key");
  • Class

    An application instance has a Class method that accepts the uid of the class whose instance is to be created.

    var PersonClass = app.Class("person");
  • Object

    An object is an instance of a class. The SDK follows this by providing an "Object" method on the "Class" instance. The "Object" method accepts an existing object"s uid or data to initialize a new object.

    var Person = PersonClass.Object("object_uid");
    Person["name"] = "Jack";
  • Query

    Query is used to retrieve objects of a class based on certain conditions. The SDK provides a Query method on the "Class" instance, which, when executed, would retrieve objects of that class.

    var query = PersonClass.Query();
  • Upload

    The Upload method can be accessed from the App instance.

    var upload = app.Upload();

Cache Policies

The SDK supports caching, and uses the local "SQLite" db to maintain it. The cache policies available for use are listed below.

  • NetworkOnly (Default)

    This is the default cache policy. It will always get the data from a network call.

  • CacheElseNetwork

    This policy will try to first get the data from cache. On failure,
    it would make a network call.

  • NetworkElseCache

    This policy will try to make a network call. On failure, it would
    fetch the data from cache.

  • CacheThenNetwork

    This policy would first get the data from cache, and then make a
    network call to get the updated copy.

  • CacheOnly

    To fetch data from cache.

  • CacheThenNetwork

    To fetch data from network call and response will not be saved cache.

    Cache policy can be set for the entire application. This means that all the queries built using this application instance would follow the defined cache policy.

    var app = Built.App("api_key").SetCachePolicy(BuiltCachePolicy.CacheElseNetwork);

    Cache policy can also be set on individual queries as given below.

    var query   = Built.App("api_key").Class("person").Query();
    query.SetCachePolicy(BuiltCachePolicy.CacheElseNetwork);

User Management

Use the BuiltUser class to login, logout, and register users in an application. You can log in as an application user with the following code:

var user    = Built.App("api_key").User();
user.Login("username@example.com", "password").ContinueWith((userTask) => {
if (userTask.IsFaulted) {
throw userTask.Exception;
}
else {
var result = userTask.Result;
string userName = result.Username;
}
});