Exemplo n.º 1
0
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // get request parameters from controls.
            TrendCTRL.Update(m_trend);

            if (m_synchronous)
            {
                // read data.
                TsCHdaAnnotationValueCollection[] results = m_trend.ReadAnnotations(new TsCHdaItem[] { item });

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

                // display results.
                ItemsCTRL.Initialize(results);

                // save results.
                m_results = results;
            }
            else
            {
                // check if already waiting for results.
                if (m_asyncSent)
                {
                    return;
                }

                // begin read data.
                OpcItemResult[] results = m_trend.ReadAnnotations(
                    new TsCHdaItem[] { item },
                    null,
                    new TsCHdaReadAnnotationsCompleteEventHandler(OnReadComplete),
                    out m_request);

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

                // display initial results.
                AsyncResultsCTRL.Initialize(m_server, results);
                m_asyncSent = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prompts the user to select items and specify trend properties.
        /// </summary>
        public TsCHdaTrend ShowDialog(TsCHdaServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server  = server;
            m_results = null;

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

            // set reasonable defaults.
            trend.StartTime = new TsCHdaTime("YEAR");
            trend.EndTime   = new TsCHdaTime("YEAR+1H");

            BrowseCTRL.Browse(m_server, null);
            TrendCTRL.Initialize(trend, RequestType.None);
            ItemsCTRL.Initialize(m_server, (OpcItem[])null);
            ResultsCTRL.Initialize(m_server, m_results);

            // update dialog state.
            SetState(false);

            // show dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // create or update the trend.
            TrendCTRL.Update(trend);

            // add new items.
            if (m_results != null)
            {
                foreach (OpcItemResult item in m_results)
                {
                    if (item.Result.Succeeded())
                    {
                        trend.Items.Add(new TsCHdaItem(item));
                    }
                }
            }

            // return new trend.
            return(trend);
        }
        /// <summary>
        /// Create server handles for new items.
        /// </summary>
        private void DoRead()
        {
            // fetch the new trend parameters.
            TrendCTRL.Update(m_trend);

            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // read data.
            TsCHdaItemValueCollection[] results = m_trend.Read(new TsCHdaItem[] { item });

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

            // save results.
            m_values = results;

            // display results.
            ValuesCTRL.Initialize(m_server, m_values[0]);
        }
        /// <summary>
        /// Runs all tests with the specified name and displays the results.
        /// </summary>
        public bool ShowDialog(TsCHdaServer server, TestData test)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server = server;

            TrendCTRL.Initialize(test.Trend, RequestType.None);

            ValuesLV.Tag = test;

            if (test.Expected != null)
            {
                // add expected result.
                ResultIDTB.Text = test.Expected.Result.Name.Name;

                // add expected values to list view.
                UpdateValues();
            }

            if (ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            // update trend and expected values.
            TrendCTRL.Update(test.Trend);

            if (test.Expected != null)
            {
                // only update result if it does not have invalid characters.
                if (ResultIDTB.Text.IndexOfAny("() ".ToCharArray()) == -1)
                {
                    test.Expected.Result = new OpcResult(ResultIDTB.Text, "");
                }

                test.Expected.Clear();

                foreach (ListViewItem listItem in ValuesLV.Items)
                {
                    if (typeof(TsCHdaItemValue).IsInstanceOfType(listItem.Tag))
                    {
                        test.Expected.Add(listItem.Tag);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Synchronously eads the values from the server.
        /// </summary>
        private TsCHdaResultCollection[] SyncDelete(TsCHdaItem[] items)
        {
            // get request parameters from controls.
            TrendCTRL.Update(m_trend);

            switch (m_type)
            {
            // synchronous delete raw.
            case RequestType.DeleteRaw:
            {
                OpcItemResult[] results = m_trend.Delete(items);

                if (results != null)
                {
                    TsCHdaResultCollection[] collections = new TsCHdaResultCollection[results.Length];

                    for (int ii = 0; ii < results.Length; ii++)
                    {
                        collections[ii] = new TsCHdaResultCollection(results[ii]);
                        collections[ii].Add(new TsCHdaResult(results[ii]));
                    }

                    return(collections);
                }

                return(null);
            }

            // synchronous delete at time.
            case RequestType.DeleteAtTime:
            {
                return(m_trend.DeleteAtTime(items));
            }
            }

            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Prompts the user to edit the properties of a trend.
        /// </summary>
        public bool ShowDialog(TsCHdaTrend trend)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            // initialize the controls.
            TrendCTRL.Initialize(trend, RequestType.None);

            // show the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            // update the trend.
            TrendCTRL.Update(trend);

            return(true);
        }
        /// <summary>
        /// Prompts the user to edit the properties of a trend.
        /// </summary>
        public bool ShowDialog(TsCHdaTrend trend, RequestType type)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            // initialize the controls.
            TrendCTRL.Initialize(trend, type);

            // adjust dialog height.
            Height -= (ButtonsPN.Top - MainPN.Height);

            // show the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            // update the trend.
            TrendCTRL.Update(trend);

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // get the attribute ids.
            if (m_attributeIDs == null)
            {
                m_attributeIDs = AttributesCTRL.GetAttributeIDs(true);
                return;
            }

            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // get the paramaters.
            TrendCTRL.Update(m_trend);

            // get the attributes.
            m_attributeIDs = AttributesCTRL.GetAttributeIDs(true);

            if (m_synchronous)
            {
                // read data.
                TsCHdaItemAttributeCollection results = m_trend.ReadAttributes(item, m_attributeIDs);

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

                // display results.
                ResultsCTRL.Initialize(m_server, results);

                // save results.
                m_results = results;
            }
            else
            {
                // check if already waiting for results.
                if (m_asyncSent)
                {
                    return;
                }

                // begin read data.
                TsCHdaResultCollection results = m_trend.ReadAttributes(
                    item,
                    m_attributeIDs,
                    null,
                    new TsCHdaReadAttributesCompleteEventHandler(OnReadComplete),
                    out m_request);

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

                // display initial results.
                AsyncResultsCTRL.Initialize(m_server, m_attributeIDs, results);
                m_asyncSent = true;
            }
        }