From 36bde2234f457f4bb93caf6d1f2e47ddf895be39 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 6 Dec 2019 21:10:57 +0200 Subject: Added new PID and heaters to hw, diagnostics and tech. Implemented proper sorting on hw version and tech board. (DB CHANGE!) Related Work Items: #1595 --- .../ViewModels/MainViewVM.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 40dc82d29..7ebcbeb55 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -236,13 +236,13 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels _db = ObservablesContext.CreateDefault(); - CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).ToSynchronizedObservableCollection(); - CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).OrderByAlphaNumeric(x => x.HardwareMotorType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).OrderByAlphaNumeric(x => x.HardwareDancerType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwarePidControls = _db.HardwarePidControlTypes.ToList().Select(x => new HardwarePidControl() { HardwarePidControlType = x }).OrderByAlphaNumeric(x => x.HardwarePidControlType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareWinders = _db.HardwareWinderTypes.ToList().Select(x => new HardwareWinder() { HardwareWinderType = x }).OrderByAlphaNumeric(x => x.HardwareWinderType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareSpeedSensors = _db.HardwareSpeedSensorTypes.ToList().Select(x => new HardwareSpeedSensor() { HardwareSpeedSensorType = x }).OrderByAlphaNumeric(x => x.HardwareSpeedSensorType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareBlowers = _db.HardwareBlowerTypes.ToList().Select(x => new HardwareBlower() { HardwareBlowerType = x }).OrderByAlphaNumeric(x => x.HardwareBlowerType.Description).ToSynchronizedObservableCollection(); + CurrentVersion.HardwareBreakSensors = _db.HardwareBreakSensorTypes.ToList().Select(x => new HardwareBreakSensor() { HardwareBreakSensorType = x }).OrderByAlphaNumeric(x => x.HardwareBreakSensorType.Description).ToSynchronizedObservableCollection(); } private void RefreshVersions() -- cgit v1.3.1 From 3cd59dd3b04168ad91cb1fe51231e9b3ddd74705 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 8 Dec 2019 00:19:54 +0200 Subject: Implemented fast database update detection of RMLL, Hardware Versions & Color Catalogs. Related Work Items: #1622 --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../ViewModels/MainViewVM.cs | 1 + .../ViewModels/MainViewVM.cs | 1 + .../MachineUpdate/MachineUpdateManager.cs | 23 +++++++++++++-- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 3 +- .../Tango.PPC.Common/Web/CheckForUpdateRequest.cs | 11 ++++++++ .../Tango.PPC.Common/Web/CheckForUpdateResponse.cs | 7 +++++ .../PPC/Tango.PPC.Common/Web/UpdatedEntity.cs | 31 +++++++++++++++++++++ .../UpdateAvailableNotificationItem.cs | 10 +++++++ .../UpdateAvailableNotificationItemView.xaml | 16 +++++++---- .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 13 ++++++++- .../Controllers/PPCController.cs | 28 +++++++++++++++++++ 13 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index a84785a6e..92884377a 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index e97b6d351..9a2dcca84 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs index 652ad3093..3cc4406d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs @@ -305,6 +305,7 @@ namespace Tango.MachineStudio.Catalogs.ViewModels try { IsFree = false; + ActiveCatalog.LastUpdated = DateTime.UtcNow; await _activeCatalogContext.SaveChangesAsync(); await LoadCatalogs(); _notification.ShowInfo("Catalog updated successfully."); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 7ebcbeb55..256ed24d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -418,6 +418,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels await Task.Factory.StartNew(() => { + CurrentVersion.LastUpdated = DateTime.UtcNow; _db.SaveChanges(); RefreshVersions(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index e98f6d717..5296a9f34 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Tango.BL; using Tango.Core; using Tango.Core.DB; using Tango.Core.ExtensionMethods; @@ -594,6 +595,8 @@ namespace Tango.PPC.Common.MachineUpdate { return Task.Factory.StartNew(() => { + _isUpdating = true; + var machineServiceAddress = SettingsManager.Default.GetOrCreate().GetMachineServiceAddress(); LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); @@ -606,12 +609,28 @@ namespace Tango.PPC.Common.MachineUpdate request.SerialNumber = serialNumber; request.Version = _app_manager.Version.ToString(); + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + request.Rmls = db.Rmls.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.HardwareVersions = db.HardwareVersions.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.Catalogs = db.ColorCatalogs.ToList().Select(x => new UpdatedEntity(x)).ToList(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred while trying to fill the existing database entities before checking for updates."); + } + CheckForUpdateResponse update_response = null; update_response = _client.CheckForUpdates(request).Result; LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}"); + _isUpdating = false; + return update_response; }); } @@ -977,10 +996,10 @@ namespace Tango.PPC.Common.MachineUpdate try { var response = await CheckForUpdate(_machineProvider.Machine.SerialNumber); - if (response.IsUpdateAvailable) + if (response.IsUpdateAvailable || response.IsDatabaseUpdateAvailable) { _checkForUpdateTimer.Interval = TimeSpan.FromMinutes(60).TotalMilliseconds; - LogManager.Log($"New application version detected ({response.Version}). Raising event..."); + LogManager.Log($"New {(response.IsDatabaseUpdateAvailable ? "database updates" : "application version")} detected ({response.Version}). Raising event..."); UpdateAvailable?.Invoke(this, response); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 671cac4f1..e3a23903e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -226,6 +226,7 @@ + @@ -406,7 +407,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs index b98848e4f..0feb32aaf 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs @@ -11,5 +11,16 @@ namespace Tango.PPC.Common.Web { public String SerialNumber { get; set; } public String Version { get; set; } + + public List Rmls { get; set; } + public List HardwareVersions { get; set; } + public List Catalogs { get; set; } + + public CheckForUpdateRequest() + { + Rmls = new List(); + HardwareVersions = new List(); + Catalogs = new List(); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs index 370c0f5ea..63d870834 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateResponse.cs @@ -10,8 +10,15 @@ namespace Tango.PPC.Common.Web public class CheckForUpdateResponse : WebResponseMessage { public bool IsUpdateAvailable { get; set; } + public bool IsDatabaseUpdateAvailable { get; set; } public String Version { get; set; } public bool SetupFirmware { get; set; } public bool SetupFPGA { get; set; } + public UpdateDBResponse UpdateDBResponse { get; set; } + + public CheckForUpdateResponse() + { + UpdateDBResponse = new UpdateDBResponse(); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs new file mode 100644 index 000000000..faee20678 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdatedEntity.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; + +namespace Tango.PPC.Common.Web +{ + public class UpdatedEntity + { + public UpdatedEntity() + { + + } + + public UpdatedEntity(IObservableEntity entity) : this() + { + Guid = entity.Guid; + LastUpdated = entity.LastUpdated; + } + + public String Guid { get; set; } + public DateTime LastUpdated { get; set; } + + public override string ToString() + { + return $"{Guid} | {LastUpdated}"; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs index 4dea142b0..9e336f276 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs @@ -31,6 +31,16 @@ namespace Tango.PPC.UI.Notifications.NotificationItems set { _version = value; RaisePropertyChangedAuto(); } } + private bool _isDatabaseUpdate; + /// + /// Gets or sets a value indicating whether this instance is database update. + /// + public bool IsDatabaseUpdate + { + get { return _isDatabaseUpdate; } + set { _isDatabaseUpdate = value; RaisePropertyChangedAuto(); } + } + /// /// Gets or sets the view type. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml index c4533b843..fc9b05b9b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml @@ -14,12 +14,16 @@ - - Version - - is available! - Tap to start updating your system. - + + + + Version + + is available! + Tap to start updating your system. + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 25a4f8c4b..0371e94da 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -162,6 +162,16 @@ namespace Tango.PPC.UI.ViewModels LatestVersion = response.Version; await NavigateTo(MachineUpdateView.UpdateAvailableView); } + else if (response.IsDatabaseUpdateAvailable) + { + IsDbUpdate = true; + _db_compare_result = new DbCompareResult() + { + RequiresUpdate = true, + UpdateDBResponse = response.UpdateDBResponse + }; + await NavigateTo(MachineUpdateView.UpdateAvailableView); + } else { _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber); @@ -418,12 +428,13 @@ namespace Tango.PPC.UI.ViewModels { if (!IsVisible && _updateNotificationItem == null) { - LogManager.Log($"New application version detected ({e.Version}). Pushing notification..."); + LogManager.Log($"New {(e.IsDatabaseUpdateAvailable ? "database updates" : "application version")} detected ({e.Version}). Pushing notification..."); InvokeUI(() => { _updateNotificationItem = new UpdateAvailableNotificationItem(); _updateNotificationItem.Version = Version.Parse(e.Version).ToString(3); + _updateNotificationItem.IsDatabaseUpdate = e.IsDatabaseUpdateAvailable && !e.IsUpdateAvailable; _updateNotificationItem.Pressed += (_, __) => { _updateNotificationItem = null; diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index f0239978f..2dee09e69 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -314,6 +314,34 @@ namespace Tango.MachineService.Controllers response.Version = latest_machine_version.Version; + //Compare database + + var rmls = db.Rmls.Select(x => new { x.Guid, x.LastUpdated }).ToList(); + var hardwareVersions = db.HardwareVersions.Select(x => new { x.Guid, x.LastUpdated }).ToList(); + var catalogs = db.ColorCatalogs.Select(x => new { x.Guid, x.LastUpdated }).ToList(); + + bool hasDatabaseUpdates = false; + + hasDatabaseUpdates = rmls.Exists(x => request.Rmls.Exists(y => x.Guid == y.Guid && x.LastUpdated > y.LastUpdated) || !request.Rmls.Exists(y => x.Guid == y.Guid)); + + if (!hasDatabaseUpdates) + { + hasDatabaseUpdates = hardwareVersions.Exists(x => request.HardwareVersions.Exists(y => x.Guid == y.Guid && x.LastUpdated > y.LastUpdated) || !request.HardwareVersions.Exists(y => x.Guid == y.Guid)); + } + + if (!hasDatabaseUpdates) + { + hasDatabaseUpdates = catalogs.Exists(x => request.Catalogs.Exists(y => x.Guid == y.Guid && x.LastUpdated > y.LastUpdated) || !request.Catalogs.Exists(y => x.Guid == y.Guid)); + } + + if (hasDatabaseUpdates) + { + response.IsDatabaseUpdateAvailable = true; + response.UpdateDBResponse = UpdateDB(new UpdateDBRequest() { SerialNumber = request.SerialNumber }); + } + + //Compare database + if (machine.ForceVersionUpdate) { response.IsUpdateAvailable = true; -- cgit v1.3.1 From 3f069bb4a5303b2c732ba1263229f62526acc693 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 10 Dec 2019 00:39:06 +0200 Subject: Refactored Object mapping extension methods ! Removed FK from JOB_RUNS => JOBS Added MACHINE_GUID to JOB_RUNS Refactored MS Statistics module for the new changes. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../ViewModels/MainViewVM.cs | 2 +- .../ViewModels/MainViewVM.cs | 2 +- .../Models/JobRunModel.cs | 45 +++++++ .../Tango.MachineStudio.Statistics.csproj | 1 + .../ViewModels/MainViewVM.cs | 23 ++-- .../ViewModels/ConnectedMachineViewVM.cs | 6 +- .../ViewModels/MainViewVM.cs | 2 +- .../Tango.BL/Builders/JobRunsBuilder.cs | 12 -- .../Visual_Studio/Tango.BL/DTO/JobRunDTOBase.cs | 8 ++ Software/Visual_Studio/Tango.BL/Entities/Job.cs | 4 +- .../Visual_Studio/Tango.BL/Entities/JobBase.cs | 38 ------ .../Visual_Studio/Tango.BL/Entities/JobRunBase.cs | 67 ++++------ .../ExtensionMethods/ObjectExtensions.cs | 113 ++++++++-------- Software/Visual_Studio/Tango.DAL.Remote/DB/JOB.cs | 3 - .../Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs | 3 +- .../Tango.DAL.Remote/DB/RemoteADO.Designer.cs | 2 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx | 61 +++------ .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 147 ++++++++++----------- .../JobRuns/BasicJobRunsLogger.cs | 3 + .../Remote/RemoteDBComparer.cs | 4 +- Software/Visual_Studio/Tango.sln | 13 +- .../Utilities/Tango.JobRunsGenerator/Program.cs | 81 +++--------- 24 files changed, 278 insertions(+), 362 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index f50c8b7fb..0336edc76 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 5b78ee141..dd9945ab8 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 256ed24d6..9a80eb9d9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -221,7 +221,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels private void CopyParameters(object obj) { - obj.MapPrimitivesTo(SelectedHardwareObject, + obj.MapPropertiesTo(SelectedHardwareObject, MappingFlags.PrimitivesOnly, (prop) => !prop.PropertyType.IsEnum && diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index ee21b9ac3..9939e4876 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -471,7 +471,7 @@ namespace Tango.MachineStudio.RML.ViewModels var rml = await new RmlBuilder(context).Set(SelectedRML.Guid).WithActiveParametersGroup().WithLiquidFactors().BuildAsync(); Rml cloned = new Rml(); - rml.MapPrimitivesWithStrings(cloned); + rml.MapPropertiesTo(cloned, MappingFlags.NoReferenceTypes); cloned.Code = Rmls.Max(x => x.Code) + 1; cloned.Guid = Guid.NewGuid().ToString(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs new file mode 100644 index 000000000..8e5642e3d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/JobRunModel.cs @@ -0,0 +1,45 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Entities; +using Tango.Core.ExtensionMethods; + +namespace Tango.MachineStudio.Statistics.Models +{ + public class JobRunModel : JobRun + { + private static Dictionary _machines = new Dictionary(); + + public JobRunModel() + { + + } + + public JobRunModel(JobRun run) + { + run.MapPropertiesTo(this, MappingFlags.NoReferenceTypes); + } + + public Task LoadMachine(ObservablesContext context) + { + return Task.Factory.StartNew(() => + { + if (!_machines.ContainsKey(MachineGuid)) + { + Machine = context.Machines.SingleOrDefault(x => x.Guid == MachineGuid); + _machines.Add(MachineGuid, Machine); + } + else + { + Machine = _machines[MachineGuid]; + } + }); + } + + public Machine Machine { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj index 243663c5a..36c371165 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj @@ -73,6 +73,7 @@ + PieChartTooltipControl.xaml diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs index ef9561d0b..dfbfe2648 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/MainViewVM.cs @@ -7,20 +7,20 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using Tango.BL; -using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core.Helpers; using Tango.MachineStudio.Common; using Tango.MachineStudio.Statistics.Models; using System.Data.Entity; using Tango.MachineStudio.Common.Notifications; +using Tango.BL.Entities; namespace Tango.MachineStudio.Statistics.ViewModels { public class MainViewVM : StudioViewModel { private ObservablesContext _context; - private List _job_runs; + private List _job_runs; private bool rendered; private INotificationProvider _notification; private bool _loaded; @@ -74,7 +74,6 @@ namespace Tango.MachineStudio.Statistics.ViewModels set { _maxDate = value; RaisePropertyChangedAuto(); } } - public MainViewVM(INotificationProvider notificationProvider) { _notification = notificationProvider; @@ -88,12 +87,12 @@ namespace Tango.MachineStudio.Statistics.ViewModels } - private List GetJobRunsByDateRange(DateTime startDate, DateTime endTime, JobRunStatus? status = null) + private List GetJobRunsByDateRange(DateTime startDate, DateTime endTime, JobRunStatus? status = null) { return _job_runs.Where(x => x.StartDate.ToLocalTime() >= startDate && x.StartDate.ToLocalTime() <= endTime && (status == null || x.JobRunStatus == status)).ToList(); } - private List GetJobRunsByDate(DateTime date, JobRunStatus? status = null) + private List GetJobRunsByDate(DateTime date, JobRunStatus? status = null) { return _job_runs.Where(x => x.StartDate.ToLocalTime().Date == date.Date && (status == null || x.JobRunStatus == status)).ToList(); } @@ -106,8 +105,6 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } - - public override async void OnNavigatedTo() { base.OnNavigatedTo(); @@ -124,7 +121,11 @@ namespace Tango.MachineStudio.Statistics.ViewModels await Task.Factory.StartNew(() => { _context = ObservablesContext.CreateDefault(); - _job_runs = _context.JobRuns.Include(x => x.Job).Include(x => x.Job.Machine).OrderBy(x => x.StartDate).ToList(); + _job_runs = _context.JobRuns.OrderBy(x => x.StartDate).ToList().Select(x => new JobRunModel(x)).ToList(); + foreach (var run in _job_runs) + { + run.LoadMachine(_context).GetAwaiter().GetResult(); + } }); if (_job_runs.Count > 0) @@ -282,12 +283,12 @@ namespace Tango.MachineStudio.Statistics.ViewModels private void GeneratePrintPerWeekChart() { - List range_job_runs = GetJobRunsByDateRange(StartDate, EndDate); + List range_job_runs = GetJobRunsByDateRange(StartDate, EndDate); Dictionary> weeks_print_avg = new Dictionary>(); //Init machines weeks averages dictionary. - foreach (var machine in range_job_runs.Select(x => x.Job.Machine).OrderBy(x => x.Name).DistinctBy(x => x.Guid)) + foreach (var machine in range_job_runs.Select(x => x.Machine).OrderBy(x => x.Name).DistinctBy(x => x.Guid)) { weeks_print_avg[machine] = new List(); } @@ -305,7 +306,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels { var week_job_runs = range_job_runs.Where(x => x.EndPosition > 10 && x.StartDate >= current_sunday && x.StartDate <= current_sunday.AddDays(7)).ToList(); - foreach (var machine_job_runs in week_job_runs.GroupBy(x => x.Job.Machine)) + foreach (var machine_job_runs in week_job_runs.GroupBy(x => x.Machine)) { weeks_print_avg[machine_job_runs.Key].Add(machine_job_runs.Select(x => x.EndPosition).Average()); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs index 16f6938a0..40479895d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs @@ -95,11 +95,11 @@ namespace Tango.MachineStudio.UI.ViewModels using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var jobs = await db.Jobs.Include(x => x.JobRuns).Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).ToListAsync(); + var jobRuns = await db.JobRuns.Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).ToListAsync(); - TotalMachineWorkTime = TimeSpan.FromHours(jobs.SelectMany(x => x.JobRuns).Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); + TotalMachineWorkTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); - int meters = (int)jobs.SelectMany(x => x.JobRuns).Select(x => x.EndPosition).Sum(); + int meters = (int)jobRuns.Select(x => x.EndPosition).Sum(); TotalMachineMeters = $"{meters.ToString("N0")} meters"; } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs index 598b1a194..3cceba6c9 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs @@ -155,7 +155,7 @@ namespace Tango.PPC.MachineSettings.ViewModels { Settings.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList(); Settings.SupportedColorSpaces = SelectedColorSpaces.SynchedSource.ToList(); - Machine.MapPrimitivesWithStrings(MachineProvider.Machine); + Machine.MapPropertiesTo(MachineProvider.Machine, MappingFlags.NoReferenceTypes); Settings.EnableHotSpot = EnableHotSpot; Settings.HotSpotPassword = HotSpotPassword; diff --git a/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs index 0a02c6a23..ca755a04c 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs @@ -15,17 +15,5 @@ namespace Tango.BL.Builders } - protected override IQueryable OnSetQuery(IQueryable query) - { - return query.Include(x => x.Job); - } - - public virtual JobRunsBuilder WithJobEvents() - { - return AddStep(2, () => - { - Context.MachinesEvents.Where(x => x.MachineGuid == Entity.Job.MachineGuid && x.DateTime >= Entity.StartDate && x.DateTime <= Entity.EndDate).OrderBy(x => x.DateTime).ToList(); - }); - } } } diff --git a/Software/Visual_Studio/Tango.BL/DTO/JobRunDTOBase.cs b/Software/Visual_Studio/Tango.BL/DTO/JobRunDTOBase.cs index 112694e1a..9726f16a7 100644 --- a/Software/Visual_Studio/Tango.BL/DTO/JobRunDTOBase.cs +++ b/Software/Visual_Studio/Tango.BL/DTO/JobRunDTOBase.cs @@ -26,6 +26,14 @@ namespace Tango.BL.DTO public abstract class JobRunDTOBase : ObservableEntityDTO { + /// + /// machine guid + /// + public String MachineGuid + { + get; set; + } + /// /// job guid /// diff --git a/Software/Visual_Studio/Tango.BL/Entities/Job.cs b/Software/Visual_Studio/Tango.BL/Entities/Job.cs index 3cb6494d4..19f374951 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Job.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Job.cs @@ -628,7 +628,7 @@ namespace Tango.BL.Entities foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { JobFileBrushStop st = new JobFileBrushStop(); - stop.MapPrimitivesWithStringsNoNullsTo(st); + stop.MapPropertiesTo(st, MappingFlags.NoReferenceTypes | MappingFlags.NoNullStrings); st.ColorCatalogItemGuid = stop.ColorCatalogsItemGuid.ToStringOrEmpty(); foreach (var idsPack in machine.Configuration.NoneEmptyIdsPacks) @@ -755,7 +755,7 @@ namespace Tango.BL.Entities BrushStop st = new BrushStop(); st.StopIndex = j + 1; st.SegmentGuid = s.Guid; - stop.MapPrimitivesWithStringsNoNullsTo(st); + stop.MapPropertiesTo(st, MappingFlags.NoReferenceTypes | MappingFlags.NoNullStrings); foreach (var volume in stop.LiquidVolumes) { diff --git a/Software/Visual_Studio/Tango.BL/Entities/JobBase.cs b/Software/Visual_Studio/Tango.BL/Entities/JobBase.cs index c5354f2c7..b356ecbfe 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/JobBase.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/JobBase.cs @@ -87,8 +87,6 @@ namespace Tango.BL.Entities public event EventHandler CustomerChanged; - public event EventHandler> JobRunsChanged; - public event EventHandler MachineChanged; public event EventHandler RmlChanged; @@ -1091,31 +1089,6 @@ namespace Tango.BL.Entities } } - protected SynchronizedObservableCollection _jobruns; - - /// - /// Gets or sets the jobbase job runs. - /// - - public virtual SynchronizedObservableCollection JobRuns - { - get - { - return _jobruns; - } - - set - { - if (_jobruns != value) - { - _jobruns = value; - - OnJobRunsChanged(value); - - } - } - } - protected Machine _machine; /// @@ -1553,15 +1526,6 @@ namespace Tango.BL.Entities RaisePropertyChanged(nameof(Customer)); } - /// - /// Called when the JobRuns has changed. - /// - protected virtual void OnJobRunsChanged(SynchronizedObservableCollection jobruns) - { - JobRunsChanged?.Invoke(this, jobruns); - RaisePropertyChanged(nameof(JobRuns)); - } - /// /// Called when the Machine has changed. /// @@ -1622,8 +1586,6 @@ namespace Tango.BL.Entities public JobBase() : base() { - JobRuns = new SynchronizedObservableCollection(); - Segments = new SynchronizedObservableCollection(); } diff --git a/Software/Visual_Studio/Tango.BL/Entities/JobRunBase.cs b/Software/Visual_Studio/Tango.BL/Entities/JobRunBase.cs index 4d53a6d66..16351179f 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/JobRunBase.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/JobRunBase.cs @@ -41,7 +41,30 @@ namespace Tango.BL.Entities public event EventHandler FailedMessageChanged; - public event EventHandler JobChanged; + protected String _machineguid; + + /// + /// Gets or sets the jobrunbase machine guid. + /// + + [Column("MACHINE_GUID")] + + public String MachineGuid + { + get + { + return _machineguid; + } + + set + { + if (_machineguid != value) + { + _machineguid = value; + + } + } + } protected String _jobguid; @@ -50,7 +73,6 @@ namespace Tango.BL.Entities /// [Column("JOB_GUID")] - [ForeignKey("Job")] public String JobGuid { @@ -206,38 +228,6 @@ namespace Tango.BL.Entities } } - protected Job _job; - - /// - /// Gets or sets the jobrunbase job. - /// - - [XmlIgnore] - [JsonIgnore] - public virtual Job Job - { - get - { - return _job; - } - - set - { - if (_job != value) - { - _job = value; - - if (Job != null) - { - JobGuid = Job.Guid; - } - - OnJobChanged(value); - - } - } - } - /// /// Called when the StartDate has changed. /// @@ -283,15 +273,6 @@ namespace Tango.BL.Entities RaisePropertyChanged(nameof(FailedMessage)); } - /// - /// Called when the Job has changed. - /// - protected virtual void OnJobChanged(Job job) - { - JobChanged?.Invoke(this, job); - RaisePropertyChanged(nameof(Job)); - } - /// /// Initializes a new instance of the class. /// diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs index fe2c7ff9a..e8ef9addd 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs @@ -12,6 +12,34 @@ using Tango.Serialization; namespace Tango.Core.ExtensionMethods { + public enum MappingFlags + { + /// + /// All properties will be mapped. + /// + All = 1, + + /// + /// Do not map string properties. + /// + NoStrings = 2, + + /// + /// Do not map string properties with value of null. + /// + NoNullStrings = 4, + + /// + /// Do not map reference types. + /// + NoReferenceTypes = 8, + + /// + /// Map only primitive values. + /// + PrimitivesOnly, + } + /// /// Contains extension methods. /// @@ -58,85 +86,62 @@ namespace Tango.Core.ExtensionMethods } /// - /// Maps the object properties values to the destination object. + /// Maps the object primitive properties values to the destination object. /// - /// The source. - /// The destination. - public static void MapPrimitivesTo(this object source, object destination) + /// The source object. + /// The destination object. + /// The mapping flags. + /// Optional condition. + public static void MapPropertiesTo(this object source, object destination, MappingFlags flags = MappingFlags.NoReferenceTypes, Func condition = null) { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive)) + foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); + var propType = prop.PropertyType; + var value = prop.GetValue(source); - if (desProp != null && desProp.PropertyType.IsPrimitive && desProp.SetMethod != null) + if (condition != null) { - desProp.SetValue(destination, prop.GetValue(source)); + if (!condition(prop)) continue; } - } - } - /// - /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. - /// - /// The source. - /// The destination. - public static void MapPrimitivesWithStringsNoNullsTo(this object source, object destination) - { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) - { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); + if (!propType.IsPrimitive && flags.HasFlag(MappingFlags.PrimitivesOnly)) + { + continue; + } - if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) + if (propType == typeof(String) && flags.HasFlag(MappingFlags.NoStrings)) { - var value = prop.GetValue(source); + continue; + } - if (desProp.PropertyType != typeof(String) || !String.IsNullOrEmpty(value as String)) - { - desProp.SetValue(destination, value); - } + if (propType.IsClass && propType != typeof(String) && flags.HasFlag(MappingFlags.NoReferenceTypes)) + { + continue; + } + + if (flags.HasFlag(MappingFlags.NoNullStrings) && propType == typeof(String) && String.IsNullOrEmpty(value as String)) + { + continue; } - } - } - /// - /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. - /// - /// The source. - /// The destination. - public static void MapPrimitivesWithStrings(this object source, object destination) - { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) - { var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) + if (desProp != null && desProp.PropertyType == prop.PropertyType && desProp.SetMethod != null) { - var value = prop.GetValue(source); - desProp.SetValue(destination, value); } } } + /// - /// Maps the object properties values to the destination object. + /// Maps the object primitive properties values to the destination object. /// /// The source. /// The destination. - public static void MapPrimitivesTo(this object source, object destination, Func condition) + public static void MapPrimitivesTo(this object source, object destination) { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive)) - { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - - if (desProp != null && desProp.PropertyType.IsPrimitive && desProp.SetMethod != null) - { - if (condition(prop)) - { - desProp.SetValue(destination, prop.GetValue(source)); - } - } - } + source.MapPropertiesTo(destination, MappingFlags.PrimitivesOnly); } /// diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB.cs index eb8c0a998..17ec544c0 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB.cs @@ -17,7 +17,6 @@ namespace Tango.DAL.Remote.DB [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public JOB() { - this.JOB_RUNS = new HashSet(); this.SEGMENTS = new HashSet(); } @@ -61,8 +60,6 @@ namespace Tango.DAL.Remote.DB public virtual COLOR_CATALOGS COLOR_CATALOGS { get; set; } public virtual COLOR_SPACES COLOR_SPACES { get; set; } public virtual CUSTOMER CUSTOMER { get; set; } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public virtual ICollection JOB_RUNS { get; set; } public virtual MACHINE MACHINE { get; set; } public virtual RML RML { get; set; } public virtual SPOOL_TYPES SPOOL_TYPES { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs index fb591afa0..24f61f03c 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs @@ -17,13 +17,12 @@ namespace Tango.DAL.Remote.DB public int ID { get; set; } public string GUID { get; set; } public System.DateTime LAST_UPDATED { get; set; } + public string MACHINE_GUID { get; set; } public string JOB_GUID { get; set; } public System.DateTime START_DATE { get; set; } public System.DateTime END_DATE { get; set; } public int STATUS { get; set; } public double END_POSITION { get; set; } public string FAILED_MESSAGE { get; set; } - - public virtual JOB JOB { get; set; } } } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs index 17bc2683d..d26e67908 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs @@ -1,4 +1,4 @@ -// T4 code generation is enabled for model 'D:\Development\Tango\Software\Visual_Studio\Tango.DAL.Remote\DB\RemoteADO.edmx'. +// T4 code generation is enabled for model 'C:\DATA\Development\Tango\Software\Visual_Studio\Tango.DAL.Remote\DB\RemoteADO.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index 8607b9f07..8c8b66a5c 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -586,7 +586,8 @@ - + + @@ -1614,20 +1615,6 @@ - - - - - - - - - - - - - - @@ -1679,7 +1666,9 @@ - + + + @@ -2077,7 +2066,9 @@ - + + + @@ -2402,10 +2393,6 @@ - - - - @@ -2863,10 +2850,6 @@ - - - - @@ -3658,13 +3641,13 @@ - + + - @@ -3709,7 +3692,6 @@ - @@ -4925,20 +4907,6 @@ - - - - - - - - - - - - - - @@ -4954,7 +4922,9 @@ - + + + @@ -5286,7 +5256,9 @@ - + + + @@ -5958,6 +5930,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 c0574cb9e..2feb68642 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,80 +5,80 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -130,7 +130,6 @@ - diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs index bacae9324..9eb010ec2 100644 --- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs @@ -117,6 +117,7 @@ namespace Tango.Integration.JobRuns StartDate = _start_date, EndDate = DateTime.UtcNow, JobGuid = _job.Guid, + MachineGuid = _job.MachineGuid, JobRunStatus = JobRunStatus.Failed, EndPosition = e.JobHandler.Status.Progress, FailedMessage = e.Exception.Message, @@ -161,6 +162,7 @@ namespace Tango.Integration.JobRuns StartDate = _start_date, EndDate = DateTime.UtcNow, JobGuid = _job.Guid, + MachineGuid = _job.MachineGuid, EndPosition = e.JobHandler.Status.Progress, JobRunStatus = JobRunStatus.Aborted, }); @@ -204,6 +206,7 @@ namespace Tango.Integration.JobRuns StartDate = _start_date, EndDate = DateTime.UtcNow, JobGuid = _job.Guid, + MachineGuid = _job.MachineGuid, EndPosition = e.JobHandler.Status.Progress, JobRunStatus = JobRunStatus.Completed, }); diff --git a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs index aaf4706a3..7022d1ae3 100644 --- a/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs +++ b/Software/Visual_Studio/Tango.Synchronization/Remote/RemoteDBComparer.cs @@ -143,7 +143,7 @@ namespace Tango.Synchronization.Remote var remote_jobs = remote_machines.SelectMany(x => x.JOBS).ToList(); OnProgress(LogManager.Log("Querying all remote job runs...")); - var remote_jobs_runs = remote_jobs.SelectMany(x => x.JOB_RUNS).ToList(); + //var remote_jobs_runs = remote_jobs.SelectMany(x => x.JOB_RUNS).ToList(); OnProgress(LogManager.Log("Querying all remote segments...")); var remote_segments = remote_jobs.SelectMany(x => x.SEGMENTS).ToList(); @@ -196,7 +196,7 @@ namespace Tango.Synchronization.Remote CompareCollections(remote_jobs, local_jobs, _remoteDB.JOBS, _localDB.JOBS); OnProgress(LogManager.Log("Comparing job runs")); - CompareCollections(remote_jobs_runs, local_job_runs, _remoteDB.JOB_RUNS, _localDB.JOB_RUNS); + //CompareCollections(remote_jobs_runs, local_job_runs, _remoteDB.JOB_RUNS, _localDB.JOB_RUNS); OnProgress(LogManager.Log("Comparing segments")); CompareCollections(remote_segments, local_segments, _remoteDB.SEGMENTS, _localDB.SEGMENTS); diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 5d601ae52..8dc160543 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -3841,6 +3841,7 @@ Global {4EDCF067-E377-42CB-A18C-8368CF484577}.AppVeyor|x86.ActiveCfg = Release|Any CPU {4EDCF067-E377-42CB-A18C-8368CF484577}.AppVeyor|x86.Build.0 = Release|Any CPU {4EDCF067-E377-42CB-A18C-8368CF484577}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4EDCF067-E377-42CB-A18C-8368CF484577}.Debug|Any CPU.Build.0 = Debug|Any CPU {4EDCF067-E377-42CB-A18C-8368CF484577}.Debug|ARM.ActiveCfg = Debug|Any CPU {4EDCF067-E377-42CB-A18C-8368CF484577}.Debug|ARM.Build.0 = Debug|Any CPU {4EDCF067-E377-42CB-A18C-8368CF484577}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -5885,12 +5886,12 @@ Global {DA391B02-AE28-4EA1-A80F-D0F4C8029FFA} = {E728CBD9-1AF4-4814-A218-E4BD26E7EDEA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_UpdateFileVersion = False - BuildVersion_StartDate = 2000/1/1 - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs BuildVersion_UseGlobalSettings = False + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_StartDate = 2000/1/1 + BuildVersion_UpdateFileVersion = False + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs index 6c3c62606..61e74957c 100644 --- a/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.JobRunsGenerator/Program.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Tango.BL; using Tango.BL.Builders; using Tango.BL.Entities; +using Tango.Core; namespace Tango.JobRunsGenerator { @@ -13,75 +14,27 @@ namespace Tango.JobRunsGenerator { static void Main(string[] args) { - Console.WriteLine("Job Runs Generator Started..."); - - DateTime now = DateTime.UtcNow; - DateTime yearago = DateTime.UtcNow.AddYears(-1); - Random rnd = new Random(); - List messages = new List() - { - "Timeout failure", - "Thread Break", - "Application Exception", - "Over Temperature", - "Communication Error" - }; - - int count = 0; - - using (ObservablesContext db = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS")) + DataSource dataSource = new DataSource(); + dataSource.Catalog = "Tango_DEV"; + dataSource.Address = "twine.database.windows.net"; + dataSource.IntegratedSecurity = false; + dataSource.UserName = "Roy"; + dataSource.Password = "Aa123456"; + + using (ObservablesContext db = ObservablesContext.CreateDefault(dataSource)) { - var machines = db.Machines.ToList(); - - foreach (var machine in machines) + foreach (var run in db.JobRuns.OrderBy(x => x.JobGuid)) { - new MachineBuilder(db).Set(machine).WithJobs().Build(); - - foreach (var job in machine.Jobs) - { - using (ObservablesContext db2 = ObservablesContext.CreateDefault("localhost\\SQLEXPRESS")) - { - for (DateTime date = yearago; date < now; date = date.AddDays(1)) - { - Console.WriteLine($"Adding job runs for machine '{machine.SerialNumber}' job '{job.Name}' date {date.ToShortDateString()}..."); - - for (int i = 0; i < rnd.Next(0, 9); i++) - { - int status = rnd.Next(0, 3); - String message = messages[rnd.Next(0, messages.Count)]; - - db2.JobRuns.Add(new JobRun() - { - StartDate = date, - EndDate = date.AddMinutes(rnd.Next(10, 61)), - JobGuid = job.Guid, - EndPosition = job.Length / rnd.Next(1, 11), - Status = status, - FailedMessage = status == 2 ? message : null, - }); - - count++; - } - } - - db2.SaveChanges(); - } - } + var job = db.Jobs.SingleOrDefault(x => x.Guid == run.JobGuid); + Console.WriteLine($"Fixing job {job.Name}..."); + run.MachineGuid = job.MachineGuid; } - Console.WriteLine($"The generator is about to insert {count} job runs to the database are you sure? [Y/N]:"); - var key = Console.ReadKey().Key; + Console.WriteLine("Saving changed..."); + db.SaveChanges(); - if (key == ConsoleKey.Y) - { - Console.WriteLine("Saving changes to database..."); - Console.WriteLine("Done!"); - Console.ReadLine(); - } - else - { - return; - } + Console.WriteLine("Done!"); + Console.ReadLine(); } } } -- cgit v1.3.1