Пример #1
0
        private void NotifyIcon_DoubleClick(object sender, EventArgs e)
        {
            if (this.NotificationConsumer == null)
            {
                if (this.BluetoothConnectDialog == null)
                {
                    this.BluetoothConnectDialog = new BluetoothConnectDialog();
                }

                if (this.BluetoothConnectDialog.Visible)
                {
                    this.BluetoothConnectDialog.Activate();
                    this.BluetoothConnectDialog.Focus();
                }
                else
                {
                    this.BluetoothConnectDialog.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("The configuration has not been implemented yet.", "Apple Notification Center", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;

                if (this.ApplicationsForm.Visible)
                {
                    ApplicationsForm.Focus();
                }
                else
                {
                    ApplicationsForm.ShowDialog();
                }
            }
        }
Пример #2
0
        private async void ConnectMenuItem_Click(object sender, EventArgs e)
        {
            if (this.NotificationConsumer == null)
            {
                if (this.BluetoothConnectDialog == null)
                {
                    this.BluetoothConnectDialog = new BluetoothConnectDialog();
                }

                if (this.BluetoothConnectDialog.Visible)
                {
                    this.BluetoothConnectDialog.Activate();
                    this.BluetoothConnectDialog.Focus();
                }
                else
                {
                    this.BluetoothConnectDialog.ShowDialog();
                }
            }
            else
            {
                GattCommunicationStatus communicationStatus = GattCommunicationStatus.Unreachable;

                try
                {
                    communicationStatus = await this.NotificationConsumer.SubscribeAsync();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (communicationStatus == GattCommunicationStatus.Success)
                {
                    this.ConnectMenuItem.Visible    = false;
                    this.DisconnectMenuItem.Visible = true;

                    // Minimal Toast notification telling the user we are connected
                    // Get a toast XML template
                    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

                    // Fill in the text elements
                    XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
                    stringElements[0].AppendChild(toastXml.CreateTextNode("Connected"));
                    stringElements[1].AppendChild(toastXml.CreateTextNode("You are now connected to " + this.NotificationConsumer.DeviceService.Device.DeviceInformation.Name));

                    ToastNotification toastNotification = new ToastNotification(toastXml);
                    toastNotification.ExpirationTime = DateTime.Now.AddSeconds(5);
                    toastNotification.Tag            = "connected";
                    toastNotification.Group          = "-1";

                    ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toastNotification);
                }
                else
                {
                    MessageBox.Show("Failed to connect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #3
0
        public TaskTrayApplicationContext()
        {
            RegisterAppForNotificationSupport();
            NotificationActivator.Initialize();

            // Common menu items
            //MenuItem configMenuItem = new MenuItem("Configuration", new EventHandler(ShowConfig));
            //MenuItem exitMenuItem = new MenuItem("Exit", new EventHandler(Exit));
            MenuItem exitMenuItem = new MenuItem("Exit", new EventHandler(Exit));

            // Dynamic Menu Items
            MenuItem ConnectionSeparatorMenuItem = new MenuItem("-");

            this.ConnectMenuItem            = new MenuItem("Connect", new EventHandler(ConnectMenuItem_Click));
            this.DisconnectMenuItem         = new MenuItem("Disconnect", new EventHandler(Disconnect));
            this.DisconnectMenuItem.Visible = false;

            notifyIcon.Icon = AppleNotificationCenter.Properties.Resources.AppIcon;
            //notifyIcon.DoubleClick += new EventHandler(ShowMessage);
            notifyIcon.ContextMenu  = new ContextMenu(new MenuItem[] { ConnectMenuItem, DisconnectMenuItem, ConnectionSeparatorMenuItem, exitMenuItem });
            notifyIcon.Text         = "Apple Notification Center";
            notifyIcon.DoubleClick += NotifyIcon_DoubleClick;
            notifyIcon.Visible      = true;

            // Display the connection window right away
            this.BluetoothConnectDialog = new BluetoothConnectDialog();
            DialogResult result = this.BluetoothConnectDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.SetNotificationConsumer(this.BluetoothConnectDialog.NotificationConsumer);
                this.BluetoothConnectDialog.Dispose();
                this.BluetoothConnectDialog = null;

                // Minimal Toast notification telling the user we are connected
                // Get a toast XML template
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

                // Fill in the text elements
                XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
                stringElements[0].AppendChild(toastXml.CreateTextNode("Connected"));
                stringElements[1].AppendChild(toastXml.CreateTextNode("You are now connected to " + this.NotificationConsumer.DeviceService.Device.DeviceInformation.Name));

                ToastNotification toastNotification = new ToastNotification(toastXml);
                toastNotification.ExpirationTime = DateTime.Now.AddSeconds(5);
                toastNotification.Tag            = "connected";
                toastNotification.Group          = "-1";

                ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toastNotification);
            }
            //else
            //{
            //    MessageBox.Show("Not yet.");
            //}
        }