GenesisMeter: - Password from DB with MeterPwdHandlerDb.GetPasswordFromDb,
MeterPwdHandlerDb.GetPasswordFromDb: - changed from string reader to json convert, MeterPwd.prj moved to Hardwre/WaterMeter/Genesis
This commit is contained in:
parent
f61fe1b99f
commit
b46663e3ce
@ -3441,6 +3441,7 @@ Global
|
||||
{E9FAAF12-8721-46AC-8181-744001E3314E} = {57AA2731-BFD9-40A5-820F-E943FBC75D91}
|
||||
{2FD60CF1-45CD-4060-B8E5-4F39FBA7F1CB} = {7A0EE7B8-6B7E-41E9-B679-319C8CA48CF1}
|
||||
{A25A96FD-604B-43BE-80CD-A953152C2175} = {0C89F3A2-BBB9-4E09-B424-D2D4395F046F}
|
||||
{AC434B18-4D7B-49BA-9AD5-0527C79E8297} = {B5F43F61-4448-4992-85B5-7EDFB82FD643}
|
||||
{4806D89A-FBFB-41BC-AAA7-2242444BF55A} = {57AA2731-BFD9-40A5-820F-E943FBC75D91}
|
||||
{0FFBCA6C-E828-4196-B0A8-988DEA3E077F} = {03D4F23E-7E4A-4091-BC96-036C996D351A}
|
||||
{70BF5094-0F03-41FC-B0BD-BEFCF51686C9} = {03D4F23E-7E4A-4091-BC96-036C996D351A}
|
||||
|
||||
@ -327,6 +327,10 @@
|
||||
<Project>{F013A56B-7BE6-4852-9CD8-B971CD1ADD0C}</Project>
|
||||
<Name>GenesisConfig</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\GenesisPwd\GenesisPwd.csproj">
|
||||
<Project>{AC434B18-4D7B-49BA-9AD5-0527C79E8297}</Project>
|
||||
<Name>GenesisPwd</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Protocols\ProtocolCore\ProtocolCore.csproj">
|
||||
<Project>{8BDD2789-96D4-43EA-AAD7-0F49D0347998}</Project>
|
||||
<Name>ProtocolCore</Name>
|
||||
|
||||
@ -26,6 +26,7 @@ using Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.EventArguments;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.MeasurementRecords;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.ProtocolCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol.Consts;
|
||||
@ -959,13 +960,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// <remarks date="2023-Jan-19" author="T.Wiedebusch">
|
||||
/// - Password had been reset to empty string if read from file, corrected!
|
||||
/// </remarks>
|
||||
/// <remarks date="2023-Feb-28" author="T.Wiedebusch">
|
||||
/// - Used <see cref="MeterPwdHandlerDb.GetPasswordFromDb"/>
|
||||
/// </remarks>
|
||||
private String GetPassword()
|
||||
{
|
||||
var url = ServiceUrls.GenesisGetPasswordServiceUrl();
|
||||
var password = "";
|
||||
|
||||
//without PCB ID it is not possible to login,
|
||||
//but if it is already assigned to this Gensis, don't read it again
|
||||
// without PCB ID it is not possible to login,
|
||||
// but if it is already assigned to this Genesis, don't read it again
|
||||
if (string.IsNullOrEmpty(PcbId))
|
||||
{
|
||||
//GetPcbId fills the PsbId property
|
||||
@ -976,41 +977,29 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
url += PcbId;
|
||||
try
|
||||
// on unknown password try to get it from DB
|
||||
if (MeterPwdHandlerDb.GetPasswordFromDb(PcbId, out var password))
|
||||
{
|
||||
//use
|
||||
var http = (HttpWebRequest)WebRequest.Create(url);
|
||||
var response = (HttpWebResponse)http.GetResponse();
|
||||
var responseStream = response.GetResponseStream();
|
||||
if (responseStream == null)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
using (var sr = new StreamReader(responseStream))
|
||||
{
|
||||
var responseJson = sr.ReadToEnd();
|
||||
password = responseJson.Trim('"');
|
||||
}
|
||||
_logger.Info($"Slot:{Slot} - Got password from GenesisPasswordServiceUrl, URL({url})");
|
||||
_logger.Info($"Slot:{Slot} - Got password from GenesisPasswordService, " +
|
||||
$"URL({ServiceUrls.GenesisGetPasswordServiceUrl() + PcbId})");
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
_logger.Info($"Slot:{Slot} - Cannot get password from GenesisPasswordService, " +
|
||||
$"URL({url}), Error({ex.Message})");
|
||||
if (File.Exists(ProgramConfig.OfflineInfoFile))
|
||||
$"URL({ServiceUrls.GenesisGetPasswordServiceUrl() + PcbId}))");
|
||||
// try to read the password from an offline password file
|
||||
if (!File.Exists(ProgramConfig.OfflineInfoFile)) return password;
|
||||
|
||||
var listOfOfflinePasswords = JsonConvert.DeserializeObject<List<OfflinePasswordItem>>(
|
||||
File.ReadAllText(ProgramConfig.OfflineInfoFile));
|
||||
password = listOfOfflinePasswords.First(x => x.PcbId == PcbId).Password;
|
||||
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
var listOfOfflinePasswords = JsonConvert.DeserializeObject<List<OfflinePasswordItem>>(
|
||||
File.ReadAllText(ProgramConfig.OfflineInfoFile));
|
||||
password = listOfOfflinePasswords.First(x => x.PcbId == PcbId).Password;
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
_logger.Info($"Slot:{Slot} - Got password from password file!");
|
||||
}
|
||||
_logger.Info($"Slot:{Slot} - Got password for PcbId:{PcbId} from password file!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
@ -26,28 +24,31 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd
|
||||
/// <remarks date="2023-Feb-23" author="Roland Drabesch/Thomas Wiedebusch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
/// <remarks date="2023-Feb-28" author="Roland Drabesch/Thomas Wiedebusch">
|
||||
/// - Used JsonConvert instead of StreamReader.
|
||||
/// </remarks>
|
||||
public static Boolean GetPasswordFromDb(String pcbId, out String password)
|
||||
{
|
||||
var url = ServiceUrls.GenesisGetPasswordServiceUrl();
|
||||
password = "";
|
||||
if (string.IsNullOrEmpty(pcbId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var http = (HttpWebRequest)WebRequest.Create(url + pcbId);
|
||||
var response = (HttpWebResponse)http.GetResponse();
|
||||
var responseStream = response.GetResponseStream();
|
||||
if (responseStream == null)
|
||||
var url = ServiceUrls.GenesisGetPasswordServiceUrl();
|
||||
var response = LocalWebRequest.GetRequest(url + pcbId, 2000);
|
||||
password = JsonConvert.DeserializeObject<String>(response);
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
password = "";
|
||||
return false;
|
||||
}
|
||||
using (var sr = new StreamReader(responseStream))
|
||||
{
|
||||
var responseJson = sr.ReadToEnd();
|
||||
password = responseJson.Trim('"');
|
||||
}
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
password = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user