コード例 #1
0
        private void SendCommand_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Flyout flyOut = new Flyout();

            flyOut.Width           = 300;
            flyOut.PlacementTarget = sender as UIElement;
            flyOut.Placement       = PlacementMode.Top;
            flyOut.Background      = new SolidColorBrush(Colors.Black);

            StackPanel panel = new StackPanel();

            panel.Margin      = new Thickness(10);
            panel.Orientation = Orientation.Vertical;
            panel.Children.Add(new TextBlock()
            {
                Text = "Command name", FontSize = 14.8
            });
            TextBox commandName = new TextBox();

            panel.Children.Add(commandName);
            panel.Children.Add(new TextBlock()
            {
                Text = "Params", FontSize = 14.8, Margin = new Thickness(0, 10, 0, 0)
            });
            TextBox commandParams = new TextBox();

            panel.Children.Add(commandParams);
            panel.Children.Add(new TextBlock()
            {
                Text = "JSON or empty string"
            });
            Button sendButton = new Button()
            {
                Content = "Send", Margin = new Thickness(0, 10, 0, 0)
            };

            panel.Children.Add(sendButton);

            if (CommandSelected != null)
            {
                commandName.Text   = CommandSelected.Name;
                commandParams.Text = (string)new ObjectToJsonStringConverter().Convert(CommandSelected.Parameters, null, null, null);
            }

            sendButton.Command = new DelegateCommand(async() =>
            {
                if (commandName.Text.Trim() == "")
                {
                    new MessageDialog("Empty command name", "Send command").ShowAsync();
                    return;
                }
                panel.ControlsEnable(false);
                LoadingItems++;
                try
                {
                    var command = new Command(commandName.Text, JObject.Parse(commandParams.Text));
                    StopPollCommandResult();
                    Debug.WriteLine("CMD SEND START");
                    var commandSent = await ClientService.Current.SendCommandAsync(deviceId, command);
                    Debug.WriteLine("CMD SEND END");
                    StartPollCommandResult((int)commandSent.Id);
                    flyOut.IsOpen = false;
                }
                catch (Exception ex)
                {
                    new MessageDialog(ex.Message, "Send command").ShowAsync();
                }
                panel.ControlsEnable(true);
                LoadingItems--;
            });

            flyOut.Content = panel;
            flyOut.IsOpen  = true;
        }
コード例 #2
0
        private void SendCommand_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Flyout flyOut = new Flyout();

            flyOut.Placement = FlyoutPlacementMode.Top;

            flyOut.FlyoutPresenterStyle = new Style(typeof(FlyoutPresenter));
            flyOut.FlyoutPresenterStyle.Setters.Add(new Setter(FlyoutPresenter.RequestedThemeProperty, ElementTheme.Dark));
            flyOut.FlyoutPresenterStyle.Setters.Add(new Setter(FlyoutPresenter.PaddingProperty, 10));

            StackPanel panel = new StackPanel();

            panel.Width       = 300;
            panel.Margin      = new Thickness(10);
            panel.Orientation = Orientation.Vertical;
            panel.Children.Add(new TextBlock()
            {
                Text = "Command name", FontSize = 14.8
            });
            TextBox commandName = new TextBox();

            panel.Children.Add(commandName);
            panel.Children.Add(new TextBlock()
            {
                Text = "Params", FontSize = 14.8, Margin = new Thickness(0, 10, 0, 0)
            });
            TextBox commandParams = new TextBox();

            panel.Children.Add(commandParams);
            panel.Children.Add(new TextBlock()
            {
                Text = "JSON or empty string"
            });
            Button sendButton = new Button()
            {
                Content = "Send", Margin = new Thickness(0, 10, 0, 0)
            };

            panel.Children.Add(sendButton);

            if (CommandSelected != null)
            {
                commandName.Text   = CommandSelected.Name;
                commandParams.Text = (string)new ObjectToJsonStringConverter().Convert(CommandSelected.Parameters, null, null, null);
            }

            sendButton.Command = new DelegateCommand(async() =>
            {
                if (commandName.Text.Trim() == "")
                {
                    new MessageDialog("Empty command name", "Send command").ShowAsync();
                    return;
                }
                panel.ControlsEnable(false);
                LoadingItems++;
                try
                {
                    var command = new Command(commandName.Text, commandParams.Text != "" ? JObject.Parse(commandParams.Text) : null);
                    Debug.WriteLine("CMD SEND START");
                    await ClientService.Current.SendCommandAsync(deviceId, command, CommandResultCallback);
                    Debug.WriteLine("CMD SEND END");
                    flyOut.Hide();
                }
                catch (Exception ex)
                {
                    new MessageDialog(ex.Message, "Send command").ShowAsync();
                }
                panel.ControlsEnable(true);
                LoadingItems--;
            });

            flyOut.Content = panel;
            flyOut.ShowAt((FrameworkElement)sender);
        }