From bcedebf90fa736e789da5d47a36f804f68af1849 Mon Sep 17 00:00:00 2001 From: Ickhee Woo Date: Fri, 30 Jun 2017 21:29:04 +0900 Subject: [PATCH] Add .Net SyncManager Online API Guide PS3: Reviewed PS5: Fixed typo PS6: Removed whitespace PS7: Fixed API name Change-Id: I91fac00b70a7db419d7df743729e43f8451b16bd Signed-off-by: Ickhee Woo --- org.tizen.guides/html/dotnet/sync_manager.htm | 295 ++++++++++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 org.tizen.guides/html/dotnet/sync_manager.htm diff --git a/org.tizen.guides/html/dotnet/sync_manager.htm b/org.tizen.guides/html/dotnet/sync_manager.htm new file mode 100644 index 0000000..fed8dd5 --- /dev/null +++ b/org.tizen.guides/html/dotnet/sync_manager.htm @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + Sync Manager + + + + + +
+ +

Sync Manager

+

You can manage a synchronization schedule for applications by using a UI application to request for sync jobs through the Sync Manager, and a service application to listen for the requests through the Sync Adapter. The service and UI applications must have the same package name.

+

The main features of the Tizen.Account.SyncManager namespace are:

+ + + +

Prerequisites

+ +

To enable your application to use the sync manager functionality:

+
    +
  • To use the Tizen.Account.SyncManager namespace, the application has to request permission by adding the following privileges to the tizen-manifest.xml file: +
    +<privileges>
    +   <privilege>http://tizen.org/privilege/account.read</privilege>
    +   <privilege>http://tizen.org/privilege/account.write</privilege>
    +   <privilege>http://tizen.org/privilege/alarm.set</privilege>
    +   <privilege>http://tizen.org/privilege/calendar.read</privilege>
    +   <privilege>http://tizen.org/privilege/contact.read</privilege>
    +</privileges>
    +
    +
  • +
  • To use the methods and properties of the Tizen.Account.SyncManager namespace, include it in your application:

    +
    +using Tizen.Account.SyncManager;
    +
    +
  • +
+
+ Note + To use the features of the Tizen.Account.SyncManager namespace, setting the callbacks needs to be carried out first by a service application. A UI application cannot initialize or set callback methods through the Tizen.Account.SyncManager.SyncAdapter class. Instead, methods of the Tizen.Account.SyncManager.SyncClient class need to be called by the UI application to request sync operations from the service application. +
+ +

Setting Sync Adapter Callbacks

+

To set callbacks in your Sync Adapter service application that your UI application can call to request sync operations:

+
    +
  1. Set up event handlers for starting and stopping data synchronization. When the startCb callback is invoked, the predefined data sync process is performed inside the callback method. The cancelCb callback works in a similar way and cancels the data sync process. +
    +SyncAdapter.StartSyncCallback startCb = (SyncJobData data) =>
    +{
    +    /// Code for starting data synchronization
    +    return true;
    +};
    +
    +SyncAdapter.CancelSyncCallback cancelCb = (SyncJobData data) =>
    +{
    +    /// Code for cancelling data synchronization
    +};
    +
    +
  2. + +
  3. Register the event callbacks with the SetSyncEventCallbacks() method of the Tizen.Account.SyncManager.SyncAdapter class to receive notifications regarding the sync operation. +

    When a specific event is detected or a sync job is requested, the StartSyncCallback or CancelSyncCallback events of the Tizen.Account.SyncManager.SyncAdapter class are invoked.

    +
    +SyncAdapter obj = new SyncAdapter();
    +obj.SetSyncEventCallbacks(startCb, cancelCb);
    +
    +
  4. + +
  5. When the sync operations are no longer needed, unset the callbacks to free the Tizen.Account.SyncManager.SyncAdapter instance: +
    +SyncAdapter obj = new SyncAdapter();
    +obj.UnsetSyncEventCallbacks();
    +
    +
  6. +
+ + +

Defining a Sync Job

+

To define a sync job, create a new Tizen.Account.SyncManager.SyncJobData instance:

+
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = "PeriodicSyncJob";
+
+

You can add user data to a sync job as an account information instance or as a data bundle:

+ +
    +
  • To add account information to a sync job, create a new instance of the Tizen.Account.AccountManager.Account class, add your account information into it, and then add it into the sync job as the Account property of the Tizen.Account.SyncManager.SyncJobData instance. For more information about creating accounts, see Creating an Account. +
    +using Tizen.Account.AccountManager;
    +
    +AccountManager.Account account = AccountManager.Account.CreateAccount();
    +account.UserName = "Kim";
    +
    +SyncData.Account = account;
    +
    +
  • + +
  • To add a data bundle to a sync job, create a new instance of the Tizen.Applications.Bundle class, add your data into it, and add it as the UserData property of the Tizen.Account.SyncManager.SyncJobData instance. +
    +using Tizen.Applications;
    +
    +Applications.Bundle bundle = new Applications.Bundle();
    +bundle.AddItem("key", "value");
    +
    +SyncData.UserData = bundle;
    +
    +
  • +
+ + +

Defining an On-demand Sync Job

+

To request a one-time sync job from the Sync Adapter service application, use the RequestOnDemandSyncJob() method of the Tizen.Account.SyncManager.SyncClient class:

+ +
+SyncJobData request = new SyncJobData();
+request.SyncJobName = "OnDemandSyncJob";
+int id = SyncClient.RequestOnDemandSyncJob(request, SyncOption.NoRetry);
+
+ + +

Defining a Periodic Sync Job

+

To register a periodically-recurring sync operation with the Sync Adapter service application:

+
    +
  1. To set up a periodic sync job with a regular sync interval, use the AddPeriodicSyncJob() method of the Tizen.Account.SyncManager.SyncClient class, and give the sync interval as a value of the Tizen.Account.SyncManager.SyncPeriod enumeration. In the following example, the sync interval is set to 30 minutes: +
    +SyncJobData SyncData = new SyncJobData();
    +SyncData.SyncJobName = "PeriodicSyncJob";
    +int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.ThirtyMin, SyncOption.None);
    +
    +

    You can also add additional parameters to the sync job using values of the Tizen.Account.SyncManager.SyncOption enumeration. The value NoRetry means that the application does not retry the sync job if it fails, and Expedited means that the sync job is handled as soon as possible.

    +
    +int id2 = SyncClient.AddPeriodicSyncJob(SyncData2, SyncPeriod.OneHour, SyncOption.NoRetry);
    +int id3 = SyncClient.AddPeriodicSyncJob(SyncData3, SyncPeriod.OneDay, SyncOption.Expedited);
    +
    +
  2. + +
  3. You can also use the AddPeriodicSyncJob() method to renew a previously registered periodic sync job by using the same Tizen.Account.SyncManager.SyncJobData instance with new parameters: +
    +SyncJobData SyncData = new SyncJobData();
    +SyncData.SyncJobName = "PeriodicSyncJob";
    +int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.ThirtyMin, SyncOption.None);
    +id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.TwoHours, SyncOption.Expedited);
    +
    +
  4. +
+ + +

Defining a Data Change Sync Job

+

To register a data change sync job with the Sync Adapter service application, to occur whenever a corresponding database changes:

+
    +
  1. Add a data change sync job with the AddDataChangeSyncJob() method of the Tizen.Account.SyncManager.SyncClient class. This method adds the sync job only for the capability given as the value of the SyncJobName property of the Tizen.Account.SyncManager.SyncJobData instance. For example, to add a data change sync job for the calendar: +
    +SyncJobData SyncData = new SyncJobData();
    +SyncData.SyncJobName = SyncJobData.CalendarCapability;
    +int id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.None);
    +
    +

    You can also add additional parameters to the sync job using values of the Tizen.Account.SyncManager.SyncOption enumeration. The value NoRetry means that the application does not retry the sync job if it fails, and Expedited means that another sync job is handled as soon as possible.

    +
    +int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.NoRetry);
    +int id3 = SyncClient.AddDataChangeSyncJob(SyncData3, SyncOption.Expedited);
    +
    +
  2. + +
  3. You can also use the AddDataChangeSyncJob() method to renew a previously registered data change sync job by using the same Tizen.Account.SyncManager.SyncJobData instance with new parameters: +
    +SyncJobData SyncData = new SyncJobData();
    +SyncData.SyncJobName = SyncJobData.ContactCapability;
    +int id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.Expedited);
    +id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.None);
    +
    +
  4. +
+ + +

Retrieving All Registered Sync Jobs

+

To retrieve a list of all registered sync jobs, use the GetAllSyncJobs() method of the Tizen.Account.SyncManager.SyncClient class:

+
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = "PeriodicSyncJob";
+
+SyncJobData SyncData2 = new SyncJobData();
+SyncData2.SyncJobName = SyncJobData.ImageCapability;
+
+int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.OneHour, SyncOption.Expedited);
+int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.None);
+
+foreach (var pair in SyncClient.GetAllSyncJobs())
+{
+    Console.Write(pair.Key + " : ");
+    Console.WriteLine(pair.Value);
+}
+
+ + +

Removing Sync Jobs

+

To remove registered sync jobs, use the RemoveSyncJob() method of the Tizen.Account.SyncManager.SyncClient class, using the id property of the job to be removed:

+
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = "PeriodicSyncJob";
+
+SyncJobData SyncData2 = new SyncJobData();
+SyncData2.SyncJobName = SyncJobData.ImageCapability;
+
+int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.OneHour, SyncOption.Expedited);
+int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.None);
+
+SyncClient.RemoveSyncJob(id);
+SyncClient.RemoveSyncJob(id2);
+
+ + + + + +
+ +Go to top + + + + + + + -- 2.7.4