Ejemplo n.º 1
0
        private async void rebootButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"Sure you want to reboot device '{ipAddressTextBox.Text}'?",
                                "Reboot?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                var sonosDeviceService = new SonosDeviceService();

                PrintOutput($"Rebooting {ipAddressTextBox.Text}...");
                await sonosDeviceService.RebootAsync(ipAddressTextBox.Text);
            }
        }
Ejemplo n.º 2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            shutUpButton.Enabled = true;
            stopButton.Enabled   = false;

            toolStripStatusLabel.Text = string.Empty;

            _discoveryService = new SonosDiscoveryService();
            _discoveryService.PlayersChanged += PlayersChanged;

            _deviceService = new SonosDeviceService();

            _sonosControllerFactory = new SonosControllerFactory();
        }
Ejemplo n.º 3
0
        private void EventLoop(CancellationToken token, string ipAddress)
        {
            var counter = 0;
            var seconds = int.Parse(intervalTextBox.Text);

            while (!token.IsCancellationRequested)
            {
                if (statusStrip.InvokeRequired)
                {
                    PrintStatusDelegate d = PrintStatus;
                    Invoke(d, string.Format("Rebooting {0}...", ipAddress));
                }

                var result = new SonosDeviceService().RebootAsync(ipAddress).Result;        // TODO: change to await
                counter++;

                if (statusStrip.InvokeRequired)
                {
                    PrintStatusDelegate d = PrintStatus;
                    Invoke(d, string.Format("Rebooted {0} {1}x. Pausing {2} seconds.", ipAddress, counter, intervalTextBox.Text));
                }

                for (var i = 0; i < seconds; i++)
                {
                    Thread.Sleep(1000);
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }

            if (shutUpButton.InvokeRequired)
            {
                EnableShutUpButtonDelegate d = EnableShutUpButton;
                Invoke(d);
            }

            if (statusStrip.InvokeRequired)
            {
                PrintStatusDelegate d = PrintStatus;
                Invoke(d, "Done.");
            }

            token.ThrowIfCancellationRequested();
        }
 public void SetUp()
 {
     _sut = new SonosDeviceService();
 }