From 9cc18084e2f9db73ce9e2820dfebcab4e50e5730 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 5 May 2019 11:43:19 +0300 Subject: MREGE. --- .../Build/Shortcuts/Machine Studio.lnk | Bin 1518 -> 1581 bytes .../DeveloperModuleSettings.cs | 13 +++ .../ViewModels/MainViewVM.cs | 13 ++- .../Views/JobView.xaml | 4 +- .../MachineStudioSettings.cs | 2 +- .../TCC/Tango.TCC.BL/Entities/Device.cs | 6 ++ .../TCC/Tango.TCC.BL/Entities/TCCEntityBase.cs | 5 ++ .../TCC/Tango.TCC.BL/Web/DefinitionResponse.cs | 3 + .../Controllers/ColorDetectionController.cs | 98 +++++++++++++++++---- .../TCC/Tango.TCC.Service/DB/TccDbContext.cs | 46 ++++++++++ .../TCC/Tango.TCC.Service/TCCServiceConfig.cs | 5 ++ .../TCC/Tango.TCC.Service/Tango.TCC.Service.csproj | 5 ++ .../Visual_Studio/TCC/Tango.TCC.Service/Web.config | 3 +- .../Tango.Web/Helpers/ObservablesContextHelper.cs | 4 +- 14 files changed, 184 insertions(+), 23 deletions(-) create mode 100644 Software/Visual_Studio/TCC/Tango.TCC.Service/DB/TccDbContext.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 793efc9e8..c6e1d0aed 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs index e6d5674e1..2099b12d9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModuleSettings.cs @@ -24,9 +24,22 @@ namespace Tango.MachineStudio.Developer public String DefaultJobRmlGuid { get; set; } + /// + /// Gets or sets a value indicating whether to enable gradient generation. + /// + public bool EnableGradientGeneration { get; set; } + + /// + /// Gets or sets the gradient resolution in centimeters. + /// + public int GradientResolutionCM { get; set; } + public DeveloperModuleSettings() { ProcessParametersIndices = new List(); + + EnableGradientGeneration = true; + GradientResolutionCM = 500; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 4ce8ab39d..3f28c2cff 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -552,6 +552,12 @@ namespace Tango.MachineStudio.Developer.ViewModels public IAuthenticationProvider AuthenticationProvider { get; set; } + public DeveloperModuleSettings Settings + { + get { return _settings; } + set { _settings = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -783,7 +789,7 @@ namespace Tango.MachineStudio.Developer.ViewModels public override void OnApplicationReady() { - _settings = SettingsManager.Default.GetOrCreate(); + Settings = SettingsManager.Default.GetOrCreate(); SelectedJobs = new ObservableCollection(); JobEvents = new ObservableCollection(); @@ -972,7 +978,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { _preparingTaskItem = _notification.PushTaskItem("Preparing job for printing..."); } - else if (percent == 100) + else if (percent == 100 && _preparingTaskItem != null) { _preparingTaskItem.Pop(); _preparingTaskItem = null; @@ -1341,6 +1347,9 @@ namespace Tango.MachineStudio.Developer.ViewModels IsFree = false; LogManager.Log("Sending job to machine operator..."); + MachineOperator.GradientGenerationConfiguration.IsEnabled = Settings.EnableGradientGeneration; + MachineOperator.GradientGenerationConfiguration.ResolutionCM = Settings.GradientResolutionCM; + if (resumeFunc == null) { JobHandler = await MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index a5d137e67..8a5ec94fa 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -867,9 +867,9 @@ Generate Gradient - + Resolution: - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs index e5fe63d87..0433ff7be 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs @@ -146,7 +146,7 @@ namespace Tango.MachineStudio.Common StudioModulesBounds = new List(); Environment = WorkingEnvironment.Remote; DeploymentSlot = DeploymentSlot.DEV; - JobUploadStrategy = JobUploadStrategy.Default; + JobUploadStrategy = JobUploadStrategy.JobDescriptionFile; MaximumCacheTime = TimeSpan.FromMinutes(5); CachingMode = ObservablesContextInMemoryCachingMode.None; } diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/Device.cs b/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/Device.cs index 709b72a21..e2b3d68e4 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/Device.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/Device.cs @@ -24,5 +24,11 @@ namespace Tango.TCC.BL.Entities [Column("LAST_LOGIN")] public DateTime LastLogin { get; set; } + + [Column("MACHINE_REGISTERED")] + public bool MachineRegistered { get; set; } + + [Column("ORGANIZATION_GUID")] + public String OrganizationGuid { get; set; } } } diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/TCCEntityBase.cs b/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/TCCEntityBase.cs index 9e3778a3c..f003bf6f0 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/TCCEntityBase.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/Entities/TCCEntityBase.cs @@ -14,5 +14,10 @@ namespace Tango.TCC.BL.Entities [Column("GUID")] public String Guid { get; set; } + + public TCCEntityBase() + { + Guid = System.Guid.NewGuid().ToString(); + } } } diff --git a/Software/Visual_Studio/TCC/Tango.TCC.BL/Web/DefinitionResponse.cs b/Software/Visual_Studio/TCC/Tango.TCC.BL/Web/DefinitionResponse.cs index 5ab6cfd6d..ea09dfdef 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.BL/Web/DefinitionResponse.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.BL/Web/DefinitionResponse.cs @@ -18,6 +18,8 @@ namespace Tango.TCC.BL.Web public CardDetectionHistogramMethods HistogramMethod { get; set; } public bool EnableDoubleChecking { get; set; } public bool EnforceBarcodeDetection { get; set; } + public List OrganizationMachines { get; set; } + public bool IsRegistered { get; set; } public DefinitionResponse() { @@ -29,6 +31,7 @@ namespace Tango.TCC.BL.Web HistogramMethod = CardDetectionHistogramMethods.Chi_Square; EnableDoubleChecking = true; EnforceBarcodeDetection = true; + OrganizationMachines = new List(); } } } diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs b/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs index a9ab84931..a28c2cb12 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs @@ -11,11 +11,14 @@ using System.Security.Authentication; using System.Web.Http; using Tango.PMR.TCC; using Tango.TCC.BL; +using Tango.TCC.BL.Entities; using Tango.TCC.BL.Web; +using Tango.TCC.Service.DB; using Tango.TCC.Service.Filters; using Tango.TCC.Service.Security; using Tango.Web.Controllers; using Tango.Web.Security; +using System.Data.Entity; namespace Tango.TCC.Service.Controllers { @@ -28,6 +31,23 @@ namespace Tango.TCC.Service.Controllers if (request.AppID == TCCServiceConfig.APP_ID) { + using (var db = TccDbContext.CreateTCC()) + { + var device = db.Devices.SingleOrDefault(x => x.DeviceID == request.DeviceID); + + if (device == null) + { + device = new Device(); + device.DeviceID = request.DeviceID; + device.DeviceModel = request.Device; + device.Email = request.Email; + device.LastLogin = DateTime.UtcNow; + device.OSVersion = request.OSVersion; + db.Devices.Add(device); + db.SaveChanges(); + } + } + response.AccessToken = WebToken.CreateNew(TCCServiceConfig.JWT_TOKEN_SECRET, new DeviceTokenObject() { DeviceID = request.DeviceID, @@ -45,20 +65,40 @@ namespace Tango.TCC.Service.Controllers [HttpPost] public DefinitionResponse GetDefinition(DefinitionRequest request) { - String s = RequestToken.Object.DeviceID; - - return new DefinitionResponse() + using (var db = TccDbContext.CreateTCC()) { - TemplateString = TCCServiceConfig.TEMPLATE_STRING, - SampleWidth = TCCServiceConfig.SAMPLE_WIDTH, - SampleHeight = TCCServiceConfig.SAMPLE_HEIGHT, - CameraWidth = TCCServiceConfig.CAMERA_WIDTH, - CameraHeight = TCCServiceConfig.CAMERA_HEIGHT, - HistogramMethod = TCCServiceConfig.HISTOGRAM_METHOD, - SimilarityTolerance = TCCServiceConfig.SIMILARITY_TOLERANCE, - EnableDoubleChecking = TCCServiceConfig.ENABLE_DOUBLE_CHECKING, - EnforceBarcodeDetection = TCCServiceConfig.ENFORCE_BARCODE_DETECTION, - }; + var response = new DefinitionResponse() + { + TemplateString = TCCServiceConfig.TEMPLATE_STRING, + SampleWidth = TCCServiceConfig.SAMPLE_WIDTH, + SampleHeight = TCCServiceConfig.SAMPLE_HEIGHT, + CameraWidth = TCCServiceConfig.CAMERA_WIDTH, + CameraHeight = TCCServiceConfig.CAMERA_HEIGHT, + HistogramMethod = TCCServiceConfig.HISTOGRAM_METHOD, + SimilarityTolerance = TCCServiceConfig.SIMILARITY_TOLERANCE, + EnableDoubleChecking = TCCServiceConfig.ENABLE_DOUBLE_CHECKING, + EnforceBarcodeDetection = TCCServiceConfig.ENFORCE_BARCODE_DETECTION, + }; + + var device = db.Devices.SingleOrDefault(x => x.DeviceID == RequestToken.Object.DeviceID); + + if (device != null && device.MachineRegistered) + { + using (var tangoDb = TccDbContext.CreateTango()) + { + var machines = tangoDb.Machines.Where(x => x.OrganizationGuid == device.OrganizationGuid); + + response.IsRegistered = true; + + foreach (var m in machines) + { + response.OrganizationMachines.Add(m.SerialNumber); + } + } + } + + return response; + } } [JwtTokenFilter] @@ -111,9 +151,37 @@ namespace Tango.TCC.Service.Controllers { MachineRegistrationResponse response = new MachineRegistrationResponse(); - response.OrganizationMachines.Add("0002"); + using (var tangoDB = TccDbContext.CreateTango()) + { + var machine = tangoDB.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber); + + if (machine == null) + { + throw new AuthenticationException("Invalid serial number."); + } + + var all_machines = tangoDB.Machines.Where(x => x.OrganizationGuid == machine.OrganizationGuid); + + foreach (var m in all_machines) + { + response.OrganizationMachines.Add(m.SerialNumber); + } - //throw new AuthenticationException("No such serial number..."); + using (var db = TccDbContext.CreateTCC()) + { + String deviceId = RequestToken.Object.DeviceID; + var device = db.Devices.SingleOrDefault(x => x.DeviceID == deviceId); + + if (device == null) + { + throw new InvalidOperationException("Could not find the device id."); + } + + device.MachineRegistered = true; + device.OrganizationGuid = machine.OrganizationGuid; + db.SaveChanges(); + } + } return response; } diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/DB/TccDbContext.cs b/Software/Visual_Studio/TCC/Tango.TCC.Service/DB/TccDbContext.cs new file mode 100644 index 000000000..de38c0b91 --- /dev/null +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/DB/TccDbContext.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Tango.BL; +using Tango.Core; +using Tango.TCC.BL.Entities; +using Tango.Web; +using Tango.Web.Helpers; + +namespace Tango.TCC.Service.DB +{ + public class TccDbContext + { + public static ObservablesContext CreateTango() + { + return ObservablesContextHelper.CreateContext(TCCServiceConfig.TANGO_DB_CATALOG); + } + + public static TCCContext CreateTCC() + { + if (System.Diagnostics.Debugger.IsAttached) + { + return new TCCContext(new Core.DataSource() + { + Address = "localhost\\SQLEXPRESS", + Catalog = "TCC", + IntegratedSecurity = true, + Type = DataSourceType.SQLServer, + }); + } + else + { + return new TCCContext(new Core.DataSource() + { + Address = WebConfig.DB_ADDRESS, + Catalog = WebConfig.DB_CATALOG, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + UserName = WebConfig.DB_USER_NAME, + Password = WebConfig.DB_PASSWORD + }); + } + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/TCCServiceConfig.cs b/Software/Visual_Studio/TCC/Tango.TCC.Service/TCCServiceConfig.cs index 14e9ef8cc..343d27e0a 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.Service/TCCServiceConfig.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/TCCServiceConfig.cs @@ -76,5 +76,10 @@ namespace Tango.TCC.Service /// Gets the mobile application ID. /// public static String APP_ID => ConfigurationManager.AppSettings[nameof(APP_ID)].ToString(); + + /// + /// Gets the database catalog. + /// + public static String TANGO_DB_CATALOG => ConfigurationManager.AppSettings[nameof(TANGO_DB_CATALOG)].ToString(); } } \ No newline at end of file diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/Tango.TCC.Service.csproj b/Software/Visual_Studio/TCC/Tango.TCC.Service/Tango.TCC.Service.csproj index fe4d6e85b..b7042197c 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.Service/Tango.TCC.Service.csproj +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/Tango.TCC.Service.csproj @@ -175,6 +175,7 @@ + Global.asax @@ -215,6 +216,10 @@ + + {f441feee-322a-4943-b566-110e12fd3b72} + Tango.BL + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/Web.config b/Software/Visual_Studio/TCC/Tango.TCC.Service/Web.config index 37e3e528d..de53d7d14 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.Service/Web.config +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/Web.config @@ -18,7 +18,8 @@ - + + diff --git a/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs b/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs index fcf6eb599..b0ef6b104 100644 --- a/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs +++ b/Software/Visual_Studio/Tango.Web/Helpers/ObservablesContextHelper.cs @@ -10,12 +10,12 @@ namespace Tango.Web.Helpers { public static class ObservablesContextHelper { - public static ObservablesContext CreateContext() + public static ObservablesContext CreateContext(String catalog = null) { return new ObservablesContext(new DataSource() { Address = WebConfig.DB_ADDRESS, - Catalog = WebConfig.DB_CATALOG, + Catalog = catalog != null ? catalog : WebConfig.DB_CATALOG, IntegratedSecurity = false, Type = DataSourceType.SQLServer, UserName = WebConfig.DB_USER_NAME, -- cgit v1.3.1