/// <summary>
        /// Runs all tests with the specified name and displays the results.
        /// </summary>
        public void ShowDialog(TsCHdaServer server, string fileName, string itemID)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server = server;
            m_itemID = itemID;

            // construct full file path.
            m_filePath = Application.StartupPath + "\\" + fileName;

            // run the test
            try
            {
                Run();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            // display dilaog.
            ShowDialog();

            // dispose of dataset.
            if (m_dataset != null)
            {
                m_dataset.Dispose();
                m_dataset = null;
            }
        }
Exemple #2
0
        public override DataSet Clone()
        {
            _DataSet cln = ((_DataSet)(base.Clone()));

            cln.InitVars();
            return(cln);
        }
        /// <summary>
        /// Loads the dataset containing the test descriptions.
        /// </summary>
        private TestData[] LoadDataSet()
        {
            try
            {
                // create the dataset.
                m_dataset = new _DataSet();

                // load the test case descriptions.
                m_dataset.ReadXml(m_filePath);

                // select only the desired test cases.
                m_dataset.TestCases.DefaultView.Sort = "Name";

                // execute the test cases.
                ArrayList tests = new ArrayList(m_dataset.TestCases.DefaultView.Count);

                foreach (DataRowView row in m_dataset.TestCases.DefaultView)
                {
                    _DataSet.TestCase testcase = (_DataSet.TestCase)row.Row;

                    // create trend.
                    TsCHdaTrend trend = new TsCHdaTrend(m_server);

                    trend.Name             = testcase.Name;
                    trend.Aggregate        = testcase.AggregateID;
                    trend.MaxValues        = testcase.MaxValues;
                    trend.IncludeBounds    = testcase.IncludeBounds;
                    trend.ResampleInterval = testcase.ResampleInterval;

                    if (testcase.StartTime != Decimal.MinValue)
                    {
                        trend.StartTime = new TsCHdaTime(BASETIME.AddSeconds((double)testcase.StartTime));
                    }

                    if (testcase.EndTime != Decimal.MinValue)
                    {
                        trend.EndTime = new TsCHdaTime(BASETIME.AddSeconds((double)testcase.EndTime));
                    }

                    TestData test = new TestData();

                    test.TestCase = testcase;
                    test.Trend    = trend;
                    test.Expected = GetExpectedResults(testcase);

                    // add to list.
                    tests.Add(test);
                }

                // return set of trends.
                return((TestData[])tests.ToArray(typeof(TestData)));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return(null);
        }
        /// <summary>
        /// Runs all test cases and displays the results.
        /// </summary>
        private void Run()
        {
            TsCHdaItem[] items = null;

            try
            {
                // clear existing results.
                ResultsLV.Items.Clear();

                // free the existing dataset.
                if (m_dataset != null)
                {
                    m_dataset.Dispose();
                    m_dataset = null;
                }

                // load the dataset.
                TestData[] tests = LoadDataSet();

                if (tests == null)
                {
                    return;
                }

                // create the item.
                OpcItemResult[] results = m_server.CreateItems(new OpcItem[] { new OpcItem(m_itemID) });

                if (results == null || results.Length != 1)
                {
                    //throw new InvalidResponseException();
                }

                // return items.
                items = new TsCHdaItem[] { new TsCHdaItem(results[0]) };

                // execute test cases.
                foreach (TestData test in tests)
                {
                    ExecuteTest(test, items);
                }

                // adjust columns.
                AdjustColumns();

                // scroll to the first failed result.
                for (int ii = 0; ii < ResultsLV.Items.Count; ii++)
                {
                    if (ResultsLV.Items[ii].ForeColor == Color.Red)
                    {
                        ResultsLV.EnsureVisible(ii);
                        break;
                    }
                }
            }
            finally
            {
                if (items != null)
                {
                    try   { m_server.ReleaseItems(items); }
                    catch {}
                }
            }
        }