Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the Button_LoadScenario control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void Button_LoadScenario_Click(object sender, RoutedEventArgs e)
        {
            //var dlg = new Windows.MainWindow.MainWindow();

            //dlg.LoadFile(@"C:\Lanser\Entwicklung\GitRepositories\SIGENCE-Scenario-Tool\Examples\TestScenario.stf");
            //dlg.ShowDialog();
            MB.NotYetImplemented();
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------


        /// <summary>
        /// Messages the mocker.
        /// </summary>
        /// <param name="strFilename">The string filename.</param>
        private void MessageMocker(string strFilename)
        {
            const int MARGIN_LEFT_RIGHT = 10;
            const int MARGIN_TOP_BOTTOM = 5;

            try
            {
                XDocument xdoc = XDocument.Load(strFilename);

                Window w = new Window
                {
                    Title                 = "SIGENCE XML MQTT Message Mocker",
                    Width                 = 600,
                    Height                = 600,
                    ResizeMode            = ResizeMode.NoResize,
                    WindowStartupLocation = WindowStartupLocation.CenterScreen
                };

                Grid grid = new Grid();

                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Auto)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });

                int iCurrentRow = 0;

                Action <UIElement, UIElement> AddRow = (e1, e2) =>
                {
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    });

                    grid.Children.Add(e1);
                    grid.Children.Add(e2);

                    Grid.SetColumn(e1, 0);
                    Grid.SetRow(e1, iCurrentRow);

                    Grid.SetColumn(e2, 1);
                    Grid.SetRow(e2, iCurrentRow);

                    iCurrentRow++;
                };

                //-----------------------------------------------------------------------------------------------------

                AddRow(
                    new Label
                {
                    Content    = "MQTT Topic",
                    Margin     = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    FontWeight = FontWeights.Bold
                },
                    new TextBox
                {
                    Text   = "",
                    Margin = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    VerticalContentAlignment = VerticalAlignment.Center
                }
                    );

                //-----------------------------------------------------------------------------------------------------

                XElement root = xdoc.Root;

                AddRow(
                    new Label
                {
                    Content    = "Name",
                    Margin     = new Thickness(MARGIN_LEFT_RIGHT),
                    FontWeight = FontWeights.Bold
                },
                    new Label
                {
                    Content         = root.Element("name").Value,
                    Margin          = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    BorderBrush     = Brushes.Black,
                    BorderThickness = new Thickness(1)
                }
                    );

                AddRow(
                    new Label
                {
                    Content    = "Id",
                    Margin     = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    FontWeight = FontWeights.Bold
                },
                    new Label
                {
                    Content         = root.Element("id").Value,
                    Margin          = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    BorderBrush     = Brushes.Black,
                    BorderThickness = new Thickness(1)
                }
                    );

                AddRow(
                    new Label
                {
                    Content    = "Version",
                    Margin     = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    FontWeight = FontWeights.Bold
                },
                    new Label
                {
                    Content         = root.Element("version").Value,
                    Margin          = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                    BorderBrush     = Brushes.Black,
                    BorderThickness = new Thickness(1)
                }
                    );

                foreach (XElement eField in root.Elements("key"))
                {
                    string strFieldName = eField.Element("name").Value;

                    AddRow(
                        new Label
                    {
                        Content    = strFieldName,
                        Margin     = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                        FontWeight = FontWeights.Bold
                    },
                        new TextBox
                    {
                        Text   = "",
                        Margin = new Thickness(MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM, MARGIN_LEFT_RIGHT, MARGIN_TOP_BOTTOM),
                        VerticalContentAlignment = VerticalAlignment.Center,
                        Tag = eField.Element("name").Value
                    }
                        );
                }

                //-----------------------------------------------------------------------------------------------------

                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                Button btnSend = new Button {
                    Content = "Send", Width = 100, Height = 40, Margin = new Thickness(20)
                };
                btnSend.Click += (s, a) => MB.NotYetImplemented();

                Button btnCancel = new Button {
                    Content = "Cancel", Width = 100, Height = 40, Margin = new Thickness(20)
                };
                btnCancel.Click += (s, a) => w.Close();

                StackPanel sp = new StackPanel {
                    Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center
                };
                sp.Children.Add(btnSend);
                sp.Children.Add(btnCancel);

                grid.Children.Add(sp);

                Grid.SetColumn(sp, 0);
                Grid.SetRow(sp, iCurrentRow);
                Grid.SetColumnSpan(sp, 2);

                //-----------------------------------------------------------------------------------------------------

                w.Content = new ScrollViewer {
                    Content = grid, VerticalScrollBarVisibility = ScrollBarVisibility.Auto
                };

                w.ShowDialog();
            }
            catch (Exception ex)
            {
                MB.Error(ex);
            }
        }