From 9259bc36791a7084ae33bcf0a698101ddb24d28f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 5 Dec 2019 18:06:21 +0200 Subject: Integrated CDN downloads to PPC and MS. --- .../MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 2ee8574b1..160041b5f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -179,6 +179,7 @@ namespace Tango.MachineStudio.UI.ViewModels _updateInfo = new CheckForUpdatesResponse(); _updateInfo.BlobAddress = response.BlobAddress; _updateInfo.Version = response.Version; + _updateInfo.CdnAddress = response.CdnAddress; LatestVersion = _updateInfo.Version; StartUpdate(); @@ -270,7 +271,7 @@ namespace Tango.MachineStudio.UI.ViewModels { logManager.Log("Creating temporary file " + tempFile); - using (StorageBlobDownloader downloader = new StorageBlobDownloader(_updateInfo.BlobAddress, tempFile.Path)) + using (AutoFileDownloader downloader = new AutoFileDownloader(_updateInfo.BlobAddress, _updateInfo.CdnAddress, tempFile.Path)) { downloader.Progress += (x, e) => { -- 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/Tango.MachineStudio.UI/ViewModels') 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 From f1ef8138154ade048b7e2ff0aac31db5594d26b9 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 13 Dec 2019 13:02:08 +0200 Subject: Modified DIalogVieVM to allow OK with CanClose = false. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../ViewModels/FirmwareUpgradeViewVM.cs | 5 +++++ .../PPC/Tango.PPC.UI/Dialogs/PowerUpViewVM.cs | 1 + .../Visual_Studio/Tango.SharedUI/DialogViewVM.cs | 2 +- 5 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index a24738a12..35dde42f3 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 d548ec168..60f6da390 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/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs index e45c29f73..365c1db49 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -207,6 +207,11 @@ namespace Tango.MachineStudio.UI.ViewModels } } + protected override bool CanOK() + { + return base.CanOK() && CanClose; + } + private async void AbortUpgrade() { CanClose = true; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpViewVM.cs index c0ef85bcc..22e489ffa 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpViewVM.cs @@ -84,6 +84,7 @@ namespace Tango.PPC.UI.Dialogs public PowerUpViewVM() { RemainingSeconds = 20; + CanClose = false; IsMinimalTemperature = true; IsTimeoutEnabled = true; _timer = new Timer(); diff --git a/Software/Visual_Studio/Tango.SharedUI/DialogViewVM.cs b/Software/Visual_Studio/Tango.SharedUI/DialogViewVM.cs index f740eab84..bf75fd6ef 100644 --- a/Software/Visual_Studio/Tango.SharedUI/DialogViewVM.cs +++ b/Software/Visual_Studio/Tango.SharedUI/DialogViewVM.cs @@ -24,7 +24,7 @@ namespace Tango.SharedUI { CanClose = true; CloseCommand = new RelayCommand(Cancel, (x) => CanClose); - OKCommand = new RelayCommand(Accept, (x) => CanClose && CanOK()); + OKCommand = new RelayCommand(Accept, (x) => CanOK()); } private bool _canClose; -- cgit v1.3.1