Exemple #1
0
        /// <summary>
        /// Publishes a value.
        /// </summary>
        private void Publish(
            OperationContext context,
            DataValue value,
            ServiceResult error,
            Queue <MonitoredItemNotification> notifications,
            Queue <DiagnosticInfo> diagnostics)
        {
            // set semantics changed bit.
            if (m_semanticsChanged)
            {
                if (value != null)
                {
                    value.StatusCode = value.StatusCode.SetSemanticsChanged(true);
                }

                if (error != null)
                {
                    error = new ServiceResult(
                        error.StatusCode.SetSemanticsChanged(true),
                        error.SymbolicId,
                        error.NamespaceUri,
                        error.LocalizedText,
                        error.AdditionalInfo,
                        error.InnerResult);
                }

                m_semanticsChanged = false;
            }

            // set structure changed bit.
            if (m_structureChanged)
            {
                if (value != null)
                {
                    value.StatusCode = value.StatusCode.SetStructureChanged(true);
                }

                if (error != null)
                {
                    error = new ServiceResult(
                        error.StatusCode.SetStructureChanged(true),
                        error.SymbolicId,
                        error.NamespaceUri,
                        error.LocalizedText,
                        error.AdditionalInfo,
                        error.InnerResult);
                }

                m_structureChanged = false;
            }

            // copy data value.
            MonitoredItemNotification item = new MonitoredItemNotification();

            item.ClientHandle = m_clientHandle;
            item.Value        = value;

            // apply timestamp filter.
            if (m_timestampsToReturn != TimestampsToReturn.Server && m_timestampsToReturn != TimestampsToReturn.Both)
            {
                item.Value.ServerTimestamp = DateTime.MinValue;
            }

            if (m_timestampsToReturn != TimestampsToReturn.Source && m_timestampsToReturn != TimestampsToReturn.Both)
            {
                item.Value.SourceTimestamp = DateTime.MinValue;
            }

            notifications.Enqueue(item);

            // update diagnostic info.
            DiagnosticInfo diagnosticInfo = null;

            if (m_lastError != null)
            {
                if ((m_diagnosticsMasks & DiagnosticsMasks.OperationAll) != 0)
                {
                    diagnosticInfo = ServerUtils.CreateDiagnosticInfo(m_source.Server, context, m_lastError);
                }
            }

            diagnostics.Enqueue(diagnosticInfo);
        }
        /// <summary>
        /// Deletes history events.
        /// </summary>
        protected override void HistoryDeleteEvents(
            ServerSystemContext context,
            IList <DeleteEventDetails> nodesToUpdate,
            IList <HistoryUpdateResult> results,
            IList <ServiceResult> errors,
            List <NodeHandle> nodesToProcess,
            IDictionary <NodeId, NodeState> cache)
        {
            for (int ii = 0; ii < nodesToProcess.Count; ii++)
            {
                NodeHandle          handle       = nodesToProcess[ii];
                DeleteEventDetails  nodeToUpdate = nodesToUpdate[handle.Index];
                HistoryUpdateResult result       = results[handle.Index];

                // delete events.
                bool failed = false;

                for (int jj = 0; jj < nodeToUpdate.EventIds.Count; jj++)
                {
                    try
                    {
                        string eventId = new Guid(nodeToUpdate.EventIds[jj]).ToString();

                        if (!m_generator.DeleteEvent(eventId))
                        {
                            result.OperationResults.Add(StatusCodes.BadEventIdUnknown);
                            failed = true;
                            continue;
                        }

                        result.OperationResults.Add(StatusCodes.Good);
                    }
                    catch
                    {
                        result.OperationResults.Add(StatusCodes.BadEventIdUnknown);
                        failed = true;
                    }
                }

                // check if diagnostics are required.
                if (failed)
                {
                    if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        for (int jj = 0; jj < nodeToUpdate.EventIds.Count; jj++)
                        {
                            if (StatusCode.IsBad(result.OperationResults[jj]))
                            {
                                result.DiagnosticInfos.Add(ServerUtils.CreateDiagnosticInfo(Server, context.OperationContext, result.OperationResults[jj]));
                            }
                        }
                    }
                }

                // clear operation results if all good.
                else
                {
                    result.OperationResults.Clear();
                }

                // all done.
                errors[handle.Index] = ServiceResult.Good;
            }
        }