Beispiel #1
0
        bool checkEventDescription(XmlElement eventNode, RecordingControlEventsTestSuite.RecordingControlEventDescription eventDescription, IXmlNamespaceResolver namespaceResolver, StringBuilder logger)
        {
            var descriptionNode = eventNode.GetMessageDescription();

            if (null == descriptionNode)
            {
                logger.AppendLine("MessageDescription element is absent.");
                return(false);
            }

            var manager = new XmlNamespaceManager(eventNode.OwnerDocument.NameTable);

            manager.AddNamespace(OnvifMessage.ONVIFPREFIX, OnvifMessage.ONVIF);

            var isPropertyAttribute = descriptionNode.Attributes[OnvifMessage.ISPROPERTY];

            if (null == isPropertyAttribute)
            {
                logger.AppendLine("The 'IsProperty' attribute is absent.");
                return(false);
            }

            var isPropertyValueXmlString = XmlConvert.ToString(eventDescription.isProperty);

            if (isPropertyAttribute.Value != isPropertyValueXmlString)
            {
                logger.AppendLine(string.Format("The 'IsProperty' attribute is incorrect. Expected: {0}. Actual: {1}",
                                                isPropertyValueXmlString,
                                                isPropertyAttribute.Value));
                return(false);
            }

            bool flag = true;

            foreach (var itemDescription in eventDescription.itemDescriptions)
            {
                var path     = itemDescription.Path.Split('/').Select(e => "tt:" + e).Aggregate("", (s, s1) => s + s1 + "/").Trim('/');
                var nodes    = descriptionNode.SelectNodes(path, manager).OfType <XmlElement>();
                var itemNode = nodes.FirstOrDefault(e => null != e.Attributes[OnvifMessage.NAME] &&
                                                    e.Attributes[OnvifMessage.NAME].Value == itemDescription.Name);
                if (null == itemNode)
                {
                    if (itemDescription.Mandatory)
                    {
                        flag = false;
                        logger.AppendLine(string.Format("Mandatory element {0} of type '{1}' is absent", itemDescription.Name, itemDescription.Type));
                    }
                }
                else
                {
                    XmlAttribute type = itemNode.Attributes[OnvifMessage.TYPE];
                    if (type == null)
                    {
                        flag = false;
                        logger.AppendLine(string.Format("'Type' attribute is missing for '{0}' simple item", itemDescription.Name));
                    }
                    else
                    {
                        string error = string.Empty;
                        if (!type.IsCorrectQName(itemDescription.Type, itemDescription.Namespace, namespaceResolver, ref error))
                        {
                            flag = false;
                            logger.AppendLine(string.Format("'Type' attribute is incorrect for '{0}' simple item: {1}", itemDescription.Name, error));
                        }
                    }
                }
            }

            return(flag);
        }