Beispiel #1
0
        /// <summary>
        /// Updates the history of an item.
        /// </summary>
        public StatusCode DeleteRaw(string itemId, DeleteRawModifiedDetails details, HistoryUpdateResult result)
        {
            // create handles.
            HdaItem[] items = GetItems(itemId);

            if (items == null || items[0].Error < 0)
            {
                result.StatusCode = StatusCodes.BadNodeIdUnknown;
                return result.StatusCode;
            }

            try
            {
                // update data.
                result.StatusCode = DeleteRaw(
                    items[0],
                    details.StartTime,
                    details.EndTime);
            }
            catch (Exception)
            {
                result.StatusCode = StatusCodes.BadUnexpectedError;
            }
            finally
            {
                // release handles.
                ReleaseItemHandles(items);
            }

            return result.StatusCode;
        }
Beispiel #2
0
        /// <summary>
        /// Deletes the history of values for a set of variables at given time interval.
        /// </summary>
        static void HistoryDeleteRaw(Session session)
        {
            // translate browse paths.
            IList<NodeOfInterest> results = GetNodeIds(session, Opc.Ua.Objects.ObjectsFolder, 
                VariableBrowsePaths.ToArray());


            DiagnosticInfoCollection diagnosticInfos;

            ExtensionObjectCollection eoc = new ExtensionObjectCollection();
            for (int ii = 0; ii < results.Count; ii++)
            {
                DeleteRawModifiedDetails deleteDetails = new DeleteRawModifiedDetails();
                deleteDetails.StartTime = new DateTime(2008, 1, 1, 12, 0, 0);
                deleteDetails.EndTime = new DateTime(2008, 1, 1, 12, 0, 10);

                deleteDetails.NodeId = results[ii].NodeId;
                deleteDetails.IsDeleteModified = false;

                ExtensionObject eo = new ExtensionObject(deleteDetails.TypeId, deleteDetails);
                eoc.Add(eo);
            }

            HistoryUpdateResultCollection historyUpdateResults;

            ResponseHeader responseHeader =
                session.HistoryUpdate(null, eoc, out historyUpdateResults, out diagnosticInfos);

            // process results.

            for (int ii = 0; ii < historyUpdateResults.Count; ii++)
            {
                HistoryUpdateResult historyUpdateResult = historyUpdateResults[ii];

                Console.WriteLine("HistoryUpdate result code for {0}:  {1}", VariableBrowsePaths[ii], historyUpdateResult.StatusCode.ToString());

                if (StatusCode.IsGood(historyUpdateResult.StatusCode))
                {
                    for (int jj = 0; jj < historyUpdateResult.OperationResults.Count; jj++)
                    {
                        Console.WriteLine("    {0}: {1}", jj, historyUpdateResult.OperationResults[jj]);
                    }
                    Console.WriteLine("");
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates the update requests.
        /// </summary>
        private List<HdaUpdateRequest> CreateUpdateRequests(
            Session session,
            DateTime startTime,
            DateTime endTime,
            int[] serverHandles)
        {
            if (startTime == DateTime.MinValue || endTime == DateTime.MinValue)
            {
                throw ComUtils.CreateComException(ResultIds.E_INVALIDARG);
            }

            List<HdaUpdateRequest> requests = new List<HdaUpdateRequest>();

            for (int ii = 0; ii < serverHandles.Length; ii++)
            {
                HdaUpdateRequest request = new HdaUpdateRequest();
                requests.Add(request);

                // find handle.
                request.Handle = m_itemManager.LookupHandle(serverHandles[ii]);

                if (request.Handle == null)
                {
                    request.Error = ResultIds.E_INVALIDHANDLE;
                    continue;
                }

                request.ClientHandle = request.Handle.ClientHandle;

                // specify the parameters for the request.
                DeleteRawModifiedDetails details = new DeleteRawModifiedDetails();

                details.NodeId = request.Handle.NodeId;
                details.IsDeleteModified = false;
                details.StartTime = startTime;
                details.EndTime = endTime;

                request.Details = new ExtensionObject(details);
            }

            return requests;
        }
        /// <summary>
        /// Validates the nodes and updates the history.
        /// </summary>
        protected virtual void HistoryUpdate(
            ServerSystemContext context,
            Type                           detailsType, 
            IList<HistoryUpdateDetails>    nodesToUpdate, 
            IList<HistoryUpdateResult>     results,
            IList<ServiceResult>           errors,
            List<NodeHandle>               nodesToProcess,
            IDictionary<NodeId, NodeState> cache)
        {
            // handle update data request.
            if (detailsType == typeof(UpdateDataDetails))
            {
                UpdateDataDetails[] details = new UpdateDataDetails[nodesToUpdate.Count];

                for (int ii = 0; ii < details.Length; ii++)
                {
                    details[ii] = (UpdateDataDetails)nodesToUpdate[ii];
                }

                HistoryUpdateData(
                    context,
                    details,
                    results,
                    errors,
                    nodesToProcess,
                    cache);

                return;
            }

            // handle update structure data request.
            if (detailsType == typeof(UpdateStructureDataDetails))
            {
                UpdateStructureDataDetails[] details = new UpdateStructureDataDetails[nodesToUpdate.Count];

                for (int ii = 0; ii < details.Length; ii++)
                {
                    details[ii] = (UpdateStructureDataDetails)nodesToUpdate[ii];
                }

                HistoryUpdateStructureData(
                    context,
                    details,
                    results,
                    errors,
                    nodesToProcess,
                    cache);

                return;
            }

            // handle update events request.
            if (detailsType == typeof(UpdateEventDetails))
            {
                UpdateEventDetails[] details = new UpdateEventDetails[nodesToUpdate.Count];

                for (int ii = 0; ii < details.Length; ii++)
                {
                    details[ii] = (UpdateEventDetails)nodesToUpdate[ii];
                }

                HistoryUpdateEvents(
                    context,
                    details,
                    results,
                    errors,
                    nodesToProcess,
                    cache);

                return;
            }

            // handle delete raw data request.
            if (detailsType == typeof(DeleteRawModifiedDetails))
            {
                DeleteRawModifiedDetails[] details = new DeleteRawModifiedDetails[nodesToUpdate.Count];

                for (int ii = 0; ii < details.Length; ii++)
                {
                    details[ii] = (DeleteRawModifiedDetails)nodesToUpdate[ii];
                }

                HistoryDeleteRawModified(
                    context,
                    details,
                    results,
                    errors,
                    nodesToProcess,
                    cache);

                return;
            }

            // handle delete at time request.
            if (detailsType == typeof(DeleteAtTimeDetails))
            {
                DeleteAtTimeDetails[] details = new DeleteAtTimeDetails[nodesToUpdate.Count];

                for (int ii = 0; ii < details.Length; ii++)
                {
                    details[ii] = (DeleteAtTimeDetails)nodesToUpdate[ii];
                }

                HistoryDeleteAtTime(
                    context,
                    details,
                    results,
                    errors,
                    nodesToProcess,
                    cache);

                return;
            }

            // handle delete at time request.
            if (detailsType == typeof(DeleteEventDetails))
            {
                DeleteEventDetails[] details = new DeleteEventDetails[nodesToUpdate.Count];

                for (int ii = 0; ii < details.Length; ii++)
                {
                    details[ii] = (DeleteEventDetails)nodesToUpdate[ii];
                }

                HistoryDeleteEvents(
                    context,
                    details,
                    results,
                    errors,
                    nodesToProcess,
                    cache);

                return;
            }
        }
        /// <summary>
        /// Deletes the block of data.
        /// </summary>
        private void DeleteRaw(bool isModified)
        {
            DeleteRawModifiedDetails details = new DeleteRawModifiedDetails();
            details.NodeId = m_nodeId;
            details.IsDeleteModified = isModified;
            details.StartTime = StartTimeDP.Value;
            details.EndTime = EndTimeDP.Value;

            ExtensionObjectCollection nodesToUpdate = new ExtensionObjectCollection();
            nodesToUpdate.Add(new ExtensionObject(details));

            HistoryUpdateResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            m_session.HistoryUpdate(
                null,
                nodesToUpdate,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, nodesToUpdate);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToUpdate);

            if (StatusCode.IsBad(results[0].StatusCode))
            {
                throw new ServiceResultException(results[0].StatusCode);
            }

            ResultsDV.Columns[ResultsDV.Columns.Count - 1].Visible = false;
            m_dataset.Clear();
        }