From 3d0ea1389f4ac2024e4b3cbad7a2d579cd291fdb Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 18 Nov 2020 06:10:56 +0200 Subject: Added DISABLED for TANGO_VERSIONS. Added ACTIVATION_KEY for MACHINE. Added activation key generation for ms designer. --- .../ViewModels/MainViewVM.cs | 6 + .../Visual_Studio/Tango.BL/DTO/MachineDTOBase.cs | 8 + .../Tango.BL/DTO/TangoVersionDTOBase.cs | 8 + .../Visual_Studio/Tango.BL/Entities/MachineBase.cs | 38 +++++ .../Tango.BL/Entities/TangoVersionBase.cs | 38 +++++ .../Tango.Core/Cryptography/PasswordGenerator.cs | 79 ++++++++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 3 +- .../Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs | 1 + .../Tango.DAL.Remote/DB/RemoteADO.edmx | 6 + .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 168 ++++++++++----------- .../Tango.DAL.Remote/DB/TANGO_VERSIONS.cs | 1 + .../Controllers/PPCController.cs | 8 +- 12 files changed, 275 insertions(+), 89 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 9c4c2281d..7f558c0c9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -28,6 +28,7 @@ using Tango.MachineStudio.RML.Models; using Tango.BL.ActionLogs; using Tango.MachineStudio.Common.Authentication; using Tango.BL.DTO; +using Tango.Core.Cryptography; namespace Tango.MachineStudio.MachineDesigner.ViewModels { @@ -642,6 +643,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels ActiveMachine.Configuration.HardwareVersionChanged += Configuration_HardwareVersionChanged; + if (ActiveMachine.ActivationKey == null) + { + ActiveMachine.ActivationKey = PasswordGenerator.Generate(8, PasswordGenerator.PasswordType.Alpha,PasswordGenerator.PasswordCasing.Upper); + } + View.NavigateTo(MachineDesignerNavigationView.MachineDetailsView); } catch (Exception ex) diff --git a/Software/Visual_Studio/Tango.BL/DTO/MachineDTOBase.cs b/Software/Visual_Studio/Tango.BL/DTO/MachineDTOBase.cs index fe8aa35d3..f88f164cd 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/MachineDTOBase.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/MachineDTOBase.cs @@ -269,5 +269,13 @@ namespace Tango.BL.DTO get; set; } + /// + /// activation key + /// + public String ActivationKey + { + get; set; + } + } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/TangoVersionDTOBase.cs b/Software/Visual_Studio/Tango.BL/DTO/TangoVersionDTOBase.cs index 3b77ba537..eea184e2e 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/TangoVersionDTOBase.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/TangoVersionDTOBase.cs @@ -77,5 +77,13 @@ namespace Tango.BL.DTO get; set; } + /// + /// disabled + /// + public Boolean Disabled + { + get; set; + } + } } diff --git a/Software/Visual_Studio/Tango.BL/Entities/MachineBase.cs b/Software/Visual_Studio/Tango.BL/Entities/MachineBase.cs index 214d70b20..cbfd43789 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/MachineBase.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/MachineBase.cs @@ -73,6 +73,8 @@ namespace Tango.BL.Entities public event EventHandler HeadTypeChanged; + public event EventHandler ActivationKeyChanged; + public event EventHandler> CatsChanged; public event EventHandler ConfigurationChanged; @@ -913,6 +915,33 @@ namespace Tango.BL.Entities } } + protected String _activationkey; + + /// + /// Gets or sets the machinebase activation key. + /// + + [Column("ACTIVATION_KEY")] + + public String ActivationKey + { + get + { + return _activationkey; + } + + set + { + if (_activationkey != value) + { + _activationkey = value; + + OnActivationKeyChanged(value); + + } + } + } + protected SynchronizedObservableCollection _cats; /// @@ -1341,6 +1370,15 @@ namespace Tango.BL.Entities RaisePropertyChanged(nameof(HeadType)); } + /// + /// Called when the ActivationKey has changed. + /// + protected virtual void OnActivationKeyChanged(String activationkey) + { + ActivationKeyChanged?.Invoke(this, activationkey); + RaisePropertyChanged(nameof(ActivationKey)); + } + /// /// Called when the Cats has changed. /// diff --git a/Software/Visual_Studio/Tango.BL/Entities/TangoVersionBase.cs b/Software/Visual_Studio/Tango.BL/Entities/TangoVersionBase.cs index f39df936a..2fece7fdb 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/TangoVersionBase.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/TangoVersionBase.cs @@ -37,6 +37,8 @@ namespace Tango.BL.Entities public event EventHandler CommentsChanged; + public event EventHandler DisabledChanged; + public event EventHandler MachineVersionChanged; public event EventHandler UserChanged; @@ -228,6 +230,33 @@ namespace Tango.BL.Entities } } + protected Boolean _disabled; + + /// + /// Gets or sets the tangoversionbase disabled. + /// + + [Column("DISABLED")] + + public Boolean Disabled + { + get + { + return _disabled; + } + + set + { + if (_disabled != value) + { + _disabled = value; + + OnDisabledChanged(value); + + } + } + } + protected MachineVersion _machineversion; /// @@ -337,6 +366,15 @@ namespace Tango.BL.Entities RaisePropertyChanged(nameof(Comments)); } + /// + /// Called when the Disabled has changed. + /// + protected virtual void OnDisabledChanged(Boolean disabled) + { + DisabledChanged?.Invoke(this, disabled); + RaisePropertyChanged(nameof(Disabled)); + } + /// /// Called when the MachineVersion has changed. /// diff --git a/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs b/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs new file mode 100644 index 000000000..50f59b744 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.Cryptography +{ + public static class PasswordGenerator + { + internal static readonly String alphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + internal static readonly String numeric = "1234567890"; + internal static readonly String alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + public enum PasswordType + { + Alphaumeric, + Numeric, + Alpha, + } + + public enum PasswordCasing + { + Any, + Upper, + Lower + } + + public static String Generate(int length, PasswordType type = PasswordType.Alphaumeric, PasswordCasing casing = PasswordCasing.Any) + { + String chars = String.Empty; + + switch (type) + { + case PasswordType.Alphaumeric: + chars = alphaNumeric; + break; + case PasswordType.Numeric: + chars = numeric; + break; + case PasswordType.Alpha: + chars = alpha; + break; + } + + switch (casing) + { + case PasswordCasing.Upper: + chars = chars.ToUpper(); + break; + case PasswordCasing.Lower: + chars = chars.ToLower(); + break; + } + + return GetUniqueKey(chars.ToCharArray(), length); + } + + private static string GetUniqueKey(char[] chars, int size) + { + byte[] data = new byte[4 * size]; + using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) + { + crypto.GetBytes(data); + } + StringBuilder result = new StringBuilder(size); + for (int i = 0; i < size; i++) + { + var rnd = BitConverter.ToUInt32(data, i * 4); + var idx = rnd % chars.Length; + + result.Append(chars[idx]); + } + + return result.ToString(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 813a31443..9a55a25f9 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -99,6 +99,7 @@ + @@ -220,7 +221,7 @@ - + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs index 2db20bbba..14fe4f04e 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs @@ -58,6 +58,7 @@ namespace Tango.DAL.Remote.DB public string DEVICE_ID { get; set; } public string DEVICE_NAME { get; set; } public int HEAD_TYPE { get; set; } + public string ACTIVATION_KEY { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection CATS { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index 13b409e05..af3179379 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -815,6 +815,7 @@ + @@ -1186,6 +1187,7 @@ + @@ -4284,6 +4286,7 @@ + @@ -4708,6 +4711,7 @@ + @@ -6851,6 +6855,7 @@ + @@ -7262,6 +7267,7 @@ + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram index 7f4f28dc0..476e859b4 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,90 +5,90 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/TANGO_VERSIONS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/TANGO_VERSIONS.cs index 4c46e8170..ba1dbb55b 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/TANGO_VERSIONS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/TANGO_VERSIONS.cs @@ -24,6 +24,7 @@ namespace Tango.DAL.Remote.DB public string COMMENTS { get; set; } public string USER_GUID { get; set; } public string MACHINE_VERSION_GUID { get; set; } + public bool DISABLED { get; set; } public virtual MACHINE_VERSIONS MACHINE_VERSIONS { get; set; } public virtual USER USER { get; set; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 0e96c14c8..161caaf23 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -105,7 +105,7 @@ namespace Tango.MachineService.Controllers var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid && !x.Disabled).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); response.Version = latest_machine_version.Version; response.FirmwareVersion = latest_machine_version.FirmwareVersion; @@ -227,7 +227,7 @@ namespace Tango.MachineService.Controllers var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid && !x.Disabled).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); response.Version = latest_machine_version.Version; response.FirmwareVersion = latest_machine_version.FirmwareVersion; @@ -346,9 +346,9 @@ namespace Tango.MachineService.Controllers { var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid && !x.Disabled).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - if (Version.Parse(latest_machine_version.Version) != Version.Parse(request.Version)) + if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version)) { response.IsUpdateAvailable = true; } -- cgit v1.3.1