Beispiel #1
0
        public IEnumerable <AccessRule> GetAcls(string resource, string verb)
        {
            OrderedList <string, AccessRule> acls = new OrderedList <string, AccessRule>();

            foreach (KeyValuePair <string, IAclProvider> provider in GetConcernedProviders(resource))
            {
                foreach (AccessRule acl in provider.Value.GetAcls(provider.Key == AclManager.ROOT ? resource : resource.Substring(provider.Key.Length), verb))
                {
                    AccessRule computedAcl = null;
                    switch (acl.Type)
                    {
                    case AccessRules.Allow:
                        computedAcl = new Allow(acl.Resource == AclManager.ROOT ? provider.Key : provider.Key + acl.Resource, acl.Verb, acl.Subject);
                        break;

                    case AccessRules.Deny:
                        computedAcl = new Deny(acl.Resource == AclManager.ROOT ? provider.Key : provider.Key + acl.Resource, acl.Verb, acl.Subject);
                        break;
                    }
                    if (computedAcl != null)
                    {
                        acls.Add(computedAcl.Resource, computedAcl);
                    }
                }
            }
            return(acls);
        }
Beispiel #2
0
        private void tsSetDeny_Click(object sender, EventArgs e)
        {
            SelectionBase selection = (SelectionBase)grid1.Selection;
            var           region    = selection.GetSelectionRegion();

            foreach (var range in region)
            {
                for (int i = range.Start.Row; i <= range.End.Row; i++)
                {
                    string channel = grid1[i, 2].Value.ToString();
                    string item    = grid1[i, 3].Value.ToString();
                    if (!Deny.ContainsKey(channel))
                    {
                        Deny.Add(channel, new List <string>());
                    }
                    Deny[channel].Add(item);
                }
            }
            _Save();
            _ApplyAllowDeny();
            c_Summary.SetValue(m_Channels.Count);
            m_DenyForm.ResetItem();

            var sum = Deny.Sum(entry => entry.Value.Count);

            tsDeny.Text = sum == 0 ? string.Empty : $"[{sum}]";
        }
Beispiel #3
0
        private void tsDeny_Click(object sender, EventArgs e)
        {
            m_DenyForm.ShowDialog(this);
            _ApplyAllowDeny();
            var sum = Deny.Sum(entry => entry.Value.Count);

            tsDeny.Text = sum == 0 ? string.Empty : $"[{sum}]";
        }
Beispiel #4
0
 public DistributorRole ToDistributorRole()
 {
     return(new DistributorRole(
                Allow.Aggregate(Role.None, (aggregate, role) => aggregate | role),
                Deny.Aggregate(Role.None, (aggregate, role) => aggregate | role),
                IsAuthorizationRequired,
                FeedRoles?.ToDictionary(x => x.Key, x => x.Value.ToFeedRole(x.Key))));
 }
Beispiel #5
0
        private void _CreateDenyAllowForm()
        {
            m_DenyForm  = new frmDeny(m_Identity, Deny);
            m_AllowForm = new frmAllow(m_Identity, Allow);
            var dsum = Deny.Sum(entry => entry.Value.Count);

            tsDeny.Text = dsum == 0 ? string.Empty : $"[{dsum}]";
            var asum = Allow.Sum(entry => entry.Value.Count) + Allow.Count(entry => entry.Value == null || entry.Value.Count <= 0);

            tsAllow.Text = asum == 0 ? string.Empty : $"[{asum}]";
        }
Beispiel #6
0
 public FeedRole ToFeedRole(string feed)
 {
     return(new FeedRole(
                feed,
                Allow.Aggregate(Role.None, (aggregate, role) => aggregate | role),
                Deny.Aggregate(Role.None, (aggregate, role) => aggregate | role),
                IsAuthorized,
                IsImpersonationAllowed,
                IsProxyAllowed,
                InteractorRoles?.SelectMany(x => x.Value.Select(y => y.Value.ToInteractorRole(x.Key, y.Key)))?.ToList()));
 }
Beispiel #7
0
 private bool?GetBit(PermissionsBits pos)
 {
     if (Allow.GetBit(pos))
     {
         return(true);
     }
     else if (Deny.GetBit(pos))
     {
         return(false);
     }
     else
     {
         return(null);
     }
 }
Beispiel #8
0
        public bool HasRole(string host, string user, string feed, Role role, bool decision)
        {
            if (Allow.HasFlag(role))
                decision = true;

            if (Deny.HasFlag(role))
                decision = false;

            if (InteractorRoles.TryGetValue(new InteractorRole.Key(host, user), out var interactorRole))
                decision = interactorRole.HasRole(role, decision);
            else if (InteractorRoles.TryGetValue(new InteractorRole.Key("*", user), out interactorRole))
                decision = interactorRole.HasRole(role, decision);

            return decision;
        }
        public bool HasRole(string host, string user, string feed, Role role)
        {
            var decision = Allow.HasFlag(role);

            if (Deny.HasFlag(role))
            {
                decision = false;
            }

            if (FeedRoles.TryGetValue(feed, out var feedPermission))
            {
                decision = feedPermission.HasRole(host, user, feed, role, decision);
            }

            return(decision);
        }
        public bool HasRole(IPAddress address, string user, string feed, Role role)
        {
            var decision = Allow.HasFlag(role);

            if (Deny.HasFlag(role))
            {
                decision = false;
            }

            FeedRole feedPermission;

            if (FeedRoles.TryGetValue(feed, out feedPermission))
            {
                decision = feedPermission.HasRole(address, user, feed, role, decision);
            }

            return(decision);
        }
Beispiel #11
0
 private void SetBit(PermissionsBits pos, bool?value)
 {
     if (value == true)
     {
         Allow.SetBit(pos, true);
         Deny.SetBit(pos, false);
     }
     else if (value == false)
     {
         Allow.SetBit(pos, false);
         Deny.SetBit(pos, true);
     }
     else
     {
         Allow.SetBit(pos, false);
         Deny.SetBit(pos, false);
     }
 }
Beispiel #12
0
        private void OnValueUpdated(string channel, string item, string value)
        {
            string key = $"{channel}.{item}";

            if (Allow.Count > 0)
            {
                //if (!Allow.ContainsKey(channel) || !Allow[channel].Contains(item))
                if (!Allow.ContainsKey(channel) || (Allow[channel].Count > 0 && !Allow[channel].Contains(item)))
                {
                    return;
                }
            }
            if (Deny.ContainsKey(channel))
            {
                if (Deny[channel].Contains(item))
                {
                    return;
                }
            }
            ThreadPool.QueueUserWorkItem((state) =>
            {
                string k = state.ToString();
                try
                {
                    if (!m_Channels.ContainsKey(k))
                    {
                        ChannelInfo info = new ChannelInfo(this, int.Parse(tsInterval.Text), channel, item, value);
                        if (m_Channels.TryAdd(k, info))
                        {
                            _ContentCell(k);
                            c_Summary.SetValue(m_Channels.Count);
                        }
                    }
                    else
                    {
                        m_Channels[key].Value.SetValue(value);
                    }
                }
                catch (Exception) { }
            }, key);
        }
        public bool HasRole(IPAddress address, string user, string feed, Role role, bool decision)
        {
            if (Allow.HasFlag(role))
            {
                decision = true;
            }

            if (Deny.HasFlag(role))
            {
                decision = false;
            }

            InteractorRole interactorRole;

            if (InteractorRoles.TryGetValue(new InteractorRole.Key(address, user), out interactorRole))
            {
                decision = interactorRole.HasRole(role, decision);
            }

            return(decision);
        }
Beispiel #14
0
        private void _Save()
        {
            if (!frmMain.INI.Sections.ContainsSection(m_Identity))
            {
                frmMain.INI.Sections.AddSection(m_Identity);
            }
            var sec = frmMain.INI.Sections[m_Identity];

            if (!sec.ContainsKey("IP"))
            {
                sec.AddKey("IP");
            }
            if (!sec.ContainsKey("PORT"))
            {
                sec.AddKey("PORT");
            }
            if (!sec.ContainsKey("INTERVAL"))
            {
                sec.AddKey("INTERVAL");
            }
            if (!sec.ContainsKey("DENY"))
            {
                sec.AddKey("DENY");
            }
            if (!sec.ContainsKey("ALLOW"))
            {
                sec.AddKey("ALLOW");
            }
            sec["IP"]       = IP;
            sec["PORT"]     = Port;
            sec["INTERVAL"] = Interval;
            sec["DENY"]     = Deny.SectionString();
            sec["ALLOW"]    = Allow.SectionString();

            var parser = new FileIniDataParser();

            parser.WriteFile("Config.ini", frmMain.INI);
        }
Beispiel #15
0
        private void _ApplyAllowDeny()
        {
            _ClearCell();
            lock (m_Channels)
            {
                for (int i = m_Channels.Count - 1; i >= 0; i--)
                {
                    string[] items = m_Channels.ElementAt(i).Key.Split('.');
                    if (Allow.Count > 0)
                    {
                        if (!Allow.ContainsKey(items[0]) || (Allow[items[0]].Count > 0 && !Allow[items[0]].Contains(items[1])))
                        {
                            ChannelInfo ci;
                            m_Channels.TryRemove(m_Channels.ElementAt(i).Key, out ci);
                            ci.Dispose();
                            continue;
                        }
                    }

                    if (Deny.ContainsKey(items[0]))
                    {
                        if (Deny[items[0]].Contains(items[1]))
                        {
                            ChannelInfo ci;
                            m_Channels.TryRemove(m_Channels.ElementAt(i).Key, out ci); ci.Dispose();
                        }
                    }
                }
            }
            _HeaderCell();
            foreach (var channel in m_Channels.Keys)
            {
                _ContentCell(channel);
            }
            grid1.AutoSizeCells();
            _Sort();
        }
        /// <summary>
        /// Check if the string looks a dialog line
        /// </summary>
        /// <param name="Str">The String</param>
        /// <param name="Trim">Internal Parameter, don't change it.</param>
        /// <returns>If looks a dialog, return true, else return false.</returns>
        public static bool IsDialog(this string String)
        {
            if (string.IsNullOrWhiteSpace(String))
            {
                return(false);
            }

            if (UseDatabase && ContainsKey(String))
            {
                return(true);
            }

            if (!DialogCheck)
            {
                return(true);
            }

            string Str = String.Trim();

            if (ForceTrim)
            {
                Str = TrimString(Str, true);
            }

            foreach (string Ignore in IgnoreList)
            {
                if (!string.IsNullOrEmpty(Ignore))
                {
                    Str = Str.Replace(Ignore, "");
                }
            }

            foreach (string Deny in DenyList)
            {
                if (!string.IsNullOrEmpty(Deny) && Str.ToLower().Contains(Deny.ToLower()))
                {
                    return(false);
                }
            }


            Str = Str.Replace(GameLineBreaker, "\n");

            if (string.IsNullOrWhiteSpace(Str))
            {
                return(false);
            }

            string[] Words = Str.Split(' ');

            char[] PontuationJapList = new char[] { '。', '?', '!', '…', '、', '―' };
            char[] SpecialList       = new char[] { '_', '=', '+', '#', ':', '$', '@' };
            char[] PontuationList    = new char[] { '.', '?', '!', '…', ',' };
            int    Spaces            = Str.Where(x => x == ' ' || x == '\t').Count();
            int    Pontuations       = Str.Where(x => PontuationList.Contains(x)).Count();
            int    WordCount         = Words.Where(x => x.Length >= 2 && !string.IsNullOrWhiteSpace(x)).Count();
            int    Specials          = Str.Where(x => char.IsSymbol(x)).Count();

            Specials += Str.Where(x => char.IsPunctuation(x)).Count() - Pontuations;
            int SpecialsStranges = Str.Where(x => SpecialList.Contains(x)).Count();

            int Uppers     = Str.Where(x => char.IsUpper(x)).Count();
            int Latim      = Str.Where(x => x >= 'A' && x <= 'z').Count();
            int Numbers    = Str.Where(x => x >= '0' && x <= '9').Count();
            int NumbersJap = Str.Where(x => x >= '0' && x <= '9').Count();
            int JapChars   = Str.Where(x => (x >= '、' && x <= 'ヿ') || (x >= '。' && x <= 'ン')).Count();
            int Kanjis     = Str.Where(x => x >= '一' && x <= '龯').Count();


            bool IsCaps = GetLineCase(Str) == Case.Upper;
            bool IsJap  = JapChars + Kanjis > Latim / 2;


            //More Points = Don't Looks a Dialogue
            //Less Points = Looks a Dialogue
            int Points = 0;

            if (Str.Length > 4)
            {
                string ext = Str.Substring(Str.Length - 4, 4);
                try {
                    if (System.IO.Path.GetExtension(ext).Trim('.').Length == 3)
                    {
                        Points += 2;
                    }
                } catch { }
            }

            bool  BeginQuote = false;
            Quote?LineQuotes = null;

            foreach (Quote Quote in QuoteList)
            {
                BeginQuote |= Str.StartsWith(Quote.Start.ToString());

                if (Str.StartsWith(Quote.Start.ToString()) && Str.EndsWith(Quote.End.ToString()))
                {
                    Points    -= 3;
                    LineQuotes = Quote;
                    break;
                }
                else if (Str.StartsWith(Quote.Start.ToString()) || Str.EndsWith(Quote.End.ToString()))
                {
                    Points--;
                    LineQuotes = Quote;
                    break;
                }
            }
            try {
                char Last = (LineQuotes == null ? Str.Last() : Str.TrimEnd(LineQuotes.Value.End).Last());
                if (IsJap && PontuationJapList.Contains(Last))
                {
                    Points -= 3;
                }

                if (!IsJap && (PontuationList).Contains(Last))
                {
                    Points -= 3;
                }
            } catch { }
            try {
                char First = (LineQuotes == null ? Str.First() : Str.TrimEnd(LineQuotes.Value.Start).First());
                if (IsJap && PontuationJapList.Contains(First))
                {
                    Points -= 3;
                }

                if (!IsJap && (PontuationList).Contains(First))
                {
                    Points -= 3;
                }
            } catch { }

            if (!IsJap)
            {
                foreach (string Word in Words)
                {
                    int WNumbers = Word.Where(c => char.IsNumber(c)).Count();
                    int WLetters = Word.Where(c => char.IsLetter(c)).Count();
                    if (WLetters > 0 && WNumbers > 0)
                    {
                        Points += 2;
                    }
                    if (Word.Trim(PontuationList).Where(c => PontuationList.Contains(c)).Count() != 0)
                    {
                        Points += 2;
                    }
                }
            }

            if (!BeginQuote && !char.IsLetter(Str.First()))
            {
                Points += 2;
            }

            if (Specials > WordCount)
            {
                Points++;
            }

            if (Specials > Latim + JapChars)
            {
                Points += 2;
            }

            if (SpecialsStranges > 0)
            {
                Points += 2;
            }

            if (SpecialsStranges > 3)
            {
                Points++;
            }

            if ((Pontuations == 0) && (WordCount <= 2) && !IsJap)
            {
                Points++;
            }

            if (Uppers > Pontuations + 2 && !IsCaps)
            {
                Points++;
            }

            if (Spaces > WordCount * 2)
            {
                Points++;
            }

            if (IsJap && Spaces == 0)
            {
                Points--;
            }

            if (!IsJap && Spaces == 0)
            {
                Points += 2;
            }

            if (WordCount <= 2 && Numbers != 0)
            {
                Points += (int)(Str.PercentOf(Numbers) / 10);
            }

            if (Str.Length <= 3 && !IsJap)
            {
                Points++;
            }

            if (Numbers >= Str.Length)
            {
                Points += 3;
            }

            if (IsJap && Kanjis / 2 > JapChars)
            {
                Points--;
            }

            if (IsJap && JapChars > Kanjis)
            {
                Points--;
            }

            if (IsJap && Latim != 0)
            {
                Points += (int)(Str.PercentOf(Latim) / 10) + 2;
            }

            if (IsJap && NumbersJap != 0)
            {
                Points += (int)(Str.PercentOf(NumbersJap) / 10) + 2;
            }

            if (IsJap && Numbers != 0)
            {
                Points += (int)(Str.PercentOf(Numbers) / 10) + 3;
            }

            if (IsJap && Pontuations != 0)
            {
                Points += (int)(Str.PercentOf(Pontuations) / 10) + 2;
            }

            if (Str.Trim() == string.Empty)
            {
                return(false);
            }

            if (Str.Trim().Trim(Str.Trim().First()) == string.Empty)
            {
                Points += 2;
            }

            if (IsJap != AsianInput)
            {
                return(false);
            }

            bool Result = Points < Sensitivity;

            return(Result);
        }
Beispiel #17
0
        public static bool IsDialogue(this string String, int? Caution = null) {
            try {
                if (string.IsNullOrWhiteSpace(String))
                    return false;

                if (Program.ForceDialogues.ContainsKey(String))
                    return Program.ForceDialogues[String];

                if (Program.FilterSettings.UseDB && Program.Cache.ContainsKey(String))
                    return true;


                string[] DenyList = Program.FilterSettings.DenyList.Unescape().Split('\n').Where(x => !string.IsNullOrEmpty(x)).ToArray();
                string[] IgnoreList = Program.FilterSettings.IgnoreList.Unescape().Split('\n').Where(x => !string.IsNullOrEmpty(x)).ToArray();

                Quote[] Quotes = Program.FilterSettings.QuoteList.Unescape().Split('\n')
                    .Where(x => x.Length == 2)
                    .Select(x => {
                        return new Quote() { Start = x[0], End = x[1] };
                    }).ToArray();

                string Str = String.Trim();
                foreach (string Ignore in IgnoreList)
                    Str = Str.Replace(Ignore, "");

                if (!VerifingDialog)
                    foreach (var Otimizator in Program.ExternalPlugins) {
                        try {
                            Otimizator.BeforeTranslate(ref Str, uint.MaxValue);
                        } catch { }
                    }

                VerifingDialog = true;
                foreach (string Deny in DenyList)
                    if (Str.ToLower().Contains(Deny.ToLower())) {
                        VerifingDialog = false;
                        return false;
                    }

                Str = Str.Replace(Program.WordwrapSettings.LineBreaker, "\n");


                if (string.IsNullOrWhiteSpace(Str))
                    return false;

                string[] Words = Str.Split(' ');

                char[] PontuationJapList = new char[] { '。', '?', '!', '…', '、', '―' };
                char[] SpecialList = new char[] { '_', '=', '+', '#', ':', '$', '@' };
                char[] PontuationList = new char[] { '.', '?', '!', '…', ',' };
                int Spaces = Str.Where(x => x == ' ' || x == '\t').Count();
                int Pontuations = Str.Where(x => PontuationList.Contains(x)).Count();
                int WordCount = Words.Where(x => x.Length >= 2 && !string.IsNullOrWhiteSpace(x)).Count();
                int Specials = Str.Where(x => char.IsSymbol(x)).Count();
                Specials += Str.Where(x => char.IsPunctuation(x)).Count() - Pontuations;
                int SpecialsStranges = Str.Where(x => SpecialList.Contains(x)).Count();

                int Uppers = Str.Where(x => char.IsUpper(x)).Count();
                int Latim = Str.Where(x => x >= 'A' && x <= 'z').Count();
                int Numbers = Str.Where(x => x >= '0' && x <= '9').Count();
                int NumbersJap = Str.Where(x => x >= '0' && x <= '9').Count();
                int JapChars = Str.Where(x => (x >= '、' && x <= 'ヿ') || (x >= '。' && x <= 'ン')).Count();
                int Kanjis = Str.Where(x => x >= '一' && x <= '龯').Count();


                bool IsCaps = Optimizator.CaseFixer.GetLineCase(Str) == Optimizator.CaseFixer.Case.Upper;
                bool IsJap = JapChars + Kanjis > Latim / 2;


                //More Points = Don't Looks a Dialogue
                //Less Points = Looks a Dialogue
                int Points = 0;

                if (Str.Length > 4) {
                    string ext = Str.Substring(Str.Length - 4, 4);
                    try {
                        if (System.IO.Path.GetExtension(ext).Trim('.').Length == 3)
                            Points += 2;
                    } catch { }
                }

                bool BeginQuote = false;
                Quote? LineQuotes = null;
                foreach (Quote Quote in Quotes) {
                    BeginQuote |= Str.StartsWith(Quote.Start.ToString());

                    if (Str.StartsWith(Quote.Start.ToString()) && Str.EndsWith(Quote.End.ToString())) {
                        Points -= 3;
                        LineQuotes = Quote;
                        break;
                    } else if (Str.StartsWith(Quote.Start.ToString()) || Str.EndsWith(Quote.End.ToString())) {
                        Points--;
                        LineQuotes = Quote;
                        break;
                    }
                }
                try {
                    char Last = (LineQuotes == null ? Str.Last() : Str.TrimEnd(LineQuotes?.End ?? ' ').Last());
                    if (IsJap && PontuationJapList.Contains(Last))
                        Points -= 3;

                    if (!IsJap && (PontuationList).Contains(Last))
                        Points -= 3;

                } catch { }
                try {
                    char First = (LineQuotes == null ? Str.First() : Str.TrimEnd(LineQuotes?.Start ?? ' ').First());
                    if (IsJap && PontuationJapList.Contains(First))
                        Points -= 3;

                    if (!IsJap && (PontuationList).Contains(First))
                        Points -= 3;

                } catch { }

                if (!IsJap) {
                    foreach (string Word in Words) {
                        int WNumbers = Word.Where(c => char.IsNumber(c)).Count();
                        int WLetters = Word.Where(c => char.IsLetter(c)).Count();
                        if (WLetters > 0 && WNumbers > 0) {
                            Points += 2;
                        }
                        if (Word.Trim(PontuationList).Where(c => PontuationList.Contains(c)).Count() != 0) {
                            Points += 2;
                        }
                    }
                }

                if (!BeginQuote && !char.IsLetter(Str.First()))
                    Points += 2;

                if (Specials > WordCount)
                    Points++;

                if (Specials > Latim + JapChars)
                    Points += 2;

                if (SpecialsStranges > 0)
                    Points += 2;

                if (SpecialsStranges > 3)
                    Points++;

                if ((Pontuations == 0) && (WordCount <= 2) && !IsJap)
                    Points++;

                if (Uppers > Pontuations + 2 && !IsCaps)
                    Points++;

                if (Spaces > WordCount * 2)
                    Points++;

                if (IsJap && Spaces == 0)
                    Points--;

                if (!IsJap && Spaces == 0)
                    Points += 2;

                if (WordCount <= 2 && Numbers != 0)
                    Points += (int)(Str.PercentOf(Numbers) / 10);

                if (Str.Length <= 3 && !IsJap)
                    Points++;

                if (Numbers >= Str.Length)
                    Points += 3;

                if (!IsJap && WordCount == 1 && char.IsUpper(Str.First()) && !char.IsPunctuation(Str.TrimEnd().Last()))
                    Points++;

                if (!IsJap && WordCount == 1 && !char.IsUpper(Str.First()))
                    Points++;

                if (Words.Where(x => x.Where(y => char.IsUpper(y)).Count() > 1
                                  && x.Where(y => char.IsLower(y)).Count() > 1).Any())
                    Points += 2;

                if (!IsJap && char.IsUpper(Str.TrimStart().First()) && char.IsPunctuation(Str.TrimEnd().Last()))
                    Points--;

                if (!char.IsPunctuation(Str.TrimEnd().Last()))
                    Points++;

                if (IsJap && Kanjis / 2 > JapChars)
                    Points--;

                if (IsJap && JapChars > Kanjis)
                    Points--;

                if (IsJap && Latim != 0)
                    Points += (int)(Str.PercentOf(Latim) / 10) + 2;

                if (IsJap && NumbersJap != 0)
                    Points += (int)(Str.PercentOf(NumbersJap) / 10) + 2;

                if (IsJap && Numbers != 0)
                    Points += (int)(Str.PercentOf(Numbers) / 10) + 3;

                if (IsJap && Pontuations != 0)
                    Points += (int)(Str.PercentOf(Pontuations) / 10) + 2;

                if (Str.Trim() == string.Empty)
                    return false;

                if (Str.Trim().Trim(Str.Trim().First()) == string.Empty)
                    Points += 2;

                if (IsJap != Program.FromAsian)
                    return false;

                VerifingDialog = false;
                bool Result = Points < (Caution ?? Program.FilterSettings.Sensitivity);
                return Result;
            } catch (Exception ex){
#if DEBUG
                throw ex;
#else
                return false;
#endif
            }
        }
Beispiel #18
0
        public bool IsDialogue(string String, int?Caution = null, bool UseAcceptableRange = true)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(String))
                {
                    return(false);
                }

                string Str = String.Trim();
                Str = Str.Replace(Breakline, "\n");

                foreach (string Ignore in IgnoreList)
                {
                    Str = Str.Replace(Ignore, "");
                }

                foreach (string Deny in DenyList)
                {
                    if (Str.ToLower().Contains(Deny.ToLower()))
                    {
                        return(false);
                    }
                }

                if (string.IsNullOrWhiteSpace(Str))
                {
                    return(false);
                }

                if (UseAcceptableRange && CharacterRanges.TotalMissmatch(Str, AcceptableRanges) > 0)
                {
                    return(false);
                }

                string[] Words = Str.Split(' ');

                int Spaces      = Str.Where(x => x == ' ' || x == '\t').Count();
                int Pontuations = Str.Where(x => PontuationList.Contains(x)).Count();
                int WordCount   = Words.Where(x => x.Length >= 2 && !string.IsNullOrWhiteSpace(x)).Count();
                int Specials    = Str.Where(x => char.IsSymbol(x)).Count();
                Specials += Str.Where(x => char.IsPunctuation(x)).Count() - Pontuations;
                int SpecialsStranges = Str.Where(x => SpecialList.Contains(x)).Count();

                int Uppers     = Str.Where(x => char.IsUpper(x)).Count();
                int Latim      = Str.Where(x => x >= 'A' && x <= 'z').Count();
                int Numbers    = Str.Where(x => x >= '0' && x <= '9').Count();
                int NumbersJap = Str.Where(x => x >= '0' && x <= '9').Count();
                int JapChars   = Str.Where(x => (x >= '、' && x <= 'ヿ') || (x >= '。' && x <= 'ン')).Count();
                int Kanjis     = Str.Where(x => x >= '一' && x <= '龯').Count();


                bool IsCaps = Str.ToUpper() == Str;
                bool IsJap  = JapChars + Kanjis > Latim / 2;


                //More Points = Don't Looks a Dialogue
                //Less Points = Looks a Dialogue
                int Points = 0;

                if (Str.Length > 4)
                {
                    string ext = Str.Substring(Str.Length - 4, 4);
                    try
                    {
                        if (System.IO.Path.GetExtension(ext).Trim('.').Length == 3)
                        {
                            Points += 2;
                        }
                    }
                    catch { }
                }

                bool  BeginQuote = false;
                Quote?LineQuotes = null;
                foreach (Quote Quote in Quotes)
                {
                    BeginQuote |= Str.StartsWith(Quote.Start.ToString());

                    if (Str.StartsWith(Quote.Start.ToString()) && Str.EndsWith(Quote.End.ToString()))
                    {
                        Points    -= 3;
                        LineQuotes = Quote;
                        break;
                    }
                    else if (Str.StartsWith(Quote.Start.ToString()) || Str.EndsWith(Quote.End.ToString()))
                    {
                        Points--;
                        LineQuotes = Quote;
                        break;
                    }
                }
                try
                {
                    char Last = (LineQuotes == null ? Str.Last() : Str.TrimEnd(LineQuotes.Value.End).Last());
                    if (IsJap && PontuationJapList.Contains(Last))
                    {
                        Points -= 3;
                    }

                    if (!IsJap && (PontuationList).Contains(Last))
                    {
                        Points -= 3;
                    }
                }
                catch { }
                try
                {
                    char First = (LineQuotes == null ? Str.First() : Str.TrimEnd(LineQuotes.Value.Start).First());
                    if (IsJap && PontuationJapList.Contains(First))
                    {
                        Points -= 3;
                    }

                    if (!IsJap && (PontuationList).Contains(First))
                    {
                        Points -= 3;
                    }
                }
                catch { }

                if (!IsJap)
                {
                    foreach (string Word in Words)
                    {
                        int WNumbers = Word.Where(c => char.IsNumber(c)).Count();
                        int WLetters = Word.Where(c => char.IsLetter(c)).Count();
                        if (WLetters > 0 && WNumbers > 0)
                        {
                            Points += 2;
                        }
                        if (Word.Trim(PontuationList).Where(c => PontuationList.Contains(c)).Count() != 0)
                        {
                            Points += 2;
                        }
                    }
                }

                if (!BeginQuote && !char.IsLetter(Str.First()))
                {
                    Points += 2;
                }

                if (Specials > WordCount)
                {
                    Points++;
                }

                if (Specials > Latim + JapChars)
                {
                    Points += 2;
                }

                if (SpecialsStranges > 0)
                {
                    Points += 2;
                }

                if (SpecialsStranges > 3)
                {
                    Points++;
                }

                if ((Pontuations == 0) && (WordCount <= 2) && !IsJap)
                {
                    Points++;
                }

                if (Uppers > Pontuations + 2 && !IsCaps)
                {
                    Points++;
                }

                if (Spaces > WordCount * 2)
                {
                    Points++;
                }

                if (Uppers > Spaces + 1 && !IsCaps)
                {
                    Points++;
                }

                if (IsJap && Spaces == 0)
                {
                    Points--;
                }

                if (!IsJap && Spaces == 0)
                {
                    Points += 2;
                }

                if (WordCount <= 2 && Numbers != 0 && !AllowNumbers)
                {
                    Points += (int)(PercentOf(Str, Numbers) / 10);
                }

                if (Str.Length <= 3 && !IsJap)
                {
                    Points++;
                }

                if (Numbers >= (IsJap ? Kanjis + JapChars : Latim))
                {
                    Points += 3;
                }

                if (IsJap && Kanjis / 2 > JapChars)
                {
                    Points--;
                }

                if (IsJap && JapChars > Kanjis)
                {
                    Points--;
                }

                if (IsJap && Latim != 0)
                {
                    Points += (int)(PercentOf(Str, Latim) / 10) + 2;
                }

                if (IsJap && NumbersJap != 0)
                {
                    Points += (int)(PercentOf(Str, NumbersJap) / 10) + 2;
                }

                if (IsJap && Numbers != 0)
                {
                    Points += (int)(PercentOf(Str, Numbers) / 10) + 3;
                }

                if (IsJap && Pontuations != 0)
                {
                    Points += (int)(PercentOf(Str, Pontuations) / 10) + 2;
                }

                if (Str.Trim() == string.Empty)
                {
                    return(false);
                }

                if (Str.Trim().Trim(Str.Trim().First()) == string.Empty)
                {
                    Points += 2;
                }

                if (IsJap != FromAsian)
                {
                    return(false);
                }

                bool Result = Points < (Caution ?? Sensitivity);
                return(Result);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(false);
            }
        }
Beispiel #19
0
 public void Init()
 {
     instance = new Deny();
 }
Beispiel #20
0
 public void Init()
 {
     instance = new Deny();
 }
Beispiel #21
0
 public override int GetHashCode() => unchecked (Allow.GetHashCode() + Deny.GetHashCode() + 1724);
Beispiel #22
0
 internal void Lock()
 {
     Allow.Lock();
     Deny.Lock();
 }