Пример #1
0
        static Rule()
        {
            foreach (NameType s in Enum.GetValues(typeof(NameType)))
            {
                IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > rts =
                    new Dictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > >();

                foreach (RuleType rt in Enum.GetValues(typeof(RuleType)))
                {
                    IDictionary <string, IDictionary <string, IList <Rule> > > rs = new Dictionary <string, IDictionary <string, IList <Rule> > >();

                    Languages ls = Languages.GetInstance(s);
                    foreach (string l in ls.GetLanguages())
                    {
                        try
                        {
                            rs[l] = ParseRules(CreateScanner(s, rt, l), CreateResourceName(s, rt, l));
                        }
                        catch (InvalidOperationException e)
                        {
                            throw new InvalidOperationException("Problem processing " + CreateResourceName(s, rt, l), e);
                        }
                    }
                    if (!rt.Equals(RuleType.RULES))
                    {
                        rs["common"] = ParseRules(CreateScanner(s, rt, "common"), CreateResourceName(s, rt, "common"));
                    }

                    rts[rt] = Collections.UnmodifiableMap(rs);
                }

                RULES[s] = Collections.UnmodifiableMap(rts);
            }
        }
Пример #2
0
        private static IDictionary <NameType, IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > > LoadRules() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
        {
            var rules = new Dictionary <NameType, IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > >();

            foreach (NameType s in Enum.GetValues(typeof(NameType)))
            {
                IDictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > > rts =
                    new Dictionary <RuleType, IDictionary <string, IDictionary <string, IList <Rule> > > >();

                foreach (RuleType rt in Enum.GetValues(typeof(RuleType)))
                {
                    IDictionary <string, IDictionary <string, IList <Rule> > > rs = new Dictionary <string, IDictionary <string, IList <Rule> > >();

                    Languages ls = Languages.GetInstance(s);
                    foreach (string l in ls.GetLanguages())
                    {
                        try
                        {
                            rs[l] = ParseRules(CreateScanner(s, rt, l), CreateResourceName(s, rt, l));
                        }
                        catch (Exception e) when(e.IsIllegalStateException())
                        {
                            throw new InvalidOperationException("Problem processing " + CreateResourceName(s, rt, l), e);
                        }
                    }
                    if (!rt.Equals(RuleType.RULES))
                    {
                        rs["common"] = ParseRules(CreateScanner(s, rt, "common"), CreateResourceName(s, rt, "common"));
                    }

                    rts[rt] = rs.AsReadOnly();
                }

                rules[s] = rts.AsReadOnly();
            }
            return(rules);
        }