예제 #1
0
        private static void BindLedToHandle(Notification notification)
        {
            NotificationError ret = NotificationError.None;

            Notification.AccessorySet accessory = notification.Accessory;

            ret = Interop.Notification.SetLed(notification.Handle, accessory.LedOption, 0);
            if (ret != NotificationError.None)
            {
                throw NotificationErrorFactory.GetException(ret, "unable to set led");
            }

            ret = Interop.Notification.SetLedTimePeriod(notification.Handle, accessory.LedOnMillisecond, accessory.LedOffMillisecond);
            if (ret != NotificationError.None)
            {
                throw NotificationErrorFactory.GetException(ret, "unable to set led period");
            }

            if (notification.Accessory.LedOption == AccessoryOption.Custom)
            {
                Color color = accessory.LedColor;
                ret = Interop.Notification.SetLed(notification.Handle, AccessoryOption.Custom, color.GetArgb());
                if (ret != NotificationError.None)
                {
                    throw NotificationErrorFactory.GetException(ret, "unable to set led color");
                }
            }
        }
예제 #2
0
 internal static void BindSafeHandle(Notification notification)
 {
     Notification.AccessorySet accessory = new Notification.AccessorySet();
     BindHandleToLed(notification, accessory);
     BindHandleToSound(notification, accessory);
     BindHandleToVibration(notification, accessory);
     notification.Accessory = accessory;
 }
예제 #3
0
 private static void BindVibrationToHandle(Notification notification)
 {
     Notification.AccessorySet accessory = notification.Accessory;
     if (accessory.CanVibrate == false)
     {
         Interop.Notification.SetVibration(notification.Handle, AccessoryOption.Off, null);
     }
     else
     {
         Interop.Notification.SetVibration(notification.Handle, AccessoryOption.On, null);
     }
 }
예제 #4
0
        private static void BindHandleToSound(Notification notification, Notification.AccessorySet accessory)
        {
            AccessoryOption type;
            string          path;

            Interop.Notification.GetSound(notification.Handle, out type, out path);

            accessory.SoundOption = type;
            if (type == AccessoryOption.Custom)
            {
                accessory.SoundPath = path;
            }
        }
예제 #5
0
        private static void BindHandleToVibration(Notification notification, Notification.AccessorySet accessory)
        {
            AccessoryOption type;
            string          path;

            Interop.Notification.GetVibration(notification.Handle, out type, out path);
            if (type == AccessoryOption.Off)
            {
                accessory.CanVibrate = false;
            }
            else
            {
                accessory.CanVibrate = true;
            }
        }
예제 #6
0
        private static void BindSoundToHandle(Notification notification)
        {
            Notification.AccessorySet accessory = notification.Accessory;

            if (accessory.SoundOption == AccessoryOption.Custom && string.IsNullOrEmpty(accessory.SoundPath))
            {
                throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "If the option is set to Custom, the path must also be set.");
            }

            NotificationError ret = Interop.Notification.SetSound(notification.Handle, accessory.SoundOption, accessory.SoundPath);

            if (ret != NotificationError.None)
            {
                throw NotificationErrorFactory.GetException(ret, "unable to set sound");
            }
        }
예제 #7
0
        private static void BindHandleToLed(Notification notification, Notification.AccessorySet accessory)
        {
            AccessoryOption type;
            int             argb;

            Interop.Notification.GetLed(notification.Handle, out type, out argb);

            accessory.LedOption = type;
            if (type == AccessoryOption.Custom)
            {
                accessory.LedColor = new Color(argb >> 16 & 255, argb >> 8 & 255, argb >> 0 & 255, argb >> 24 & 255);
            }

            int onMillisecond, offMillisecond;

            Interop.Notification.GetLedTimePeriod(notification.Handle, out onMillisecond, out offMillisecond);
            accessory.LedOnMillisecond  = onMillisecond;
            accessory.LedOffMillisecond = offMillisecond;
        }