public static void AskRenameDevice(ParticleDevice particleDevice, Page page, FrameworkElement placementTarget)
        {
            var flyout            = (Flyout)page.Resources["RenameDeviceFlyout"];
            var newDeviceNameGrid = FindNameInContainer <Grid>(flyout.Content, "NewDeviceNameGrid");
            var textbox           = FindNameInContainer <TextBox>(flyout.Content, "NewDeviceName");
            var refreshButton     = FindNameInContainer <Button>(flyout.Content, "RefreshButton");
            var actionButton      = FindNameInContainer <Button>(flyout.Content, "RenameDeviceButton");
            var cancelButton      = FindNameInContainer <Button>(flyout.Content, "RenameCancelButton");

            textbox.Text = DeviceNameGenerator.GenerateUniqueName(TinkerData.GetDeviceNames());
            textbox.SelectAll();

            actionButton.DataContext = particleDevice;

            RoutedEventHandler refreshButtonDelegate = null;
            RoutedEventHandler actionClickDelegate   = null;
            RoutedEventHandler cancelClickDelegate   = null;

            refreshButtonDelegate = new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                textbox.Text = DeviceNameGenerator.GenerateUniqueName(TinkerData.GetDeviceNames());
                textbox.SelectAll();
            });

            actionClickDelegate = new RoutedEventHandler(async delegate(object sender, RoutedEventArgs e)
            {
                var newName = textbox.Text;

                flyout.Hide();
                refreshButton.Click -= refreshButtonDelegate;
                actionButton.Click  -= actionClickDelegate;
                cancelButton.Click  -= cancelClickDelegate;

                await particleDevice.RenameAsync(newName);
            });

            cancelClickDelegate = new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                flyout.Hide();
                refreshButton.Click -= refreshButtonDelegate;
                actionButton.Click  -= actionClickDelegate;
                cancelButton.Click  -= cancelClickDelegate;
            });

            refreshButton.Click += refreshButtonDelegate;
            actionButton.Click  += actionClickDelegate;
            cancelButton.Click  += cancelClickDelegate;

            flyout.ShowAt(placementTarget);
        }
Beispiel #2
0
        private void ShowResult()
        {
            ResultImage.Source = null;
            ResultHeader.Text  = "";
            ResultText.Text    = "";

            ResourceLoader resourceLoader    = new ResourceLoader();
            string         imageSource       = null;
            string         headerText        = null;
            string         textText          = null;
            bool           showNameNewDevice = false;

            switch (SoftAP.SoftAPResult.Result)
            {
            case SoftAPSetupResult.NotStarted:
            case SoftAPSetupResult.Started:
                break;

            case SoftAPSetupResult.Success:
                imageSource       = "Success";
                headerText        = SetupResources.SoftAPCompletedHeaderSuccess;
                textText          = SetupResources.SoftAPCompletedTextSuccess;
                showNameNewDevice = true;
                break;

            case SoftAPSetupResult.SuccessUnknown:
                imageSource = "Success";
                headerText  = SetupResources.SoftAPCompletedHeaderSuccessUnknown;
                textText    = SetupResources.SoftAPCompletedTextSuccessUnknown;
                break;

            case SoftAPSetupResult.SuccessDeviceOffline:
                imageSource = "Warning";
                headerText  = SetupResources.SoftAPCompletedHeaderSuccessDeviceOffline;
                textText    = SetupResources.SoftAPCompletedTextSuccessDeviceOffline;
                break;

            case SoftAPSetupResult.FailureClaiming:
                break;

            case SoftAPSetupResult.FailureConfigure:
                imageSource = "Failure";
                headerText  = SetupResources.SoftAPCompletedHeaderFailureConfigure;
                textText    = SetupResources.SoftAPCompletedTextFailureConfigure;
                break;

            case SoftAPSetupResult.FailureCannotDisconnectFromDevice:
            case SoftAPSetupResult.FailureLostConnectionToDevice:
                break;
            }

            if (imageSource != null)
            {
                ResultImage.Source = new BitmapImage(new Uri($"ms-appx:///Particle.Setup/Assets/SoftAP/StatusIcons/StatusIcon{imageSource}.png"));
            }
            if (headerText != null)
            {
                ResultHeader.Text = headerText;
            }
            if (textText != null)
            {
                ResultText.Text = textText.Replace("{device}", "Photon");
            }

            if (showNameNewDevice)
            {
                if (string.IsNullOrWhiteSpace(SoftAP.SoftAPResult.ParticleDevice.Name))
                {
                    NewDeviceNameTextBox.Text = DeviceNameGenerator.GenerateUniqueName(SoftAP.CurrentSoftAPSettings.CurrentDeviceNames);
                }
                else
                {
                    NewDeviceNameTextBox.Text = SoftAP.SoftAPResult.ParticleDevice.Name;
                }

                NameNewDevicePanel.Visibility = Visibility.Visible;
            }
        }
Beispiel #3
0
 private void RefreshButton_Click(object sender, RoutedEventArgs e)
 {
     NewDeviceNameTextBox.Text = DeviceNameGenerator.GenerateUniqueName(SoftAP.CurrentSoftAPSettings.CurrentDeviceNames);
 }