/// <summary>
        /// Initializes the control with a set of attribute ids.
        /// </summary>
        public void Initialize(TsCHdaServer server, int[] attributeIDs, TsCHdaResultCollection results)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_ = server;

            itemsLv_.Items.Clear();

            // check if there is nothing to do.
            if (attributeIDs == null || results == null)
            {
                return;
            }

            // collapse the array of collections into indiviual items in the list.
            for (int ii = 0; ii < attributeIDs.Length; ii++)
            {
                if (ii < results.Count)
                {
                    AddListItem(new AttributeResult(results, attributeIDs[ii], results[ii]));
                }
            }

            // adjust the list view columns to fit the data.
            AdjustColumns();
        }
        /// <summary>
        /// Displays the values of an attribute.
        /// </summary>
        public void Initialize(TsCHdaServer server, int attributeIDs, TsCHdaResultCollection results)
        {
            mServer_ = server;

            attributesLv_.Items.Clear();

            if (results != null)
            {
                foreach (TsCHdaResult result in results)
                {
                    AddListItem(result);
                }

                AdjustColumns();
            }
        }
Example #3
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);
        }
Example #4
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;
            }
        }
Example #5
0
        /// <summary>
        /// Called when an asynchronous update request completes.
        /// </summary>
        public void OnUpdateComplete(
            int dwTransactionID,
            int hrStatus,
            int dwCount,
            int[] phClients,
            int[] phrErrors)
        {
            try
            {
                lock (this)
                {
                    // lookup request transaction.
                    Request request = (Request)m_requests[dwTransactionID];

                    if (request == null)
                    {
                        return;
                    }

                    // unmarshal results.
                    ArrayList results = new ArrayList();

                    if (dwCount > 0)
                    {
                        // subscription results in collections for the same item id.
                        int currentHandle = phClients[0];

                        TsCHdaResultCollection itemResults = new TsCHdaResultCollection();

                        for (int ii = 0; ii < dwCount; ii++)
                        {
                            // create a new collection for the next item's results.
                            if (phClients[ii] != currentHandle)
                            {
                                itemResults.ServerHandle = currentHandle;
                                results.Add(itemResults);

                                currentHandle = phClients[ii];
                                itemResults   = new TsCHdaResultCollection();
                            }

                            TsCHdaResult result = new TsCHdaResult(Technosoftware.DaAeHdaClient.Utilities.Interop.GetResultID(phrErrors[ii]));
                            itemResults.Add(result);
                        }

                        // add the last set of item results.
                        itemResults.ServerHandle = currentHandle;
                        results.Add(itemResults);
                    }

                    // invoke callback - remove request if all results arrived.
                    if (request.InvokeCallback((TsCHdaResultCollection[])results.ToArray(typeof(TsCHdaResultCollection))))
                    {
                        m_requests.Remove(request.RequestID);
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(dwTransactionID, exception);
            }
        }
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // get the attribute ids.
            if (mAttributeIDs_ == null)
            {
                mAttributeIDs_ = attributesCtrl_.GetAttributeIDs(true);
                return;
            }

            // create item (if necessary).
            TsCHdaItem item = mTrend_.Items[mItem_];

            if (item == null)
            {
                item = mTrend_.AddItem(mItem_);
            }

            // get the paramaters.
            trendCtrl_.Update(mTrend_);

            // get the attributes.
            mAttributeIDs_ = attributesCtrl_.GetAttributeIDs(true);

            if (mSynchronous_)
            {
                // read data.
                TsCHdaItemAttributeCollection results = mTrend_.ReadAttributes(item, mAttributeIDs_);

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

                // display results.
                resultsCtrl_.Initialize(mServer_, results);

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

                // begin read data.
                TsCHdaResultCollection results = mTrend_.ReadAttributes(
                    item,
                    mAttributeIDs_,
                    null,
                    new TsCHdaReadAttributesCompleteEventHandler(OnReadComplete),
                    out mRequest_);

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

                // display initial results.
                asyncResultsCtrl_.Initialize(mServer_, mAttributeIDs_, results);
                mAsyncSent_ = true;
            }
        }