예제 #1
0
        private void _NotificationSource_NotificationRemoved(NotificationSource sender, NotificationSourceData args)
        {
            if (sender == _NotificationSource)
            {
                if (Notifications.ContainsKey(args.NotificationUID))
                {
                    Notifications.Remove(args.NotificationUID);
                }

                this.NotificationRemoved?.Invoke(this, args);
            }
        }
예제 #2
0
        private async void _NotificationSource_NotificationAdded(NotificationSource sender, NotificationSourceData args)
        {
            if (sender == _NotificationSource)
            {
                if (!Notifications.ContainsKey(args.NotificationUID))
                {
                    Notifications.Add(args.NotificationUID, args);
                }
                else
                {
                    Notifications[args.NotificationUID] = args;
                }

                // We don't trigger the notification added event as we need to query for
                // the notification data.

                // Build the attributes list for the GetNotificationAttributtes command.
                List <NotificationAttributeID> attributes = new List <NotificationAttributeID>();
                attributes.Add(NotificationAttributeID.AppIdentifier);
                attributes.Add(NotificationAttributeID.Title);
                attributes.Add(NotificationAttributeID.Message);

                if (args.EventFlags.HasFlag(EventFlags.EventFlagPositiveAction))
                {
                    attributes.Add(NotificationAttributeID.PositiveActionLabel);
                }

                if (args.EventFlags.HasFlag(EventFlags.EventFlagNegativeAction))
                {
                    attributes.Add(NotificationAttributeID.NegativeActionLabel);
                }

                try
                {
                    GattCommunicationStatus communicationStatus = await ControlPoint.GetNotificationAttributesAsync(args.NotificationUID, attributes);
                }
                catch (Exception e)
                {
                    // Simply log the exception to output console
                    //System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }
예제 #3
0
        private void LoadBaseCharacteristics()
        {
            Guid notificationSourceUuid = new Guid("9FBF120D-6301-42D9-8C58-25E699A21DBD");
            Guid controlPointUuid       = new Guid("69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9");
            Guid dataSourceUuid         = new Guid("22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB");

            IReadOnlyList <GattCharacteristic> allCharacteristics = DeviceService.GetAllCharacteristics();

            foreach (GattCharacteristic c in allCharacteristics)
            {
                if (c.Uuid == controlPointUuid)
                {
                    try
                    {
                        _ControlPoint = new ControlPoint(c);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else if (c.Uuid == dataSourceUuid)
                {
                    try
                    {
                        _DataSource = new DataSource(c);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else if (c.Uuid == notificationSourceUuid)
                {
                    try
                    {
                        _NotificationSource = new NotificationSource(c);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }

            if (_NotificationSource == null)
            {
                //    throw new AppleNotificationCenterServiceCharacteristicNotFound("Missing notification source characteristic");
                throw new Exception("Missing notification source characteristic");
            }
            else if (_ControlPoint == null)
            {
                //    throw new AppleNotificationCenterServiceCharacteristicNotFound("Missing control point characteristic");
                throw new Exception("Missing control point characteristic");
            }
            else if (_DataSource == null)
            {
                //    throw new AppleNotificationCenterServiceCharacteristicNotFound("Missing data source characteristic");
                throw new Exception("Missing data source characteristic");
            }

            // Add watcher for connection status changes
            //DeviceService.Device.ConnectionStatusChanged += Device_ConnectionStatusChanged;
        }