Beispiel #1
0
        // In this method the layout of the dockable panel is defined/setup.
        // The ITapDockContext enables you to set the TestPlan, attach ResultListeners,
        // configure Settings and start execution of a TestPlan.
        public FrameworkElement CreateElement(ITapDockContext context)
        {
            var loadPlanBtn = new Button()
            {
                Content = "Load Plan"
            };
            var runPlanBtn = new Button()
            {
                Content = "Run Plan"
            };
            var stopPlanBtn = new Button()
            {
                Content = "Stop Plan"
            };
            var statusTxt = new TextBlock
            {
                FontSize            = 40,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center
            };

            // Setup UI panel and add elements
            var panel = new StackPanel()
            {
                Orientation = System.Windows.Controls.Orientation.Vertical
            };

            panel.Children.Add(loadPlanBtn);
            panel.Children.Add(runPlanBtn);
            panel.Children.Add(stopPlanBtn);
            panel.Children.Add(statusTxt);

            TapThread planThread = null;

            // Register event-handling methods for each of the buttons
            runPlanBtn.Click  += (s, e) => planThread = context.Run();
            stopPlanBtn.Click += (s, e) => planThread?.Abort();
            loadPlanBtn.Click += (s, e) =>
            {
                var fd = new OpenFileDialog();
                fd.CheckFileExists = true;
                var r = fd.ShowDialog();
                try
                {
                    if (r == DialogResult.OK)
                    {
                        context.Plan = TestPlan.Load(fd.FileName);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Log.Warning("{0}", ex.Message);
                }
            };
            // Attach Result listener. runPlanBtn and statusTxt is updated according to status
            context.ResultListeners.Add(listener = new dockResultListener(runPlanBtn, statusTxt));

            return(panel);
        }