Example #1
0
 private void NotificationConsumer_NotificationRemoved(NotificationConsumer sender, NotificationSourceData args)
 {
     try
     {
         ToastNotificationManager.History.Remove(args.NotificationUID.ToString(), args.CategoryId.ToString(), "Apple Notification Center");
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #2
0
        public MainPage()
        {
            this.InitializeComponent();

            // This is a static public property that allows downstream pages to get a handle to the MainPage instance
            // in order to call methods that are in this class.
            Current = this;

            ANCS = new NotificationConsumer();
            ANCS.NotificationAdded   += ANCS_NotificationAdded;
            ANCS.NotificationRemoved += ANCS_NotificationRemoved;
        }
Example #3
0
        private void ANCS_NotificationRemoved(NotificationConsumer sender, NotificationSourceData args)
        {
            var toastHistory = ToastNotificationManager.History;

            try
            {
                toastHistory.Remove(args.NotificationUID.ToString());
            }
            catch (Exception)
            {
                // Just be silent
            }
        }
Example #4
0
        public void Run()
        {
            cancellationTokenSource = new CancellationTokenSource();
            List <string> lstQueue = new List <string>();

            lstQueue.Add("DataQueue.AllEmployee");
            var _rabbitMQServer = RabbitMQManager.GetRabbitMQServer("rabbitMQ_Notification");

            for (int i = 0; i < lstQueue.Count; i++)
            {
                string queueName = lstQueue[i];
                Task.Factory.StartNew(() =>
                {
                    string queueNameData = queueName;
                    QT.Moduls.Notifycation.NotifycationAdapter adapter = new QT.Moduls.Notifycation.NotifycationAdapter();
                    log.Info("Start a consumer");
                    Websosanh.NotificationSystem.Common.NotificationConsumer basicConsumer = new NotificationConsumer(_rabbitMQServer, queueName, true, "123456");
                    while (true)
                    {
                        try
                        {
                            BasicGetResult result = basicConsumer.GetMessage();
                            if (result != null && result.Body != null)
                            {
                                string strMessage = System.Text.Encoding.UTF8.GetString(result.Body, 0, result.Body.Length);
                                adapter.InsertMessage(queueNameData, strMessage, 0);
                                log.Info(string.Format("MSS:{0}. Queue:{1}", strMessage, queueNameData));
                            }
                            else
                            {
                                log.Info("Not item");
                            }
                            Thread.Sleep(1000);
                        }
                        catch (OperationCanceledException operationCanceled)
                        {
                            return;
                        }
                        catch (Exception ex01)
                        {
                            log.Error(ex01);
                            Thread.Sleep(10000);
                        }
                    }
                });
            }
        }
Example #5
0
        private void SetNotificationConsumer(NotificationConsumer notificationConsumer)
        {
            this.NotificationConsumer = notificationConsumer;

            // Register event handlers
            this.NotificationConsumer.NotificationAdded   += NotificationConsumer_NotificationAdded;
            this.NotificationConsumer.NotificationRemoved += NotificationConsumer_NotificationRemoved;

            if (this.NotificationConsumer.DeviceService.Device.ConnectionStatus == Windows.Devices.Bluetooth.BluetoothConnectionStatus.Connected)
            {
                this.ConnectMenuItem.Visible    = false;
                this.DisconnectMenuItem.Visible = true;
            }
            else
            {
                this.ConnectMenuItem.Visible    = true;
                this.DisconnectMenuItem.Visible = false;
            }
        }
Example #6
0
        private void NotificationConsumer_NotificationAdded(NotificationConsumer sender, NotificationEventArgs args)
        {
            XmlDocument            toastXml;
            AppleToastNotification toastBuilder = new AppleToastNotification(args.NotificationSource, args.NotificationAttributes);

            toastXml = toastBuilder.GetXml();

            ToastNotification toastNotification = new ToastNotification(toastXml);

            // Data used to remove the notification if requested
            toastNotification.Tag            = args.NotificationSource.NotificationUID.ToString();
            toastNotification.Group          = args.NotificationSource.CategoryId.ToString();
            toastNotification.ExpirationTime = DateTime.Now.AddMinutes(30);

            toastNotification.Activated += Toast_Activated;
            toastNotification.Dismissed += Toast_Dismissed;
            toastNotification.Failed    += Toast_Failed;

            ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toastNotification);
        }
Example #7
0
        private void ANCS_NotificationAdded(NotificationConsumer sender, AppleNotificationEventArgs args)
        {
            XmlDocument toastXml = null;

            ToastVisual toastVisual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = args.NotificationAttributes[NotificationAttributeID.Title]
                        },
                        new AdaptiveText
                        {
                            Text = args.NotificationAttributes[NotificationAttributeID.Message]
                        }
                    },
                },
            };

            // toast actions
            ToastActionsCustom toastActions = new ToastActionsCustom();

            if (args.NotificationSource.EventFlags.HasFlag(EventFlags.EventFlagPositiveAction))
            {
                string positiveActionLabel = "Positive";
                if (args.NotificationAttributes.ContainsKey(NotificationAttributeID.PositiveActionLabel))
                {
                    positiveActionLabel = args.NotificationAttributes[NotificationAttributeID.PositiveActionLabel];
                }

                toastActions.Buttons.Add(new ToastButton(positiveActionLabel, new QueryString()
                {
                    { "action", "positive" },
                    { "uid", args.NotificationAttributes.NotificationUID.ToString() }
                }.ToString())
                {
                    ActivationType = ToastActivationType.Foreground
                });
            }

            if (args.NotificationSource.EventFlags.HasFlag(EventFlags.EventFlagNegativeAction))
            {
                string negativeActionLabel = "Negative";
                if (args.NotificationAttributes.ContainsKey(NotificationAttributeID.NegativeActionLabel))
                {
                    negativeActionLabel = args.NotificationAttributes[NotificationAttributeID.NegativeActionLabel];
                }

                toastActions.Buttons.Add(new ToastButton(negativeActionLabel, new QueryString()
                {
                    { "action", "negative" },
                    { "uid", args.NotificationAttributes.NotificationUID.ToString() }
                }.ToString())
                {
                    ActivationType = ToastActivationType.Foreground
                });
            }

            ToastContent toastContent = new ToastContent()
            {
                Visual   = toastVisual,
                Scenario = ToastScenario.Default,
                Actions  = toastActions,
            };

            toastXml = toastContent.GetXml();

            ToastNotification toastNotification = new ToastNotification(toastXml)
            {
                ExpirationTime = DateTime.Now.AddMinutes(5),
                Tag            = args.NotificationSource.NotificationUID.ToString()
            };

            ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
        }
Example #8
0
        private async void Connect()
        {
            if (this.DevicesListView.SelectedItems.Count == 1)
            {
                NotificationConsumer nc   = null;
                ListViewItem         item = this.DevicesListView.SelectedItems[0];
                this.StopDeviceWatcher();
                this.DevicesListView.Enabled = false;
                this.RefreshButton.Enabled   = false;
                this.ButtonConnect.Enabled   = false;

                string deviceId = (string)item.Tag;

                try
                {
                    BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceId);

                    nc = new AppleNotificationCenterService.NotificationConsumer(device);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DevicesListView.Enabled = true;
                    this.RefreshButton.Enabled   = true;
                    this.ButtonConnect.Enabled   = true;
                    return;
                }

                if (nc == null)
                {
                    MessageBox.Show("Unable to connect to " + item.Text, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.DevicesListView.Enabled = true;
                    this.RefreshButton.Enabled   = true;
                    this.ButtonConnect.Enabled   = true;
                    return;
                }

                GattCommunicationStatus communicationStatus = GattCommunicationStatus.Unreachable;

                // Try to establlish the connection by subscribing
                try
                {
                    communicationStatus = await nc.SubscribeAsync();
                }
                catch (Exception ex)
                {
                    // TODO: dispose NC
                    MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.DevicesListView.Enabled = true;
                    this.RefreshButton.Enabled   = true;
                    this.ButtonConnect.Enabled   = true;
                    return;
                }

                if (communicationStatus != GattCommunicationStatus.Success)
                {
                    MessageBox.Show("Apple notification center service is unreachable.\n\nHave you opened the application on your iOS device?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.DevicesListView.Enabled = true;
                    this.RefreshButton.Enabled   = true;
                    this.ButtonConnect.Enabled   = true;
                    return;
                }

                this.NotificationConsumer = nc;
                this.DialogResult         = DialogResult.OK;
            }
        }