Exemplo n.º 1
0
        protected Proxies.Event.FilterType CreateSubscriptionFilter(IEnumerable <TopicInfo> topicInfos)
        {
            Proxies.Event.FilterType filter = new Proxies.Event.FilterType();

            XmlDocument filterDoc          = new XmlDocument();
            XmlElement  filterTopicElement = filterDoc.CreateTopicElement();

            string topicPath = string.Empty;

            foreach (TopicInfo topicInfo in topicInfos)
            {
                string topicExpression = TopicInfo.CreateTopicPath(filterTopicElement, topicInfo);

                if (string.IsNullOrEmpty(topicPath))
                {
                    topicPath = topicExpression;
                }
                else
                {
                    topicPath = string.Format("{0}|{1}", topicPath, topicExpression);
                }
            }

            filterTopicElement.InnerText = topicPath;

            filter.Any = new XmlElement[] { filterTopicElement };

            return(filter);
        }
Exemplo n.º 2
0
        void SubscribeToBegin(SubscriptionHandler Handler)
        {
            FilterType  Filter             = new FilterType();
            XmlDocument filterDoc          = new XmlDocument();
            XmlElement  filterTopicElement = filterDoc.CreateTopicElement();
            // result is not used, but filterTopicElement is updating its namespaces
            string topicPath = TopicInfo.CreateTopicPath(filterTopicElement, BeginTopic);

            filterTopicElement.InnerText = BeginPath;
            Filter.Any = new XmlElement[] { filterTopicElement };

            Handler.Subscribe(Filter, -1);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets invalid MessageContentFilter for element passed.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="manager"></param>
        /// <returns></returns>
        private FilterInfo GetInvalidMessageContentFilter(XmlElement element, XmlNamespaceManager manager)
        {
            FilterInfo filter = null;

            // if element is a topic
            if (element.RepresentsTopic())
            {
                // Element represents a topic.
                // Look for MessageDescription

                List <string> itemNames          = new List <string>();
                XmlElement    messageDescription = element.GetMessageDescription();
                if (messageDescription != null)
                {
                    CollectItemNames(messageDescription, manager, OnvifMessage.SIMPLEITEMDESCRIPTION, itemNames);
                    CollectItemNames(messageDescription, manager, OnvifMessage.ELEMENTITEMDESCRIPTION, itemNames);
                }

                string invalidItemName = itemNames.GetNonMatchingString();

                filter = new FilterInfo();

                filter.Filter = new FilterType();

                XmlDocument doc          = new XmlDocument();
                XmlElement  topicElement = doc.CreateTopicElement();

                TopicInfo topicInfo = TopicInfo.ConstructTopicInfo(element);
                string    topicPath = TopicInfo.CreateTopicPath(topicElement, topicInfo);

                topicElement.InnerText = topicPath;

                XmlElement contentFilterElement = doc.CreateContentFilterElement();

                string simpleItemPrefix = contentFilterElement.GetNamespacePrefix(OnvifMessage.ONVIF);
                contentFilterElement.InnerText = string.Format("boolean((//{0}:{1}[@{2}=\"{3}\"] )",
                                                               simpleItemPrefix, OnvifMessage.SIMPLEITEM, OnvifMessage.NAME, invalidItemName);

                filter.Filter.Any         = new XmlElement[] { topicElement, contentFilterElement };
                filter.Topic              = topicInfo;
                filter.MessageDescription = messageDescription;

                return(filter);
            }

            foreach (XmlNode childNode in element.ChildNodes)
            {
                XmlElement child = childNode as XmlElement;
                if (child != null)
                {
                    filter = GetInvalidMessageContentFilter(child, manager);
                    if (filter != null)
                    {
                        return(filter);
                    }
                }
            }

            // if cannot create filter for any element - return null
            return(null);
        }