コード例 #1
0
        private static NetworkACLConfig ParseACL(IConfiguration config, string section)
        {
            var acl = new NetworkACLConfig();

            var v = config?.GetSection(section);

            acl.Path = ParseString(v, "path");
            acl.Type = ParseEnum(v, "type", NetworkACLConfig.ACLType.None);

            return(acl);
        }
コード例 #2
0
        /// <summary>
        /// Initiate the ACL
        /// </summary>
        /// <param name="cfg">Config</param>
        public void Load(NetworkACLConfig cfg)
        {
            if (cfg == null)
            {
                return;
            }

            Type = cfg.Type;

            if (!string.IsNullOrEmpty(cfg.Path) && File.Exists(cfg.Path))
            {
                string  json = File.ReadAllText(cfg.Path);
                JObject jo   = JObject.Parse(json);

                if (!(jo is JArray array))
                {
                    return;
                }

                Entries = new Entry[array.Count];

                for (int x = 0, m = array.Count; x < m; x++)
                {
                    JObject j = array[x];
                    if (!j.ContainsProperty("value"))
                    {
                        continue;
                    }

                    string value = j.Properties["value"].AsString();

                    if (j.ContainsProperty("regex") && j.Properties["regex"].AsBooleanOrDefault(false))
                    {
                        Entries[x] = new RegexEntry(value);
                    }
                    else
                    {
                        Entries[x] = new Entry(value);
                    }
                }
            }
        }