コード例 #1
0
        /// <summary>
        /// Returns the notification list.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/notification</privilege>
        /// <since_tizen> 4 </since_tizen>
        public static IList <NotificationEventArgs> GetList()
        {
            Interop.NotificationEventListener.ErrorCode err;
            IntPtr notificationList            = IntPtr.Zero;
            IntPtr currentList                 = IntPtr.Zero;
            IList <NotificationEventArgs> list = new List <NotificationEventArgs>();

            err = Interop.NotificationEventListener.GetList(NotificationType.None, -1, out notificationList);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                throw NotificationEventListenerErrorFactory.GetException(err, "unable to get notification list");
            }

            if (notificationList != IntPtr.Zero)
            {
                currentList = notificationList;
                while (currentList != IntPtr.Zero)
                {
                    IntPtr notification;
                    NotificationEventArgs eventargs = new NotificationEventArgs();

                    notification = Interop.NotificationEventListener.GetData(currentList);

                    eventargs = NotificationEventArgsBinder.BindObject(notification, false);

                    list.Add(eventargs);

                    currentList = Interop.NotificationEventListener.GetNext(currentList);
                }

                Interop.NotificationEventListener.NotificationListFree(notificationList);
            }

            return(list);
        }
コード例 #2
0
        public static NotificationEventArgs GetNotificationEventArgs(int uniqueNumber)
        {
            if (uniqueNumber <= 0)
            {
                throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "Invalid parameter");
            }

            IntPtr notificationPtr = Interop.NotificationEventListener.LoadNotification(null, uniqueNumber);

            if (notificationPtr == IntPtr.Zero)
            {
                int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
                if (err.Equals((int)Interop.NotificationEventListener.ErrorCode.DbError))
                {
                    throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "Not exist");
                }
                else
                {
                    throw NotificationEventListenerErrorFactory.GetException((Interop.NotificationEventListener.ErrorCode)err, "failed to get NotificationEventArgs");
                }
            }

            NotificationEventArgs eventArgs = new NotificationEventArgs();

            eventArgs = NotificationEventArgsBinder.BindObject(notificationPtr, false);

            return(eventArgs);
        }
コード例 #3
0
        private static void ChangedEvent(IntPtr userData, NotificationType type, IntPtr operationList, int num)
        {
            IntPtr operationType;
            IntPtr uniqueNumber;
            IntPtr notification;

            NotificationEventArgs       eventargs;
            NotificationDeleteEventArgs deleteargs;

            for (int i = 0; i < num; i++)
            {
                uniqueNumber  = IntPtr.Zero;
                operationType = IntPtr.Zero;
                notification  = IntPtr.Zero;

                Interop.NotificationEventListener.GetOperationData(operationList + (i * Marshal.SizeOf <NotificationOperation>()), NotificationOperationDataType.Type, out operationType);
                Interop.NotificationEventListener.GetOperationData(operationList + (i * Marshal.SizeOf <NotificationOperation>()), NotificationOperationDataType.UniqueNumber, out uniqueNumber);
                Interop.NotificationEventListener.GetOperationData(operationList + (i * Marshal.SizeOf <NotificationOperation>()), NotificationOperationDataType.Notification, out notification);

                if (operationType == IntPtr.Zero)
                {
                    Log.Error(LogTag, "unable to get operationType");
                    continue;
                }

                Log.Info(LogTag, "type : " + ((int)operationType).ToString());
                Log.Info(LogTag, "Add : " + (AddEventHandler == null ? "0" : AddEventHandler.GetInvocationList().Length.ToString()));
                Log.Info(LogTag, "update: " + (UpdateEventHandler == null ? "0" : UpdateEventHandler.GetInvocationList().Length.ToString()));
                Log.Info(LogTag, "delete : " + (DeleteEventHandler == null ? "0" : DeleteEventHandler.GetInvocationList().Length.ToString()));

                switch ((int)operationType)
                {
                case (int)NotificationOperationType.Insert:
                    if (notification != IntPtr.Zero)
                    {
                        try
                        {
                            eventargs = NotificationEventArgsBinder.BindObject(notification, false);
                            AddEventHandler?.Invoke(null, eventargs);
                        }
                        catch (Exception e)
                        {
                            Log.Error(LogTag, e.Message);
                        }
                    }

                    break;

                case (int)NotificationOperationType.Update:
                    if (notification != IntPtr.Zero)
                    {
                        try
                        {
                            eventargs = NotificationEventArgsBinder.BindObject(notification, false);
                            UpdateEventHandler?.Invoke(null, eventargs);
                        }
                        catch (Exception e)
                        {
                            Log.Error(LogTag, e.Message);
                        }
                    }

                    break;

                case (int)NotificationOperationType.Delete:
                    if (uniqueNumber != IntPtr.Zero)
                    {
                        try
                        {
                            deleteargs = NotificationDeleteEventArgsBinder.BindObject((int)uniqueNumber);
                            DeleteEventHandler?.Invoke(null, deleteargs);
                        }
                        catch (Exception e)
                        {
                            Log.Error(LogTag, e.Message);
                        }
                    }

                    break;

                default:
                    Log.Info(LogTag, "Event : " + (int)operationType);
                    break;
                }
            }
        }