<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace BetterDefaultBrowser.Lib.Filters
{
    /// <summary>
    /// Filter which is managed with the GUI
    /// </summary>
    public class ManagedFilter : PlainFilter
    {
        private Protocols protocol;
        private String url = "";
        private Ignore flags;

        /// <summary>
        /// Create a managed filter for an assigned browser.
        /// </summary>
        /// <param name="browser">Assigned browser</param>
        public ManagedFilter() : base()
        {
            this.Type = FType.MANAGED;
        }


        #region Properties
        /// <summary>
        /// The matching protocols.
        /// </summary>
        public Protocols Protocols
        {
            get
            {
                return protocol;
            }
            set
            {
                if (!protocol.Equals(value))
                {
                    protocol = value;
                    RebuildRegex();
                    OnPropertyChanged("Protocol");
                }
            }
        }

        /// <summary>
        /// The matching url. This must be reduced by the set flags before it can be used in a regular expression.
        /// </summary>
        public String URL
        {
            get
            {
                return url;
            }
            set
            {
                if (!url.Equals(value))
                {
                    url = value;
                    RebuildRegex();
                    OnPropertyChanged("URL");
                }
            }
        }

        /// <summary>
        /// The set flags.
        /// </summary>
        public Ignore Flags
        {
            get
            {
                return flags;
            }
            set
            {
                if (!flags.Equals(value))
                {
                    flags = value;
                    RebuildRegex();
                    OnPropertyChanged("Flags");
                }
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Convert this filter to an XML representation.
        /// </summary>
        /// <returns>XML Element</returns>
        internal override XElement ToXML()
        {
            var e = base.ToXML();

            e.Add(new XElement("protocols", Protocols),
                new XElement("flags", Flags),
                new XElement("url", URL)
                );
            return e;
        }<commit_msg>Added helper properties for GUI binding.<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace BetterDefaultBrowser.Lib.Filters
{
    /// <summary>
    /// Filter which is managed with the GUI
    /// </summary>
    public class ManagedFilter : PlainFilter
    {
        private Protocols protocol;
        private String url = "";
        private Ignore flags;

        /// <summary>
        /// Create a managed filter for an assigned browser.
        /// </summary>
        /// <param name="browser">Assigned browser</param>
        public ManagedFilter() : base()
        {
            this.Type = FType.MANAGED;
        }


        #region Properties
        /// <summary>
        /// The matching protocols.
        /// </summary>
        public Protocols Protocols
        {
            get
            {
                return protocol;
            }
            set
            {
                if (!protocol.Equals(value))
                {
                    protocol = value;
                    RebuildRegex();
                    OnPropertyChanged("Protocol");
                    OnPropertyChanged("ProtocolHTTP");
                    OnPropertyChanged("ProtocolHTTPS");
                }
            }
        }

        /// <summary>
        /// The matching url. This must be reduced by the set flags before it can be used in a regular expression.
        /// </summary>
        public String URL
        {
            get
            {
                return url;
            }
            set
            {
                if (!url.Equals(value))
                {
                    url = value;
                    RebuildRegex();
                    OnPropertyChanged("URL");
                }
            }
        }

        /// <summary>
        /// The set flags.
        /// </summary>
        public Ignore Flags
        {
            get
            {
                return flags;
            }
            set
            {
                if (!flags.Equals(value))
                {
                    flags = value;
                    RebuildRegex();
                    OnPropertyChanged("Flags");
                    OnPropertyChanged("IgnoreSD");
                    OnPropertyChanged("IgnoreTLD");
                    OnPropertyChanged("IgnorePort");
                    OnPropertyChanged("IgnorePage");
                    OnPropertyChanged("IgnoreParameter");
                }
            }
        }
        #endregion

        #region Helper Properties
        public bool IgnoreSD
        {
            get
            {
                return Flags.HasFlag(Ignore.SD);
            }
            set
            {
                if (!Flags.HasFlag(Ignore.SD))
                {
                    if (value)
                        Flags |= Ignore.SD;
                    else
                        Flags &= ~Ignore.SD;
                }
            }
        }

        public bool IgnoreTLD
        {
            get
            {
                return Flags.HasFlag(Ignore.TLD);
            }
            set
            {
                if (!Flags.HasFlag(Ignore.TLD))
                {
                    if (value)
                        Flags |= Ignore.TLD;
                    else
                        Flags &= ~Ignore.TLD;
                }
            }
        }

        public bool IgnorePort
        {
            get
            {
                return Flags.HasFlag(Ignore.Port);
            }
            set
            {
                if (!Flags.HasFlag(Ignore.Port))
                {
                    if (value)
                        Flags |= Ignore.Port;
                    else
                        Flags &= ~Ignore.Port;
                }
            }
        }

        public bool IgnorePage
        {
            get
            {
                return Flags.HasFlag(Ignore.Page);
            }
            set
            {
                if (!Flags.HasFlag(Ignore.Page))
                {
                    if (value)
                        Flags |= Ignore.Page;
                    else
                        Flags &= ~Ignore.Page;
                }
            }
        }

        public bool IgnoreParameter
        {
            get
            {
                return Flags.HasFlag(Ignore.Parameter);
            }
            set
            {
                if (!Flags.HasFlag(Ignore.Parameter))
                {
                    if (value)
                        Flags |= Ignore.Parameter;
                    else
                        Flags &= ~Ignore.Parameter;
                }
            }
        }
        #endregion


        public bool ProtocolHTTP
        {
            get
            {
                return Protocols.HasFlag(Protocols.HTTP);
            }
            set
            {
                if (!Protocols.HasFlag(Protocols.HTTP))
                {
                    if (value)
                        Protocols |= Protocols.HTTP;
                    else
                        Protocols &= ~Protocols.HTTP;
                }
            }
        }

        public bool ProtocolHTTPS
        {
            get
            {
                return Protocols.HasFlag(Protocols.HTTPS);
            }
            set
            {
                if (!Protocols.HasFlag(Protocols.HTTPS))
                {
                    if (value)
                        Protocols |= Protocols.HTTPS;
                    else
                        Protocols &= ~Protocols.HTTPS;
                }
            }
        }

        #region Methods
        /// <summary>
        /// Convert this filter to an XML representation.
        /// </summary>
        /// <returns>XML Element</returns>
        internal override XElement ToXML()
        {
            var e = base.ToXML();

            e.Add(new XElement("protocols", Protocols),
                new XElement("flags", Flags),
                new XElement("url", URL)
                );
            return e;
        }
{'fraction_non_alphanumeric': 0.08793827300578691, 'fraction_numerical': 0.0, 'mean_word_length': 0.8370154230929554, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487239', 'n_tokens_mistral': 2078, 'n_tokens_neox': 1939, 'n_words': 450}