How it works?
The Cloud Data Sync mechanism is designed to work with any type of Cloud Service or a Local Storage Provider. In the CTP version we ship support for SQLite for storing objects locally and the Telerik Cloud Services for storing objects in the Cloud. The whole functionality is accessible through a single class called SynchronizationContext. It is easily initialized with a couple of lines of code as shown below:
SynchronizationContextPool.RegisterContextForType<Task>(
new
EverliveSyncServiceProvider<Task>(
"local_db"
));
this
.tasksContext = SynchronizationContextPool.GetContextForType<Task>();
public
class
Task : SynchronizableDataItem
{
private
string
name;
private
string
description;
private
DateTime dueDate;
public
string
Name
{
get
{
return
this
.name;
}
set
{
if
(
this
.name != value)
{
this
.name = value;
this
.OnPropertyChanged(
"Name"
);
}
}
}
public
string
Description
{
get
{
return
this
.description;
}
set
{
if
(
this
.description != value)
{
this
.description = value;
this
.OnPropertyChanged(
"Description"
);
}
}
}
public
DateTime DueDate
{
get
{
return
this
.dueDate;
}
set
{
if
(
this
.dueDate != value)
{
this
.dueDate = value;
this
.OnPropertyChanged(
"DueDate"
);
}
}
}
}
SynchronizationContext<Task> tasksContext = SynchronizationContextPool.GetContextForType<Task>();
Task task =
new
Task();
task.Name =
"Meeting with John"
;
task.Description =
"Meet with John to discuss the sales statistics from the last month."
;
task.DueDate =
new
DateTime(26, 12, 2013);
// Registers adds the item to the context. This stores is locally and schedules the item for server creation during the next synchronization routine
await tasksContext.AddAsync(task);
// Starts a new synchronization routine which makes sure local and Cloud items of the corresponding type are synchronized
await tasksContext.SynchronizeAsync();
// Marks the given object as deleted. It will be permanently deleted during the next synchronization routine.
await tasksContext.DeleteAsync(task);
// Deletes the task
task.Delete();
// Synchronizes the task
task.SynchronizeAsync();