FwUpdateBuilder: - Fw Update Sw taken from DB,- Configuration files taken from DB

This commit is contained in:
Thomas Wiedebusch
2021-10-27 12:47:29 +02:00
parent 56ef6731cd
commit ae4dcf9fbc
8 changed files with 346 additions and 240 deletions
@@ -21,6 +21,12 @@ namespace Xylem.Common.CommonCore.Configuration
private const String DefaultListAllFwPackagesServiceUrl =
"http://10.49.40.25/MeterProcessState/api/FileUpToDate/GetFwFiles?FileIsForDeveloperOnly=false&FileCategoryID=1";
private const String DefaultListAllSwPackagesServiceUrl =
"http://10.49.40.25/MeterProcessState/api/FileUpToDate/GetFwFiles?FileIsForDeveloperOnly=false&FileCategoryID=5";
private const String DefaultListAllConfigFilePackagesServiceUrl =
"http://10.49.40.25/MeterProcessState/api/FileUpToDate/GetFwFiles?FileIsForDeveloperOnly=false&FileCategoryID=6";
private const String DefaultListAllFwUpdateSafesServiceUrl =
"http://10.49.40.25/MeterProcessState/api/FileUpToDate/GetFwFiles?FileIsForDeveloperOnly=false&FileCategoryID=4";
@@ -259,6 +265,26 @@ namespace Xylem.Common.CommonCore.Configuration
DefaultListAllFwPackagesServiceUrl;
}
/// <summary>
/// Get all Cordonel FW update SW package description files.
/// </summary>
/// <returns></returns>
public static String ListAllSwPackages()
{
return ConfigurationManager.AppSettings["ListAllSwPackagesServiceUrl"] ??
DefaultListAllSwPackagesServiceUrl;
}
/// <summary>
/// Get all Cordonel FW update SW package description files.
/// </summary>
/// <returns></returns>
public static String ListAllConfigurationFilePackages()
{
return ConfigurationManager.AppSettings["ListAllConfigFilePackagesServiceUrl"] ??
DefaultListAllConfigFilePackagesServiceUrl;
}
/// <summary>
/// Set all applications versions installed to a specific Cordonel.
/// </summary>
@@ -1 +1 @@
46bd00889699f5a20a4981a22f62b66368323855
7ac73abb7afd9e6ddc0520a1568581c7ed0afd36
@@ -80,6 +80,16 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateConfig.Consts
/// </summary>
public const String FwUpdateFileExtension = ".safe";
/// <summary>
/// Library-subfolder: For releases the files are sorted to subfolders to avoid confusion of the user.
/// </summary>
public const String LibrarySubFolderName = "Library";
/// <summary>
/// Library-subfolder: For releases the files are sorted to subfolders to avoid confusion of the user.
/// </summary>
public const String ConfigSubFolderName = "Config";
/// <summary>
/// Separator in file name between PcbId CustomerName and OrderNumber for the FW-Update Safe and all report
/// files.
+149 -19
View File
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -37,6 +37,16 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
/// </summary>
public List<UserInformation> DbAllUpdateOperators { get; private set; }
/// <summary>
/// Cordonel SW package.
/// </summary>
public List<FilePart> DbFwUpdateSwPackage { get; private set; }
/// <summary>
/// Cordonel configuration files.
/// </summary>
public List<FilePart> DbFwUpdateConfigFiles { get; private set; }
/// <summary>
/// Cordonel FW packages.
/// </summary>
@@ -316,7 +326,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
/// </remarks>
public Boolean GetAllBuilderOperatorsFromDb()
{
if (DbAllBuilderOperators == null) DbAllBuilderOperators = new List<UserInformation>();
DbAllBuilderOperators.Clear();
@@ -374,6 +384,126 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
}
}
/// <summary>
/// Load the latest FW update SW package from DB.
/// </summary>
/// <returns>true if successful</returns>
/// <remarks date="2021-Oct-26" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public Boolean DownloadFwUpdateSwContainerFromDb()
{
try
{
var url = ServiceUrls.ListAllSwPackages();
var requestResponse = LocalWebRequest.GetRequest(url, 10000);
if (string.IsNullOrEmpty(requestResponse))
{
DbIsConnected = false;
return false;
}
DbIsConnected = true;
// get a list of all stored FW update SW packages
var dbCordonelSwPackages = JsonConvert.DeserializeObject<List<ClusteredFile>>(requestResponse);
if (dbCordonelSwPackages == null || dbCordonelSwPackages.Count == 0)
{
return false;
}
// get latest version
var fileId = dbCordonelSwPackages.Select(package => package.FileId).Prepend(0).Max();
if (fileId == 0)
{
return false;
}
if (DbFwUpdateSwPackage == null) DbFwUpdateSwPackage = new List<FilePart>();
DbFwUpdateSwPackage.Clear();
// download content
url = ServiceUrls.DownloadFileParts();
url += $"{fileId}&readContent=true";
requestResponse = LocalWebRequest.GetRequest(url, 15000);
if (string.IsNullOrEmpty(requestResponse))
{
DbIsConnected = false;
return false;
}
DbIsConnected = true;
DbFwUpdateSwPackage = JsonConvert.DeserializeObject<List<FilePart>>(requestResponse);
return DbFwUpdateSwPackage != null && DbFwUpdateSwPackage.Count > 0;
}
catch (Exception)
{
DbIsConnected = false;
return false;
}
}
/// <summary>
/// Load the latest FW update configuration files from DB.
/// </summary>
/// <returns>true if successful</returns>
/// <remarks date="2021-Oct-26" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public Boolean DownloadFwUpdateConfigurationFilesFromDb()
{
try
{
var url = ServiceUrls.ListAllConfigurationFilePackages();
var requestResponse = LocalWebRequest.GetRequest(url, 10000);
if (string.IsNullOrEmpty(requestResponse))
{
DbIsConnected = false;
return false;
}
DbIsConnected = true;
// get a list of all stored FW update config file packages
var dbConfigFilePackages = JsonConvert.DeserializeObject<List<ClusteredFile>>(requestResponse);
if (dbConfigFilePackages == null || dbConfigFilePackages.Count == 0)
{
return false;
}
// get latest version
var fileId = dbConfigFilePackages.Select(package => package.FileId).Prepend(0).Max();
if (fileId == 0)
{
return false;
}
if (DbFwUpdateConfigFiles == null) DbFwUpdateConfigFiles = new List<FilePart>();
DbFwUpdateConfigFiles.Clear();
// download content
url = ServiceUrls.DownloadFileParts();
url += $"{fileId}&readContent=true";
requestResponse = LocalWebRequest.GetRequest(url, 10000);
if (string.IsNullOrEmpty(requestResponse))
{
DbIsConnected = false;
return false;
}
DbIsConnected = true;
DbFwUpdateConfigFiles = JsonConvert.DeserializeObject<List<FilePart>>(requestResponse);
return DbFwUpdateConfigFiles != null && DbFwUpdateConfigFiles.Count > 0;
}
catch (Exception)
{
DbIsConnected = false;
return false;
}
}
/// <summary>
/// Get all Cordonel safe info files from DB.
/// </summary>
@@ -524,7 +654,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
}
}
/// <summary>
/// <summary>
/// Get all Cordonel customers from DB. The return can be used to select a specific customer and get
/// the customer number which is the base for the order search.
/// </summary>
@@ -538,7 +668,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
// for the DB interface a specific search pattern will be used, so replace it from the user interface
// as there is a "*" the placeholder for "all".
searchPattern = searchPattern.Replace("*", "%");
if (DbSearchedCordonelCustomers == null)
if (DbSearchedCordonelCustomers == null)
DbSearchedCordonelCustomers = new List<CordonelCustomerInfosDb>();
DbSearchedCordonelCustomers.Clear();
@@ -554,7 +684,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
}
DbIsConnected = true;
DbSearchedCordonelCustomers =
DbSearchedCordonelCustomers =
JsonConvert.DeserializeObject<List<CordonelCustomerInfosDb>>(requestResponse);
return DbSearchedCordonelCustomers != null && DbSearchedCordonelCustomers.Count != 0;
}
@@ -574,9 +704,9 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
/// <remarks date="2021-Mar-31" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public Boolean GetAllCordonelCustomerOrdersFromDb(Int64 customerNumber )
public Boolean GetAllCordonelCustomerOrdersFromDb(Int64 customerNumber)
{
if (DbCordonelCustomerOrders == null)
if (DbCordonelCustomerOrders == null)
DbCordonelCustomerOrders = new List<CordonelCustomerOrderDb>();
DbCordonelCustomerOrders.Clear();
@@ -592,7 +722,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
}
DbIsConnected = true;
DbCordonelCustomerOrders =
DbCordonelCustomerOrders =
JsonConvert.DeserializeObject<List<CordonelCustomerOrderDb>>(requestResponse);
return DbCordonelCustomerOrders != null && DbCordonelCustomerOrders.Count != 0;
}
@@ -611,9 +741,9 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
/// <remarks date="2021-Mar-31" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public Boolean GetAllCordonelSerialNumbersFromDb(Int64 orderNumber, Int64 orderPos )
public Boolean GetAllCordonelSerialNumbersFromDb(Int64 orderNumber, Int64 orderPos)
{
if (DbCordonelSerialNumbers == null)
if (DbCordonelSerialNumbers == null)
DbCordonelSerialNumbers = new List<CordonelSerialNumbersDb>();
DbCordonelSerialNumbers.Clear();
@@ -629,7 +759,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
}
DbIsConnected = true;
DbCordonelSerialNumbers =
DbCordonelSerialNumbers =
JsonConvert.DeserializeObject<List<CordonelSerialNumbersDb>>(requestResponse);
return DbCordonelSerialNumbers != null && DbCordonelSerialNumbers.Count != 0;
}
@@ -694,7 +824,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
{
// The fully specified user has to be defined by FullName, LogInName, Domain, Hw Id and User Pwd Hash.
// The user id mustn't be set as this will be returned by the DB search.
if (dbCheckFullSpecUpdateOperator == null || DbAllUpdateOperators == null ||
if (dbCheckFullSpecUpdateOperator == null || DbAllUpdateOperators == null ||
DbAllUpdateOperators.Count == 0 ||
string.IsNullOrEmpty(dbCheckFullSpecUpdateOperator.FullName) ||
string.IsNullOrEmpty(dbCheckFullSpecUpdateOperator.LogInName) ||
@@ -1226,13 +1356,13 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
if (pcbId > 0)
{
url += $"PcbId={pcbId}";
if( userId > 0 ) url += $"&UserId={userId}";
if( orderNr > 0 ) url += $"&OrderNr={orderNr}";
if (userId > 0) url += $"&UserId={userId}";
if (orderNr > 0) url += $"&OrderNr={orderNr}";
}
else if (userId > 0)
{
url += $"UserId={userId}";
if( orderNr > 0 ) url += $"&OrderNr={orderNr}";
if (orderNr > 0) url += $"&OrderNr={orderNr}";
}
else if (orderNr > 0)
{
@@ -1304,7 +1434,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
/// <remarks date="2021-Apr-27" author="Roland Drabesch">
/// - Set container Id, needed to assign PCB IDs.
/// </remarks>
public Boolean UploadFwUpdateSafeToDb(FwUpdateSafeDb fwUpdateSafeDb, List<String> pcbIds )
public Boolean UploadFwUpdateSafeToDb(FwUpdateSafeDb fwUpdateSafeDb, List<String> pcbIds)
{
if (fwUpdateSafeDb == null) return false;
fwUpdateSafeDb.ContainerId = 0;
@@ -1316,10 +1446,10 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
url += $"&PValidDate={fwUpdateSafeDb.ValidDate:yyyy-MM-ddTHH:mm:ss}";
url += $"&PBuilderOperatorName={fwUpdateSafeDb.OperatorNameBuilder}";
var success = LocalWebRequest.PostBinaryFileRequestAsync(url, fwUpdateSafeDb.Name,fwUpdateSafeDb.Content, out var requestResponse);
var success = LocalWebRequest.PostBinaryFileRequestAsync(url, fwUpdateSafeDb.Name, fwUpdateSafeDb.Content, out var requestResponse);
var containerId = JsonConvert.DeserializeObject<Int32>(requestResponse);
if (success && !string.IsNullOrEmpty(requestResponse) && containerId > 0)
if (success && !string.IsNullOrEmpty(requestResponse) && containerId > 0)
{
fwUpdateSafeDb.ContainerId = containerId;
@@ -187,7 +187,6 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// </summary>
private const Int32 DbConnectionTimeoutMs = 5000;
private Int32 _dbAccessDelayCtrMs;
private Boolean _dbAccessIsLocked;
/// <summary>
/// Project name for the DLL to load:
@@ -219,7 +218,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
ProgramConfig.NlogConfig);
/// <summary>
/// Source folder of binaries
/// Source folder of software package if taken from local [user]/downloads/ServiceFwUpdateSw
/// </summary>
private static readonly String FwUpdateSwSourcePath = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.UserProfile), FwUpdateConfig.DefaultFwUpdateSwSourcePath);
@@ -452,7 +451,6 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
private void infoToolStripMenuItem_Click(Object sender, EventArgs e)
{
_processState = ProcessState.UserRegistration;
_dbAccessIsLocked = true;
var frmRegister = new FrmRegister(_regUser);
DisableAllControlsInvoked();
frmRegister.Show();
@@ -472,7 +470,6 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
Show();
Update();
CheckUserRegistration();
_dbAccessIsLocked = false;
}
/// <summary>
/// Exit the program
@@ -692,7 +689,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
if (e.TabPage == tabPageFwPackageSelection)
{
// Load fw packages only if not selected indicated in count
if (_fwUpdatePackages.Count > 0 ||
if (_fwUpdatePackages.Count > 0 ||
_cordonelFwPackageInfoSearch != null && _cordonelFwPackageInfoSearch.Count > 0) return;
DisableAllControlsInvoked();
@@ -926,9 +923,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
if (File.Exists(nLogConfigSourcePathName) && !File.Exists(NLogConfigurationDestPathFile))
SystemControl.CopyFile(nLogConfigSourcePathName, NLogConfigurationDestPathFile);
var rulerPathName = Path.Combine(fwUpdateBuilderLibraryPath,
var rulerPathName = Path.Combine(fwUpdateBuilderLibraryPath,
FwUpdateConfig.MeterFwUpdateRulerConfigFileName);
if (!File.Exists(rulerPathName)) rulerPathName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
if (!File.Exists(rulerPathName)) rulerPathName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
FwUpdateConfig.MeterFwUpdateRulerConfigFileName);
if (File.Exists(rulerPathName))
{
@@ -1129,8 +1126,8 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
GetFwUpdateSwLicenseFromDb(FwUpdateSwFullName, out fwUpdateSafe.License);
if (fwUpdateSafe.License == null)
if (fwUpdateSafe.License == null)
{
LogErrorText(Resources.StrSwLicenseMissing);
MessageBoxShow(Resources.StrSwLicenseMissing, Resources.StrError, MessageBoxButtons.OK,
@@ -1139,15 +1136,15 @@ if (fwUpdateSafe.License == null)
return false;
}
// overwrite license as operator has decided for FW-Update Valid date
// overwrite license validation date as operator has selected this
fwUpdateSafe.License.ValidTo =
DateTimeServer.GetDateTimeFromDateString(lblFwUpdateDutyDate.Text + " 23:59:59", _cultureInfo);
LogSuccessText($@"{Resources.StrSwLicenseLoadedSuccessfully} {FwUpdateProjectName}" +
$" {fwUpdateSafe.License.Major}.{fwUpdateSafe.License.Minor}.{fwUpdateSafe.License.Build}");
//GetFwUpdateSwContainerFromDb();
if (!BuildFwUpdateSwContainer(fwUpdateSafe.License) ||
// local files: if (!BuildFwUpdateSwContainer(fwUpdateSafe.License) ||
if (!BuildFwUpdateSwContainerFromDb(fwUpdateSafe.License) ||
_fwUpdateSwContainer?.RegisterDefinitionFile == null ||
_fwUpdateSwContainer.SoftwareSetupFile == null ||
_fwUpdateSwContainer.MeterFilesEraseRestore == null ||
@@ -1285,113 +1282,6 @@ if (fwUpdateSafe.License == null)
}
}
///// <summary>
///// Take user input to fill the FW-Update collection information.
///// </summary>
///// <remarks date="2021-Feb-02" author="Thomas Wiedebusch">
///// - Initial.
///// </remarks>
///// <remarks date="2021-Mar-25" author="Thomas Wiedebusch">
///// - Clear update info on entry.
///// </remarks>
///// <remarks date="2021-Apr-01" author="Thomas Wiedebusch">
///// - Checkbox to enable DEBUG Cordonels for development.
///// </remarks>
///// <remarks date="2021-Apr-08" author="Thomas Wiedebusch">
///// - Added DEBUG Cordonels to CordonelProductionInfos.
///// </remarks>
//public void DebugDeviceAndFwPackageSelection()
//{
// _cordonelProductionInfos.Clear();
// if (!cbxAddDebugCordonels.Checked) return;
// var updateInfo = new CordonelDeviceInfo
// {
// PcbId = "182100041",
// CustomerSerialNumber = @"Octopus 1",
// RequiredRelease = "EMEA R106D 868MHz"
// //RequiredRelease = "EMEA R106B TEST (it is R106D)"
// //RequiredRelease = "EMEA R106B 433MHz"
// };
// if (_cordonelDeviceInfos.All(d => d.PcbId != updateInfo.PcbId)) _cordonelDeviceInfos.Add(updateInfo);
// updateInfo = new CordonelDeviceInfo
// {
// PcbId = "192000001",
// CustomerSerialNumber = @"Octopus 2",
// RequiredRelease = "EMEA R1066 433MHz"
// };
// if (_cordonelDeviceInfos.All(d => d.PcbId != updateInfo.PcbId)) _cordonelDeviceInfos.Add(updateInfo);
// updateInfo = new CordonelDeviceInfo
// {
// PcbId = "192000004",
// CustomerSerialNumber = @"Octopus 3",
// RequiredRelease = "EMEA R106D 868MHz"
// };
// if (_cordonelDeviceInfos.All(d => d.PcbId != updateInfo.PcbId)) _cordonelDeviceInfos.Add(updateInfo);
// updateInfo = new CordonelDeviceInfo
// {
// PcbId = "192000006",
// CustomerSerialNumber = @"Octopus 4",
// RequiredRelease = "EMEA R106D 868MHz"
// };
// if (_cordonelDeviceInfos.All(d => d.PcbId != updateInfo.PcbId)) _cordonelDeviceInfos.Add(updateInfo);
// updateInfo = new CordonelDeviceInfo
// {
// PcbId = "192000007",
// CustomerSerialNumber = @"Octopus 5",
// RequiredRelease = "EMEA R106D 868MHz"
// };
// if (_cordonelDeviceInfos.All(d => d.PcbId != updateInfo.PcbId)) _cordonelDeviceInfos.Add(updateInfo);
// updateInfo = new CordonelDeviceInfo
// {
// PcbId = "192000009",
// CustomerSerialNumber = @"Octopus 6",
// RequiredRelease = "EMEA R106D 868MHz"
// };
// if (_cordonelDeviceInfos.All(d => d.PcbId != updateInfo.PcbId)) _cordonelDeviceInfos.Add(updateInfo);
// foreach (var cordonelUpdateInfo in _cordonelDeviceInfos)
// {
// var cordonel = new CordonelProductionInfosDb
// {
// IsSelected = true,
// CatalogNumber = "OCTOPUS",
// CustomerOrderNumber = 999999,
// CustomerOrderPos = 99,
// Diameter = "0",
// Length = "0",
// PcbId = cordonelUpdateInfo.PcbId,
// CustomerSerialNumber = cordonelUpdateInfo.CustomerSerialNumber,
// SensusSerialNumber = @"Test-Cordonel",
// RequiredReleaseNameVersion = cordonelUpdateInfo.RequiredRelease
// };
// if (_fwUpdateDbAccess != null &&
// _fwUpdateDbAccess.DownloadCordonelAppVersionsFromDb(cordonel.PcbId, out var cordonelAppVersions))
// {
// foreach (var appVersion in cordonelAppVersions)
// {
// if (appVersion.Id == -1) cordonel.CoreRevision = appVersion.Version;
// if (appVersion.Id == 0x0F)
// {
// cordonel.Metrology = appVersion.Version;
// cordonel.MetrologyIsUpdateable = appVersion.IsUpdateable;
// }
// if (appVersion.Id == 0x18)
// cordonel.InstalledReleaseNameVersion = appVersion.Version;
// }
// }
// if (_cordonelProductionInfos.All(d => d.PcbId != cordonel.PcbId))
// _cordonelProductionInfos.Add(cordonel);
// }
// _cordonelsPropertyChanged = true;
//}
#endregion --------------------------------------- Build FW-Update Safe ---------------------------------------
@@ -1404,9 +1294,6 @@ if (fwUpdateSafe.License == null)
/// </remarks>
private void CheckUserRegistration()
{
if (_fwUpdateDbAccess == null || _regUser == null) return;
_regUser.Domain = CryptInformation.GetSysDomain();
_regUser.LogInName = CryptInformation.GetSysUserLoginName();
@@ -1519,7 +1406,6 @@ if (fwUpdateSafe.License == null)
if (_fwUpdateDbAccess.DbIsConnected)
{
// DB is free to use
_dbAccessIsLocked = false;
if (_dbLicenseRefreshDelayCtrMs > DbLicenseRefreshTimeoutMs)
{
@@ -2373,7 +2259,6 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
}
@@ -2383,7 +2268,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
_processState = ProcessState.Idle;
});
}
@@ -2409,7 +2293,6 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
GetAllUpdateOperatorsFromDb();
@@ -2420,7 +2303,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
_fwUpdateOperatorsPropertyChanged = true;
_processState = ProcessState.Idle;
});
@@ -2441,7 +2323,6 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
GetLicenseFromDb();
@@ -2452,7 +2333,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
if (_regUser.AccountActive)
{
_licenseValidDateTimeOffset = DateTimeServer.GetDateTimeTodayUntilMidnight();
@@ -2468,6 +2348,12 @@ if (fwUpdateSafe.License == null)
/// <remarks date="2021-Apr-08" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
/// <remarks date="2021-Oct-26" author="Thomas Wiedebusch">
/// - Load configuration files from DB as the latest MeterFwUpdateRuler.json is needed for the
/// FwUpdateBuilder FW package check and validation routine! This step has to be done in advance
/// to the FW package load, as the Builder uses the information of the MeterFwUpdateRuler to
/// create the package information!
/// </remarks>
private void LoadDbCordonelFwPackagesTask()
{
_invokerProcessState = _processState;
@@ -2477,9 +2363,11 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
// has to be done first to extract the MeterFwUpdateRuler
GetFwUpdateConfigFilesFromDb();
// load the packages and use the MeterFwUpdateRuler to assign the DN, EMEA, NA, 868, 433..
GetCordonelFwPackagesFromDb();
}
catch (Exception)
@@ -2488,7 +2376,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
_fwPackagePropertyChanged = true;
_processState = ProcessState.Idle;
});
@@ -2515,7 +2402,6 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
GetAllCordonelCustomersFromDb();
@@ -2526,7 +2412,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
_customersPropertyChanged = true;
_processState = ProcessState.Idle;
});
@@ -2553,7 +2438,6 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
GetAllCordonelSerialNumbersOfOrderFromDb();
@@ -2564,7 +2448,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
_cordonelsPropertyChanged = true;
_processState = ProcessState.Idle;
});
@@ -2588,7 +2471,6 @@ if (fwUpdateSafe.License == null)
Thread.CurrentThread.CurrentCulture = _cultureInfo;
try
{
_dbAccessIsLocked = true;
// check DB connection in advance to overcome the timing issues for DB service startup
_fwUpdateDbAccess.CheckDbConnection();
GetAllCordonelOrdersOfCustomerFromDb();
@@ -2599,7 +2481,6 @@ if (fwUpdateSafe.License == null)
}
}).ContinueWith(delegate
{
_dbAccessIsLocked = false;
_cordonelsPropertyChanged = true;
_processState = ProcessState.Idle;
});
@@ -3833,7 +3714,7 @@ if (fwUpdateSafe.License == null)
}
var initialSortColumn = gridViewCustomerSelection.Columns[Resources.StrTableCustomerName];
if (initialSortColumn != null)
if (initialSortColumn != null)
gridViewCustomerSelection.Sort(initialSortColumn, ListSortDirection.Ascending);
}
catch (Exception)
@@ -4000,6 +3881,9 @@ if (fwUpdateSafe.License == null)
/// <remarks date="2021-Apr-29" author="Thomas Wiedebusch">
/// - Meter FW update ruler.
/// </remarks>
/// <remarks date="2021-Oct-15" author="Thomas Wiedebusch">
/// - Configuration files loading from DB: - MeterFwUpdateRuler, configuration.json and MeterEraseRestore.
/// </remarks>
private Boolean GetCordonelFwPackagesFromDb()
{
if (_fwUpdateDbAccess == null || !_fwUpdateDbAccess.GetAllCordonelFwInfoFilesFromDb() ||
@@ -4007,6 +3891,10 @@ if (fwUpdateSafe.License == null)
return false;
_cordonelFwPackageInfoSearch.Clear();
// The configuration files contain the latest MeterFwUpdateRuler.json (needed for the FwUpdateBuilder),
// the latest configuration.json and the latest MeterEraseRestore.json (needed for the FwUpdateSw).
// GetConfigurationFilesFromDb();
// Start with the last package, as this will be the latest
for (var idx = _fwUpdateDbAccess.DbCordonelFwPackages.Count - 1;
idx > _fwUpdateDbAccess.DbCordonelFwPackages.Count - 40; idx--)
@@ -4055,10 +3943,10 @@ if (fwUpdateSafe.License == null)
$"{rule.Release.Substring(3, 2)}";
if (releaseVersion == fwPackInfo.ReleaseVersion)
{
Int32.TryParse(rule.CoreVersionMin, out var x);
int.TryParse(rule.CoreVersionMin, out var x);
fwPackInfo.CoreVersionMin = x;
x = 0;
Int32.TryParse(rule.CoreVersionMax, out x);
int.TryParse(rule.CoreVersionMax, out x);
fwPackInfo.CoreVersionMax = x;
fwPackInfo.FwIsReleased = !string.IsNullOrEmpty(rule.ApproverName);
}
@@ -4216,6 +4104,135 @@ if (fwUpdateSafe.License == null)
return false;
}
/// <summary>
/// Get Cordonel Fa update configuration files from DB.
/// The configuration files contain the latest MeterFwUpdateRuler.json (needed for the FwUpdateBuilder),
/// the latest configuration.json and the latest MeterEraseRestore.json (needed for the FwUpdateSw).
/// Copies the MeterFwUpdateRuler.json to the [exe-root] or [exe-root]/Library of the FwUpdateBuilder.
/// </summary>
/// <returns>true if successful</returns>
/// <remarks date="2021-Oct-27" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private Boolean GetFwUpdateConfigFilesFromDb()
{
if (_fwUpdateDbAccess == null ||
!_fwUpdateDbAccess.DownloadFwUpdateConfigurationFilesFromDb() ||
_fwUpdateDbAccess.DbFwUpdateConfigFiles.Count == 0)
return false;
try
{
// extract the MeterFwUpdateRuler
foreach (var f in _fwUpdateDbAccess.DbFwUpdateConfigFiles)
{
if (f.FileName == FwUpdateConfig.MeterFwUpdateRulerConfigFileName)
{
// Copy MeterFwUpdateRuler either to exe-path or if existing to Library-subfolder
var fwUpdateBuilderExePath = AppDomain.CurrentDomain.BaseDirectory;
var fwUpdateBuilderLibraryPath = Path.Combine(fwUpdateBuilderExePath,
FwUpdateConfig.LibrarySubFolderName);
// check the Library path existence (will be used in Release build)
var meterFwUpdateRulerPath = Directory.Exists(fwUpdateBuilderLibraryPath) ?
fwUpdateBuilderLibraryPath : fwUpdateBuilderExePath;
var sourceFile = Path.Combine(meterFwUpdateRulerPath, f.FileName);
var fs = File.Open(sourceFile, FileMode.Create);
fs.Write(f.FileContent, 0, f.FileContent.Length);
fs.Close();
}
}
}
catch (Exception)
{
return false;
}
return true;
}
/// <summary>
/// Get Cordonel SW and configuration files from DB.
/// The software is a container of dll files, language packages and logging setups.
/// The configuration files contain the latest MeterFwUpdateRuler.json (needed for the FwUpdateBuilder),
/// the latest configuration.json and the latest MeterEraseRestore.json (needed for the FwUpdateSw).
/// Creates License, FileCrc, FileLength and SubDiractories.
/// </summary>
/// <param name="fwUpdateSwLicense">license information of valid software</param>
/// <returns>true if successful</returns>
/// <remarks date="2021-Oct-27" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private Boolean BuildFwUpdateSwContainerFromDb(SoftwareLicense fwUpdateSwLicense)
{
if (_fwUpdateDbAccess?.DbFwUpdateConfigFiles == null ||
!_fwUpdateDbAccess.DownloadFwUpdateSwContainerFromDb() ||
_fwUpdateDbAccess.DbFwUpdateSwPackage.Count == 0 ||
_fwUpdateDbAccess.DbFwUpdateConfigFiles.Count == 0)
return false;
_fwUpdateSwContainer = new SoftwareContainer
{
Major = fwUpdateSwLicense.Major,
Minor = fwUpdateSwLicense.Minor,
Build = fwUpdateSwLicense.Build,
Program = fwUpdateSwLicense.Program,
SoftwareDynLinkLibs = new List<FilePart>(),
RegisterDefinitionFile = new FilePart(),
SoftwareSetupFile = new FilePart(),
MeterFilesEraseRestore = new FilePart()
};
foreach (var f in _fwUpdateDbAccess.DbFwUpdateConfigFiles)
{
// load the register definition
if (f.FileName == ProgramConfig.RegisterDefinitionFileName)
{
f.FileContentLength = f.FileContent.Length;
f.FileContentCrc16CcittMsb = Crc16Ccitt.CalculateMsb1021(f.FileContent);
_fwUpdateSwContainer.RegisterDefinitionFile = f;
}
// load the meter files to erase and restore
if (f.FileName == FwUpdateConfig.MeterFilesEraseRestoreConfigFileName)
{
f.FileContentLength = f.FileContent.Length;
f.FileContentCrc16CcittMsb = Crc16Ccitt.CalculateMsb1021(f.FileContent);
_fwUpdateSwContainer.MeterFilesEraseRestore = f;
}
}
foreach (var f in _fwUpdateDbAccess.DbFwUpdateSwPackage)
{
// load the logging configuration
if (f.FileName == ProgramConfig.NlogConfig)
{
f.FileContentLength = f.FileContent.Length;
f.FileContentCrc16CcittMsb = Crc16Ccitt.CalculateMsb1021(f.FileContent);
_fwUpdateSwContainer.SoftwareSetupFile = f;
}
// load the DLLs
if (f.FileName.EndsWith(".dll"))
{
// extract sub-directory from file name in DB for sub-directory creation in FwUpdateLoader
// supports only depth of one level
if (f.FileName.Contains("\\"))
{
var fileName = f.FileName.Split('\\');
var subDirectory = fileName[0];
f.FileName = fileName[fileName.Length - 1];
f.SubDirectory = subDirectory;
}
f.FileContentLength = f.FileContent.Length;
f.FileContentCrc16CcittMsb = Crc16Ccitt.CalculateMsb1021(f.FileContent);
_fwUpdateSwContainer.SoftwareDynLinkLibs.Add(f);
}
}
return true;
}
/// <summary>
/// Build the FW-Update SW container
/// </summary>
@@ -4232,6 +4249,7 @@ if (fwUpdateSafe.License == null)
/// <remarks date="2021-Apr-29" author="Thomas Wiedebusch">
/// - Take license from DB.
/// </remarks>
// ReSharper disable once UnusedMember.Local
private Boolean BuildFwUpdateSwContainer(SoftwareLicense fwUpdateSwLicense)
{
_fwUpdateSwContainer = new SoftwareContainer
@@ -4247,7 +4265,7 @@ if (fwUpdateSafe.License == null)
};
try
{
//TODO THW for debug purposes the locally values are taken
// for debug purposes the locally stored files from download folder are taken
// copy all elements of software release in the main directory
var fileList = new List<String>();
@@ -4498,84 +4516,6 @@ if (fwUpdateSafe.License == null)
return false;
}
///// <summary>
///// Load firmware package from local HDD.
///// </summary>
///// <param name="releaseNameVersion"></param>
///// <returns>true if succeeded</returns>
///// <remarks date="2020-Dec-14" author="Thomas Wiedebusch">
///// - Initial.
///// </remarks>
///// <remarks date="2021-Feb-02" author="Thomas Wiedebusch">
///// - Returns bool.
///// </remarks>
///// <remarks date="2021-Mar-26" author="Thomas Wiedebusch">
///// - Logging added.
///// </remarks>
//private Boolean LoadFirmwarePackage(String releaseNameVersion)
//{
// // if this packages has already been loaded, exit immediately
// if (_fwUpdatePackages.Any(version => version.ReleaseNameVersion == releaseNameVersion))
// {
// return true;
// }
// var cordonelFwPackage = new CordonelFirmware
// {
// ReleaseNameVersion = releaseNameVersion,
// PackageDescriptionFile = new FilePart(),
// BinaryApplicationFiles = new List<FilePart>()
// };
// try
// {
// // copy all firmware releases which later will be the "Cordonel Firmware" container
// var files = Directory.GetFiles(FwUpdateFwSourceFolder + releaseNameVersion);
// if (files.Length == 0)
// {
// var msg = Resources.StrFwPackageLoadFailed + @" " + releaseNameVersion;
// LogErrorText(msg);
// MessageBoxShow(msg, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error);
// return false;
// }
// foreach (var f in files)
// {
// // extract the file name
// var fileName = Path.GetFileName(f);
// // load the ADF
// if (f.Contains("product") && f.EndsWith(".txt"))
// {
// cordonelFwPackage.PackageDescriptionFile.FileName = fileName;
// var file = File.ReadAllBytes(f);
// cordonelFwPackage.PackageDescriptionFile.FileContent = new Byte[file.Length];
// cordonelFwPackage.PackageDescriptionFile.FileContent = file;
// }
// // load the binaries
// if (f.Contains("binfile") && f.EndsWith(".bin"))
// {
// var filePart = new FilePart { FileName = fileName };
// var file = new List<Byte>(File.ReadAllBytes(f));
// filePart.FileContent = new Byte[file.Count];
// filePart.FileContent = file.ToArray();
// cordonelFwPackage.BinaryApplicationFiles.Add(filePart);
// }
// }
// _fwUpdatePackages.Add(cordonelFwPackage);
// LogSuccessText(Resources.StrFwPackageLoadSuccess + " " + releaseNameVersion);
// }
// catch (Exception e)
// {
// var msg = Resources.StrFwPackageLoadFailed + @" " + releaseNameVersion;
// LogErrorText(msg);
// MessageBoxShow(msg, Resources.StrError, MessageBoxButtons.OK, MessageBoxIcon.Error);
// MessageBoxShow(e.ToString(), Resources.StrError, MessageBoxButtons.OK,
// MessageBoxIcon.Error);
// _processState = ProcessState.Error;
// return false;
// }
// return true;
//}
#endregion --------------------------------------- Load DB Contents -------------------------------------------
#region ------------------------------------------ Language ---------------------------------------------------
@@ -509,7 +509,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateLoader
public FrmFwUpdateLoader()
{
var fwUpdateLoaderExePath = AppDomain.CurrentDomain.BaseDirectory;
var fwUpdateLoaderConfigPath = Path.Combine(fwUpdateLoaderExePath, "Config");
var fwUpdateLoaderConfigPath = Path.Combine(fwUpdateLoaderExePath, FwUpdateConfig.ConfigSubFolderName);
// Set the FW-Update SW destination folder to the FW-Update Loader exe path
_fwUpdateSwDestinationPath = Path.Combine(fwUpdateLoaderExePath, FwUpdateProjectName);