コード例 #1
0
        protected bool ValidateNotifications(Dictionary <Proxies.Event.NotificationMessageHolderType, XmlElement> messages, TopicInfo topic, string accessProfileToken, StringBuilder logger)
        {
            var filtered = messages.Where(pair => EventServiceExtensions.NotificationTopicMatch(pair.Key, pair.Value, topic)).Select(k => k.Key);

            if (!filtered.Any())
            {
                logger.AppendLine(string.Format("There is no notification with topic '{0}'", topic.GetDescription()));
                return(false);
            }

            foreach (var msg in filtered)
            {
                var source = msg.Message.GetMessageSourceSimpleItems();

                if (source.Any(s => s.Key == "AccessProfileToken" && s.Value == accessProfileToken))
                {
                    return(true);
                }
            }

            logger.AppendLine(string.Format("There is no notification containing 'Source/SimpleItem' element with Name = 'AccessProfileToken' and Value = '{0}'", accessProfileToken));
            return(false);
        }
コード例 #2
0
        bool messageFilterBase(Proxies.Event.NotificationMessageHolderType msg, TopicInfo topicInfo, string expectedPropertyOperation, string expectedAccessProfileToken, Func <StringBuilder, bool> action)
        {
            var invalidFlag = false;
            var log         = new StringBuilder();

            try
            {
                if (!EventServiceExtensions.NotificationTopicMatch(msg, topicInfo))
                {
                    log.AppendLine(string.Format("Received notification has unexpected topic '{0}' while the expected one should have with topic '{1}'",
                                                 EventServiceExtensions.GetTopicInfo(msg).GetDescription(), topicInfo.GetDescription()));
                    invalidFlag = true;
                }

                if (null != expectedPropertyOperation)
                {
                    if (!msg.Message.HasAttribute(OnvifMessage.PROPERTYOPERATIONTYPE))
                    {
                        log.AppendLine("Received notification has no 'PropertyOperation' field");
                        invalidFlag = true;
                    }
                    else
                    {
                        XmlAttribute propertyOperationType = msg.Message.Attributes[OnvifMessage.PROPERTYOPERATIONTYPE];
                        //Skip non-changed messages
                        if (propertyOperationType.Value != expectedPropertyOperation)
                        {
                            log.AppendLine(string.Format("Received notification has 'PropertyOperation' field with value = '{0}' but value = '{1}' is expected", propertyOperationType.Value, expectedPropertyOperation));
                            invalidFlag = true;
                        }
                    }
                }

                var source = msg.Message.GetMessageSourceSimpleItems();
                if (!source.ContainsKey("AccessProfileToken"))
                {
                    log.AppendLine("Received notification has no Source/SimpleItem with Name = 'AccessProfileToken'");
                    invalidFlag = true;
                }
                else
                {
                    var token = source["AccessProfileToken"];
                    if (token != expectedAccessProfileToken)
                    {
                        log.AppendLine(string.Format("Received notification has Source/SimpleItem with Name = 'AccessProfileToken' and Value = '{0}' but notification for AccessProfile item with token = '{1}' is expected", token, expectedAccessProfileToken));
                        invalidFlag = true;
                    }
                }

                if (null != action && action(log))
                {
                    invalidFlag = true;
                }

                return(true);
            }
            finally
            {
                Assert(!invalidFlag, log.ToStringTrimNewLine(), "Validation of received notification");
            }
        }