Skip to content

Commit 06981a0

Browse files
authored
Merge pull request #33 from nutdotnet/battruntime
Runtime calculation enabled, and extensive refactoring and changes
2 parents 2262ef1 + 87b6515 commit 06981a0

File tree

6 files changed

+378
-430
lines changed

6 files changed

+378
-430
lines changed

WinNUT_V2/WinNUT-Client_Common/Common_Classes.vb

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,70 @@ Public Class UPS_Values
2323
Public UPS_Status As Integer = Nothing
2424
End Class
2525

26-
Public Class UPS_Datas
27-
Public Name As String = ""
28-
Public Mfr As String = ""
29-
Public Model As String = ""
30-
Public Serial As String = ""
31-
Public Firmware As String = ""
26+
Public Class UPSData
27+
Public ReadOnly Mfr As String
28+
Public ReadOnly Model As String
29+
Public ReadOnly Serial As String
30+
Public ReadOnly Firmware As String
3231
Public UPS_Value As New UPS_Values
33-
End Class
3432

35-
Public Class Nut_Exception
36-
Inherits System.ApplicationException
33+
Public Sub New(Mfr As String, Model As String, Serial As String, Firmware As String)
34+
Me.Mfr = Mfr
35+
Me.Model = Model
36+
Me.Serial = Serial
37+
Me.Firmware = Firmware
38+
End Sub
3739

38-
Public Property ExceptionValue As Nut_Exception_Value
39-
Public Property ProtocolError As NUTResponse
40+
End Class
4041

41-
Public Sub New(ByVal Nut_Error_Lvl As Nut_Exception_Value)
42-
MyBase.New(StringEnum.GetStringValue(Nut_Error_Lvl))
43-
End Sub
42+
''' <summary>
43+
''' Encapsulates a query and response between a NUT client and server.
44+
''' </summary>
45+
Public Class Transaction
46+
''' <summary>
47+
''' The original query sent by the client, to the server.
48+
''' </summary>
49+
''' <returns></returns>
50+
Public ReadOnly Property Query As String
51+
''' <summary>
52+
''' See <see cref="NUTResponse"/>
53+
''' </summary>
54+
''' <returns></returns>
55+
Public ReadOnly Property ResponseType As NUTResponse
56+
''' <summary>
57+
''' The full, unaltered response from the server.
58+
''' </summary>
59+
''' <returns></returns>
60+
Public ReadOnly Property RawResponse As String
4461

45-
Public Sub New(ByVal Nut_Error_Lvl As Nut_Exception_Value, ByVal Message As String, Optional innerEx As Exception = Nothing)
46-
MyBase.New(StringEnum.GetStringValue(Nut_Error_Lvl) & Message, innerEx)
47-
ExceptionValue = Nut_Error_Lvl
62+
Public Sub New(query As String, rawResponse As String, responseType As NUTResponse)
63+
Me.Query = query
64+
Me.RawResponse = rawResponse
65+
Me.ResponseType = responseType
4866
End Sub
67+
End Class
68+
69+
Public Class NutException
70+
Inherits ApplicationException
71+
72+
Public ReadOnly Property LastTransaction As Transaction
4973

5074
''' <summary>
51-
''' Raise a Nut_Exception that resulted from an error as part of the NUT protocol.
75+
''' Raise a NutException that resulted from either an error as part of the NUT protocol, or a general error during
76+
''' the query.
5277
''' </summary>
5378
''' <param name="protocolError"></param>
54-
''' <param name="message"></param>
55-
Public Sub New(protocolError As NUTResponse, message As String)
56-
MyBase.New(message)
57-
Me.ProtocolError = protocolError
79+
''' <param name="queryResponse"></param>
80+
Public Sub New(query As String, protocolError As NUTResponse, queryResponse As String,
81+
Optional innerException As Exception = Nothing)
82+
MyBase.New(Nothing, innerException)
83+
LastTransaction = New Transaction(query, queryResponse, protocolError)
84+
End Sub
85+
86+
Public Sub New(transaction As Transaction)
87+
MyBase.New(String.Format("{0} ({1})" & vbNewLine & "Query: {2}", transaction.ResponseType,
88+
transaction.RawResponse, transaction.Query))
89+
LastTransaction = transaction
5890
End Sub
5991
End Class
6092

WinNUT_V2/WinNUT-Client_Common/Common_Enums.vb

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ End Enum
6969

7070
' Define possible responses according to NUT protcol v1.2
7171
Public Enum NUTResponse
72+
NORESPONSE
7273
OK
7374
VAR
7475
ACCESSDENIED
@@ -94,32 +95,10 @@ Public Enum NUTResponse
9495
PASSWORDREQUIRED
9596
UNKNOWNCOMMAND
9697
INVALIDVALUE
97-
NORESPONSE
9898
BEGINLIST
9999
ENDLIST
100100
End Enum
101101

102-
Public Enum Nut_Exception_Value
103-
<StringValue("Unable to create connection: ")>
104-
CONNECT_ERROR
105-
<StringValue("Invalid Username.")>
106-
INVALID_USERNAME
107-
<StringValue("Invalid Password.")>
108-
INVALID_PASSWORD
109-
<StringValue("Access is denied.")>
110-
ACCESS_DENIED
111-
<StringValue("Incorrect login ID / password.")>
112-
INVALID_AUTH_DATA
113-
<StringValue("Authentification errork")>
114-
LOGIN_ERROR
115-
<StringValue("Connection to Nut Host seem broken when querying : ")>
116-
SOCKET_BROKEN
117-
<StringValue("Unknown Login error: ")>
118-
UNKNOWN_LOGIN_ERROR
119-
<StringValue("Unknown UPS Name.")>
120-
UNKNOWN_UPS
121-
End Enum
122-
123102
Public Enum UPS_States
124103
OL = 1
125104
OB = 2

0 commit comments

Comments
 (0)