<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NAppUpdate.Framework.Conditions
{
    public sealed class BooleanCondition : IUpdateCondition
    {
        #region Condition types

        [Flags]
        public enum ConditionType : byte
        {
            AND = 1,
            OR = 2,
            NOT = 4,
        }

        public static ConditionType ConditionTypeFromString(string type)
        {
            if (!string.IsNullOrEmpty(type))
            {
                switch (type.ToLower())
                {
                    case "and":
                        return ConditionType.AND;
                    case "or":
                        return ConditionType.OR;
                    case "not":
                    case "and-not":
                        return ConditionType.AND | ConditionType.NOT;
                    case "or-not":
                        return ConditionType.OR | ConditionType.NOT;
                }
            }

            // Make AND the default condition type
            return ConditionType.AND;
        }
        #endregion

        private class ConditionItem
        {
            public ConditionItem(IUpdateCondition cnd, ConditionType typ)
            {
                this._Condition = cnd;
                this._ConditionType = typ;
            }

            public IUpdateCondition _Condition;
            public ConditionType _ConditionType;
        }

        public BooleanCondition()
        {
            Attributes = new Dictionary<string, string>();
        }

        private LinkedList<ConditionItem> ChildConditions { get; set; }
        public int ChildConditionsCount { get { if (ChildConditions != null) return ChildConditions.Count; return 0; } }

        public void AddCondition(IUpdateCondition cnd)
        {
            AddCondition(cnd, ConditionType.AND);
        }

        public void AddCondition(IUpdateCondition cnd, ConditionType type)
        {
            if (ChildConditions == null) ChildConditions = new LinkedList<ConditionItem>();
            ChildConditions.AddLast(new ConditionItem(cnd, type));
        }

        public IUpdateCondition Degrade()
        {
            if (ChildConditionsCount == 1)
                return ChildConditions.First.Value._Condition;
            return this;
        }

        #region IUpdateCondition Members

        public IDictionary<string, string> Attributes { get; private set; }

        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            if (ChildConditions == null)
                return true;

            bool Passed = true, firstRun = true;
            foreach (ConditionItem item in ChildConditions)
            {<commit_msg>A NOT condition cannot be evaluated by its own (or: fixing scenarios where conditions weren't evaluated correctly)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NAppUpdate.Framework.Conditions
{
    public sealed class BooleanCondition : IUpdateCondition
    {
        #region Condition types

        [Flags]
        public enum ConditionType : byte
        {
            AND = 1,
            OR = 2,
            NOT = 4,
        }

        public static ConditionType ConditionTypeFromString(string type)
        {
            if (!string.IsNullOrEmpty(type))
            {
                switch (type.ToLower())
                {
                    case "and":
                        return ConditionType.AND;
                    case "or":
                        return ConditionType.OR;
                    case "not":
                    case "and-not":
                        return ConditionType.AND | ConditionType.NOT;
                    case "or-not":
                        return ConditionType.OR | ConditionType.NOT;
                }
            }

            // Make AND the default condition type
            return ConditionType.AND;
        }
        #endregion

        private class ConditionItem
        {
            public ConditionItem(IUpdateCondition cnd, ConditionType typ)
            {
                this._Condition = cnd;
                this._ConditionType = typ;
            }

            public IUpdateCondition _Condition;
            public ConditionType _ConditionType;
        }

        public BooleanCondition()
        {
            Attributes = new Dictionary<string, string>();
        }

        private LinkedList<ConditionItem> ChildConditions { get; set; }
        public int ChildConditionsCount { get { if (ChildConditions != null) return ChildConditions.Count; return 0; } }

        public void AddCondition(IUpdateCondition cnd)
        {
            AddCondition(cnd, ConditionType.AND);
        }

        public void AddCondition(IUpdateCondition cnd, ConditionType type)
        {
            if (ChildConditions == null) ChildConditions = new LinkedList<ConditionItem>();
            ChildConditions.AddLast(new ConditionItem(cnd, type));
        }

        public IUpdateCondition Degrade()
        {
            if (ChildConditionsCount == 1 && (ChildConditions.First.Value._ConditionType & ConditionType.NOT) == 0)
                return ChildConditions.First.Value._Condition;

            return this;
        }

        #region IUpdateCondition Members

        public IDictionary<string, string> Attributes { get; private set; }

        public bool IsMet(NAppUpdate.Framework.Tasks.IUpdateTask task)
        {
            if (ChildConditions == null)
                return true;

            bool Passed = true, firstRun = true;
            foreach (ConditionItem item in ChildConditions)
            {
{'fraction_non_alphanumeric': 0.07066079295154185, 'fraction_numerical': 0.0019383259911894273, 'mean_word_length': 1.5706521739130435, 'pattern_counts': {'":': 10, '<': 11, '<?xml version=': 0, '>': 11, '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': '10567', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1279, 'n_words': 350}