示例#1
0
        /// <summary>
        /// Writes any changes through the session
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestHeader"></param>
        /// <param name="operations"></param>
        /// <param name="skipAttributeIdInvalid"></param>
        /// <param name="traceOnly"></param>
        /// <returns></returns>
        public async Task WriteAsync(Session session, RequestHeader requestHeader,
                                     List <OperationResultModel> operations, bool skipAttributeIdInvalid, bool traceOnly)
        {
            var writeValueCollection = new WriteValueCollection(_attributes
                                                                .Where(a => a.Value != null)
                                                                .Select(a => new WriteValue {
                NodeId      = LocalId,
                AttributeId = a.Key,
                Value       = a.Value
            }));

            var writeResponse = await session.WriteAsync(requestHeader,
                                                         writeValueCollection);

            OperationResultEx.Validate("Write_" + LocalId, operations, writeResponse.Results
                                       .Select(code => skipAttributeIdInvalid &&
                                               code == StatusCodes.BadAttributeIdInvalid ? StatusCodes.Good : code),
                                       writeResponse.DiagnosticInfos,
                                       writeValueCollection
                                       .Select(v => AttributeMap.GetBrowseName(v.AttributeId)), traceOnly);
        }
示例#2
0
        /// <summary>
        /// Read using value collection
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestHeader"></param>
        /// <param name="readValueCollection"></param>
        /// <param name="operations"></param>
        /// <param name="skipAttributeIdInvalid"></param>
        /// <param name="traceOnly"></param>
        /// <returns></returns>
        internal async Task ReadAsync(Session session, RequestHeader requestHeader,
                                      ReadValueIdCollection readValueCollection, List <OperationResultModel> operations,
                                      bool skipAttributeIdInvalid, bool traceOnly)
        {
            var readResponse = await session.ReadAsync(requestHeader, 0,
                                                       TimestampsToReturn.Both, readValueCollection);

            OperationResultEx.Validate("Read_" + LocalId, operations,
                                       readResponse.Results
                                       .Select(v => skipAttributeIdInvalid &&
                                               v.StatusCode == StatusCodes.BadAttributeIdInvalid  ?
                                               StatusCodes.Good : v.StatusCode),
                                       readResponse.DiagnosticInfos, readValueCollection
                                       .Select(v => AttributeMap.GetBrowseName(v.AttributeId)), traceOnly);

            for (var i = 0; i < readValueCollection.Count; i++)
            {
                var attributeId = readValueCollection[i].AttributeId;
                if (readResponse.Results[i].StatusCode != StatusCodes.BadAttributeIdInvalid)
                {
                    _attributes[attributeId] = readResponse.Results[i];
                }
            }
        }