Пример #1
0
 //-----------------------------------------------------------------
 // If the user tries to close the form while a test is in progress, ask if they are sure
 private async void TestPointManager_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (runTestPoint.Text.Contains("Cancel"))
     {
         DialogResult dr = MessageBox.Show("Test in progress!\nAre you sure?", "Test In Progress", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
         if (dr == DialogResult.Yes)
         {
             if (requestTestCancel != null)
             {
                 requestTestCancel.Cancel();
             }
             // Close the previous ports if there were any
             if (previousTp != null)
             {
                 IHoldResources prevTask = previousTp as IHoldResources;
                 if (prevTask != null)
                 {
                     await Task.Run(() =>
                     {
                         prevTask.UnSelect();
                     });
                 }
                 IHazAPort prevPort = previousTp as IHazAPort;
                 if (prevPort != null)
                 {
                     int i = tabControl1.TabPages.Count - 1;
                     foreach (var port in prevPort.Ports)
                     {
                         port.Cancel();
                     }
                 }
             }
         }
         else
         {
             e.Cancel = true;
             return;
         }
     }
 }
Пример #2
0
        //-----------------------------------------------------------------
        // Set menu and controls when the testpoint is changed
        private async void testPointSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            AllowFormControls(false);
            ITestPoint selectedTp = testPointSelect.SelectedValue as ITestPoint;

            testPointInfo.ForeColor = default(Color);

            try
            {
                if (previousTp != selectedTp || errorSelectingIndex)
                {
                    testProgressBar.Value   = 10;
                    testProgressBar.BarText = "Clearing Previous Testpoint";

                    // Close the previous ports if there were any
                    if (previousTp != null)
                    {
                        IHoldResources prevTask = previousTp as IHoldResources;
                        if (prevTask != null)
                        {
                            await prevTask.UnSelect();
                        }
                        IHazAPort prevPort = previousTp as IHazAPort;
                        if (prevPort != null)
                        {
                            int i = tabControl1.TabPages.Count - 1;
                            foreach (var port in prevPort.Ports)
                            {
                                //port.Cancel();

                                if (portTabsActive)
                                {
                                    TabPage tp = tabControl1.TabPages[i];
                                    tp.Controls.Clear();
                                    tabControl1.TabPages.RemoveAt(i);
                                    tp.Dispose();
                                    i--;
                                }
                            }
                        }
                        portTabsActive = false;
                    }
                    previousTp = selectedTp;

                    // Set the status interface
                    selectedTp.StatusHandle = progressHandler;
                    var flags = GetFlags();
                    selectedTp.Flags = flags;

                    testProgressBar.Value   = 80;
                    testProgressBar.BarText = "Creating Controls";

                    // Update the window to pick which tasks to run
                    if (selectedTp.Tasks != null)
                    {
                        testPicker.TaskList = selectedTp.Tasks.Select(s => s.DisplayName).ToList();
                    }
                    else
                    {
                        testPicker.TaskList = null;
                    }

                    // Update the testpoint control (or hide the tab if the TP doesn't have one
                    // Size to grow the GUI by is there is a large test point control
                    int addX = 0;
                    int addY = 0;

                    // Clear any existing test point control
                    testPointControls.Controls.Clear();

                    UserControl testControl = selectedTp.TestControl;
                    // If the testpoint doesn't have a control, hide the control tab
                    if (testControl == null)
                    {
                        if (!controlsHidden)
                        {
                            testPointControls.SetInvisible();
                            controlsHidden = true;
                        }
                        this.Size = this.MinimumSize;
                    }

                    // Otherwise configure to show the test point control
                    else
                    {
                        // Show the tab if it isn't already
                        if (controlsHidden)
                        {
                            testPointControls.SetVisible(tabControl1);
                            controlsHidden = false;
                        }
                        // Add the control
                        testPointControls.Controls.Add(testControl);
                        testControl.Location    = new Point(0, 0);
                        tabControl1.SelectedTab = testPointControls;
                        Size controlSize = testControl.Size;
                        // Calculate form size adjustment
                        addX = Math.Max(0, controlSize.Width - 700);
                        addY = Math.Max(0, controlSize.Height - 380);
                        // clear anchor styles first to avoid problems
                        testControl.Anchor = AnchorStyles.Top | AnchorStyles.Left;
                    }

                    // Set the form size
                    this.Size = new Size(this.MinimumSize.Width + addX, this.MinimumSize.Height + addY);
                    // Set the anchor after resize so it looks right
                    if (testControl != null)
                    {
                        testControl.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
                    }

                    // Get the version information
                    string tpDllName = Assembly.GetAssembly(selectedTp.GetType()).GetName().Name;
                    string tpVersion = Assembly.GetAssembly(selectedTp.GetType()).GetName().Version.ToString();
                    this.Text = titleText + " : " + tpDllName + " " + tpVersion;

                    IHoldResources thisTask = selectedTp as IHoldResources;
                    if (thisTask != null)
                    {
                        await thisTask.Select();
                    }
                    // Open the new ports if there are any
                    IHazAPort portObject = selectedTp as IHazAPort;
                    if (portObject != null)
                    {
                        int i = 0;
                        foreach (var port in portObject.Ports)
                        {
                            port.Start();

                            if (engineeringMode.Checked)
                            {
                                TabPage tp = new TabPage();
                                //tp.Name = "Port " + i.ToString();
                                tp.Text = "Port " + i.ToString();
                                UutCompact ctrl = null;
                                if (portControls.ContainsKey(selectedTp.TestPointName + i.ToString()))
                                {
                                    ctrl = portControls[selectedTp.TestPointName + i.ToString()];
                                }
                                else
                                {
                                    ctrl      = new UutCompact();
                                    ctrl.Port = port;
                                    portControls.Add(selectedTp.TestPointName + i.ToString(), ctrl);
                                }
                                tp.Controls.Add(ctrl);
                                ctrl.Location = new Point(0, 0);
                                ctrl.Size     = new Size(tabControl1.Size.Width - 10, tabControl1.Size.Height - 30);
                                tabControl1.TabPages.Add(tp);
                                i++;

                                portTabsActive = true;
                            }
                        }
                    }
                }
                testProgressBar.Value   = 0;
                testProgressBar.BarText = "Ready";
                errorSelectingIndex     = false;
                runTestPoint.Enabled    = true;
                runTestPoint.BackColor  = Color.Yellow;
            }
            catch (Exception ex)
            {
                errorSelectingIndex  = true;
                runTestPoint.Enabled = false;

                if (selectedTp.StatusHandle != null)
                {
                    StatusInfo.ReportException(selectedTp.StatusHandle, "SelectedIndexChanged", ex);
                }
                // Clear any existing test point control
                testPointControls.Controls.Clear();

                MessageBox.Show(ex.ToString(), "Error Selecting Testpoint", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            AllowFormControls(true);
        }