예제 #1
0
        /// <summary>
        /// Removes the badge information.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="appId">Application ID.</param>
        /// <feature>http://tizen.org/feature/badge</feature>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <exception cref="ArgumentException">Thrown when failed because of a an invalid argument.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
        /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
        public static void Remove(string appId)
        {
            BadgeError err = Interop.Badge.Remove(appId);

            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to Remove badge of " + appId);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the badge information from the application ID.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="appId">Application ID.</param>
        /// <returns>The Badge object with inputted application ID</returns>
        /// <feature>http://tizen.org/feature/badge</feature>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
        /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
        public static Badge Find(string appId)
        {
            uint count;
            uint display;

            BadgeError err = Interop.Badge.GetCount(appId, out count);

            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to find badge count of " + appId);
            }

            err = Interop.Badge.GetDisplay(appId, out display);
            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to find badge display of " + appId);
            }

            return(new Badge(appId, (int)count, display == 0 ? false : true));
        }
예제 #3
0
        /// <summary>
        /// Updates the badge information.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="badge">The Badge object.</param>
        /// <feature>http://tizen.org/feature/badge</feature>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
        /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
        public static void Update(Badge badge)
        {
            if (badge == null)
            {
                throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object");
            }

            BadgeError err = Interop.Badge.SetCount(badge.AppId, (uint)badge.Count);

            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + badge.AppId);
            }

            err = Interop.Badge.SetDisplay(badge.AppId, badge.Visible ? 1U : 0U);
            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + badge.AppId);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets all the badge information.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>List of all Badge instances.</returns>
        /// <feature>http://tizen.org/feature/badge</feature>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
        /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
        public static IEnumerable <Badge> GetBadges()
        {
            IList <Badge> list = new List <Badge>();

            BadgeError err = Interop.Badge.Foreach((appId, count, userData) =>
            {
                uint display             = 0;
                BadgeError errGetDisplay = Interop.Badge.GetDisplay(appId, out display);
                if (errGetDisplay != BadgeError.None)
                {
                    throw BadgeErrorFactory.GetException(errGetDisplay, "Failed to get badges ");
                }

                list.Add(new Badge(appId, (int)count, display == 0 ? false : true));
            }, IntPtr.Zero);

            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to get badges");
            }

            return(list);
        }
예제 #5
0
        internal static Exception GetException(BadgeError ret, string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            Log.Error(LogTag, memberName + " : " + lineNumber);

            switch (ret)
            {
            case BadgeError.InvalidParameter:
                Log.Error(LogTag, msg);
                return(new ArgumentException(ret + " error occurred."));

            case BadgeError.PermissionDenied:
                Log.Error(LogTag, msg);
                throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)");

            case BadgeError.NotSupported:
                Log.Error(LogTag, msg);
                throw new NotSupportedException("Not Supported (http://tizen.org/feature/badge)");

            default:
                Log.Error(LogTag, msg);
                return(new InvalidOperationException(ret + " error occurred."));
            }
        }
예제 #6
0
        /// <summary>
        /// Adds the badge information.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="badge">The Badge object.</param>
        /// <feature>http://tizen.org/feature/badge</feature>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
        /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
        public static void Add(Badge badge)
        {
            if (badge == null)
            {
                throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object");
            }

            BadgeError err = Interop.Badge.Add(badge.AppId);

            if (err != BadgeError.None)
            {
                throw BadgeErrorFactory.GetException(err, "Failed to add badge of " + badge.AppId);
            }

            try
            {
                Update(badge);
            }
            catch (Exception e)
            {
                Remove(badge.AppId);
                throw e;
            }
        }