diff --git a/WinNUT_V2/Setup/Setup.vdproj b/WinNUT_V2/Setup/Setup.vdproj index 9ce3637..eb4d3f1 100644 --- a/WinNUT_V2/Setup/Setup.vdproj +++ b/WinNUT_V2/Setup/Setup.vdproj @@ -39,6 +39,12 @@ } "Entry" { + "MsmKey" = "8:_0418C0A68EC444EE896C1D543C8AFD63" + "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { "MsmKey" = "8:_04CF9F50AFCFD75A7E6088F3621CA4ED" "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" @@ -159,12 +165,6 @@ } "Entry" { - "MsmKey" = "8:_3AE119B8ED2B789D525357C468BE19EF" - "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_3BB4C815C80263264F0835B05D6C29B5" "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" @@ -255,6 +255,12 @@ } "Entry" { + "MsmKey" = "8:_4F81608AEF82517B403CCE166E5C9E7B" + "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { "MsmKey" = "8:_55900C9611A2611D3971BBB8926ECB47" "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" @@ -316,13 +322,13 @@ "Entry" { "MsmKey" = "8:_5FE446066F12393E77A2B0F5915CB43A" - "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" + "OwnerKey" = "8:_4F81608AEF82517B403CCE166E5C9E7B" "MsmSig" = "8:_UNDEFINED" } "Entry" { "MsmKey" = "8:_5FE446066F12393E77A2B0F5915CB43A" - "OwnerKey" = "8:_7DBECEAB3A758928543F2F67B0BCFD5E" + "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -435,12 +441,6 @@ } "Entry" { - "MsmKey" = "8:_7DBECEAB3A758928543F2F67B0BCFD5E" - "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_7E781465BFAC4DC08591FE1EDE1E2D1F" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -579,12 +579,6 @@ } "Entry" { - "MsmKey" = "8:_99295A60B760C5A7B2A217EF6A2482C4" - "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { "MsmKey" = "8:_9E48304B1DC71476548406FCF4AA74CA" "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" @@ -700,13 +694,13 @@ "Entry" { "MsmKey" = "8:_BED24066F49F1B908C4DB31C0CBA928C" - "OwnerKey" = "8:_7DBECEAB3A758928543F2F67B0BCFD5E" + "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" } "Entry" { "MsmKey" = "8:_BED24066F49F1B908C4DB31C0CBA928C" - "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" + "OwnerKey" = "8:_4F81608AEF82517B403CCE166E5C9E7B" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -801,6 +795,12 @@ } "Entry" { + "MsmKey" = "8:_DCF566685AE6F7520AB676CC882EB40F" + "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { "MsmKey" = "8:_DFB70ADFBF7091B8D6D0D3AF054894F6" "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" @@ -916,19 +916,13 @@ "Entry" { "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_7DBECEAB3A758928543F2F67B0BCFD5E" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_99295A60B760C5A7B2A217EF6A2482C4" + "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" "MsmSig" = "8:_UNDEFINED" } "Entry" { "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_70DBA11C2BF449198BA594449914C1BC" + "OwnerKey" = "8:_4F81608AEF82517B403CCE166E5C9E7B" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -982,7 +976,13 @@ "Entry" { "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_3AE119B8ED2B789D525357C468BE19EF" + "OwnerKey" = "8:_DCF566685AE6F7520AB676CC882EB40F" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_0418C0A68EC444EE896C1D543C8AFD63" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -1654,7 +1654,7 @@ "IsDebugOnly" = "11:TRUE" "IsReleaseOnly" = "11:FALSE" "OutputFilename" = "8:Debug\\WinNUT-Setup.msi" - "PackageFilesAs" = "3:2" + "PackageFilesAs" = "3:1" "PackageFileSize" = "3:-2147483648" "CabType" = "3:1" "Compression" = "3:2" @@ -1674,9 +1674,14 @@ { "{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.5.2" { - "Name" = "8:Microsoft .NET Framework 4.5.2 (x86 et x64)" + "Name" = "8:Microsoft .NET Framework 4.5.2 (x86 and x64)" "ProductCode" = "8:.NETFramework,Version=v4.5.2" } + "{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2" + { + "Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)" + "ProductCode" = "8:.NETFramework,Version=v4.7.2" + } } } } @@ -1864,6 +1869,32 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_0418C0A68EC444EE896C1D543C8AFD63" + { + "AssemblyRegister" = "3:1" + "AssemblyIsInGAC" = "11:FALSE" + "AssemblyAsmDisplayName" = "8:AGauge, Version=2.1.8244.26895, Culture=neutral, processorArchitecture=MSIL" + "ScatterAssemblies" + { + } + "SourcePath" = "8:AGauge.dll" + "TargetName" = "8:" + "Tag" = "8:" + "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Vital" = "11:TRUE" + "ReadOnly" = "11:FALSE" + "Hidden" = "11:FALSE" + "System" = "11:FALSE" + "Permanent" = "11:FALSE" + "SharedLegacy" = "11:FALSE" + "PackageAs" = "3:1" + "Register" = "3:1" + "Exclude" = "11:TRUE" + "IsDependency" = "11:TRUE" + "IsolateTo" = "8:" + } "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_04CF9F50AFCFD75A7E6088F3621CA4ED" { "AssemblyRegister" = "3:1" @@ -2431,37 +2462,6 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_3AE119B8ED2B789D525357C468BE19EF" - { - "AssemblyRegister" = "3:1" - "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL" - "ScatterAssemblies" - { - "_3AE119B8ED2B789D525357C468BE19EF" - { - "Name" = "8:Newtonsoft.Json.dll" - "Attributes" = "3:512" - } - } - "SourcePath" = "8:Newtonsoft.Json.dll" - "TargetName" = "8:" - "Tag" = "8:" - "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_3BB4C815C80263264F0835B05D6C29B5" { "AssemblyRegister" = "3:1" @@ -2792,6 +2792,32 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_4F81608AEF82517B403CCE166E5C9E7B" + { + "AssemblyRegister" = "3:1" + "AssemblyIsInGAC" = "11:FALSE" + "AssemblyAsmDisplayName" = "8:WinNUT-Client_Common, Version=2.1.8253.27437, Culture=neutral, processorArchitecture=MSIL" + "ScatterAssemblies" + { + } + "SourcePath" = "8:WinNUT-Client_Common.dll" + "TargetName" = "8:" + "Tag" = "8:" + "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Vital" = "11:TRUE" + "ReadOnly" = "11:FALSE" + "Hidden" = "11:FALSE" + "System" = "11:FALSE" + "Permanent" = "11:FALSE" + "SharedLegacy" = "11:FALSE" + "PackageAs" = "3:1" + "Register" = "3:1" + "Exclude" = "11:FALSE" + "IsDependency" = "11:TRUE" + "IsolateTo" = "8:" + } "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_55900C9611A2611D3971BBB8926ECB47" { "AssemblyRegister" = "3:1" @@ -3587,37 +3613,6 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_7DBECEAB3A758928543F2F67B0BCFD5E" - { - "AssemblyRegister" = "3:1" - "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:WinNUT-Client_Common, Version=2.1.7740.35836, Culture=neutral, processorArchitecture=MSIL" - "ScatterAssemblies" - { - "_7DBECEAB3A758928543F2F67B0BCFD5E" - { - "Name" = "8:WinNUT-Client_Common.dll" - "Attributes" = "3:512" - } - } - "SourcePath" = "8:WinNUT-Client_Common.dll" - "TargetName" = "8:" - "Tag" = "8:" - "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:FALSE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_7E781465BFAC4DC08591FE1EDE1E2D1F" { "SourcePath" = "8:..\\..\\README.md" @@ -3665,7 +3660,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -3727,7 +3722,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -4165,37 +4160,6 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } - "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_99295A60B760C5A7B2A217EF6A2482C4" - { - "AssemblyRegister" = "3:1" - "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:AGauge, Version=2.1.7740.35836, Culture=neutral, processorArchitecture=MSIL" - "ScatterAssemblies" - { - "_99295A60B760C5A7B2A217EF6A2482C4" - { - "Name" = "8:AGauge.dll" - "Attributes" = "3:512" - } - } - "SourcePath" = "8:AGauge.dll" - "TargetName" = "8:" - "Tag" = "8:" - "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" - "Condition" = "8:" - "Transitive" = "11:FALSE" - "Vital" = "11:TRUE" - "ReadOnly" = "11:FALSE" - "Hidden" = "11:FALSE" - "System" = "11:FALSE" - "Permanent" = "11:FALSE" - "SharedLegacy" = "11:FALSE" - "PackageAs" = "3:1" - "Register" = "3:1" - "Exclude" = "11:TRUE" - "IsDependency" = "11:TRUE" - "IsolateTo" = "8:" - } "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_9E48304B1DC71476548406FCF4AA74CA" { "AssemblyRegister" = "3:1" @@ -4409,7 +4373,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -4595,7 +4559,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -4812,7 +4776,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -5157,6 +5121,37 @@ "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } + "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_DCF566685AE6F7520AB676CC882EB40F" + { + "AssemblyRegister" = "3:1" + "AssemblyIsInGAC" = "11:FALSE" + "AssemblyAsmDisplayName" = "8:Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL" + "ScatterAssemblies" + { + "_DCF566685AE6F7520AB676CC882EB40F" + { + "Name" = "8:Newtonsoft.Json.dll" + "Attributes" = "3:512" + } + } + "SourcePath" = "8:Newtonsoft.Json.dll" + "TargetName" = "8:" + "Tag" = "8:" + "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Vital" = "11:TRUE" + "ReadOnly" = "11:FALSE" + "Hidden" = "11:FALSE" + "System" = "11:FALSE" + "Permanent" = "11:FALSE" + "SharedLegacy" = "11:FALSE" + "PackageAs" = "3:1" + "Register" = "3:1" + "Exclude" = "11:FALSE" + "IsDependency" = "11:TRUE" + "IsolateTo" = "8:" + } "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_DFB70ADFBF7091B8D6D0D3AF054894F6" { "AssemblyRegister" = "3:1" @@ -5556,7 +5551,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -5647,22 +5642,22 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:WinNUT" - "ProductCode" = "8:{27453A08-363D-4020-BC5E-81D55CAD026D}" - "PackageCode" = "8:{1B08EE15-0DA7-4B7A-9331-8DAAB7671FF3}" + "ProductCode" = "8:{D86CC521-7EEF-48A4-A043-7C2A4C440FDB}" + "PackageCode" = "8:{3EC9F76F-07E8-4AC6-BE64-ACE016374A6F}" "UpgradeCode" = "8:{7EA17151-76E7-4E29-8F6A-621C1B4144C2}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" - "DetectNewerInstalledVersion" = "11:FALSE" + "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:2.1.7740" - "Manufacturer" = "8:Gawindx" + "ProductVersion" = "8:2.2" + "Manufacturer" = "8:NUTDotNet" "ARPHELPTELEPHONE" = "8:" - "ARPHELPLINK" = "8:https://github.com/gawindx/WinNUT-Client/issues" + "ARPHELPLINK" = "8:https://github.com/nutdotnet/WinNUT-Client/issues" "Title" = "8:WinNUT-Setup" - "Subject" = "8:WinNUT-Client v2.1.77.40" - "ARPCONTACT" = "8:Gawindx" - "Keywords" = "8:WinNUT v2.1.7740.35837" + "Subject" = "8:WinNUT-Client" + "ARPCONTACT" = "8:Gawindx, gbakeman, et. al." + "Keywords" = "8:WinNUT" "ARPCOMMENTS" = "8:Windows NUT Client" "ARPURLINFOABOUT" = "8:" "ARPPRODUCTICON" = "8:_33BCB1EF059B4E9B87FA7435A8F2499C" @@ -5823,7 +5818,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_F2DF41070EDA4742A54807F28C07C52B" { "Sequence" = "3:100" - "DisplayName" = "8:Progression" + "DisplayName" = "8:Progress" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdAdminProgressDlg.wid" @@ -5874,7 +5869,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_4B119B4342AC4E45B4B3EECDD278671F" { "Sequence" = "3:100" - "DisplayName" = "8:Bienvenue" + "DisplayName" = "8:Welcome" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdWelcomeDlg.wid" @@ -5923,7 +5918,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_AFF745EBBD1442A0B0BC7153BEEFC80D" { "Sequence" = "3:200" - "DisplayName" = "8:Dossier d'installation" + "DisplayName" = "8:Installation Folder" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdFolderDlg.wid" @@ -5959,7 +5954,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_B5BDDB8BFC80452FBE242360137F4674" { "Sequence" = "3:300" - "DisplayName" = "8:Confirmer l'installation" + "DisplayName" = "8:Confirm Installation" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdConfirmDlg.wid" @@ -5991,7 +5986,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_E6555EC75F9C4A04A845F450455B0835" { "Sequence" = "3:100" - "DisplayName" = "8:Terminé" + "DisplayName" = "8:Finished" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdAdminFinishedDlg.wid" @@ -6023,7 +6018,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_2A48C931E2DF44E7880C60E12E11A45F" { "Sequence" = "3:100" - "DisplayName" = "8:Bienvenue" + "DisplayName" = "8:Welcome" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdAdminWelcomeDlg.wid" @@ -6072,7 +6067,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_3AA54EF723754A82AFCF2C63819D1E52" { "Sequence" = "3:200" - "DisplayName" = "8:Dossier d'installation" + "DisplayName" = "8:Installation Folder" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdAdminFolderDlg.wid" @@ -6095,7 +6090,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_916E910666934ED6AC81A2EBE5B56D75" { "Sequence" = "3:300" - "DisplayName" = "8:Confirmer l'installation" + "DisplayName" = "8:Confirm Installation" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdAdminConfirmDlg.wid" @@ -6133,7 +6128,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_A64DF3D6139E46AC8A9FA1B01433C9BE" { "Sequence" = "3:100" - "DisplayName" = "8:Terminé" + "DisplayName" = "8:Finished" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdFinishedDlg.wid" @@ -6178,7 +6173,7 @@ "{688940B3-5CA9-4162-8DEE-2993FA9D8CBC}:_D79DF3D3BFA94C198607E6D5E942EC04" { "Sequence" = "3:100" - "DisplayName" = "8:Progression" + "DisplayName" = "8:Progress" "UseDynamicProperties" = "11:TRUE" "IsDependency" = "11:FALSE" "SourcePath" = "8:\\VsdProgressDlg.wid" @@ -6221,7 +6216,7 @@ { "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_314CE5030A4040E69371869B1C94AA16" { - "SourcePath" = "8:..\\AGauge_mod\\obj\\Release\\AGauge.dll" + "SourcePath" = "8:..\\AGauge_mod\\obj\\Debug\\AGauge.dll" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" @@ -6249,7 +6244,7 @@ } "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_70DBA11C2BF449198BA594449914C1BC" { - "SourcePath" = "8:..\\WInNUT_GUI\\obj\\Release\\WinNUT-Client.exe" + "SourcePath" = "8:..\\WInNUT_GUI\\obj\\Debug\\WinNUT-Client.exe" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7A1917372AF14D75845D775AAEB7CD48" diff --git a/WinNUT_V2/SharedAssemblyInfo.vb b/WinNUT_V2/SharedAssemblyInfo.vb index 28742be..fef9b63 100644 --- a/WinNUT_V2/SharedAssemblyInfo.vb +++ b/WinNUT_V2/SharedAssemblyInfo.vb @@ -8,9 +8,7 @@ ' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY Imports System.Resources -Imports System Imports System.Reflection -Imports System.Runtime.InteropServices ' Les informations générales relatives à un assembly dépendent de ' l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations @@ -18,9 +16,9 @@ Imports System.Runtime.InteropServices ' Vérifiez les valeurs des attributs de l'assembly - + - + ' Les informations de version pour un assembly se composent des quatre valeurs suivantes : @@ -34,5 +32,5 @@ Imports System.Runtime.InteropServices ' en utilisant '*', comme indiqué ci-dessous : ' - + diff --git a/WinNUT_V2/WinNUT-Client_Common/Common_Classes.vb b/WinNUT_V2/WinNUT-Client_Common/Common_Classes.vb index 67177cd..b8c501f 100644 --- a/WinNUT_V2/WinNUT-Client_Common/Common_Classes.vb +++ b/WinNUT_V2/WinNUT-Client_Common/Common_Classes.vb @@ -35,12 +35,15 @@ End Class Public Class Nut_Exception Inherits System.ApplicationException + Public Property ExceptionValue As Nut_Exception_Value + Public Sub New(ByVal Nut_Error_Lvl As Nut_Exception_Value) MyBase.New(StringEnum.GetStringValue(Nut_Error_Lvl)) End Sub - Public Sub New(ByVal Nut_Error_Lvl As Nut_Exception_Value, ByVal Message As String) - MyBase.New(StringEnum.GetStringValue(Nut_Error_Lvl) & Message) + Public Sub New(ByVal Nut_Error_Lvl As Nut_Exception_Value, ByVal Message As String, Optional innerEx As Exception = Nothing) + MyBase.New(StringEnum.GetStringValue(Nut_Error_Lvl) & Message, innerEx) + ExceptionValue = Nut_Error_Lvl End Sub End Class @@ -51,4 +54,24 @@ Public Class Nut_Parameter Public Password As String = "" Public UPSName As String = "" Public AutoReconnect As Boolean = False + + Public Sub New(Host As String, Port As Integer, Login As String, Password As String, UPSName As String, + Optional AutoReconnect As Boolean = False) + Me.Host = Host + Me.Port = Port + Me.Login = Login + Me.Password = Password + Me.UPSName = UPSName + Me.AutoReconnect = AutoReconnect + End Sub + + ''' + ''' Generate an informative String representing this Parameter object. Note password is not printed. + ''' + ''' + Public Overrides Function ToString() As String + Return String.Format("{0}@{1}:{2}, Name: {3}" & If(AutoReconnect, " [AutoReconnect]", Nothing), + Login, Host, Port, UPSName, AutoReconnect) + ' Return MyBase.ToString()) + End Function End Class diff --git a/WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb b/WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb index c9c3f11..86caf37 100644 --- a/WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb +++ b/WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb @@ -12,9 +12,44 @@ ' Class dealing only with the management of the communication socket with the Nut server Imports System.Net.Sockets Imports System.IO -Imports System.Windows.Forms Public Class Nut_Socket + +#Region "Properties" + + Public ReadOnly Property ConnectionStatus As Boolean + Get + If NutSocket IsNot Nothing Then + Return NutSocket.Connected + Else + Return False + End If + End Get + End Property + + Public ReadOnly Property IsConnected() As Boolean + Get + Return ConnectionStatus + End Get + End Property + + Public ReadOnly Property Nut_Version() As String + Get + Return Nut_Ver + End Get + End Property + + Public ReadOnly Property Net_Version() As String + Get + Return Net_Ver + End Get + End Property + +#End Region + + Private LogFile As Logger + Private NutConfig As Nut_Parameter + 'Socket Variables Private NutSocket As Socket Private NutTCP As TcpClient @@ -22,17 +57,11 @@ Public Class Nut_Socket Private ReaderStream As StreamReader Private WriterStream As StreamWriter - Private Nut_Parameter As Nut_Parameter - Private Nut_Ver As String Private Net_Ver As String - Private ConnectionStatus As Boolean = False - - Private Nut_Config As Nut_Parameter - Public Auth_Success As Boolean = False - Private ReadOnly WatchDog As New Timer + ' Private ReadOnly WatchDog As New Timer 'Public Event OnNotice(Message As String, NoticeLvl As LogLvl, sender As Object, ReportToGui As Boolean) Public Event OnNotice(Message As String, NoticeLvl As LogLvl, sender As Object) @@ -42,79 +71,53 @@ Public Class Nut_Socket Public Event Unknown_UPS() Public Event Socket_Broken() - Public Event Socket_Deconnected() - Public Sub New(ByVal Nut_Config As Nut_Parameter) + ''' + ''' Socket was disconnected as a part of normal operations. + ''' + Public Event SocketDisconnected() - With Me.WatchDog - .Interval = 1000 - .Enabled = False - AddHandler .Tick, AddressOf Event_WatchDog - End With - Update_Config(Nut_Config) - End Sub - Public ReadOnly Property IsConnected() As Boolean - Get - Return Me.ConnectionStatus - End Get - End Property - Public ReadOnly Property Nut_Version() As String - Get - Return Me.Nut_Ver - End Get - End Property - Public ReadOnly Property Net_Version() As String - Get - Return Me.Net_Ver - End Get - End Property + Public Sub New(Nut_Config As Nut_Parameter, ByRef logger As Logger) + LogFile = logger + NutConfig = Nut_Config - Public ReadOnly Property IsKnownUPS(Test_UPSname As String) As Boolean - Get - If Not Me.ConnectionStatus Then - Return False - Else - Dim IsKnow As Boolean = False - Dim ListOfUPSs = Query_List_Datas("LIST UPS") - For Each Known_UPS In ListOfUPSs - If Known_UPS.VarValue = Test_UPSname Then - IsKnow = True - End If - Next - Return IsKnow - End If - End Get - End Property - Public Sub Update_Config(ByVal New_Nut_Config As Nut_Parameter) - Me.Nut_Config = New_Nut_Config + 'With Me.WatchDog + ' .Interval = 1000 + ' .Enabled = False + ' AddHandler .Tick, AddressOf Event_WatchDog + 'End With End Sub + Public Function Connect() As Boolean Try 'TODO: Use LIST UPS protocol command to get valid UPSs. - Dim Host = Me.Nut_Config.Host - Dim Port = Me.Nut_Config.Port - Dim Login = Me.Nut_Config.Login - Dim Password = Me.Nut_Config.Password + Dim Host = NutConfig.Host + Dim Port = NutConfig.Port + Dim Login = NutConfig.Login + Dim Password = NutConfig.Password If Not String.IsNullOrEmpty(Host) And Not IsNothing(Port) Then - If Not Create_Socket(Host, Port) Then - ' Don't duplicate/override Create_Socket's error throwing functionality. - ' Throw New Nut_Exception(Nut_Exception_Value.CONNECT_ERROR) - Disconnect() - Else - If Not AuthLogin(Login, Password) Then - Throw New Nut_Exception(Nut_Exception_Value.INVALID_AUTH_DATA) - End If + Create_Socket(Host, Port) + + If ConnectionStatus Then + AuthLogin(Login, Password) + ' Bad login shouldn't necessarily preclude a successful connection (basic ops can still occur.) + 'If Not AuthLogin(Login, Password) Then + ' ' Throw New Nut_Exception(Nut_Exception_Value.INVALID_AUTH_DATA) + ' RaiseEvent OnNUTException() + 'End If Dim Nut_Query = Query_Data("VER") If Nut_Query.Response = NUTResponse.OK Then - Me.Nut_Ver = (Nut_Query.Data.Split(" "c))(4) + Nut_Ver = (Nut_Query.Data.Split(" "c))(4) End If Nut_Query = Query_Data("NETVER") If Nut_Query.Response = NUTResponse.OK Then - Me.Net_Ver = Nut_Query.Data + Net_Ver = Nut_Query.Data End If + + LogFile.LogTracing(String.Format("NUT server reports VER: {0} NETVER: {1}", Nut_Ver, Net_Ver), LogLvl.LOG_NOTICE, Me) Return True End If End If @@ -126,46 +129,97 @@ Public Class Nut_Socket Catch Excep As Exception RaiseEvent OnError(Excep, LogLvl.LOG_ERROR, Me) Return False - Finally - End Try + + Return False End Function - Private Function Create_Socket(ByVal Host As String, ByVal Port As Integer) As Boolean + ''' + ''' Perform various functions necessary to disconnect the socket from the NUT server. + ''' + ''' Skip raising the event if true. + ''' Skip sending the LOGOUT command to the NUT server. Unknown effects. + Public Sub Disconnect(Optional silent = False, Optional forceful = False) + ' WatchDog.Stop() + + If Not forceful Then + Query_Data("LOGOUT") + End If + + Close_Socket() + + If Not silent Then + LogFile.LogTracing("NutSocket raising Disconnected event.", LogLvl.LOG_DEBUG, Me) + RaiseEvent SocketDisconnected() + End If + + LogFile.LogTracing("NutSocket has been Disconnected.", LogLvl.LOG_DEBUG, Me) + End Sub + + Private Sub Create_Socket(Host As String, Port As Integer) Try - Me.NutSocket = New Socket(AddressFamily.InterNetwork, ProtocolType.IP) - Me.NutTCP = New TcpClient(Host, Port) - Me.NutStream = NutTCP.GetStream - Me.ReaderStream = New StreamReader(NutStream) - Me.WriterStream = New StreamWriter(NutStream) - Me.ConnectionStatus = True + ' NutSocket = New Socket(AddressFamily.InterNetwork, ProtocolType.IP) + NutSocket = New Socket(SocketType.Stream, ProtocolType.IP) + LogFile.LogTracing(String.Format("Attempting TCP socket connection to {0}:{1}...", Host, Port), LogLvl.LOG_NOTICE, Me) + NutSocket.Connect(Host, Port) + NutTCP = New TcpClient(Host, Port) + NutStream = NutTCP.GetStream + ReaderStream = New StreamReader(NutStream) + WriterStream = New StreamWriter(NutStream) + LogFile.LogTracing(String.Format("Connection established and streams ready for {0}:{1}", Host, Port), LogLvl.LOG_NOTICE, Me) Catch Excep As Exception + Disconnect(True) RaiseEvent OnNUTException(New Nut_Exception(Nut_Exception_Value.CONNECT_ERROR, Excep.Message), LogLvl.LOG_ERROR, Me) - Me.ConnectionStatus = False End Try - Return Me.ConnectionStatus - End Function + End Sub + + Public ReadOnly Property IsKnownUPS(Test_UPSname As String) As Boolean + Get + If Not ConnectionStatus Then + Return False + Else + Dim IsKnow As Boolean = False + Dim ListOfUPSs = Query_List_Datas("LIST UPS") + For Each Known_UPS In ListOfUPSs + If Known_UPS.VarValue = Test_UPSname Then + IsKnow = True + End If + Next + Return IsKnow + End If + End Get + End Property + Public Function Query_Data(Query_Msg As String) As (Data As String, Response As NUTResponse) Dim Response As NUTResponse = NUTResponse.NORESPONSE Dim DataResult As String = "" - Try - If Me.ConnectionStatus Then - Me.WriterStream.WriteLine(Query_Msg & vbCr) - Me.WriterStream.Flush() - DataResult = Trim(Me.ReaderStream.ReadLine()) - - If DataResult = Nothing Then - Disconnect() - RaiseEvent Socket_Broken() - Throw New Nut_Exception(Nut_Exception_Value.SOCKET_BROKEN, Query_Msg) - End If - Response = EnumResponse(DataResult) + ' Try + If Me.ConnectionStatus Then + Me.WriterStream.WriteLine(Query_Msg & vbCr) + Me.WriterStream.Flush() + DataResult = Trim(Me.ReaderStream.ReadLine()) + + If DataResult = Nothing Then + ' TODO: Does null dataresult really mean an error condition? + ' https://stackoverflow.com/a/6523010/530172 + Disconnect() + RaiseEvent Socket_Broken() + Throw New Nut_Exception(Nut_Exception_Value.SOCKET_BROKEN, Query_Msg) End If - Return (DataResult, Response) - Catch Excep As Exception - RaiseEvent OnError(Excep, LogLvl.LOG_ERROR, Me) - Return (DataResult, Response) - End Try + Response = EnumResponse(DataResult) + End If + Return (DataResult, Response) + 'Catch ioEx As IOException + ' ' Something's gone wrong with the connection. + ' ' Try to safely shut everything down and notify listeners. + ' ' Disconnect() + ' RaiseEvent Socket_Broken() + ' RaiseEvent OnNUTException(New Nut_Exception(Nut_Exception_Value.SOCKET_BROKEN, Query_Msg, ioEx), LogLvl.LOG_ERROR, Me) + ' ' Return (Nothing, NUTResponse.NORESPONSE) + 'Catch Excep As Exception + ' RaiseEvent OnError(Excep, LogLvl.LOG_ERROR, Me) + ' Return (DataResult, Response) + 'End Try End Function Public Function Query_Desc(ByVal VarName As String) As String Try @@ -174,7 +228,7 @@ Public Class Nut_Socket RaiseEvent Socket_Broken() Throw New Nut_Exception(Nut_Exception_Value.SOCKET_BROKEN, VarName) Else - Dim Nut_Query = Query_Data("GET DESC " & Me.Nut_Config.UPSName & " " & VarName) + Dim Nut_Query = Query_Data("GET DESC " & Me.NutConfig.UPSName & " " & VarName) Select Case Nut_Query.Response Case NUTResponse.OK 'LogFile.LogTracing("Process Result With " & VarName & " : " & Nut_Query.Data, LogLvl.LOG_DEBUG, Me) @@ -337,9 +391,11 @@ Public Class Nut_Socket End Select Return Response End Function - Private Function AuthLogin(ByVal Login As String, ByVal Password As String) As Boolean + + Private Sub AuthLogin(Login As String, Password As String) Try - Me.Auth_Success = False + LogFile.LogTracing("Attempting authentication...", LogLvl.LOG_NOTICE, Me) + Auth_Success = False If Not String.IsNullOrEmpty(Login) AndAlso String.IsNullOrEmpty(Password) Then Dim Nut_Query = Query_Data("USERNAME " & Login) @@ -365,23 +421,27 @@ Public Class Nut_Socket End If End If End If - Me.Auth_Success = True - Return Me.Auth_Success + + LogFile.LogTracing("Authenticated successfully.", LogLvl.LOG_NOTICE, Me) + Auth_Success = True + ' Return Me.Auth_Success + Catch nutEx As Nut_Exception + ' Auth issues aren't necessarily fatal - some interaction can still occur unauthenticated. + RaiseEvent OnNUTException(nutEx, LogLvl.LOG_ERROR, Me) + ' Auth_Success = False + ' Disconnect(True) Catch Excep As Exception RaiseEvent OnError(Excep, LogLvl.LOG_ERROR, Me) - Me.Disconnect() - Return False + Disconnect(True) + ' Auth_Success = False End Try - End Function + End Sub Private Sub Event_WatchDog(sender As Object, e As EventArgs) Dim Nut_Query = Query_Data("") If Nut_Query.Response = NUTResponse.NORESPONSE Then - Me.ConnectionStatus = False Disconnect(True) RaiseEvent Socket_Broken() - ElseIf Nut_Query.Response = NUTResponse.UNKNOWNCOMMAND Then - Me.ConnectionStatus = True End If End Sub @@ -407,16 +467,8 @@ Public Class Nut_Socket NutSocket.Close() End If Catch Excep As Exception + LogFile.LogTracing("Error encountered while shutting down socket: " & vbNewLine & Excep.ToString(), + LogLvl.LOG_ERROR, Me) End Try - Me.ConnectionStatus = False - End Sub - - Public Sub Disconnect(Optional ByVal ForceDisconnect = False) - Query_Data("LOGOUT") - Close_Socket() - Me.WatchDog.Stop() - If Not ForceDisconnect Then - RaiseEvent Socket_Deconnected() - End If End Sub End Class diff --git a/WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb b/WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb index 9277c6a..c6dd0b3 100644 --- a/WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb +++ b/WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb @@ -8,26 +8,38 @@ ' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY Imports System.Globalization +Imports System.Windows.Forms + Public Class UPS_Device + Private Const CosPhi As Double = 0.6 + ' How many milliseconds to wait before the Reconnect routine tries again. +#If DEBUG Then + Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 3000 +#Else + Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 30000 +#End If + + 'Private Nut_Conn As Nut_Comm ' Private LogFile As Logger Private Freq_Fallback As Double - Private ciClone As System.Globalization.CultureInfo - Private Const CosPhi As Double = 0.6 + Private ciClone As CultureInfo - Private Nut_Config As Nut_Parameter + Public Nut_Config As Nut_Parameter Public UPS_Datas As New UPS_Datas Public WithEvents Nut_Socket As Nut_Socket Public Retry As Integer = 0 Public MaxRetry As Integer = 30 - Private ReadOnly Reconnect_Nut As New System.Windows.Forms.Timer - Private ReadOnly WatchDog As New System.Windows.Forms.Timer - Private Socket_Status As Boolean = False + Private WithEvents Reconnect_Nut As New System.Windows.Forms.Timer + ' Private ReadOnly WatchDog As New System.Windows.Forms.Timer + ' Private Socket_Status As Boolean = False + - 'Private LogFile As Logger + + Private LogFile As Logger 'Private ConnectionStatus As Boolean = False 'Private Server As String 'Private Port As Integer @@ -74,17 +86,22 @@ Public Class UPS_Device Public Event Unknown_UPS() Public Event DataUpdated() - Public Event Connected() - Public Event ReConnected() - Public Event Deconnected() + Public Event Connected(sender As UPS_Device) + Public Event ReConnected(sender As UPS_Device) + ' Notify that the connection was closed gracefully. + Public Event Disconnected() + ' Notify of an unexpectedly lost connection (??) Public Event Lost_Connect() Public Event New_Retry() Public Event Shutdown_Condition() Public Event Stop_Shutdown() + Private Polling_Interval As Integer + Private WithEvents Update_Data As New Timer + Public ReadOnly Property IsConnected() As Boolean Get - Return (Me.Nut_Socket.IsConnected And Me.Socket_Status) + Return (Me.Nut_Socket.IsConnected) ' And Me.Socket_Status End Get End Property @@ -94,51 +111,43 @@ Public Class UPS_Device End Get End Property - Private Sub Event_WatchDog(sender As Object, e As EventArgs) - If Me.IsConnected Then - Dim Nut_Query = Nut_Socket.Query_Data("") - If Nut_Query.Response = NUTResponse.NORESPONSE Then - LogFile.LogTracing("WatchDog Socket report a Broken State", LogLvl.LOG_WARNING, Me) - Nut_Socket.Disconnect(True) - RaiseEvent Lost_Connect() - Me.Socket_Status = False - End If - End If - End Sub - - Public Sub New(ByVal Nut_Config As Nut_Parameter, ByRef LogFile As Logger) - ' Me.LogFile = LogFile + Public Sub New(ByRef Nut_Config As Nut_Parameter, ByRef LogFile As Logger, pollInterval As Integer) + Me.LogFile = LogFile Me.Nut_Config = Nut_Config - Me.ciClone = CType(CultureInfo.InvariantCulture.Clone(), CultureInfo) - Me.ciClone.NumberFormat.NumberDecimalSeparator = "." - Me.Nut_Socket = New Nut_Socket(Me.Nut_Config) - With Me.Reconnect_Nut - .Interval = 30000 - .Enabled = False - AddHandler .Tick, AddressOf Reconnect_Socket - End With - With Me.WatchDog - .Interval = 1000 + ' Polling_Interval = pollInterval + Update_Data.Interval = pollInterval + ciClone = CType(CultureInfo.InvariantCulture.Clone(), CultureInfo) + ciClone.NumberFormat.NumberDecimalSeparator = "." + Nut_Socket = New Nut_Socket(Me.Nut_Config, LogFile) + With Reconnect_Nut + .Interval = DEFAULT_RECONNECT_WAIT_MS .Enabled = False - AddHandler .Tick, AddressOf Event_WatchDog + ' AddHandler .Tick, AddressOf Reconnect_Socket End With - AddHandler Nut_Socket.Socket_Deconnected, AddressOf Socket_Deconnected - Connect_UPS() + 'With WatchDog + ' .Interval = 1000 + ' .Enabled = False + ' AddHandler .Tick, AddressOf Event_WatchDog + 'End With End Sub + Public Sub Connect_UPS() - Dim UPSName = Me.Nut_Config.UPSName + ' Dim UPSName = Me.Nut_Config.UPSName + LogFile.LogTracing("Beginning connection: " & Nut_Config.ToString(), LogLvl.LOG_DEBUG, Me) + If Me.Nut_Socket.Connect() And Me.Nut_Socket.IsConnected Then LogFile.LogTracing("TCP Socket Created", LogLvl.LOG_NOTICE, Me) - Me.Socket_Status = True - If Nut_Socket.IsKnownUPS(UPSName) Then + ' Me.Socket_Status = True + If Nut_Socket.IsKnownUPS(Nut_Config.UPSName) Then Me.UPS_Datas = GetUPSProductInfo() Init_Constant(Nut_Socket) - RaiseEvent Connected() + Update_Data.Start() + RaiseEvent Connected(Me) Else LogFile.LogTracing("Given UPS Name is unknown", LogLvl.LOG_NOTICE, Me) RaiseEvent Unknown_UPS() End If - Me.WatchDog.Start() + ' WatchDog.Start() 'Else ' If Not Reconnect_Nut.Enabled Then ' RaiseEvent Lost_Connect() @@ -146,11 +155,120 @@ Public Class UPS_Device ' End If End If End Sub - Public Sub ReConnect() - If Not Me.IsConnected Then - Nut_Socket.Connect() + + 'Private Sub HandleDisconnectRequest(sender As Object, Optional cancelAutoReconnect As Boolean = True) Handles Me.RequestDisconnect + ' If disconnectInProgress Then + ' Throw New InvalidOperationException("Disconnection already in progress.") + ' End If + + ' ' WatchDog.Stop() + + ' If cancelAutoReconnect And Reconnect_Nut.Enabled = True Then + ' Debug.WriteLine("Cancelling ") + ' End If + 'End Sub + + Public Sub Disconnect(Optional cancelReconnect As Boolean = True, Optional silent As Boolean = False, Optional forceful As Boolean = False) + LogFile.LogTracing("Processing request to disconnect...", LogLvl.LOG_DEBUG, Me) + ' WatchDog.Stop() + Update_Data.Stop() + If cancelReconnect And Reconnect_Nut.Enabled Then + LogFile.LogTracing("Stopping Reconnect timer.", LogLvl.LOG_DEBUG, Me) + Reconnect_Nut.Stop() + End If + + Retry = 0 + Nut_Socket.Disconnect(silent, forceful) + ' Confirmation of disconnection will come from raised Disconnected event. + + 'LogFile.LogTracing("Completed disconnecting UPS, notifying listeners.", LogLvl.LOG_DEBUG, Me) + 'RaiseEvent Disconnected() + End Sub + +#Region "Socket Interaction" + + Private Sub SocketDisconnected() Handles Nut_Socket.SocketDisconnected + ' WatchDog.Stop() + LogFile.LogTracing("NutSocket raised Disconnected event.", LogLvl.LOG_DEBUG, Me) + 'If Not Me.Socket_Status Then + ' RaiseEvent Lost_Connect() + 'End If + ' Me.Socket_Status = False + 'If Me.Nut_Config.AutoReconnect Then + ' LogFile.LogTracing("Reconnection Process Started", LogLvl.LOG_NOTICE, Me) + ' Reconnect_Nut.Enabled = True + ' Reconnect_Nut.Start() + 'End If + RaiseEvent Disconnected() + End Sub + + ''' + ''' Check underlying connection for an error state by sending an empty query to the server. + ''' A watchdog may not actually be necessary under normal circumstances, since queries are regularly being sent to + ''' the NUT server and will catch a broken socket that way. + ''' + ''' + ''' + Private Sub Event_WatchDog(sender As Object, e As EventArgs) + If Me.IsConnected Then + Dim Nut_Query = Nut_Socket.Query_Data("") + If Nut_Query.Response = NUTResponse.NORESPONSE Then + LogFile.LogTracing("WatchDog Socket report a Broken State", LogLvl.LOG_WARNING, Me) + Nut_Socket.Disconnect(True) + RaiseEvent Lost_Connect() + ' Me.Socket_Status = False + End If + End If + End Sub + + Private Sub Socket_Broken() Handles Nut_Socket.Socket_Broken + ' LogFile.LogTracing("TCP Socket seems Broken", LogLvl.LOG_WARNING, Me) + LogFile.LogTracing("Socket has reported a Broken event.", LogLvl.LOG_WARNING, Me) + ' SocketDisconnected() + RaiseEvent Lost_Connect() + + If Nut_Config.AutoReconnect Then + LogFile.LogTracing("Reconnection Process Started", LogLvl.LOG_NOTICE, Me) + Reconnect_Nut.Start() + End If + End Sub + + Private Sub Reconnect_Socket(sender As Object, e As EventArgs) Handles Reconnect_Nut.Tick + Me.Retry += 1 + If Me.Retry <= Me.MaxRetry Then + RaiseEvent New_Retry() + LogFile.LogTracing(String.Format("Try Reconnect {0} / {1}", Me.Retry, Me.MaxRetry), LogLvl.LOG_NOTICE, Me, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_NEW_RETRY), Me.Retry, Me.MaxRetry)) + Me.Connect_UPS() + If Me.IsConnected Then + LogFile.LogTracing("Nut Host Reconnected", LogLvl.LOG_DEBUG, Me) + Reconnect_Nut.Stop() + Me.Retry = 0 + RaiseEvent ReConnected(Me) + End If + Else + LogFile.LogTracing("Max Retry reached. Stop Process Autoreconnect and wait for manual Reconnection", LogLvl.LOG_ERROR, Me, WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_STOP_RETRY)) + 'Reconnect_Nut.Stop() + 'RaiseEvent Disconnected() + Disconnect(True) + End If + End Sub + + Private Sub NUTSocketError(nutEx As Nut_Exception, NoticeLvl As LogLvl, sender As Object) Handles Nut_Socket.OnNUTException + If nutEx.ExceptionValue = Nut_Exception_Value.SOCKET_BROKEN AndAlso nutEx.InnerException IsNot Nothing Then + LogFile.LogTracing("Socket_Broken event InnerException: " & nutEx.InnerException.ToString(), LogLvl.LOG_DEBUG, Me) End If + + LogFile.LogTracing("[" & Nut_Config.UPSName & "] " & nutEx.ToString(), LogLvl.LOG_WARNING, Nut_Socket) End Sub + +#End Region + + 'Public Sub ReConnect() + ' If Not Me.IsConnected Then + ' Nut_Socket.Connect() + ' End If + 'End Sub + Private Function GetUPSProductInfo() As UPS_Datas Dim UDatas As New UPS_Datas Dim UPSName = Me.Nut_Config.UPSName @@ -166,13 +284,14 @@ Public Class UPS_Device Me.UPS_Datas.UPS_Value.Batt_Capacity = Double.Parse(Me.GetUPSVar("battery.capacity", UPSName, 7), ciClone) Me.Freq_Fallback = Double.Parse(Me.GetUPSVar("output.frequency.nominal", UPSName, (50 + CInt(WinNUT_Params.Arr_Reg_Key.Item("FrequencySupply")) * 10)), Me.ciClone) End Sub - Public Function Retrieve_UPS_Datas() As UPS_Datas + + Public Sub Retrieve_UPS_Datas() Handles Update_Data.Tick ' As UPS_Datas Dim UPSName = Me.Nut_Config.UPSName LogFile.LogTracing("Enter Retrieve_UPS_Datas", LogLvl.LOG_DEBUG, Me) Try Dim UPS_rt_Status As String Dim InputA As Double - LogFile.LogTracing("Enter Retrieve_UPS_Data", LogLvl.LOG_DEBUG, Me) + ' LogFile.LogTracing("Enter Retrieve_UPS_Data", LogLvl.LOG_DEBUG, Me) If Me.IsConnected Then With Me.UPS_Datas Select Case "Unknown" @@ -288,55 +407,59 @@ Public Class UPS_Device RaiseEvent DataUpdated() End If Catch Excep As Exception + ' Something went wrong while trying to read the data... Consider the socket broken and proceed from here. + LogFile.LogTracing("Something went wrong in Retrieve_UPS_Datas: " & Excep.ToString(), LogLvl.LOG_ERROR, Me) + Disconnect(False, True, True) + Socket_Broken() 'Me.Disconnect(True) 'Enter_Reconnect_Process(Excep, "Error When Retrieve_UPS_Data : ") End Try - Return Me.UPS_Datas - End Function + ' Return Me.UPS_Datas + End Sub Public Function GetUPSVar(ByVal varName As String, ByVal UPSName As String, Optional ByVal Fallback_value As Object = Nothing) As String - Try - LogFile.LogTracing("Enter GetUPSVar", LogLvl.LOG_DEBUG, Me) - 'If Not Me.ConnectionStatus Then - If Not Me.IsConnected Then - Throw New Nut_Exception(Nut_Exception_Value.SOCKET_BROKEN, varName) - Return Nothing - Else - Dim Nut_Query = Me.Nut_Socket.Query_Data("GET VAR " & UPSName & " " & varName) - - Select Case Nut_Query.Response - Case NUTResponse.OK - LogFile.LogTracing("Process Result With " & varName & " : " & Nut_Query.Data, LogLvl.LOG_DEBUG, Me) - Return ExtractData(Nut_Query.Data) - Case NUTResponse.UNKNOWNUPS - 'Me.Invalid_Data = False - 'Me.Unknown_UPS_Name = True - RaiseEvent Unknown_UPS() - Throw New Nut_Exception(Nut_Exception_Value.UNKNOWN_UPS) - Case NUTResponse.VARNOTSUPPORTED - 'Me.Unknown_UPS_Name = False - 'Me.Invalid_Data = False - If Not String.IsNullOrEmpty(Fallback_value) Then - LogFile.LogTracing("Apply Fallback Value when retrieving " & varName, LogLvl.LOG_WARNING, Me) - Dim FakeData = "VAR " & UPSName & " " & varName & " " & """" & Fallback_value & """" - Return ExtractData(FakeData) - Else - LogFile.LogTracing("Error Result On Retrieving " & varName & " : " & Nut_Query.Data, LogLvl.LOG_ERROR, Me) - Return Nothing - End If - Case NUTResponse.DATASTALE - 'Me.Invalid_Data = True + ' Try + ' LogFile.LogTracing("Enter GetUPSVar", LogLvl.LOG_DEBUG, Me) + 'If Not Me.ConnectionStatus Then + If Not Me.IsConnected Then + Throw New Nut_Exception(Nut_Exception_Value.SOCKET_BROKEN, varName) + Return Nothing + Else + Dim Nut_Query = Me.Nut_Socket.Query_Data("GET VAR " & UPSName & " " & varName) + + Select Case Nut_Query.Response + Case NUTResponse.OK + ' LogFile.LogTracing("Process Result With " & varName & " : " & Nut_Query.Data, LogLvl.LOG_DEBUG, Me) + Return ExtractData(Nut_Query.Data) + Case NUTResponse.UNKNOWNUPS + 'Me.Invalid_Data = False + 'Me.Unknown_UPS_Name = True + RaiseEvent Unknown_UPS() + Throw New Nut_Exception(Nut_Exception_Value.UNKNOWN_UPS) + Case NUTResponse.VARNOTSUPPORTED + 'Me.Unknown_UPS_Name = False + 'Me.Invalid_Data = False + If Not String.IsNullOrEmpty(Fallback_value) Then + LogFile.LogTracing("Apply Fallback Value when retrieving " & varName, LogLvl.LOG_WARNING, Me) + Dim FakeData = "VAR " & UPSName & " " & varName & " " & """" & Fallback_value & """" + Return ExtractData(FakeData) + Else LogFile.LogTracing("Error Result On Retrieving " & varName & " : " & Nut_Query.Data, LogLvl.LOG_ERROR, Me) - Throw New System.Exception(varName & " : " & Nut_Query.Data) Return Nothing - Case Else - Return Nothing - End Select - End If - Catch Excep As Exception - 'RaiseEvent OnError(Excep, LogLvl.LOG_ERROR, Me) - Return Nothing - End Try + End If + Case NUTResponse.DATASTALE + 'Me.Invalid_Data = True + LogFile.LogTracing("Error Result On Retrieving " & varName & " : " & Nut_Query.Data, LogLvl.LOG_ERROR, Me) + Throw New System.Exception(varName & " : " & Nut_Query.Data) + Return Nothing + Case Else + Return Nothing + End Select + End If + 'Catch Excep As Exception + ' 'RaiseEvent OnError(Excep, LogLvl.LOG_ERROR, Me) + ' Return Nothing + 'End Try End Function Public Function GetUPS_ListVar() As List(Of UPS_List_Datas) @@ -371,47 +494,4 @@ Public Class UPS_Device End Try Return StringArray(StringArray.Length - 1) End Function - - Private Sub Socket_Deconnected() - WatchDog.Stop() - LogFile.LogTracing("TCP Socket Deconnected", LogLvl.LOG_WARNING, Me) - If Not Me.Socket_Status Then - RaiseEvent Lost_Connect() - End If - Me.Socket_Status = False - If Me.Nut_Config.AutoReconnect Then - LogFile.LogTracing("Reconnection Process Started", LogLvl.LOG_NOTICE, Me) - Reconnect_Nut.Enabled = True - Reconnect_Nut.Start() - End If - End Sub - - Private Sub Socket_Broken() Handles Nut_Socket.Socket_Broken - LogFile.LogTracing("TCP Socket seems Broken", LogLvl.LOG_WARNING, Me) - Socket_Deconnected() - End Sub - Private Sub Reconnect_Socket(sender As Object, e As EventArgs) - Me.Retry += 1 - If Me.Retry <= Me.MaxRetry Then - RaiseEvent New_Retry() - LogFile.LogTracing(String.Format("Try Reconnect {0} / {1}", Me.Retry, Me.MaxRetry), LogLvl.LOG_NOTICE, Me, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_NEW_RETRY), Me.Retry, Me.MaxRetry)) - Me.Connect_UPS() - If Me.IsConnected Then - LogFile.LogTracing("Nut Host Reconnected", LogLvl.LOG_DEBUG, Me) - Reconnect_Nut.Enabled = False - Reconnect_Nut.Stop() - Me.Retry = 0 - RaiseEvent ReConnected() - End If - Else - LogFile.LogTracing("Max Retry reached. Stop Process Autoreconnect and wait for manual Reconnection", LogLvl.LOG_ERROR, Me, WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_STOP_RETRY)) - Reconnect_Nut.Enabled = False - Reconnect_Nut.Stop() - RaiseEvent Deconnected() - End If - End Sub - - Private Sub NUTSocketError(nutEx As Nut_Exception, NoticeLvl As LogLvl, sender As Object) Handles Nut_Socket.OnNUTException - LogFile.LogTracing("[" & Nut_Config.UPSName & "] " & nutEx.ToString(), LogLvl.LOG_WARNING, Nut_Socket) - End Sub End Class diff --git a/WinNUT_V2/WinNUT-Client_Common/WinNUT_Globals.vb b/WinNUT_V2/WinNUT-Client_Common/WinNUT_Globals.vb index 246d749..2ab7659 100644 --- a/WinNUT_V2/WinNUT-Client_Common/WinNUT_Globals.vb +++ b/WinNUT_V2/WinNUT-Client_Common/WinNUT_Globals.vb @@ -32,7 +32,7 @@ Public Module WinNUT_Globals Public IsConnected As Boolean ' Public LogFile As String ' Handle application messages and debug events. - Public WithEvents LogFile As Logger ' As New Logger(False, 0) + ' Public WithEvents LogFile As Logger ' As New Logger(False, 0) Public AppIcon As Dictionary(Of Integer, System.Drawing.Icon) Public StrLog As New List(Of String) ' Public LogFilePath As String diff --git a/WinNUT_V2/WinNUT_GUI/ApplicationEvents.vb b/WinNUT_V2/WinNUT_GUI/ApplicationEvents.vb index be2b1cb..866c06d 100644 --- a/WinNUT_V2/WinNUT_GUI/ApplicationEvents.vb +++ b/WinNUT_V2/WinNUT_GUI/ApplicationEvents.vb @@ -23,6 +23,7 @@ Namespace My Private BtnGenerate As New Button Private Msg_Crash As New Label Private Msg_Error As New TextBox + Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException e.ExitApplication = False @@ -81,7 +82,7 @@ Namespace My End With AddHandler BtnClose.Click, AddressOf My.Application.Close_Button_Click - AddHandler BtnGenerate.Click, AddressOf My.Application.Generate_Button_Click + AddHandler BtnGenerate.Click, AddressOf Application.Generate_Button_Click AddHandler CrashBug_Form.FormClosing, AddressOf My.Application.CrashBug_FormClosing CrashBug_Form.Show() @@ -122,7 +123,7 @@ Namespace My Crash_Report &= Msg_Error.Text & vbNewLine & vbNewLine Crash_Report &= "Last Events :" & vbNewLine - For Each WinNUT_Event In LogFile.LastEvents + For Each WinNUT_Event In WinNUT.LogFile.LastEvents Crash_Report &= WinNUT_Event & vbNewLine Next My.Computer.Clipboard.SetText(Crash_Report) diff --git a/WinNUT_V2/WinNUT_GUI/List_Var_Gui.vb b/WinNUT_V2/WinNUT_GUI/List_Var_Gui.vb index 79b3f6c..bceb7fa 100644 --- a/WinNUT_V2/WinNUT_GUI/List_Var_Gui.vb +++ b/WinNUT_V2/WinNUT_GUI/List_Var_Gui.vb @@ -8,13 +8,11 @@ ' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY Imports WinNUT_Client_Common -Imports System.Threading -Imports System.ComponentModel Public Class List_Var_Gui Private List_Var_Datas As List(Of UPS_List_Datas) Private LogFile As Logger - Private UPS_Name = WinNUT.Nut_Config.UPSName + Private UPS_Name = WinNUT.UPS_Device.Nut_Config.UPSName Private Sub List_Var_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Me.LogFile = WinNUT.LogFile LogFile.LogTracing("Load List Var Gui", LogLvl.LOG_DEBUG, Me) diff --git a/WinNUT_V2/WinNUT_GUI/Pref_Gui.vb b/WinNUT_V2/WinNUT_GUI/Pref_Gui.vb index 92df120..48bbfbf 100644 --- a/WinNUT_V2/WinNUT_GUI/Pref_Gui.vb +++ b/WinNUT_V2/WinNUT_GUI/Pref_Gui.vb @@ -8,9 +8,7 @@ ' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY Imports WinNUT_Params = WinNUT_Client_Common.WinNUT_Params -Imports Logger = WinNUT_Client_Common.Logger Imports LogLvl = WinNUT_Client_Common.LogLvl -Imports WinNUT_Client_Common.WinNUT_Globals Imports System.IO Public Class Pref_Gui @@ -18,14 +16,14 @@ Public Class Pref_Gui Private IsSaved As Boolean = False Private Sub Btn_Cancel_Click(sender As Object, e As EventArgs) Handles Btn_Cancel.Click - LogFile.LogTracing("Close Pref Gui from Button Cancel", LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing("Close Pref Gui from Button Cancel", LogLvl.LOG_DEBUG, Me) Me.Close() End Sub Private Sub Save_Params() Try Me.IsSaved = False - LogFile.LogTracing("Save Parameters.", LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing("Save Parameters.", LogLvl.LOG_DEBUG, Me) WinNUT_Params.Arr_Reg_Key.Item("ServerAddress") = Tb_Server_IP.Text WinNUT_Params.Arr_Reg_Key.Item("Port") = CInt(Tb_Port.Text) WinNUT_Params.Arr_Reg_Key.Item("UPSName") = Tb_UPS_Name.Text @@ -66,19 +64,19 @@ Public Class Pref_Gui If CB_Start_W_Win.Checked Then If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", Application.ProductName, Nothing) Is Nothing Then My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath) - LogFile.LogTracing("WinNUT Added to Startup.", LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing("WinNUT Added to Startup.", LogLvl.LOG_DEBUG, Me) End If Else If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", Application.ProductName, Nothing) Is Nothing Then My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName) - LogFile.LogTracing("WinNUT Removed From Startup.", LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing("WinNUT Removed From Startup.", LogLvl.LOG_DEBUG, Me) End If End If - LogFile.LogLevel = Cbx_LogLevel.SelectedIndex - LogFile.IsWritingToFile = CB_Use_Logfile.Checked + WinNUT.LogFile.LogLevel = Cbx_LogLevel.SelectedIndex + WinNUT.LogFile.IsWritingToFile = CB_Use_Logfile.Checked - LogFile.LogTracing("Pref_Gui Params Saved", 1, Me) + WinNUT.LogFile.LogTracing("Pref_Gui Params Saved", 1, Me) SetLogControlsStatus() WinNUT.WinNUT_PrefsChanged() @@ -184,11 +182,11 @@ Public Class Pref_Gui Next Me.Btn_Apply.Enabled = False Me.IsShowed = True - LogFile.LogTracing("Pref Gui Opened.", LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing("Pref Gui Opened.", LogLvl.LOG_DEBUG, Me) Catch Except As Exception Me.IsShowed = False Me.Close() - LogFile.LogTracing("Error on Opening Pref_Gui.", LogLvl.LOG_ERROR, Me) + WinNUT.LogFile.LogTracing("Error on Opening Pref_Gui.", LogLvl.LOG_ERROR, Me) End Try End Sub @@ -238,7 +236,7 @@ Public Class Pref_Gui Dim Result As Object = 0 Dim MinValue, MaxValue As Integer - LogFile.LogTracing(String.Format("Check that the value of {0} for {1} is correct.", sender.Text, sender.Name), LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing(String.Format("Check that the value of {0} for {1} is correct.", sender.Text, sender.Name), LogLvl.LOG_DEBUG, Me) Select Case sender.Name Case "Tb_Delay_Com" MinValue = 0 @@ -267,10 +265,10 @@ Public Class Pref_Gui If Integer.TryParse(sender.Text, Result) Then If (Result >= MinValue And Result <= MaxValue) Then - LogFile.LogTracing(String.Format("Value of {0} for {1} is valid.", Result, sender.Name), LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing(String.Format("Value of {0} for {1} is valid.", Result, sender.Name), LogLvl.LOG_DEBUG, Me) sender.BackColor = Color.White Else - LogFile.LogTracing(String.Format("Value of {0} for {1} is invalid.", Result, sender.Name), LogLvl.LOG_ERROR, Me) + WinNUT.LogFile.LogTracing(String.Format("Value of {0} for {1} is invalid.", Result, sender.Name), LogLvl.LOG_ERROR, Me) e.Cancel = True sender.BackColor = Color.Red End If @@ -281,7 +279,7 @@ Public Class Pref_Gui End If End Sub Private Sub Correct_IP_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Tb_Server_IP.Validating - LogFile.LogTracing("Check that the Nut Host address is valid.", LogLvl.LOG_DEBUG, Me) + WinNUT.LogFile.LogTracing("Check that the Nut Host address is valid.", LogLvl.LOG_DEBUG, Me) Dim Pattern As String Dim StrTest As String = sender.Text Dim Is_Correct As Boolean = False @@ -289,26 +287,26 @@ Public Class Pref_Gui Pattern = "^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$" If System.Text.RegularExpressions.Regex.IsMatch(sender.Text, Pattern) Then Is_Correct = True - LogFile.LogTracing("The Nut Host address is a valid IPV4 address.", LogLvl.LOG_WARNING, Me) + WinNUT.LogFile.LogTracing("The Nut Host address is a valid IPV4 address.", LogLvl.LOG_WARNING, Me) End If 'Test IPV6 Pattern = "^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$" If (System.Text.RegularExpressions.Regex.IsMatch(sender.Text, Pattern) And Not Is_Correct) Then Is_Correct = True - LogFile.LogTracing("The Nut Host address is a valid IPV6 address.", LogLvl.LOG_WARNING, Me) + WinNUT.LogFile.LogTracing("The Nut Host address is a valid IPV6 address.", LogLvl.LOG_WARNING, Me) End If 'Test fqdn Pattern = "^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?v4.7.2 false - C:\Users\Nicolas\OneDrive\Documents\GitHub\WinNUT-Client\Releases\ + true Disk false @@ -25,7 +25,7 @@ false true 1 - 2.0.0.%2a + 2.2.0.%2a false true true diff --git a/WinNUT_V2/WinNUT_GUI/WinNUT.vb b/WinNUT_V2/WinNUT_GUI/WinNUT.vb index 7b3f3ea..0f42d8a 100644 --- a/WinNUT_V2/WinNUT_GUI/WinNUT.vb +++ b/WinNUT_V2/WinNUT_GUI/WinNUT.vb @@ -14,15 +14,16 @@ Public Class WinNUT #End Region ' Logging - Private WithEvents ClientLogger As Logger + Public Shared WithEvents LogFile As Logger 'Object for UPS management Public WithEvents UPS_Device As UPS_Device - Public Nut_Socket As Nut_Socket - Public Nut_Config As New Nut_Parameter - Public Device_Data As UPS_Datas - Private Polling_Interval As Integer - Private Update_Data As New System.Windows.Forms.Timer + ' Public Nut_Socket As Nut_Socket + ' Public Nut_Config As New Nut_Parameter + ' Private Device_Data As UPS_Datas + + ' ^--- Shall be referenced from inside UPS_Device object + Private AutoReconnect As Boolean Private UPS_Retry As Integer = 0 Private UPS_MaxRetry As Integer = 30 @@ -64,30 +65,31 @@ Public Class WinNUT 'Events Declaration Private Event On_Battery() Private Event On_Line() - Private Event Data_Updated() + ' Private Event Data_Updated() Private Event UpdateNotifyIconStr(ByVal Reason As String, ByVal Message As String) Private Event UpdateBatteryState(ByVal Reason As String) + Private Event RequestConnect() 'Handle sleep/hibernate mode from windows API Declare Function SetSuspendState Lib "PowrProf" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer Public Property UpdateMethod() As String Get - If Me.mUpdate Then - Me.mUpdate = False + If mUpdate Then + mUpdate = False Return True Else Return False End If End Get Set(ByVal Value As String) - Me.mUpdate = Value + mUpdate = Value End Set End Property Public WriteOnly Property HasCrashed() As Boolean Set(ByVal Value As Boolean) - Me.WinNUT_Crashed = Value + WinNUT_Crashed = Value End Set End Property @@ -98,6 +100,7 @@ Public Class WinNUT LogFile = New Logger(False, LogLvl.LOG_DEBUG) AddHandler Microsoft.Win32.SystemEvents.PowerModeChanged, AddressOf SystemEvents_PowerModeChanged + AddHandler RequestConnect, AddressOf UPS_Connect 'Init WinNUT Variables Init_Globals() @@ -158,18 +161,18 @@ Public Class WinNUT ' Setup logging preferences LogFile.LogLevel = Arr_Reg_Key.Item("Log Level") LogFile.IsWritingToFile = Arr_Reg_Key.Item("UseLogFile") - ClientLogger = LogFile + LogFile.LogTracing("Logging is configured.", LogLvl.LOG_DEBUG, Me) 'Init Systray - Me.NotifyIcon.Text = WinNUT_Globals.LongProgramName & " - " & WinNUT_Globals.ShortProgramVersion - Me.NotifyIcon.Visible = False + NotifyIcon.Text = WinNUT_Globals.LongProgramName & " - " & WinNUT_Globals.ShortProgramVersion + NotifyIcon.Visible = False LogFile.LogTracing("NotifyIcons Initialised", LogLvl.LOG_DEBUG, Me) 'Verify If Toast Compatible - If Me.MinOsVersionToast.CompareTo(Me.WindowsVersion) < 0 Then - Me.AllowToast = True + If MinOsVersionToast.CompareTo(WindowsVersion) < 0 Then + AllowToast = True ToastPopup.ToastHeader = WinNUT_Globals.ProgramName & " - " & WinNUT_Globals.ShortProgramVersion LogFile.LogTracing("Windows 10 Toast Notification Available", LogLvl.LOG_DEBUG, Me) 'Dim ico As Icon = Me.Icon @@ -182,26 +185,6 @@ Public Class WinNUT LogFile.LogTracing("Windows 10 Toast Notification Not Available. Too Old Windows Version", LogLvl.LOG_DEBUG, Me) End If - 'Init Connexion to UPS - With Me.Nut_Config - .Host = WinNUT_Params.Arr_Reg_Key.Item("ServerAddress") - .Port = WinNUT_Params.Arr_Reg_Key.Item("Port") - .Login = WinNUT_Params.Arr_Reg_Key.Item("NutLogin") - .Password = WinNUT_Params.Arr_Reg_Key.Item("NutPassword") - .UPSName = WinNUT_Params.Arr_Reg_Key.Item("UPSName") - .AutoReconnect = WinNUT_Params.Arr_Reg_Key.Item("AutoReconnect") - End With - - 'Nut_Socket = New Nut_Comm(Me.Nut_Parameter) - 'UPS_Device = New UPS_Device(Nut_Socket, WinNUT_Params.Arr_Reg_Key.Item("UPSName"), WinNUT.LogFile) - UPS_Device = New UPS_Device(Me.Nut_Config, LogFile) - Nut_Socket = UPS_Device.Nut_Socket - Me.Polling_Interval = WinNUT_Params.Arr_Reg_Key.Item("Delay") - With Me.Update_Data - .Interval = Me.Polling_Interval - .Enabled = True - End With - 'UPS_Device.Battery_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitBatteryCharge") 'UPS_Device.Backup_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitUPSRemainTime") 'UPS_Device.UPS_Follow_FSD = WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") @@ -211,43 +194,43 @@ Public Class WinNUT .Location = New Point(6, 26) .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage") .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage") - .Value1 = Me.UPS_InputV + .Value1 = UPS_InputV .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) End With With AG_InF .Location = New Point(6, 26) .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxInputFrequency") .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinInputFrequency") - .Value1 = Me.UPS_InputF + .Value1 = UPS_InputF .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) End With With AG_OutV .Location = New Point(6, 26) .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxOutputVoltage") .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinOutputVoltage") - .Value1 = Me.UPS_OutputV + .Value1 = UPS_OutputV .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) End With With AG_BattCh .Location = New Point(6, 26) .MaxValue = 100 .MinValue = 0 - .Value1 = Me.UPS_BattCh + .Value1 = UPS_BattCh .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) End With With AG_Load .Location = New Point(6, 26) .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxUPSLoad") .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinUPSLoad") - .Value1 = Me.UPS_Load - .Value2 = Me.UPS_OutPower + .Value1 = UPS_Load + .Value2 = UPS_OutPower .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) End With With AG_BattV .Location = New Point(6, 26) .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxBattVoltage") .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage") - .Value1 = Me.UPS_BattV + .Value1 = UPS_BattV .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) End With @@ -275,7 +258,7 @@ Public Class WinNUT Else Start_App_Icon = AppIconIdx.IDX_ICO_OFFLINE Or AppIconIdx.IDX_OFFSET End If - Me.Icon = GetIcon(Start_App_Icon) + Icon = GetIcon(Start_App_Icon) If WinDarkMode Then Start_Tray_Icon = AppIconIdx.IDX_ICO_OFFLINE Or AppIconIdx.WIN_DARK Or AppIconIdx.IDX_OFFSET Else @@ -286,9 +269,10 @@ Public Class WinNUT NotifyIcon.Visible = False NotifyIcon.Icon = GetIcon(Start_Tray_Icon) RaiseEvent UpdateNotifyIconStr(Nothing, Nothing) - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) + ActualAppIconIdx = Start_App_Icon UpdateIcon_NotifyIcon() - Start_Tray_Icon = Nothing + LogFile.LogTracing("Update Icon at Startup", LogLvl.LOG_DEBUG, Me) + ' Start_Tray_Icon = Nothing 'Run Update If WinNUT_Params.Arr_Reg_Key.Item("VerifyUpdate") = True And WinNUT_Params.Arr_Reg_Key.Item("VerifyUpdateAtStart") = True Then @@ -299,8 +283,7 @@ Public Class WinNUT HasFocus = False End If 'ToastPopup.CreateToastCollection() - LogFile.LogTracing("Try to connect to UPS", LogLvl.LOG_DEBUG, Me) - UPS_Connect() + ' RaiseEvent RequestConnect() End Sub Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As Microsoft.Win32.PowerModeChangedEventArgs) @@ -313,55 +296,132 @@ Public Class WinNUT End If Case Microsoft.Win32.PowerModes.Suspend LogFile.LogTracing("Windows standby, WinNUT will disconnect", LogLvl.LOG_NOTICE, Me, WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_GOTOSLEEP)) - 'UPS_Device.Disconnect() + ' UPSDisconnect() + UPS_Device.Disconnect() End Select End Sub Private Sub UPS_Connect() - LogFile.LogTracing("Connect To Nut Server", LogLvl.LOG_DEBUG, Me) + Dim Nut_Config As Nut_Parameter + ' LogFile.LogTracing("Client UPS_Connect subroutine beginning.", LogLvl.LOG_NOTICE, Me) + + Nut_Config = New Nut_Parameter(Arr_Reg_Key.Item("ServerAddress"), + Arr_Reg_Key.Item("Port"), + Arr_Reg_Key.Item("NutLogin"), + Arr_Reg_Key.Item("NutPassword"), + Arr_Reg_Key.Item("UPSName"), + Arr_Reg_Key.Item("AutoReconnect")) + + UPS_Device = New UPS_Device(Nut_Config, LogFile, Arr_Reg_Key.Item("Delay")) UPS_Device.Connect_UPS() - Dim Host = Me.Nut_Config.Host - Dim Port = Me.Nut_Config.Port - Dim Login = Me.Nut_Config.Login - Dim Password = Me.Nut_Config.Password - If Not (Me.UPS_Device.IsConnected And UPS_Device.IsAuthenticated) Then - LogFile.LogTracing("Error When Connection to Nut Host.", LogLvl.LOG_ERROR, Me, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_CON_FAILED), Host, Port, "Connection Error")) + End Sub + + ''' + ''' Prepare the form to begin receiving data from a connected UPS. + ''' + Private Sub UPSReady(nutUps As UPS_Device) Handles UPS_Device.Connected, UPS_Device.ReConnected + Dim upsConf = nutUps.Nut_Config + LogFile.LogTracing(upsConf.UPSName & " has indicated it's ready to start sending data.", LogLvl.LOG_DEBUG, Me) + + ' Setup and begin polling data from UPS. + ' Polling_Interval = Arr_Reg_Key.Item("Delay") + 'With Update_Data + ' .Interval = Polling_Interval + ' ' .Enabled = True + 'End With + + If Not (UPS_Device.IsConnected And UPS_Device.IsAuthenticated) Then + LogFile.LogTracing(String.Format("Something went wrong connecting to UPS {0}. IsConnected: {1}, IsAuthenticated: {2}", + upsConf.UPSName, UPS_Device.IsConnected, UPS_Device.IsAuthenticated), LogLvl.LOG_ERROR, Me, + String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_CON_FAILED), upsConf.Host, upsConf.Port, "Connection Error")) + ' UPSDisconnect() + UPS_Device.Disconnect() Else - LogFile.LogTracing("Connection to Nut Host Established", LogLvl.LOG_NOTICE, Me, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_CONNECTED), Host, Port)) - Update_Data.Start() - AddHandler Update_Data.Tick, AddressOf Retrieve_UPS_Datas - Me.Device_Data = UPS_Device.Retrieve_UPS_Datas() - RaiseEvent Data_Updated() + LogFile.LogTracing("Connection to Nut Host Established", LogLvl.LOG_NOTICE, Me, + String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_CONNECTED), + upsConf.Host, upsConf.Port)) + + ' AddHandler Update_Data.Tick, AddressOf Retrieve_UPS_Datas + ' AddHandler UPS_Device.Lost_Connect, AddressOf UPS_Lostconnect + ' Me.Device_Data = UPS_Device.Retrieve_UPS_Datas() + ' RaiseEvent Data_Updated() + ' Update_Data.Start() + Menu_UPS_Var.Enabled = True + + UpdateIcon_NotifyIcon() + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) + RaiseEvent UpdateNotifyIconStr("Connected", Nothing) End If End Sub - Private Sub Retrieve_UPS_Datas(sender As Object, e As EventArgs) - Me.Device_Data = UPS_Device.Retrieve_UPS_Datas() - RaiseEvent Data_Updated() + ''' + ''' Prepare application for and handle disconnecting from the UPS. + ''' + Private Sub UPSDisconnect() Handles UPS_Device.Disconnected + ' LogFile.LogTracing("Running Client disconnect subroutine.", LogLvl.LOG_DEBUG, Me) + + ' Update_Data.Stop() + ' Update_Data. + ' RemoveHandler Update_Data.Tick, AddressOf Retrieve_UPS_Datas + + 'If UPS_Device IsNot Nothing Then + ' ' RemoveHandler UPS_Device.Connected, AddressOf UPSReady + ' RemoveHandler UPS_Device.Lost_Connect, AddressOf UPS_Lostconnect + 'End If + + 'If UPS_Device.Nut_Socket IsNot Nothing Then + ' UPS_Device.Nut_Socket.Disconnect(True) + 'End If + + ReInitDisplayValues() + ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE + LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) + UpdateIcon_NotifyIcon() + RaiseEvent UpdateNotifyIconStr("Deconnected", Nothing) + RaiseEvent UpdateBatteryState("Deconnected") + + LogFile.LogTracing("Disconnected from Nut Host", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_LOG_LOGOFF)) + ' Nut_Socket = Nothing + ' UPS_Device.Dispose() Dispose in the future... End Sub + 'Private Sub Retrieve_UPS_Datas(sender As Object, e As EventArgs) Handles Update_Data.Tick + ' If Not Update_Data.Enabled Then + ' LogFile.LogTracing("Update_Data timer Ticked while disabled. Ignoring.", LogLvl.LOG_DEBUG, Me) + ' Else + ' Me.Device_Data = UPS_Device.Retrieve_UPS_Datas() + ' RaiseEvent Data_Updated() + ' End If + 'End Sub + Private Sub WinNUT_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) UpdateIcon_NotifyIcon() If WinNUT_Params.Arr_Reg_Key.Item("MinimizeToTray") = True And WinNUT_Params.Arr_Reg_Key.Item("MinimizeOnStart") = True Then LogFile.LogTracing("Minimize WinNut On Start", LogLvl.LOG_DEBUG, Me) - Me.WindowState = FormWindowState.Minimized - Me.NotifyIcon.Visible = True + WindowState = FormWindowState.Minimized + NotifyIcon.Visible = True Else LogFile.LogTracing("Show WinNut Main Gui", LogLvl.LOG_DEBUG, Me) - Me.NotifyIcon.Visible = False + NotifyIcon.Visible = False End If If WinNUT_Params.Arr_Reg_Key.Item("VerifyUpdate") = True Then - Me.Menu_Help_Sep1.Visible = True - Me.Menu_Update.Visible = True - Me.Menu_Update.Visible = Enabled = True + Menu_Help_Sep1.Visible = True + Menu_Update.Visible = True + Menu_Update.Visible = Enabled = True Else - Me.Menu_Help_Sep1.Visible = False - Me.Menu_Update.Visible = False - Me.Menu_Update.Visible = Enabled = False + Menu_Help_Sep1.Visible = False + Menu_Update.Visible = False + Menu_Update.Visible = Enabled = False + End If + + ' Begin auto-connecting if user indicated they wanted it. (Note: Will hang form because we don't do threading yet) + If Arr_Reg_Key.Item("AutoReconnect") Then + LogFile.LogTracing("Auto-connecting to UPS on startup.", LogLvl.LOG_NOTICE, Me) + UPS_Connect() End If - LogFile.LogTracing("Init Connexion to NutServer", LogLvl.LOG_DEBUG, Me) + LogFile.LogTracing("Completed WinNUT_Shown", LogLvl.LOG_DEBUG, Me) End Sub Private Sub WinNUT_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing @@ -369,15 +429,16 @@ Public Class WinNUT LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) UpdateIcon_NotifyIcon() LogFile.LogTracing("Minimize Main Gui To Notify Icon", LogLvl.LOG_DEBUG, Me) - Me.WindowState = FormWindowState.Minimized - Me.Visible = False - Me.NotifyIcon.Visible = True + WindowState = FormWindowState.Minimized + Visible = False + NotifyIcon.Visible = True e.Cancel = True Else LogFile.LogTracing("Init Disconnecting Before Close WinNut", LogLvl.LOG_DEBUG, Me) - Nut_Socket.Disconnect(True) - LogFile.LogTracing("WinNut Is now Closed", LogLvl.LOG_DEBUG, Me) RemoveHandler Microsoft.Win32.SystemEvents.PowerModeChanged, AddressOf SystemEvents_PowerModeChanged + ' UPSDisconnect() + UPS_Device.Disconnect() + LogFile.LogTracing("WinNut Is now Closed", LogLvl.LOG_DEBUG, Me) End End If End Sub @@ -409,9 +470,9 @@ Public Class WinNUT Private Sub NotifyIcon_MouseClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon.MouseClick, NotifyIcon.MouseDoubleClick If e.Button <> MouseButtons.Right Then LogFile.LogTracing("Restore Main Gui On Mouse Click Notify Icon", LogLvl.LOG_DEBUG, Me) - Me.Visible = True - Me.NotifyIcon.Visible = False - Me.WindowState = FormWindowState.Normal + Visible = True + NotifyIcon.Visible = False + WindowState = FormWindowState.Normal End If End Sub @@ -421,17 +482,17 @@ Public Class WinNUT LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) UpdateIcon_NotifyIcon() LogFile.LogTracing("Minimize Main Gui To Notify Icon", LogLvl.LOG_DEBUG, Me) - Me.WindowState = FormWindowState.Minimized - Me.Visible = False - Me.NotifyIcon.Visible = True + WindowState = FormWindowState.Minimized + Visible = False + NotifyIcon.Visible = True End If - If Me.NotifyIcon.Visible = False Then - Me.Text = Me.FormText + If NotifyIcon.Visible = False Then + Text = FormText Else - Me.Text = "WinNUT" + Text = "WinNUT" End If ElseIf sender.WindowState = FormWindowState.Maximized Or sender.WindowState = FormWindowState.Normal Then - Me.Text = "WinNUT" + Text = "WinNUT" End If End Sub @@ -442,21 +503,11 @@ Public Class WinNUT LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) End Sub - Private Sub Reconnect_NotifyIcon() Handles UPS_Device.Connected - Menu_UPS_Var.Enabled = True - UpdateIcon_NotifyIcon() - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) - RaiseEvent UpdateNotifyIconStr("Connected", Nothing) - End Sub + 'Private Sub Reconnect_NotifyIcon() Handles UPS_Device.Connected + + 'End Sub + - Private Sub Deconnected_NotifyIcon() Handles UPS_Device.Deconnected - ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) - UpdateIcon_NotifyIcon() - RaiseEvent UpdateNotifyIconStr("Deconnected", Nothing) - RaiseEvent UpdateBatteryState("Deconnected") - Update_Data.Stop() - End Sub Private Sub Event_UpdateNotifyIconStr(ByVal Optional Reason As String = Nothing, ByVal Optional Message As String = Nothing) Handles Me.UpdateNotifyIconStr Dim ShowVersion As String = WinNUT_Globals.ShortProgramVersion @@ -464,17 +515,17 @@ Public Class WinNUT Dim FormText As String = WinNUT_Globals.ProgramName Select Case Reason Case Nothing - If Not Me.UPS_Device.IsConnected Then + If (UPS_Device Is Nothing) OrElse Not UPS_Device.IsConnected Then NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_NOTCONN) FormText &= " - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_NOTCONN) End If Case "Retry" NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RECONNECT) & vbNewLine NotifyStr &= Message - FormText &= " - Bat: " & Me.UPS_BattCh & "% - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RECONNECT) & " - " & Message + FormText &= " - Bat: " & UPS_BattCh & "% - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RECONNECT) & " - " & Message Case "Connected" NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_CONN) - FormText &= " - Bat: " & Me.UPS_BattCh & "% - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_CONN) + FormText &= " - Bat: " & UPS_BattCh & "% - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_CONN) Case "Deconnected" NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_NOTCONN) FormText &= " - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_NOTCONN) @@ -482,12 +533,12 @@ Public Class WinNUT NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_UNKNOWN_UPS) FormText &= " - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_UNKNOWN_UPS) Case "Lost Connect" - NotifyStr &= String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Me.Nut_Config.Host, Me.Nut_Config.Port) - FormText &= " - " & String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Me.Nut_Config.Host, Me.Nut_Config.Port) + NotifyStr &= String.Format(StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), UPS_Device.Nut_Config.Host, UPS_Device.Nut_Config.Port) + FormText &= " - " & String.Format(StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), UPS_Device.Nut_Config.Host, UPS_Device.Nut_Config.Port) Case "Update Data" - FormText &= " - Bat: " & Me.UPS_BattCh & "% - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_CONN) & " - " + FormText &= " - Bat: " & UPS_BattCh & "% - " & WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_CONN) & " - " NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_CONN) & vbNewLine - If Me.UPS_Status.Trim().StartsWith("OL") Or StrReverse(Me.UPS_Status.Trim()).StartsWith("LO") Then + If UPS_Status.Trim().StartsWith("OL") Or StrReverse(UPS_Status.Trim()).StartsWith("LO") Then NotifyStr &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_OL) & vbNewLine FormText &= WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_OL) & " - " Else @@ -506,42 +557,42 @@ Public Class WinNUT If NotifyStr.Length > 64 Then NotifyStr = NotifyStr.Substring(0, (64 - NotifyStr.Length - 4)) & "..." End If - Me.NotifyIcon.Text = NotifyStr - If Me.WindowState = System.Windows.Forms.FormWindowState.Minimized And Me.NotifyIcon.Visible = False Then - Me.Text = FormText + NotifyIcon.Text = NotifyStr + If Me.WindowState = System.Windows.Forms.FormWindowState.Minimized And NotifyIcon.Visible = False Then + Text = FormText Else - Me.Text = WinNUT_Globals.LongProgramName + Text = WinNUT_Globals.LongProgramName End If Me.FormText = FormText LogFile.LogTracing("NotifyIcon Text => " & vbNewLine & NotifyStr, LogLvl.LOG_DEBUG, Me) End Sub - Private Shared Sub Event_UpdateBatteryState(ByVal Optional Reason As String = Nothing) Handles Me.UpdateBatteryState - Static Dim Old_Battery_Value As Integer = WinNUT.UPS_BattCh + Private Sub Event_UpdateBatteryState(ByVal Optional Reason As String = Nothing) Handles Me.UpdateBatteryState + Static Dim Old_Battery_Value As Integer = UPS_BattCh Dim Status As String = "Unknown" Select Case Reason Case Nothing, "Deconnected", "Lost Connect" - If Not WinNUT.UPS_Device.Nut_Socket.IsConnected Then - WinNUT.PBox_Battery_State.Image = Nothing + If (UPS_Device IsNot Nothing) AndAlso Not UPS_Device.Nut_Socket.IsConnected Then + PBox_Battery_State.Image = Nothing End If Status = "Unknown" Case "Update Data" - If WinNUT.UPS_BattCh = 100 Then - WinNUT.PBox_Battery_State.Image = My.Resources.Battery_Charged + If UPS_BattCh = 100 Then + PBox_Battery_State.Image = My.Resources.Battery_Charged Status = "Charged" Else - If WinNUT.UPS_Status.Trim().StartsWith("OL") Or StrReverse(WinNUT.UPS_Status.Trim()).StartsWith("LO") Then - WinNUT.PBox_Battery_State.Image = My.Resources.Battery_Charging + If UPS_Status.Trim().StartsWith("OL") Or StrReverse(UPS_Status.Trim()).StartsWith("LO") Then + PBox_Battery_State.Image = My.Resources.Battery_Charging Status = "Charging" Else - WinNUT.PBox_Battery_State.Image = My.Resources.Battery_Discharging + PBox_Battery_State.Image = My.Resources.Battery_Discharging Status = "Discharging" End If End If End Select - Old_Battery_Value = WinNUT.UPS_BattCh - LogFile.LogTracing("Battery Status => " & Status, LogLvl.LOG_DEBUG, WinNUT) + Old_Battery_Value = UPS_BattCh + LogFile.LogTracing("Battery Status => " & Status, LogLvl.LOG_DEBUG, Me) End Sub Public Sub Event_Unknown_UPS() Handles UPS_Device.Unknown_UPS, UPS_Device.Unknown_UPS @@ -568,15 +619,17 @@ Public Class WinNUT End Sub Private Sub UPS_Lostconnect() Handles UPS_Device.Lost_Connect - Dim Host = Nut_Config.Host - Dim Port = Nut_Config.Port - Update_Data.Stop() - LogFile.LogTracing("Nut Server Lost Connection", LogLvl.LOG_ERROR, Me, String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Host, Port)) - LogFile.LogTracing("Fix All data to null/empty String", LogLvl.LOG_DEBUG, Me) - LogFile.LogTracing("Fix All Dial Data to Min Value/0", LogLvl.LOG_DEBUG, Me) - - ReInitDisplayValues() - If AutoReconnect And UPS_Retry <= UPS_MaxRetry Then + LogFile.LogTracing("Notify user of lost connection", LogLvl.LOG_ERROR, Me, + String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), UPS_Device.Nut_Config.Host, UPS_Device.Nut_Config.Port)) + UPSDisconnect() + 'Dim Host = UPS_Device.Nut_Config.Host + 'Dim Port = UPS_Device.Nut_Config.Port + 'Update_Data.Stop() + 'LogFile.LogTracing("Fix All data to null/empty String", LogLvl.LOG_DEBUG, Me) + 'LogFile.LogTracing("Fix All Dial Data to Min Value/0", LogLvl.LOG_DEBUG, Me) + + 'ReInitDisplayValues() + If UPS_Device.Nut_Config.AutoReconnect And UPS_Retry <= UPS_MaxRetry Then ActualAppIconIdx = AppIconIdx.IDX_ICO_RETRY Else ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE @@ -589,7 +642,7 @@ Public Class WinNUT End Sub Public Shared Sub Event_ChangeStatus() Handles Me.On_Battery, Me.On_Line, - UPS_Device.Lost_Connect, UPS_Device.Connected, UPS_Device.Deconnected, UPS_Device.New_Retry, UPS_Device.Unknown_UPS, UPS_Device.ReConnected, + UPS_Device.Lost_Connect, UPS_Device.Connected, UPS_Device.Disconnected, UPS_Device.New_Retry, UPS_Device.Unknown_UPS, UPS_Device.ReConnected, UPS_Device.Unknown_UPS ', UPS_Device.InvalidLogin, @@ -602,16 +655,18 @@ Public Class WinNUT End If End Sub - Public Shared Sub Event_ReConnected() Handles UPS_Device.ReConnected - With WinNUT - .Update_Data.Start() - .Device_Data = .UPS_Device.Retrieve_UPS_Datas() - .Update_UPS_Data() - End With - End Sub - - Private Sub Update_UPS_Data() Handles Me.Data_Updated - With Me.Device_Data + 'TODO: FIX + 'Public Shared Sub Event_ReConnected() Handles UPS_Device.ReConnected + ' With WinNUT + ' .Update_Data.Start() + ' .Device_Data = .UPS_Device.Retrieve_UPS_Datas() + ' .Update_UPS_Data() + ' End With + 'End Sub + + Private Sub Update_UPS_Data() Handles UPS_Device.DataUpdated ' Me.Data_Updated + LogFile.LogTracing("Updating UPS data for Form.", LogLvl.LOG_DEBUG, Me) + With UPS_Device.UPS_Datas If Lbl_VMfr.Text = "" And Lbl_VName.Text = "" And Lbl_VSerial.Text = "" And Lbl_VFirmware.Text = "" Then LogFile.LogTracing("Retrieve UPS Informations", LogLvl.LOG_DEBUG, Me) Lbl_VMfr.Text = .Mfr @@ -620,18 +675,18 @@ Public Class WinNUT Lbl_VFirmware.Text = .Firmware End If End With - With Me.Device_Data.UPS_Value - Me.UPS_BattCh = .Batt_Charge - Me.UPS_BattV = .Batt_Voltage - Me.UPS_BattRuntime = .Batt_Runtime - Me.UPS_BattCapacity = .Batt_Capacity - Me.UPS_InputF = .Power_Frequency - Me.UPS_InputV = .Input_Voltage - Me.UPS_OutputV = .Output_Voltage - Me.UPS_Load = .Load + With UPS_Device.UPS_Datas.UPS_Value + UPS_BattCh = .Batt_Charge + UPS_BattV = .Batt_Voltage + UPS_BattRuntime = .Batt_Runtime + UPS_BattCapacity = .Batt_Capacity + UPS_InputF = .Power_Frequency + UPS_InputV = .Input_Voltage + UPS_OutputV = .Output_Voltage + UPS_Load = .Load 'Me.UPS_Status = Me.Device_Data - Me.UPS_Status = "OL" - Me.UPS_OutPower = .Output_Power + UPS_Status = "OL" + UPS_OutPower = .Output_Power If (.UPS_Status And UPS_States.OL) Then Lbl_VOL.BackColor = Color.Green @@ -667,7 +722,7 @@ Public Class WinNUT ' Lbl_VOLoad.BackColor = Color.White ' End If - Select Case Me.UPS_BattCh + Select Case UPS_BattCh Case 76 To 100 Lbl_VBL.BackColor = Color.White ActualAppIconIdx = ActualAppIconIdx Or AppIconIdx.IDX_BATT_100 @@ -694,30 +749,30 @@ Public Class WinNUT LogFile.LogTracing("Low Battery", LogLvl.LOG_DEBUG, Me) End Select - Dim iSpan As TimeSpan = TimeSpan.FromSeconds(Me.UPS_BattRuntime) + Dim iSpan As TimeSpan = TimeSpan.FromSeconds(UPS_BattRuntime) 'Lbl_VRTime.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & 'iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & 'iSpan.Seconds.ToString.PadLeft(2, "0"c) 'End If LogFile.LogTracing("Update Dial", LogLvl.LOG_DEBUG, Me) - AG_InV.Value1 = Me.UPS_InputV - AG_InF.Value1 = Me.UPS_InputF - AG_OutV.Value1 = Me.UPS_OutputV - AG_BattCh.Value1 = Me.UPS_BattCh - AG_Load.Value1 = Me.UPS_Load - AG_Load.Value2 = Me.UPS_OutPower - AG_BattV.Value1 = Me.UPS_BattV + AG_InV.Value1 = UPS_InputV + AG_InF.Value1 = UPS_InputF + AG_OutV.Value1 = UPS_OutputV + AG_BattCh.Value1 = UPS_BattCh + AG_Load.Value1 = UPS_Load + AG_Load.Value2 = UPS_OutPower + AG_BattV.Value1 = UPS_BattV LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) UpdateIcon_NotifyIcon() RaiseEvent UpdateNotifyIconStr("Update Data", Nothing) RaiseEvent UpdateBatteryState("Update Data") 'TODO : improve following - If Me.UPS_Status = "OL" And Me.UPS_Status = "OB" Then + If UPS_Status = "OL" And UPS_Status = "OB" Then RaiseEvent On_Battery() End If - If Me.UPS_Status = "OB" And Me.UPS_Status = "OL" Then + If UPS_Status = "OB" And UPS_Status = "OL" Then RaiseEvent On_Line() End If End With @@ -725,31 +780,25 @@ Public Class WinNUT Private Sub Menu_Disconnect_Click(sender As Object, e As EventArgs) Handles Menu_Disconnect.Click LogFile.LogTracing("Force Disconnect from menu", LogLvl.LOG_DEBUG, Me) - Update_Data.Stop() - Nut_Socket.Disconnect(True) - ReInitDisplayValues() - ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE - LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) - UpdateIcon_NotifyIcon() - RaiseEvent UpdateNotifyIconStr("Deconnected", Nothing) - RaiseEvent UpdateBatteryState("Deconnected") + ' UPSDisconnect() + UPS_Device.Disconnect() End Sub Private Sub ReInitDisplayValues() - LogFile.LogTracing("Update all informations displayed ton empty values", LogLvl.LOG_DEBUG, Me) - Me.UPS_Mfr = "" - Me.UPS_Model = "" - Me.UPS_Serial = "" - Me.UPS_Firmware = "" + LogFile.LogTracing("Update all informations displayed to empty values", LogLvl.LOG_DEBUG, Me) + UPS_Mfr = "" + UPS_Model = "" + UPS_Serial = "" + UPS_Firmware = "" Lbl_VOL.BackColor = Color.White Lbl_VOB.BackColor = Color.White Lbl_VOLoad.BackColor = Color.White Lbl_VBL.BackColor = Color.White Lbl_VRTime.Text = "" - Lbl_VMfr.Text = Me.UPS_Mfr - Lbl_VName.Text = Me.UPS_Model - Lbl_VSerial.Text = Me.UPS_Serial - Lbl_VFirmware.Text = Me.UPS_Firmware + Lbl_VMfr.Text = UPS_Mfr + Lbl_VName.Text = UPS_Model + Lbl_VSerial.Text = UPS_Serial + Lbl_VFirmware.Text = UPS_Firmware AG_InV.Value1 = WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage") AG_InF.Value1 = WinNUT_Params.Arr_Reg_Key.Item("MinInputFrequency") AG_OutV.Value1 = WinNUT_Params.Arr_Reg_Key.Item("MinOutputVoltage") @@ -761,13 +810,18 @@ Public Class WinNUT Private Sub Menu_Reconnect_Click(sender As Object, e As EventArgs) Handles Menu_Reconnect.Click LogFile.LogTracing("Force Reconnect from menu", LogLvl.LOG_DEBUG, Me) - UPS_Device.ReConnect() + + ' UPSDisconnect() + If UPS_Device.IsConnected Then + UPS_Device.Disconnect() + End If + UPS_Connect() End Sub Private Sub WinNUT_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate If WinNUT_Crashed Then - Me.Hide() + Hide() Else LogFile.LogTracing("Main Gui Lose Focus", LogLvl.LOG_DEBUG, Me) HasFocus = False @@ -778,7 +832,7 @@ Public Class WinNUT Tmp_App_Mode = AppIconIdx.IDX_OFFSET End If Dim TmpGuiIDX = ActualAppIconIdx Or Tmp_App_Mode - Me.Icon = GetIcon(TmpGuiIDX) + Icon = GetIcon(TmpGuiIDX) LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) UpdateIcon_NotifyIcon() End If @@ -786,7 +840,7 @@ Public Class WinNUT Private Sub WinNUT_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated If WinNUT_Crashed Then - Me.Hide() + Hide() Else LogFile.LogTracing("Main Gui Has Focus", LogLvl.LOG_DEBUG, Me) HasFocus = True @@ -797,52 +851,56 @@ Public Class WinNUT Tmp_App_Mode = AppIconIdx.IDX_OFFSET End If Dim TmpGuiIDX = ActualAppIconIdx Or Tmp_App_Mode - Me.Icon = GetIcon(TmpGuiIDX) + Icon = GetIcon(TmpGuiIDX) LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) UpdateIcon_NotifyIcon() End If End Sub Public Sub WinNUT_PrefsChanged() - 'LogFile.LogTracing("WinNut Preferences Changed", LogLvl.LOG_NOTICE, Me, WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_PREFS)) + LogFile.LogTracing("WinNut Preferences Changed", LogLvl.LOG_NOTICE, Me, WinNUT_Globals.StrLog.Item(AppResxStr.STR_LOG_PREFS)) 'Dim NeedReconnect As Boolean = False - ''If WinNUT_Params.Arr_Reg_Key.Item("AutoReconnect") <> UPS_Device.AutoReconnect Then - '' If WinNUT_Params.Arr_Reg_Key.Item("AutoReconnect") Then - '' UPS_Device.AutoReconnect = True - '' Else - '' UPS_Device.AutoReconnect = False - '' End If - ''End If - 'If UPS_Device.NutHost <> WinNUT_Params.Arr_Reg_Key.Item("ServerAddress") Then - ' NeedReconnect = True - ' UPS_Device.NutHost = WinNUT_Params.Arr_Reg_Key.Item("ServerAddress") - 'End If - 'If UPS_Device.NutPort <> WinNUT_Params.Arr_Reg_Key.Item("Port") Then - ' NeedReconnect = True - ' UPS_Device.NutPort = WinNUT_Params.Arr_Reg_Key.Item("Port") - 'End If - 'If UPS_Device.NutUPS <> WinNUT_Params.Arr_Reg_Key.Item("UPSName") Then - ' NeedReconnect = True - ' UPS_Device.NutUPS = WinNUT_Params.Arr_Reg_Key.Item("UPSName") - 'End If - 'If UPS_Device.NutDelay <> WinNUT_Params.Arr_Reg_Key.Item("Delay") Then - ' NeedReconnect = True - ' UPS_Device.NutDelay = WinNUT_Params.Arr_Reg_Key.Item("Delay") - 'End If - 'If UPS_Device.NutLogin <> WinNUT_Params.Arr_Reg_Key.Item("NutLogin") Then - ' NeedReconnect = True - ' UPS_Device.NutLogin = WinNUT_Params.Arr_Reg_Key.Item("NutLogin") - 'End If - 'If UPS_Device.NutPassword <> WinNUT_Params.Arr_Reg_Key.Item("NutPassword") Then - ' NeedReconnect = True - ' UPS_Device.NutPassword = WinNUT_Params.Arr_Reg_Key.Item("NutPassword") - 'End If - 'If UPS_Device.UPS_Follow_FSD <> WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") Then - ' UPS_Device.UPS_Follow_FSD = WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") - 'End If - 'UPS_Device.Battery_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitBatteryCharge") - 'UPS_Device.Backup_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitUPSRemainTime") - 'If NeedReconnect And UPS_Device.IsConnected Then + + 'With UPS_Device.Nut_Config + ' If .AutoReconnect <> WinNUT_Params.Arr_Reg_Key.Item("autoreconnect") Then + ' .AutoReconnect = WinNUT_Params.Arr_Reg_Key.Item("autoreconnect") + ' End If + ' If .Host <> WinNUT_Params.Arr_Reg_Key.Item("ServerAddress") Then + ' NeedReconnect = True + ' .Host = WinNUT_Params.Arr_Reg_Key.Item("ServerAddress") + ' End If + ' If .Port <> WinNUT_Params.Arr_Reg_Key.Item("Port") Then + ' NeedReconnect = True + ' .Port = WinNUT_Params.Arr_Reg_Key.Item("Port") + ' End If + ' If .UPSName <> WinNUT_Params.Arr_Reg_Key.Item("UPSName") Then + ' NeedReconnect = True + ' .UPSName = WinNUT_Params.Arr_Reg_Key.Item("UPSName") + ' End If + ' If Polling_Interval <> WinNUT_Params.Arr_Reg_Key.Item("Delay") Then + ' NeedReconnect = True + ' Polling_Interval = WinNUT_Params.Arr_Reg_Key.Item("Delay") + ' End If + ' If .Login <> WinNUT_Params.Arr_Reg_Key.Item("NutLogin") Then + ' NeedReconnect = True + ' .Login = WinNUT_Params.Arr_Reg_Key.Item("NutLogin") + ' End If + ' If UPS_Device.NutPassword <> WinNUT_Params.Arr_Reg_Key.Item("NutPassword") Then + ' NeedReconnect = True + ' UPS_Device.NutPassword = WinNUT_Params.Arr_Reg_Key.Item("NutPassword") + ' End If + ' If UPS_Device.UPS_Follow_FSD <> WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") Then + ' UPS_Device.UPS_Follow_FSD = WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") + ' End If + ' UPS_Device.Battery_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitBatteryCharge") + ' UPS_Device.Backup_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitUPSRemainTime") + 'End With + + ' Automatically reconnect regardless + ' UPSDisconnect() + UPS_Device.Disconnect() + UPS_Connect() + 'If UPS_Device.IsConnected Then ' NeedReconnect And ' LogFile.LogTracing("Connection parameters Changed. Force Disconnect", LogLvl.LOG_DEBUG, Me) ' 'UPS_Device.Disconnect(True, True) ' ReInitDisplayValues() @@ -858,60 +916,60 @@ Public Class WinNUT ' UPS_Connect() 'End If 'NeedReconnect = Nothing - 'With AG_InV - ' If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage")) Then - ' LogFile.LogTracing("Parameter Dial Input Voltage Need to be Updated", LogLvl.LOG_DEBUG, Me) - ' .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage") - ' .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage") - ' .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - ' LogFile.LogTracing("Parameter Dial Input Voltage Updated", LogLvl.LOG_DEBUG, Me) - ' End If - 'End With - 'With AG_InF - ' If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxInputFrequency")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinInputFrequency")) Then - ' LogFile.LogTracing("Parameter Dial Input Frequency Need to be Updated", LogLvl.LOG_DEBUG, Me) - ' .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxInputFrequency") - ' .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinInputFrequency") - ' .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - ' LogFile.LogTracing("Parameter Dial Input Frequency Updated", LogLvl.LOG_DEBUG, Me) - ' End If - 'End With - 'With AG_OutV - ' If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxOutputVoltage")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinOutputVoltage")) Then - ' LogFile.LogTracing("Parameter Dial Output Voltage Need to be Updated", LogLvl.LOG_DEBUG, Me) - ' .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxOutputVoltage") - ' .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinOutputVoltage") - ' .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - ' LogFile.LogTracing("Parameter Dial Output Voltage Updated", LogLvl.LOG_DEBUG, Me) - ' End If - 'End With - 'With AG_Load - ' If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxUPSLoad")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinUPSLoad")) Then - ' LogFile.LogTracing("Parameter Dial UPS Load Need to be Updated", LogLvl.LOG_DEBUG, Me) - ' .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxUPSLoad") - ' .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinUPSLoad") - ' .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - ' LogFile.LogTracing("Parameter Dial UPS Load Updated", LogLvl.LOG_DEBUG, Me) - ' End If - 'End With - 'With AG_BattV - ' If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage")) Then - ' LogFile.LogTracing("Parameter Dial Voltage Battery Need to be Updated", LogLvl.LOG_DEBUG, Me) - ' .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxBattVoltage") - ' .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage") - ' .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - ' LogFile.LogTracing("Parameter Dial Voltage Battery Updated", LogLvl.LOG_DEBUG, Me) - ' End If - 'End With - 'If WinNUT_Params.Arr_Reg_Key.Item("VerifyUpdate") = True Then - ' Me.Menu_Help_Sep1.Visible = True - ' Me.Menu_Update.Visible = True - ' Me.Menu_Update.Visible = Enabled = True - 'Else - ' Me.Menu_Help_Sep1.Visible = False - ' Me.Menu_Update.Visible = False - ' Me.Menu_Update.Visible = Enabled = False - 'End If + With AG_InV + If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage")) Then + LogFile.LogTracing("Parameter Dial Input Voltage Need to be Updated", LogLvl.LOG_DEBUG, Me) + .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxInputVoltage") + .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinInputVoltage") + .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) + LogFile.LogTracing("Parameter Dial Input Voltage Updated", LogLvl.LOG_DEBUG, Me) + End If + End With + With AG_InF + If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxInputFrequency")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinInputFrequency")) Then + LogFile.LogTracing("Parameter Dial Input Frequency Need to be Updated", LogLvl.LOG_DEBUG, Me) + .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxInputFrequency") + .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinInputFrequency") + .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) + LogFile.LogTracing("Parameter Dial Input Frequency Updated", LogLvl.LOG_DEBUG, Me) + End If + End With + With AG_OutV + If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxOutputVoltage")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinOutputVoltage")) Then + LogFile.LogTracing("Parameter Dial Output Voltage Need to be Updated", LogLvl.LOG_DEBUG, Me) + .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxOutputVoltage") + .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinOutputVoltage") + .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) + LogFile.LogTracing("Parameter Dial Output Voltage Updated", LogLvl.LOG_DEBUG, Me) + End If + End With + With AG_Load + If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MaxUPSLoad")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinUPSLoad")) Then + LogFile.LogTracing("Parameter Dial UPS Load Need to be Updated", LogLvl.LOG_DEBUG, Me) + .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxUPSLoad") + .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinUPSLoad") + .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) + LogFile.LogTracing("Parameter Dial UPS Load Updated", LogLvl.LOG_DEBUG, Me) + End If + End With + With AG_BattV + If (.MaxValue <> WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage")) Or (.MinValue <> WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage")) Then + LogFile.LogTracing("Parameter Dial Voltage Battery Need to be Updated", LogLvl.LOG_DEBUG, Me) + .MaxValue = WinNUT_Params.Arr_Reg_Key.Item("MaxBattVoltage") + .MinValue = WinNUT_Params.Arr_Reg_Key.Item("MinBattVoltage") + .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) + LogFile.LogTracing("Parameter Dial Voltage Battery Updated", LogLvl.LOG_DEBUG, Me) + End If + End With + If WinNUT_Params.Arr_Reg_Key.Item("VerifyUpdate") = True Then + Menu_Help_Sep1.Visible = True + Menu_Update.Visible = True + Menu_Update.Visible = Enabled = True + Else + Menu_Help_Sep1.Visible = False + Menu_Update.Visible = False + Menu_Update.Visible = Enabled = False + End If End Sub Private Sub UpdateIcon_NotifyIcon() @@ -937,7 +995,7 @@ Public Class WinNUT LogFile.LogTracing("New Icon Value For Systray : " & TmpTrayIDX.ToString, LogLvl.LOG_DEBUG, Me) LogFile.LogTracing("New Icon Value For Gui : " & TmpGuiIDX.ToString, LogLvl.LOG_DEBUG, Me) NotifyIcon.Icon = GetIcon(TmpTrayIDX) - Me.Icon = GetIcon(TmpGuiIDX) + Icon = GetIcon(TmpGuiIDX) LastAppIconIdx = ActualAppIconIdx End If End Sub @@ -1004,7 +1062,7 @@ Public Class WinNUT HasFocus = False End Sub - Public Shared Sub Update_InstantLog(ByVal sender As System.Object) Handles ClientLogger.NewData + Public Shared Sub Update_InstantLog(sender As Object) Handles LogFile.NewData Dim Message As String = LogFile.CurrentLogData Static Dim Event_Id = 1 LogFile.LogTracing("New Log to CB_Current Log : " & Message, LogLvl.LOG_DEBUG, sender.ToString) @@ -1021,6 +1079,8 @@ Public Class WinNUT Private Sub Shutdown_Event() Handles UPS_Device.Shutdown_Condition If WinNUT_Params.Arr_Reg_Key.Item("ImmediateStopAction") Then + ' UPSDisconnect() + UPS_Device.Disconnect() Shutdown_Action() Else LogFile.LogTracing("Open Shutdown Gui", LogLvl.LOG_DEBUG, Me) @@ -1051,12 +1111,12 @@ Public Class WinNUT End Sub Private Sub Menu_Update_Click(sender As Object, e As EventArgs) Handles Menu_Update.Click - Me.mUpdate = True + mUpdate = True 'Dim th As System.Threading.Thread = New Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf Run_Update)) 'th.SetApartmentState(System.Threading.ApartmentState.STA) 'th.Start(Me.UpdateMethod) LogFile.LogTracing("Open About Gui From Menu", LogLvl.LOG_DEBUG, Me) - Dim Update_Frm = New Update_Gui(Me.mUpdate) + Dim Update_Frm = New Update_Gui(mUpdate) Update_Frm.Activate() Update_Frm.Visible = True HasFocus = False @@ -1096,7 +1156,7 @@ Public Class WinNUT LogFile.LogTracing("Initialisation Params Complete", LogLvl.LOG_DEBUG, Me) LogFile.LogTracing("Loaded Params Complete", LogLvl.LOG_DEBUG, Me) End If - Me.WinNUT_PrefsChanged() + WinNUT_PrefsChanged() UPS_Connect() End Sub End Class diff --git a/WinNUT_V2/WinNUT_V2.sln b/WinNUT_V2/WinNUT_V2.sln index a9816a0..dd4db48 100644 --- a/WinNUT_V2/WinNUT_V2.sln +++ b/WinNUT_V2/WinNUT_V2.sln @@ -52,7 +52,6 @@ Global {194AB29D-1F80-497B-86BE-4F35DACBA6BC}.Release|x86.ActiveCfg = Release|Any CPU {194AB29D-1F80-497B-86BE-4F35DACBA6BC}.Release|x86.Build.0 = Release|Any CPU {FAFFBA8B-E9DB-419E-9669-999E8EFEFCB5}.Debug|Any CPU.ActiveCfg = Debug - {FAFFBA8B-E9DB-419E-9669-999E8EFEFCB5}.Debug|Any CPU.Build.0 = Debug {FAFFBA8B-E9DB-419E-9669-999E8EFEFCB5}.Debug|ARM.ActiveCfg = Debug {FAFFBA8B-E9DB-419E-9669-999E8EFEFCB5}.Debug|ARM64.ActiveCfg = Debug {FAFFBA8B-E9DB-419E-9669-999E8EFEFCB5}.Debug|x64.ActiveCfg = Debug diff --git a/changelog.md b/changelog.md index d466c89..2d29676 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,24 @@ ## History: +### Version 2.2.8253 +Beta Release +#### Fix : + - Many functionality changes throughout the program and library, in an attempt to make code cleaner, more understandable, and less error-prone. + - Special attention is paid to connection and disconnection subroutines, and what happens in the Socket, UPS, and WinForm. + - Updated de_DE German translations + - Implemented suspend states not working correctly ([#2](https://github.com/nutdotnet/WinNUT-Client/issues/2)) + +#### Changed : + - Small updates to Logging backend to make errors more informative + - Many changes to where debug information is printed to the log + - Disabled WatchDog functionality, since this is essentially handled by value updates. + ### Version 2.1.7740 Beta Release #### Fix : - Fixed a string length error for the German language (this problem should also exist with other languages but only if the strings were long enough) - related to issue #74 -### Changed +#### Changed - Redesign of the connection functions to the Nut server - Creation of a DLL containing functions not essential to the GUI in order to prepare for the upcoming arrival of service mode - Modification of the instantaneous power calculation method in the case of inverters not supporting the variables previously used - in conjunction with issue #68 (thanks to faugusztin)