Ejemplo n.º 1
0
        public void Init(ExpressionArguments arguments, bool IsIncludeEvents = true)
        {
            this.arguments = arguments;
            if (IsIncludeEvents)
            {
                includeEvents.Visibility = System.Windows.Visibility.Visible;
            }
            //panelFilterEditor.Children.Add(new ExpressionFilterEditor());
            if (AppDefaults.visualSettings.UseOnlyCommonFilterView)
            {
                exprEditor = new ExpressionDefaultEditor(arguments, AddFilter);
            }
            else
            {
                exprEditor = new ExpressionFilterEditor(arguments, AddFilter);
            }
            panelFilterEditor.Children.Add((UserControl)exprEditor);


            filtersList = new ObservableCollection <FilterExpression>();

            //buttons initialization
            //Delete filter button
            btnDeleteFilter.IsEnabled = valueFilters.SelectedItem == null ? false : true;
            //Current filter list
            valueFilters.ItemsSource       = filtersList;
            valueFilters.SelectionChanged += new SelectionChangedEventHandler((o, e) => {
                if (valueFilters.SelectedItem == null)
                {
                    btnDeleteFilter.IsEnabled = false;
                }
                else
                {
                    btnDeleteFilter.IsEnabled = true;
                    FilterSelected((FilterExpression)valueFilters.SelectedItem);
                }
            });

            btnDeleteFilter.Click += new RoutedEventHandler((o, e) => {
                if (valueFilters.SelectedItem == null)
                {
                    return;
                }
                FilterExpression sitem = valueFilters.SelectedItem as FilterExpression;
                if (sitem != null)
                {
                    filtersList.Remove(sitem);
                }
            });

            //fill startup filters
            arguments.messageContentFilters.ForEach(f => {
                filtersList.Add(ContentFilterExpression.CreateFilter(f));
            });
            arguments.topicExpressionFilters.ForEach(f => {
                filtersList.Add(TopicFilterExpression.CreateFilter(f));
            });
        }
        FilterExpression CreateFilter()
        {
            FilterExpression fExpr = null;

            if (valueExpressionType.SelectedItem == null)
            {
                return(null);
            }
            var tp = ((KeyValuePair <odm.ui.controls.FilterExpression.ftype, string>)valueExpressionType.SelectedItem).Key;

            XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();

            PrefixList.ForEach(p => {
                nspaces.Add(p.Prefix, p.Space);
            });

            switch (tp)
            {
            case FilterExpression.ftype.CONTENT:
                var confiltr = new global::onvif.services.MessageContentFilter();
                confiltr.expression = ExpressionValue;
                if (valueExpressionDialect.SelectedValue != null)
                {
                    confiltr.dialect = ((KeyValuePair <string, string>)valueExpressionDialect.SelectedValue).Key;
                }
                confiltr.namespaces = nspaces;
                fExpr = ContentFilterExpression.CreateFilter(confiltr);
                break;

            default:
                var topfiltr = new global::onvif.services.TopicExpressionFilter();
                topfiltr.expression = ExpressionValue;
                if (valueExpressionDialect.SelectedValue != null)
                {
                    topfiltr.dialect = ((KeyValuePair <string, string>)valueExpressionDialect.SelectedValue).Key;
                }
                topfiltr.namespaces = nspaces;
                fExpr = TopicFilterExpression.CreateFilter(topfiltr);
                break;
            }

            return(fExpr);
        }
        FilterExpression CreateFilter()
        {
            FilterExpression fExpr = null;

            if (valueExpressionType.SelectedItem == null)
            {
                return(null);
            }
            var typeDialect = (TypeDialectPair)valueExpressionType.SelectedItem;


            XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();

            PrefixList.ForEach(p => {
                nspaces.Add(p.Prefix, p.Space);
            });

            switch (typeDialect.tp)
            {
            case FilterExpression.ftype.CONTENT:
                var confiltr = new global::onvif.services.MessageContentFilter();
                confiltr.expression = ExpressionValue;
                confiltr.dialect    = typeDialect.dialect;
                confiltr.namespaces = nspaces;
                fExpr = ContentFilterExpression.CreateFilter(confiltr);
                break;

            default:
                var topfiltr = new global::onvif.services.TopicExpressionFilter();
                topfiltr.expression = ExpressionValue;
                topfiltr.dialect    = typeDialect.dialect;
                topfiltr.namespaces = nspaces;
                fExpr = TopicFilterExpression.CreateFilter(topfiltr);
                break;
            }

            return(fExpr);
        }