/// <summary> /// Invokes the HistoryUpdate service. /// </summary> public virtual ResponseHeader HistoryUpdate( RequestHeader requestHeader, ExtensionObjectCollection historyUpdateDetails, out HistoryUpdateResultCollection results, out DiagnosticInfoCollection diagnosticInfos) { results = null; diagnosticInfos = null; ValidateRequest(requestHeader); // Insert implementation. return(CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported)); }
public void HistoryUpdate(bool eventDetails) { HistoryUpdateResultCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; // there are no historizing nodes, instead use some real nodes to test var testSet = GetTestSetSimulation(Session.NamespaceUris); // see https://reference.opcfoundation.org/v104/Core/docs/Part11/6.8.1/ as to why // history update of event, data or annotations should be called individually ExtensionObjectCollection historyUpdateDetails; if (eventDetails) { historyUpdateDetails = new ExtensionObjectCollection( testSet.Select(nodeId => new ExtensionObject(new UpdateEventDetails() { NodeId = nodeId, PerformInsertReplace = PerformUpdateType.Insert }))); } else { historyUpdateDetails = new ExtensionObjectCollection( testSet.Select(nodeId => new ExtensionObject( new UpdateDataDetails() { NodeId = nodeId, PerformInsertReplace = PerformUpdateType.Replace }))); } var responseHeader = Session.HistoryUpdate( null, historyUpdateDetails, out results, out diagnosticInfos); Session.ValidateResponse(results, historyUpdateDetails); Session.ValidateDiagnosticInfos(diagnosticInfos, historyUpdateDetails); }
/// <summary> /// Invokes the HistoryUpdate service. /// </summary> public virtual ResponseHeader HistoryUpdate( RequestHeader requestHeader, ExtensionObjectCollection historyUpdateDetails, out HistoryUpdateResultCollection results, out DiagnosticInfoCollection diagnosticInfos) { results = null; diagnosticInfos = null; ValidateRequest(requestHeader); // Insert implementation. return CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported); }
/// <summary> /// Invokes the HistoryUpdate service. /// </summary> /// <param name="requestHeader">The request header.</param> /// <param name="historyUpdateDetails">The details defined for the update.</param> /// <param name="results">The list of update results for the history update details.</param> /// <param name="diagnosticInfos">The diagnostic information for the results.</param> /// <returns> /// Returns a <see cref="ResponseHeader"/> object /// </returns> public override ResponseHeader HistoryUpdate( RequestHeader requestHeader, ExtensionObjectCollection historyUpdateDetails, out HistoryUpdateResultCollection results, out DiagnosticInfoCollection diagnosticInfos) { OperationContext context = ValidateRequest(requestHeader, RequestType.HistoryUpdate); try { if (historyUpdateDetails == null || historyUpdateDetails.Count == 0) { throw new ServiceResultException(StatusCodes.BadNothingToDo); } m_serverInternal.NodeManager.HistoryUpdate( context, historyUpdateDetails, out results, out diagnosticInfos); return CreateResponse(requestHeader, context.StringTable); } catch (ServiceResultException e) { lock (ServerInternal.DiagnosticsLock) { ServerInternal.ServerDiagnostics.RejectedRequestsCount++; if (IsSecurityError(e.StatusCode)) { ServerInternal.ServerDiagnostics.SecurityRejectedRequestsCount++; } } throw TranslateException(context, e); } finally { OnRequestComplete(context); } }
/// <summary> /// Deletes the recent history. /// </summary> private void DeleteHistory(NodeId areaId, List <VariantCollection> events, FilterDeclaration filter) { // find the event id. int index = 0; foreach (FilterDeclarationField field in filter.Fields) { if (field.InstanceDeclaration.BrowseName == Opc.Ua.BrowseNames.EventId) { break; } index++; } // can't delete events if no event id. if (index >= filter.Fields.Count) { throw ServiceResultException.Create(StatusCodes.BadEventIdUnknown, "Cannot delete events if EventId was not selected."); } // build list of nodes to delete. DeleteEventDetails details = new DeleteEventDetails(); details.NodeId = areaId; foreach (VariantCollection e in events) { byte[] eventId = null; if (e.Count > index) { eventId = e[index].Value as byte[]; } details.EventIds.Add(eventId); } // delete the events. 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); } // check for item level errors. if (results[0].OperationResults.Count > 0) { int count = 0; for (int ii = 0; ii < results[0].OperationResults.Count; ii++) { if (StatusCode.IsBad(results[0].OperationResults[ii])) { count++; } } // raise an error. if (count > 0) { throw ServiceResultException.Create( StatusCodes.BadEventIdUnknown, "Error deleting events. Only {0} of {1} deletes succeeded.", events.Count - count, events.Count); } } }
/// <summary> /// Updates the history for a set of nodes. /// </summary> public virtual void HistoryUpdate( OperationContext context, ExtensionObjectCollection historyUpdateDetails, out HistoryUpdateResultCollection results, out DiagnosticInfoCollection diagnosticInfos) { Type detailsType = null; List<HistoryUpdateDetails> nodesToUpdate = new List<HistoryUpdateDetails>(); // verify that all extension objects in the list have the same type. foreach (ExtensionObject details in historyUpdateDetails) { if (detailsType == null) { detailsType = details.Body.GetType(); } if (!ExtensionObject.IsNull(details)) { nodesToUpdate.Add(details.Body as HistoryUpdateDetails); } } // create result lists. bool diagnosticsExist = false; results = new HistoryUpdateResultCollection(nodesToUpdate.Count); diagnosticInfos = new DiagnosticInfoCollection(nodesToUpdate.Count); // pre-validate items. bool validItems = false; for (int ii = 0; ii < nodesToUpdate.Count; ii++) { HistoryUpdateResult result = null; DiagnosticInfo diagnosticInfo = null; // check the type of details parameter. ServiceResult error = null; if (nodesToUpdate[ii].GetType() != detailsType) { error = StatusCodes.BadHistoryOperationInvalid; } // pre-validate and pre-parse parameter. else { error = HistoryUpdateDetails.Validate(nodesToUpdate[ii]); } // return error status. if (ServiceResult.IsBad(error)) { nodesToUpdate[ii].Processed = true; result = new HistoryUpdateResult(); result.StatusCode = error.Code; // add diagnostics if requested. if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0) { diagnosticInfo = ServerUtils.CreateDiagnosticInfo(m_server, context, error); diagnosticsExist = true; } } // found at least one valid item. else { nodesToUpdate[ii].Processed = false; validItems = true; } results.Add(result); diagnosticInfos.Add(diagnosticInfo); } // call each node manager. if (validItems) { List<ServiceResult> errors = new List<ServiceResult>(results.Count); for (int ii = 0; ii < nodesToUpdate.Count; ii++) { errors.Add(null); } foreach (INodeManager nodeManager in m_nodeManagers) { nodeManager.HistoryUpdate( context, detailsType, nodesToUpdate, results, errors); } for (int ii = 0; ii < nodesToUpdate.Count; ii++) { HistoryUpdateResult result = results[ii]; // set an error code for nodes that were not handled by any node manager. if (!nodesToUpdate[ii].Processed) { nodesToUpdate[ii].Processed = true; result = results[ii] = new HistoryUpdateResult(); result.StatusCode = StatusCodes.BadNodeIdUnknown; errors[ii] = result.StatusCode; } // update the diagnostic info and ensure the status code in the result is the same as the error code. if (errors[ii] != null && errors[ii].Code != StatusCodes.Good) { if (result == null) { result = results[ii] = new HistoryUpdateResult(); } result.StatusCode = errors[ii].Code; // add diagnostics if requested. if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0) { diagnosticInfos[ii] = ServerUtils.CreateDiagnosticInfo(m_server, context, errors[ii]); diagnosticsExist = true; } } } } // clear the diagnostics array if no diagnostics requested or no errors occurred. UpdateDiagnostics(context, diagnosticsExist, ref diagnosticInfos); }
/// <summary> /// Finishes an asynchronous invocation of the HistoryUpdate service. /// </summary> public ResponseHeader EndHistoryUpdate( IAsyncResult result, out HistoryUpdateResultCollection results, out DiagnosticInfoCollection diagnosticInfos) { HistoryUpdateResponse response = null; try { if (UseTransportChannel) { IServiceResponse genericResponse = TransportChannel.EndSendRequest(result); if (genericResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } ValidateResponse(genericResponse.ResponseHeader); response = (HistoryUpdateResponse)genericResponse; } else { HistoryUpdateResponseMessage responseMessage = InnerChannel.EndHistoryUpdate(result); if (responseMessage == null || responseMessage.HistoryUpdateResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } response = responseMessage.HistoryUpdateResponse; ValidateResponse(response.ResponseHeader); } results = response.Results; diagnosticInfos = response.DiagnosticInfos; } finally { RequestCompleted(null, response, "HistoryUpdate"); } return response.ResponseHeader; }
/// <summary> /// Invokes the HistoryUpdate service. /// </summary> public virtual ResponseHeader HistoryUpdate( RequestHeader requestHeader, ExtensionObjectCollection historyUpdateDetails, out HistoryUpdateResultCollection results, out DiagnosticInfoCollection diagnosticInfos) { HistoryUpdateRequest request = new HistoryUpdateRequest(); HistoryUpdateResponse response = null; request.RequestHeader = requestHeader; request.HistoryUpdateDetails = historyUpdateDetails; UpdateRequestHeader(request, requestHeader == null, "HistoryUpdate"); try { if (UseTransportChannel) { IServiceResponse genericResponse = TransportChannel.SendRequest(request); if (genericResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } ValidateResponse(genericResponse.ResponseHeader); response = (HistoryUpdateResponse)genericResponse; } else { HistoryUpdateResponseMessage responseMessage = InnerChannel.HistoryUpdate(new HistoryUpdateMessage(request)); if (responseMessage == null || responseMessage.HistoryUpdateResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } response = responseMessage.HistoryUpdateResponse; ValidateResponse(response.ResponseHeader); } results = response.Results; diagnosticInfos = response.DiagnosticInfos; } finally { RequestCompleted(request, response, "HistoryUpdate"); } return response.ResponseHeader; }