Opc.Ua.ServerTest.TestBase.VerifyTimestamps C# (CSharp) Method

VerifyTimestamps() protected method

Verifies that the timestamps match the requested filter.
protected VerifyTimestamps ( Node node, uint attributeId, TimestampsToReturn timestampsToReturn, DataValue value ) : bool
node Node
attributeId uint
timestampsToReturn TimestampsToReturn
value DataValue
return bool
        protected bool VerifyTimestamps(
            Node node, 
            uint attributeId,
            TimestampsToReturn timestampsToReturn, 
            DataValue value)
        {
            // check server timestamp.
            if (timestampsToReturn != TimestampsToReturn.Server && timestampsToReturn != TimestampsToReturn.Both)
            {
                if (value.ServerTimestamp != DateTime.MinValue || value.ServerPicoseconds != 0)
                {                    
                    Log(
                        "Unexpected ServerTimestamp returned during read for Node '{0}'. NodeId = {1}, Attribute = {2}, Timestamp = {3}, Picoseconds = {4}",
                        node,
                        node.NodeId,
                        Attributes.GetBrowseName(attributeId),
                        value.ServerTimestamp,
                        value.ServerPicoseconds);

                    return false;
                }
            }

            if (timestampsToReturn == TimestampsToReturn.Server || timestampsToReturn == TimestampsToReturn.Both)
            {
                if (value.ServerTimestamp.AddHours(1) < DateTime.UtcNow || DateTime.UtcNow.AddHours(1) < value.ServerTimestamp)
                {                    
                    Log(
                        "Valid ServerTimestamp not returned during read for Node '{0}'. NodeId = {1}, Attribute = {2}, Timestamp = {3}, Picoseconds = {4}",
                        node,
                        node.NodeId,
                        Attributes.GetBrowseName(attributeId),
                        value.ServerTimestamp,
                        value.ServerPicoseconds);

                    return false;
                }
            }
            
            // check source timestamp.
            if (timestampsToReturn != TimestampsToReturn.Source && timestampsToReturn != TimestampsToReturn.Both)
            {
                if (value.SourceTimestamp != DateTime.MinValue || value.SourcePicoseconds != 0)
                {                    
                    Log(
                        "Unexpected SourceTimestamp returned during read for Node '{0}'. NodeId = {1}, Attribute = {2}, Timestamp = {3}, Picoseconds = {4}",
                        node,
                        node.NodeId,
                        Attributes.GetBrowseName(attributeId),
                        value.SourceTimestamp,
                        value.ServerPicoseconds);

                    return false;
                }
            }

            // check non-value attribute source timestamp.
            if (attributeId != Attributes.Value)
            {
                if (value.SourceTimestamp != DateTime.MinValue || value.SourcePicoseconds != 0)
                {                    
                    Log(
                        "Unexpected SourceTimestamp returned during non-value attribute for Node '{0}'. NodeId = {1}, Attribute = {2}, Timestamp = {3}, Picoseconds = {4}",
                        node,
                        node.NodeId,
                        Attributes.GetBrowseName(attributeId),
                        value.SourceTimestamp,
                        value.ServerPicoseconds);

                    return false;
                }
            }
            else if (StatusCode.IsGood(value.StatusCode))
            {
                if (timestampsToReturn == TimestampsToReturn.Source || timestampsToReturn == TimestampsToReturn.Both)
                {
                    if (value.SourceTimestamp.AddYears(10) < DateTime.UtcNow || DateTime.UtcNow.AddHours(1) < value.SourceTimestamp)
                    {                    
                        Log(
                            "Valid SourceTimestamp not returned during read for Node '{0}'. NodeId = {1}, Attribute = {2}, Timestamp = {3}, Picoseconds = {4}",
                            node,
                            node.NodeId,
                            Attributes.GetBrowseName(attributeId),
                            value.SourceTimestamp,
                            value.SourcePicoseconds);

                        return false;
                    }
                }
            }

            return true;
        }