Exemple #1
0
        public async Task <(int bulkwalkResult, IList <Variable> results)> GetSubtreeV3TsmAsync(IPAddress ip, string oid, int port, int?maxRepetitions,
                                                                                                int?retries, TimeSpan?timeout, X509Certificate2 certificate, TimeSpan?connectionTimeout)
        {
            if (ip == null)
            {
                throw new ArgumentNullException(nameof(ip));
            }

            if (string.IsNullOrWhiteSpace(oid))
            {
                throw new ArgumentNullException(nameof(oid));
            }

            if (!Regex.IsMatch(oid, @"^(([0-9]+)\.)+[0-9]+$"))
            {
                throw new ArgumentException(oid, nameof(oid));
            }

            if (port <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(port), port.ToString());
            }

            var maxRepetitionsValue = maxRepetitions ?? 10;

            if (maxRepetitionsValue <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxRepetitions), maxRepetitions.ToString());
            }

            var retriesValue = retries ?? 2;

            if (retriesValue <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(retries), retries.ToString());
            }

            var timeoutMs = timeout ?? TimeSpan.FromSeconds(5);

            if (timeoutMs <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(timeout), timeout.ToString());
            }

            var connTimeout = connectionTimeout ?? TimeSpan.FromSeconds(2);

            if (connTimeout <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(connectionTimeout));
            }

            if (certificate is null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }

            var auth = TsmAuthenticationProvider.Instance;
            var priv = new TsmPrivacyProvider(auth);

            var results        = new List <Variable>();
            var bulkwalkResult = await MyMessenger.BulkWalkV3TsmAsync(
                new IPEndPoint(ip, port),
                new ObjectIdentifier(oid),
                results,
                maxRepetitionsValue,
                retriesValue,
                timeoutMs,
                WalkMode.WithinSubtree,
                priv,
                null,
                certificate,
                connTimeout
                ).ConfigureAwait(false);

            return(bulkwalkResult, results);
        }