• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lextudio / sharpsnmplib / 11823966615

13 Nov 2024 06:58PM UTC coverage: 49.626% (-3.4%) from 53.042%
11823966615

push

github

lextm
Removed .NET 6.

819 of 1881 branches covered (43.54%)

Branch coverage included in aggregate %.

2232 of 4267 relevant lines covered (52.31%)

15136.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.5
/SharpSnmpLib/Messaging/NumberGenerator.cs
1
// PDU counter class.
2
// Copyright (C) 2008-2010 Malcolm Crowe, Lex Li, and other contributors.
3
// 
4
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5
// software and associated documentation files (the "Software"), to deal in the Software
6
// without restriction, including without limitation the rights to use, copy, modify, merge,
7
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8
// to whom the Software is furnished to do so, subject to the following conditions:
9
// 
10
// The above copyright notice and this permission notice shall be included in all copies or
11
// substantial portions of the Software.
12
// 
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
// DEALINGS IN THE SOFTWARE.
19

20
using System;
21

22
namespace Lextm.SharpSnmpLib.Messaging
23
{
24
    /// <summary>
25
    /// A counter that generates ID.
26
    /// </summary>
27
    /// <remarks>The request ID is used to identifier sessions.</remarks>
28
    public sealed class NumberGenerator
29
    {
30
        /// <summary>
31
        /// Initializes a new instance of the <see cref="NumberGenerator"/> class.
32
        /// </summary>
33
        /// <param name="min">The min.</param>
34
        /// <param name="max">The max.</param>
35
        public NumberGenerator(int min, int max)
1✔
36
        {
37
            _min = min;
1✔
38
            _max = max;
1✔
39
            _salt = new Random().Next(_min, _max);
1✔
40
        }
1✔
41

42
        /// <summary>
43
        /// Returns next ID. This method is thread-safe within this instance of NumberGenerator.
44
        /// </summary>
45
        public int NextId
46
        {
47
            get
48
            {
49
                lock (_root)
×
50
                {
51
                    if (_salt == _max)
×
52
                    {
53
                        _salt = _min;
×
54
                    }
55
                    else
56
                    {
57
                        _salt++;
×
58
                    }
59
                    return _salt;
×
60
                }
61
            }
×
62
        }
63

64
        private readonly object _root = new();
1✔
65
        private int _salt;
66
        private readonly int _min;
67
        private readonly int _max;
68

69
        internal void SetSalt(int value)
70
        {
71
            _salt = value;
×
72
        }
×
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc