Add .Net SyncManager Online API Guide 45/136645/8
authorIckhee Woo <ickhee.woo@samsung.com>
Fri, 30 Jun 2017 12:29:04 +0000 (21:29 +0900)
committerIckhee Woo <ickhee.woo@samsung.com>
Fri, 14 Jul 2017 07:07:03 +0000 (07:07 +0000)
PS3: Reviewed
PS5: Fixed typo
PS6: Removed whitespace
PS7: Fixed API name

Change-Id: I91fac00b70a7db419d7df743729e43f8451b16bd
Signed-off-by: Ickhee Woo <ickhee.woo@samsung.com>
org.tizen.guides/html/dotnet/sync_manager.htm [new file with mode: 0644]

diff --git a/org.tizen.guides/html/dotnet/sync_manager.htm b/org.tizen.guides/html/dotnet/sync_manager.htm
new file mode 100644 (file)
index 0000000..fed8dd5
--- /dev/null
@@ -0,0 +1,295 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+       <head>
+               <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+               <meta http-equiv="X-UA-Compatible" content="IE=9" />
+               <link rel="stylesheet" type="text/css" href="../css/styles.css" />
+               <link rel="stylesheet" type="text/css" href="../css/snippet.css" />
+               <script type="text/javascript" src="../scripts/snippet.js"></script>
+               <script type="text/javascript" src="../scripts/jquery.util.js" charset="utf-8"></script>
+               <script type="text/javascript" src="../scripts/common.js" charset="utf-8"></script>
+               <script type="text/javascript" src="../scripts/core.js" charset="utf-8"></script>
+               <script type="text/javascript" src="../scripts/search.js" charset="utf-8"></script>
+
+               <title>Sync Manager</title>
+       </head>
+
+       <body onload="prettyPrint()" style="overflow: auto;">
+               <div id="toc-navigation">
+                       <div id="profile">
+                               <p><img alt="Mobile C#" src="../images/mobile_s_cs.png"/></p>
+                       </div>
+                       <div id="toc_border"><div id="toc">
+                       <p class="toc-title">Dependencies</p>
+                       <ul class="toc">
+                               <li>Tizen 4.0 and Higher for Mobile</li>
+                       </ul>
+                       <p class="toc-title">Content</p>
+                       <ul class="toc">
+                               <li><a href="#prerequisites">Prerequisites</a></li>
+                               <li><a href="#set_callback">Setting Sync Adapter Callbacks</a></li>
+                               <li><a href="#set_parameters">Defining a Sync Job</a></li>
+                               <li><a href="#on_demand_sync">Defining an On-demand Sync Job</a></li>
+                               <li><a href="#periodic_sync">Defining a Periodic Sync Job</a></li>
+                               <li><a href="#data_change_sync">Defining a Data Change Sync Job</a></li>
+                               <li><a href="#foreach_sync">Retrieving All Registered Sync Jobs</a></li>
+                               <li><a href="#remove_sync">Removing Sync Jobs</a></li>
+                       </ul>
+                       <p class="toc-title">Related Info</p>
+                       <ul class="toc">
+                               <li><a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager.html">Tizen.Account.SyncManager Namespace</a></li>
+                       </ul>
+                       </div></div>
+               </div>
+
+               <div id="container"><div id="contents"><div class="content">
+
+               <h1>Sync Manager</h1>
+               <p>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.</p>
+               <p>The main features of the Tizen.Account.SyncManager namespace are:</p>
+               <ul>
+                       <li>Sync Adapter
+                       <ul>
+                               <li>Setting Sync Adapter callbacks
+                               <p>You can <a href="#set_callback">set the callback methods</a> in your Sync Adapter service application that your client application can call to set up a sync operation.</p></li>
+                       </ul>
+                       </li>
+
+                       <li>Sync Manager
+                       <ul>
+                               <li>Defining a sync job
+                               <p>You can <a href="#set_parameters">create a new sync job</a> and add user data into it as either an account information instance or a data bundle.</p></li>
+                               <li>Defining an on-demand sync job
+                               <p>You can <a href="#on_demand_sync">add an on-demand sync job</a> for a one-time operation.</p></li>
+                               <li>Defining a periodic sync job
+                               <p>You can <a href="#periodic_sync">add a periodic sync job</a> with a recurring cycle.</p></li>
+                               <li>Defining a data chance sync job
+                               <p>You can <a href="#data_change_sync">add a data change sync job</a> for receiving a notification whenever a specific database changes.</p></li>
+                               <li>Retrieving all registered sync jobs
+                               <p>You can <a href="#foreach_sync">get a list of all registered sync jobs</a>.</p></li>
+                               <li>Removing sync job
+                               <p>You can <a href="#remove_sync">remove registered sync jobs</a> when they are no longer needed.</p></li>
+                       </ul>
+                       </li>
+               </ul>
+
+
+       <h2 id="prerequisites">Prerequisites</h2>
+
+<p>To enable your application to use the sync manager functionality:</p>
+<ul>
+<li>To use the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager.html">Tizen.Account.SyncManager</a> namespace, the application has to request permission by adding the following privileges to the <code>tizen-manifest.xml</code> file:
+<pre class="prettyprint">
+&lt;privileges&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/account.read&lt;/privilege&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/account.write&lt;/privilege&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/alarm.set&lt;/privilege&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/calendar.read&lt;/privilege&gt;
+   &lt;privilege&gt;http://tizen.org/privilege/contact.read&lt;/privilege&gt;
+&lt;/privileges&gt;
+</pre>
+</li>
+<li> <p>To use the methods and properties of the Tizen.Account.SyncManager namespace, include it in your application:</p>
+<pre class="prettyprint">
+using Tizen.Account.SyncManager;
+</pre>
+</li>
+</ul>
+               <div class="note">
+               <strong>Note</strong>
+               To use the features of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager.html">Tizen.Account.SyncManager</a> namespace, <a href="#set_callback">setting the callbacks</a> needs to be carried out first by a service application. A UI application cannot initialize or set callback methods through the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncAdapter.html">Tizen.Account.SyncManager.SyncAdapter</a> class. Instead, methods of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class need to be called by the UI application to request sync operations from the service application.
+               </div>
+
+               <h2 id="set_callback">Setting Sync Adapter Callbacks</h2>
+               <p>To set callbacks in your Sync Adapter service application that your UI application can call to request sync operations:</p>
+               <ol>
+                       <li>Set up event handlers for starting and stopping data synchronization. When the <code>startCb</code> callback is invoked, the predefined data sync process is performed inside the callback method. The <code>cancelCb</code> callback works in a similar way and cancels the data sync process.
+<pre class="prettyprint">
+SyncAdapter.StartSyncCallback startCb = (SyncJobData data) =&gt;
+{
+    /// Code for starting data synchronization
+    return true;
+};
+
+SyncAdapter.CancelSyncCallback cancelCb = (SyncJobData data) =&gt;
+{
+    /// Code for cancelling data synchronization
+};
+</pre>
+                       </li>
+
+                       <li>Register the event callbacks with the <code>SetSyncEventCallbacks()</code> method of the <code>Tizen.Account.SyncManager.SyncAdapter</code> class to receive notifications regarding the sync operation.
+                       <p>When a specific event is detected or a sync job is requested, the <code>StartSyncCallback</code> or <code>CancelSyncCallback</code> events of the <code>Tizen.Account.SyncManager.SyncAdapter</code> class are invoked.</p>
+<pre class="prettyprint">
+SyncAdapter obj = new SyncAdapter();
+obj.SetSyncEventCallbacks(startCb, cancelCb);
+</pre>
+                       </li>
+
+                       <li>When the sync operations are no longer needed, unset the callbacks to free the <code>Tizen.Account.SyncManager.SyncAdapter</code> instance:
+<pre class="prettyprint">
+SyncAdapter obj = new SyncAdapter();
+obj.UnsetSyncEventCallbacks();
+</pre>
+                       </li>
+               </ol>
+
+
+               <h2 id="set_parameters">Defining a Sync Job</h2>
+               <p>To define a sync job, create a new <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance:</p>
+<pre class="prettyprint">
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = "PeriodicSyncJob";
+</pre>
+<p>You can add user data to a sync job as an account information instance or as a data bundle:</p>
+
+               <ul>
+                       <li>To add account information to a sync job, create a new instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Account_1_1AccountManager_1_1Account.html">Tizen.Account.AccountManager.Account</a> class, add your account information into it, and then add it into the sync job as the <code>Account</code> property of the <code>Tizen.Account.SyncManager.SyncJobData</code> instance. For more information about creating accounts, see <a href="account.htm#add">Creating an Account</a>.
+<pre class="prettyprint">
+using Tizen.Account.AccountManager;
+
+AccountManager.Account account = AccountManager.Account.CreateAccount();
+account.UserName = "Kim";
+
+SyncData.Account = account;
+</pre>
+                       </li>
+
+                       <li>To add a data bundle to a sync job, create a new instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Applications_1_1Bundle.html">Tizen.Applications.Bundle</a> class, add your data into it, and add it as the <code>UserData</code> property of the <code>Tizen.Account.SyncManager.SyncJobData</code> instance.
+<pre class="prettyprint">
+using Tizen.Applications;
+
+Applications.Bundle bundle = new Applications.Bundle();
+bundle.AddItem("key", "value");
+
+SyncData.UserData = bundle;
+</pre>
+                       </li>
+               </ul>
+
+
+               <h2 id="on_demand_sync">Defining an On-demand Sync Job</h2>
+               <p>To request a one-time sync job from the Sync Adapter service application, use the <code>RequestOnDemandSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class:</p>
+
+<pre class="prettyprint">
+SyncJobData request = new SyncJobData();
+request.SyncJobName = "OnDemandSyncJob";
+int id = SyncClient.RequestOnDemandSyncJob(request, SyncOption.NoRetry);
+</pre>
+
+
+               <h2 id="periodic_sync">Defining a Periodic Sync Job</h2>
+               <p>To register a periodically-recurring sync operation with the Sync Adapter service application:</p>
+               <ol>
+                       <li>To set up a periodic sync job with a regular sync interval, use the <code>AddPeriodicSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class, and give the sync interval as a value of the <code>Tizen.Account.SyncManager.SyncPeriod</code> enumeration. In the following example, the sync interval is set to 30 minutes:
+<pre class="prettyprint">
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = "PeriodicSyncJob";
+int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.ThirtyMin, SyncOption.None);
+</pre>
+                       <p>You can also add additional parameters to the sync job using values of the <code>Tizen.Account.SyncManager.SyncOption</code> enumeration. The value <code>NoRetry</code> means that the application does not retry the sync job if it fails, and <code>Expedited</code> means that the sync job is handled as soon as possible.</p>
+<pre class="prettyprint">
+int id2 = SyncClient.AddPeriodicSyncJob(SyncData2, SyncPeriod.OneHour, SyncOption.NoRetry);
+int id3 = SyncClient.AddPeriodicSyncJob(SyncData3, SyncPeriod.OneDay, SyncOption.Expedited);
+</pre>
+                       </li>
+
+                       <li>You can also use the <code>AddPeriodicSyncJob()</code> method to renew a previously registered periodic sync job by using the same <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance with new parameters:
+<pre class="prettyprint">
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = "PeriodicSyncJob";
+int id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.ThirtyMin, SyncOption.None);
+id = SyncClient.AddPeriodicSyncJob(SyncData, SyncPeriod.TwoHours, SyncOption.Expedited);
+</pre>
+                       </li>
+               </ol>
+
+
+               <h2 id="data_change_sync">Defining a Data Change Sync Job</h2>
+               <p>To register a data change sync job with the Sync Adapter service application, to occur whenever a corresponding database changes:</p>
+               <ol>
+                       <li>Add a data change sync job with the <code>AddDataChangeSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class. This method adds the sync job only for the capability given as the value of the <code>SyncJobName</code> property of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance. For example, to add a data change sync job for the calendar:
+<pre class="prettyprint">
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = SyncJobData.CalendarCapability;
+int id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.None);
+</pre>
+                       <p>You can also add additional parameters to the sync job using values of the <code>Tizen.Account.SyncManager.SyncOption</code> enumeration. The value <code>NoRetry</code> means that the application does not retry the sync job if it fails, and <code>Expedited</code> means that another sync job is handled as soon as possible.</p>
+<pre class="prettyprint">
+int id2 = SyncClient.AddDataChangeSyncJob(SyncData2, SyncOption.NoRetry);
+int id3 = SyncClient.AddDataChangeSyncJob(SyncData3, SyncOption.Expedited);
+</pre>
+                       </li>
+
+                       <li>You can also use the <code>AddDataChangeSyncJob()</code> method to renew a previously registered data change sync job by using the same <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncJobData.html">Tizen.Account.SyncManager.SyncJobData</a> instance with new parameters:
+<pre class="prettyprint">
+SyncJobData SyncData = new SyncJobData();
+SyncData.SyncJobName = SyncJobData.ContactCapability;
+int id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.Expedited);
+id = SyncClient.AddDataChangeSyncJob(SyncData, SyncOption.None);
+</pre>
+                       </li>
+               </ol>
+
+
+               <h2 id="foreach_sync">Retrieving All Registered Sync Jobs</h2>
+               <p>To retrieve a list of all registered sync jobs, use the <code>GetAllSyncJobs()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class:</p>
+<pre class="prettyprint">
+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 <span class="highlight">SyncClient.GetAllSyncJobs()</span>)
+{
+    Console.Write(pair.Key + " : ");
+    Console.WriteLine(pair.Value);
+}
+</pre>
+
+
+               <h2 id="remove_sync">Removing Sync Jobs</h2>
+               <p>To remove registered sync jobs, use the <code>RemoveSyncJob()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Account_1_1SyncManager_1_1SyncClient.html">Tizen.Account.SyncManager.SyncClient</a> class, using the <code>id</code> property of the job to be removed:</p>
+<pre class="prettyprint">
+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);
+
+<span class="highlight">SyncClient.RemoveSyncJob(id);</span>
+<span class="highlight">SyncClient.RemoveSyncJob(id2);</span>
+</pre>
+
+
+
+<script type="text/javascript" src="../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+       </body>
+</html>