コード例 #1
0
        public async Task <bool> InsertNewOne(string host)
        {
            (bool isSubnet, int mask, string ip) = NetworkUtility.Deconstruct(host);

            await using (var command = new NpgsqlCommand("select * from register(@mask, '@ip', @subnet)", _connection))
            {
                command.Parameters.AddWithValue("mask", mask);
                command.Parameters.AddWithValue("ip", ip);
                command.Parameters.AddWithValue("subnet", isSubnet);

                return((await command.ExecuteScalarAsync()).ToString() != UUID_NIL);
            }
        }
コード例 #2
0
        public async Task <bool> AttachPolicy(string host, string wildcard)
        {
            (_, int mask, string ip) = NetworkUtility.Deconstruct(host);

            await using (var command = new NpgsqlCommand("select * from register_rule_on_host(@mask, '@ip', '@wildcard')",
                                                         _connection))
            {
                command.Parameters.AddWithValue("mask", mask);
                command.Parameters.AddWithValue("ip", ip);
                command.Parameters.AddWithValue("wildcard", wildcard);

                return(bool.Parse((await command.ExecuteScalarAsync())?.ToString()?.ToLower()
                                  ?? throw new InvalidOperationException()));
            }
        }