Esempio n. 1
0
        /// <summary>
        /// Gets all the sync jobs registered with the sync manager.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <returns>
        /// Returns the list of SyncJobData corresponding to sync requests.
        /// </returns>
        public static IEnumerable <KeyValuePair <int, SyncJobData> > GetAllSyncJobs()
        {
            IDictionary <int, SyncJobData> syncJobs = new Dictionary <int, SyncJobData>();

            Interop.Manager.SyncManagerSyncJobCallback cb = (IntPtr accountHandle, string syncJobName, string syncCapability, int syncJobId, IntPtr syncJobUserData, IntPtr userData) =>
            {
                AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true));
                Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true));

                SyncJobData syncJobData = new SyncJobData();
                syncJobData.Account = account;
                if (syncJobName != null)
                {
                    syncJobData.SyncJobName = syncJobName;
                }
                else
                {
                    syncJobData.SyncJobName = syncCapability;
                }
                syncJobData.UserData = bundle;

                syncJobs.Add(syncJobId, syncJobData);
                return(true);
            };

            int ret = Interop.Manager.ForeachSyncJob(cb, IntPtr.Zero);

            if (ret != (int)SyncManagerErrorCode.None)
            {
                Log.Error(ErrorFactory.LogTag, "Failed to get registered sync job");
                throw ErrorFactory.GetException(ret);
            }
            return(syncJobs);
        }
Esempio n. 2
0
 /// <summary>
 /// Used to add Video data change sync job.
 /// </summary>
 public void AddVideoDataChange()
 {
     TAS.SyncJobData request = new TAS.SyncJobData();
     request.SyncJobName = TAS.SyncJobData.VideoCapability;
     // If some data related with video is changed, you can know the time by using below API
     Video = TAS.SyncClient.AddDataChangeSyncJob(request, TAS.SyncOption.Expedited);
 }
Esempio n. 3
0
 /// <summary>
 /// Used to add Contact data change sync job.
 /// </summary>
 public void AddContactDataChange()
 {
     TAS.SyncJobData request = new TAS.SyncJobData();
     request.SyncJobName = TAS.SyncJobData.ContactCapability;
     // If some data related with contact is changed, you can know the time by using below API
     Contact = TAS.SyncClient.AddDataChangeSyncJob(request, TAS.SyncOption.Expedited);
 }
Esempio n. 4
0
 /// <summary>
 /// Used to add Periodic sync job.
 /// </summary>
 public void AddPeriodic()
 {
     TAS.SyncJobData request = new TAS.SyncJobData();
     request.SyncJobName = "AddPeriodic";
     // This sync job has an interval as 30 minutes
     Periodic = TAS.SyncClient.AddPeriodicSyncJob(request, TAS.SyncPeriod.ThirtyMin, TAS.SyncOption.Expedited);
 }
Esempio n. 5
0
        /// <summary>
        /// Sets the client (sync adapter) callback functions.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="startSyncCb"> A callback function to be called by the sync manager for performing the sync operation. </param>
        /// <param name="cancelSyncCb"> A callback function to be called by the sync manager for cancelling the sync operation. </param>
        /// <exception cref="ArgumentNullException"> Thrown when any of the arguments are null. </exception>
        /// <exception cref="InvalidOperationException"> Thrown when the application calling this API cannot be a sync adapter. </exception>
        public void SetSyncEventCallbacks(StartSyncCallback startSyncCb, CancelSyncCallback cancelSyncCb)
        {
            if (startSyncCb == null || cancelSyncCb == null)
            {
                throw new ArgumentNullException();
            }

            _startSyncCallback = (IntPtr accountHandle, string syncJobName, string syncCapability, IntPtr syncJobUserData) =>
            {
                Log.Debug(ErrorFactory.LogTag, "Start sync event received");

                AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true));
                Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true));

                SyncJobData syncJobData = new SyncJobData();
                syncJobData.Account = account;
                if (syncJobName == null)
                {
                    syncJobData.SyncJobName = syncCapability;
                }
                else
                {
                    syncJobData.SyncJobName = syncJobName;
                }
                syncJobData.UserData = bundle;


                return(startSyncCb(syncJobData));
            };

            _cancelSyncCallback = (IntPtr accountHandle, string syncJobName, string syncCapability, IntPtr syncJobUserData) =>
            {
                Log.Debug(ErrorFactory.LogTag, "cancel sync event received");

                AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true));
                Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true));

                SyncJobData syncJobData = new SyncJobData();
                syncJobData.Account = account;
                if (syncJobName == null)
                {
                    syncJobData.SyncJobName = syncCapability;
                }
                else
                {
                    syncJobData.SyncJobName = syncJobName;
                }
                syncJobData.UserData = bundle;

                cancelSyncCb(syncJobData);
            };

            int ret = Interop.Adapter.SetCallbacks(_startSyncCallback, _cancelSyncCallback);

            if (ret != (int)SyncManagerErrorCode.None)
            {
                Log.Error(ErrorFactory.LogTag, "Failed to set callbacks");
                throw ErrorFactory.GetException(ret);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Used to request On Demand sync job.
 /// </summary>
 public void OnDemand()
 {
     TAS.SyncJobData request = new TAS.SyncJobData();
     request.SyncJobName = "RequestOnDemand";
     // This id is used to remove pended On Demand sync job
     // Generally, it is processed immediately if the device has network connection
     int id = TAS.SyncClient.RequestOnDemandSyncJob(request, TAS.SyncOption.None);
 }
Esempio n. 7
0
        /// <summary>
        /// Used to be invoked by Sync Service.
        /// </summary>
        /// <returns>true for success, other values for failure</returns>
        static bool StartSyncCallback(TAS.SyncJobData request)
        {
            if (request.SyncJobName == "RequestOnDemand")
            {
                // Synchronize data with a server here
                // Update when the OnDemand sync job is completed
                pEvent.UpdateOnDemandDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == "AddPeriodic")
            {
                // Synchronize data with a server here
                // Update when the Periodic sync job is completed
                pEvent.UpdatePeriodicDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == TAS.SyncJobData.CalendarCapability)
            {
                // Synchronize data with a server here
                // Update when the Calendar data change sync job is completed
                pEvent.UpdateCalendarDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == TAS.SyncJobData.ContactCapability)
            {
                // Synchronize data with a server here
                // Update when the Contact data change sync job is completed
                pEvent.UpdateContactDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == TAS.SyncJobData.ImageCapability)
            {
                // Synchronize data with a server here
                // Update when the Image data change sync job is completed
                pEvent.UpdateImageDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == TAS.SyncJobData.MusicCapability)
            {
                // Synchronize data with a server here
                // Update when the Music data change sync job is completed
                pEvent.UpdateMusicDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == TAS.SyncJobData.SoundCapability)
            {
                // Synchronize data with a server here
                // Update when the Sound data change sync job is completed
                pEvent.UpdateSoundDate(DateTime.Now.ToString());
            }
            else if (request.SyncJobName == TAS.SyncJobData.VideoCapability)
            {
                // Synchronize data with a server here
                // Update when the Video data change sync job is completed
                pEvent.UpdateVideoDate(DateTime.Now.ToString());
            }

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Requests the sync manager to perform periodic sync operations.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="request"> The sync job information of the sync job request. </param>
        /// <param name="period"> Determines the time interval of the periodic sync. The periodic sync operation can be triggered in that interval, but it does not guarantee the exact time. The minimum value is 30 minutes. </param>
        /// <param name="syncOptions"> Sync options determine a way to operate the sync job and can be used as ORing. </param>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <exception cref="UnauthorizedAccessException"> In case of a privilege not defined. </exception>
        /// <exception cref="ArgumentNullException"> Thrown when any of the arguments are null. </exception>
        /// <exception cref="InvalidOperationException"> Thrown when the application calling this API doesn't have a sync adapter. </exception>
        /// <returns> A unique value which can manage sync jobs. The number of sync job IDs is limited as it is less than hundred. </returns>
        public static int AddPeriodicSyncJob(SyncJobData request, SyncPeriod period, SyncOption syncOptions)
        {
            if (request == null || request.SyncJobName == null)
            {
                throw new ArgumentNullException();
            }

            SafeAccountHandle accountHandle = (request.Account != null) ? request.Account.SafeAccountHandle : new SafeAccountHandle();
            SafeBundleHandle  bundleHandle  = (request.UserData != null) ? request.UserData.SafeBundleHandle : new SafeBundleHandle();

            int id  = 0;
            int ret = Interop.Manager.AddPeriodicSyncJob(accountHandle, request.SyncJobName, (int)period, (int)syncOptions, bundleHandle, out id);

            if (ret != (int)SyncManagerErrorCode.None)
            {
                Log.Error(ErrorFactory.LogTag, "Failed to add periodic sync job");
                throw ErrorFactory.GetException(ret);
            }
            return(id);
        }
Esempio n. 9
0
 public void CancelSyncCallback(TAS.SyncJobData data)
 {
 }