diff --git a/Common/Ui/GenesisToolBox/frmMainForm.cs b/Common/Ui/GenesisToolBox/frmMainForm.cs index 40a12146..436e5799 100644 --- a/Common/Ui/GenesisToolBox/frmMainForm.cs +++ b/Common/Ui/GenesisToolBox/frmMainForm.cs @@ -3,7 +3,6 @@ using System; using System.Drawing; using System.IO; -using System.Reflection; using System.Windows.Forms; using Xylem.Common.CommonCore.Consts; @@ -16,9 +15,6 @@ namespace Xylem.Common.Ui.GenesisToolBox /// public partial class FrmMainForm : Form { - private readonly String _configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "Genesis", ProgramConfig.SerialConfigFileName); - /// /// Ctor /// @@ -27,9 +23,9 @@ namespace Xylem.Common.Ui.GenesisToolBox this.InitializeComponent(); this.InitializeFormState(); + this.lblVersionNumber.Text = ApplicationVersion.Current; var logger = NLogHelper.CreateOrGetLogger("GenesisToolBox"); - var version = Assembly.GetExecutingAssembly().GetName().Version; - logger.Info($"GenesisToolBox Version: {version.Major}.{version.Minor}.{version.Build}"); + logger.Info($"GenesisToolBox {ApplicationVersion.Current}"); //bool valid = false; @@ -38,7 +34,6 @@ namespace Xylem.Common.Ui.GenesisToolBox // valid = context.ValidateCredentials("drabesch_ro", "password"); //} - lblVersionNumber.Text = $@"Version: {version.Major}.{version.Minor}.{version.Build}"; } private void btnSetup_Click(Object sender, EventArgs e) @@ -74,24 +69,19 @@ namespace Xylem.Common.Ui.GenesisToolBox private void FrmMainForm_Load(Object sender, EventArgs e) { - var versionString = "NA"; Boolean access; btnFiles.Enabled = true; try { - var assemblyName = Assembly.GetExecutingAssembly().GetName(); - versionString = $@"Version: {assemblyName.Version.Major}.{assemblyName.Version.Minor}.{assemblyName.Version.Build}"; - - - access = Logic.SoftwareAccessHelper.Access.HasAccess(assemblyName); + access = Logic.SoftwareAccessHelper.Access.HasAccess(ApplicationVersion.Current.Assembly); } catch (Exception ex) { MessageBox.Show("GenesisToolBox\n\n" + "Starting in OfflineMode\n\n" + - $"Your version ({versionString}) could not be verified Error\n\n" + + $"Your version (NA) could not be verified Error\n\n" + ex.Message); Close(); @@ -109,7 +99,7 @@ namespace Xylem.Common.Ui.GenesisToolBox { MessageBox.Show("GenesisToolBox\n\n" + "Your version licence has expired\n\n" + - versionString); + ApplicationVersion.Current); Close(); } @@ -144,22 +134,16 @@ namespace Xylem.Common.Ui.GenesisToolBox private void CheckConfigs() { + var applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + var genesisFolder = Directory.CreateDirectory(Path.Combine(applicationDataFolder, "Genesis")).FullName; - var nLogFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "Genesis", ProgramConfig.NlogConfig); - var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Genesis"); - - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } + var nLogFile = Path.Combine(genesisFolder, ProgramConfig.NlogConfig); if (!File.Exists(nLogFile)) { - const String fileCop = ProgramConfig.NlogConfig; try { - File.Copy(fileCop, nLogFile); + File.Copy(ProgramConfig.NlogConfig, nLogFile); } catch (Exception) { @@ -167,10 +151,10 @@ namespace Xylem.Common.Ui.GenesisToolBox } } - if (!File.Exists(_configFile)) + var configFile = Path.Combine(genesisFolder, ProgramConfig.SerialConfigFileName); + + if (!File.Exists(configFile)) { - //btnZeroFlow.Enabled = false; - //btnOBS.Enabled = false; btnRegisterStore.Enabled = false; btnPassword.Enabled = false; var text = "Configuration file cannot be found!\nExecute setup."; @@ -395,6 +379,9 @@ namespace Xylem.Common.Ui.GenesisToolBox #region Form initialization + /// + /// Heids all currently available controls from the main window. + /// private void HideContent() { foreach (var control in this.Controls) @@ -406,6 +393,9 @@ namespace Xylem.Common.Ui.GenesisToolBox } } + /// + /// Gives all buttons that pointing to software function or other forms, tag with specific software function. + /// private void SetSoftwareFunctions() { this.btnSetup.Tag = SoftwareFunctions.GENERAL_SETUP; @@ -431,7 +421,10 @@ namespace Xylem.Common.Ui.GenesisToolBox this.btnLowLevelTools.Tag = SoftwareFunctions.DEV_LOW_LEVEL_TOOLS; } - private void ShowErrorMessage() + /// + /// Sets a label with error message that says the UI is not available. + /// + private void UINotAvailable() { this.Controls.Add(new Label() { @@ -444,6 +437,12 @@ namespace Xylem.Common.Ui.GenesisToolBox }); } + /// + /// Callback method that is called when user enters valid username and password. + /// + /// Not null or empty string. + /// Not null or empty string. + /// Is the LoginForm from whitch is this method called. private void LoginFormSubmitted(string username, string password, object sender) { if (sender is LoginForm loginForm) @@ -460,6 +459,9 @@ namespace Xylem.Common.Ui.GenesisToolBox } } + /// + /// Shows all UI controlls. Sets control enabled or disabled, having tag that is from type SoftwareFunctions. + /// private void ShowAvailableSoftwareFunctions() { foreach (var control in this.Controls) @@ -484,6 +486,11 @@ namespace Xylem.Common.Ui.GenesisToolBox } } + /// + /// Tracks users interactions with the UI by sending it to the web service. + /// + /// + /// private void LogUserAction(object sender, EventArgs e) { if (sender is Button button) @@ -492,6 +499,10 @@ namespace Xylem.Common.Ui.GenesisToolBox } } + /// + /// Hides all members but the login form if the app is initialized otherwise shows error message. + /// In case that the app is initialized and user is authorized shows all buttons as enabled or disabled depending on the user permissions. + /// private void InitializeFormState() { this.HideContent(); @@ -499,7 +510,7 @@ namespace Xylem.Common.Ui.GenesisToolBox if (!ApplicationState.Initialized) { - this.ShowErrorMessage(); + this.UINotAvailable(); } else if (!ApplicationState.IsAuthorized) {