コード例 #1
0
        /// <summary>
        /// Cancels all scheduled alarms that are registered by the application that calls this API.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static void CancelAll()
        {
            AlarmError ret = (AlarmError)Interop.Alarm.CancelAllAlarms();

            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to cancel Alarms");
            }
        }
コード例 #2
0
        /// <summary>
        /// Cancels the specific alarm.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied due to insufficient privileges.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void Cancel()
        {
            AlarmError ret = (AlarmError)Interop.Alarm.CancelAlarm(AlarmId);

            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to Cancel alarm");
            }
        }
コード例 #3
0
        /// <summary>
        /// Sets an alarm to be triggered after a specific time.
        /// The alarm will go off delay seconds later.
        /// </summary>
        /// <param name="delay"> The amount of time before the execution (in seconds). </param>
        /// <param name="appControl"> The destination AppControl to perform a specific task when the alarm is triggered. </param>
        /// <returns> An alarm instance is created with the set param values.</returns>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static Alarm CreateAlarm(int delay, AppControl appControl)
        {
            Alarm      alarm = null;
            int        alarmId;
            AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmOnceAfterDelay(appControl.SafeAppControlHandle, delay, out alarmId);

            alarm = new Alarm(alarmId);
            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
            }

            return(alarm);
        }
コード例 #4
0
        /// <summary>
        /// Sets a notification alarm to be triggered after a specific time.
        /// The alarm will go off delay seconds later.
        /// </summary>
        /// <param name="delay">The amount of time before the first execution (in seconds).</param>
        /// <param name="notification"> The notification to be posted when the alarm is triggered. </param>
        /// <returns> An alarm instance is created with the set param values.</returns>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static Alarm CreateAlarm(int delay, Notification notification)
        {
            Alarm alarm = null;
            int   alarmId;
            NotificationSafeHandle safeHandle = NotificationManager.MakeNotificationSafeHandle(notification);
            AlarmError             ret        = Interop.Alarm.CreateAlarmNotiOnceAfterDelay(safeHandle, delay, out alarmId);

            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
            }

            alarm = new Alarm(alarmId);

            return(alarm);
        }
コード例 #5
0
        /// <summary>
        /// Sets an alarm to be triggered periodically, starting at a specific time.
        /// The date describes the time of the first occurrence.
        /// The weekFlag is the repeat value of the days of the week.
        /// If the weekFlag is AlarmWeekFlag.Tuesday, the alarm will repeat every Tuesday at a specific time.
        /// </summary>
        /// <remarks>This operation is permitted with UI application appcontrol only.</remarks>
        /// <param name="value"> The first active alarm time. </param>
        /// <param name="weekFlag"> The day of the week, AlarmWeekFlag may be a combination of days, like AlarmWeekFlag.Sunday | AlarmWeekFlag.Monday.</param>
        /// <param name="appControl"> The destination AppControl to perform specific work when the alarm is triggered. </param>
        /// <returns> An alarm instance is created with the set param values.</returns>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static Alarm CreateAlarm(DateTime value, AlarmWeekFlag weekFlag, AppControl appControl)
        {
            Alarm alarm = null;
            int   alarmId;

            Interop.Alarm.DateTime time = ConvertDateTimeToStruct(value);
            AlarmError             ret  = (AlarmError)Interop.Alarm.CreateAlarmRecurWeek(appControl.SafeAppControlHandle, ref time, (int)weekFlag, out alarmId);

            alarm = new Alarm(alarmId);
            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
            }

            return(alarm);
        }
コード例 #6
0
        /// <summary>
        /// Gets the current system time.
        /// </summary>
        /// <returns>The current system time.</returns>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <since_tizen> 3 </since_tizen>
        public static DateTime GetCurrentTime()
        {
            DateTime time;

            Interop.Alarm.DateTime value;
            AlarmError             ret = (AlarmError)Interop.Alarm.GetCurrentTime(out value);

            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to get Currenttime");
            }
            else
            {
                time = ConvertIntPtrToDateTime(value);
            }

            return(time);
        }
コード例 #7
0
        /// <summary>
        /// Sets a notification alarm to be triggered periodically, starting at a specific time.
        /// The date describes the time of the first occurrence.
        /// The weekFlag is the repeat value of the days of the week.
        /// If the weekFlag is AlarmWeekFlag.Tuesday, the alarm will repeat every Tuesday at a specific time.
        /// </summary>
        /// <param name="dateTime"> The first active alarm time. </param>
        /// <param name="weekFlag"> The day of the week, AlarmWeekFlag may be a combination of days,
        ///                         like AlarmWeekFlag.Sunday | AlarmWeekFlag.Monday.</param>
        /// <param name="notification"> The notification to be posted when the alarm is triggered. </param>
        /// <returns> An alarm instance is created with the set param values.</returns>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static Alarm CreateAlarm(DateTime dateTime, AlarmWeekFlag weekFlag, Notification notification)
        {
            Alarm alarm = null;
            int   alarmId;
            NotificationSafeHandle safeHandle = NotificationManager.MakeNotificationSafeHandle(notification);

            Interop.Alarm.DateTime time = ConvertDateTimeToStruct(dateTime);
            AlarmError             ret  = Interop.Alarm.CreateAlarmNotiRecurWeek(safeHandle, ref time, (int)weekFlag, out alarmId);

            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
            }

            alarm = new Alarm(alarmId);

            return(alarm);
        }
コード例 #8
0
        /// <summary>
        /// Retrieves all registered alarms.
        /// </summary>
        /// <returns>List of all alarm instances.</returns>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.get</privilege>
        /// <since_tizen> 4 </since_tizen>
        public static IEnumerable <Alarm> GetAllScheduledAlarms()
        {
            List <Alarm> alarms = new List <Alarm>();

            Interop.Alarm.RegisteredAlarmCallback callback = (int alarmId, IntPtr userData) =>
            {
                alarms.Add(new Alarm(alarmId));
                return(true);
            };

            AlarmError ret = (AlarmError)Interop.Alarm.GetAllRegisteredAlarms(callback, IntPtr.Zero);

            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to get Alarms");
            }

            return(alarms);
        }
コード例 #9
0
        /// <summary>
        /// Sets an alarm to be triggered after a specific time.
        /// The alarm will first go off delay seconds later and then will go off every certain amount of time defined using period seconds.
        /// </summary>
        /// <param name="delay">The amount of time before the first execution (in seconds).</param>
        /// <param name="period"> The amount of time between subsequent alarms (in seconds). This value does not guarantee the accuracy.
        /// The actual interval is calculated by the OS. The minimum value is 600sec.</param>
        /// <param name="appControl"> The destination AppControl is used to perform a specific task when the alarm is triggered. </param>
        /// <returns> An alarm instance is created with the set param values.</returns>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static Alarm CreateAlarm(int delay, int period, AppControl appControl)
        {
            if (appControl == null)
            {
                throw AlarmErrorFactory.GetException(AlarmError.InvalidParameter, "AppControl should be not null");
            }

            Alarm      alarm = null;
            int        alarmId;
            AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmAfterDelay(appControl.SafeAppControlHandle, delay, period, out alarmId);

            alarm = new Alarm(alarmId);
            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
            }

            return(alarm);
        }
コード例 #10
0
        /// <summary>
        /// Sets an alarm to be triggered at a specific time.
        /// The date describes the time of the first occurrence.
        /// </summary>
        /// <param name="value"> The first active alarm time. </param>
        /// <param name="appControl"> The destination AppControl to perform specific work when the alarm is triggered. </param>
        /// <returns> An alarm instance is created with the set param values.</returns>
        /// <remarks>This operation is permitted with the UI application appcontrol only.</remarks>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/alarm.set</privilege>
        /// <since_tizen> 3 </since_tizen>
        public static Alarm CreateAlarm(DateTime value, AppControl appControl)
        {
            if (appControl == null)
            {
                throw AlarmErrorFactory.GetException(AlarmError.InvalidParameter, "AppControl should be not null");
            }

            Alarm alarm = null;
            int   alarmId;

            Interop.Alarm.DateTime time = ConvertDateTimeToStruct(value);
            AlarmError             ret  = (AlarmError)Interop.Alarm.CreateAlarmOnceAtDate(appControl.SafeAppControlHandle, ref time, out alarmId);

            alarm = new Alarm(alarmId);
            if (ret != AlarmError.None)
            {
                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
            }

            return(alarm);
        }
コード例 #11
0
ファイル: AlarmErrorFactory.cs プロジェクト: yunmiha/TizenFX
        internal static Exception GetException(AlarmError ret, string msg)
        {
            switch (ret)
            {
            case AlarmError.InvalidParameter:
            //fall through
            case AlarmError.InvalidTime:
            //fall through
            case AlarmError.InvalidDate:
                Log.Error(_logTag, msg);
                return(new ArgumentException(ret + " error occurred."));

            case AlarmError.NotPermittedApp:
            //fall through
            case AlarmError.PermissionDenied:
                Log.Error(_logTag, msg);
                return(new UnauthorizedAccessException(ret + "error occured."));

            default:
                Log.Error(_logTag, msg);
                return(new InvalidOperationException(ret + " error occurred."));
            }
        }