Opc.Ua.ServerTest.ReadTest.VerifyDataEncoding C# (CSharp) Method

VerifyDataEncoding() private method

private VerifyDataEncoding ( IVariableBase variable, BuiltInType type, QualifiedName dataEncoding, DataValue result ) : bool
variable IVariableBase
type BuiltInType
dataEncoding QualifiedName
result DataValue
return bool
        private bool VerifyDataEncoding(IVariableBase variable, BuiltInType type, QualifiedName dataEncoding, DataValue result)
        {  
            // allow DA status codes to be returned before checking the 
            if (IsDaBadStatus(result.StatusCode))
            {
                return true;
            }

            IList<INode> encodings = Session.NodeCache.Find(
                variable.DataType,
                ReferenceTypeIds.HasEncoding,
                false,
                true);

            if (StatusCode.IsBad(result.StatusCode))
            {
                for (int ii = 0; ii < encodings.Count; ii++)
                {
                    if (encodings[ii].BrowseName == dataEncoding)
                    {
                        Log(
                            "Did not return a valid value for a supported data encoding '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                            variable,
                            variable.NodeId,
                            variable.Value,
                            result.StatusCode);

                        return false;
                    }
                }

                return true;
            }
                        
            ExtensionObject extension = result.Value as ExtensionObject;

            if (extension != null)
            {
                for (int ii = 0; ii < encodings.Count; ii++)
                {
                    if (encodings[ii].BrowseName == dataEncoding)
                    {
                        if (ExpandedNodeId.ToNodeId(extension.TypeId, Session.NamespaceUris) != encodings[ii].NodeId)
                        {
                            Log(
                                "Did not return value with correct data encoding '{0}'. NodeId = {1}, Expected = {2}, Actual = {3}",
                                variable,
                                variable.NodeId,
                                encodings[ii].NodeId,
                                extension.TypeId);

                            return false;
                        }
                    }
                }
            }
                        
            ExtensionObject[] extensions = result.Value as ExtensionObject[];

            if (extensions != null)
            {
                for (int jj = 0; jj < extensions.Length; jj++)
                {
                    extension = extensions[jj];

                    for (int ii = 0; ii < encodings.Count; ii++)
                    {
                        if (encodings[ii].BrowseName == dataEncoding)
                        {
                            if (ExpandedNodeId.ToNodeId(extension.TypeId, Session.NamespaceUris) != encodings[ii].NodeId)
                            {
                                Log(
                                    "Did not return value with correct data encoding '{0}'. NodeId = {1}, Expected = {2}, Actual = {3}",
                                    variable,
                                    variable.NodeId,
                                    encodings[ii].NodeId,
                                    extension.TypeId);

                                return false;
                            }
                        }
                    }
                }
            }

            return true;
        }