diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-02-15 04:26:39 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-02-15 04:26:39 +0200 |
| commit | 29ffa937475d82d2c32cbccfb97c2f5f7c8f24cd (patch) | |
| tree | 2c19e49dc72270036e27cdc23b0ee0d8a3429664 /Software/Visual_Studio | |
| parent | f1af9d5e2c3c7b3fa48a113f41b03aea9deab188 (diff) | |
| download | Tango-29ffa937475d82d2c32cbccfb97c2f5f7c8f24cd.tar.gz Tango-29ffa937475d82d2c32cbccfb97c2f5f7c8f24cd.zip | |
Implemented MS machine prototypes.
Diffstat (limited to 'Software/Visual_Studio')
5 files changed, 132 insertions, 250 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs index 4584d3508..340f92edd 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineCreationDialogVM.cs @@ -10,9 +10,9 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { public class MachineCreationDialogVM : DialogViewVM { - public List<MachineVersion> MachineVersions { get; set; } + public List<MachinePrototype> Prototypes { get; set; } - public MachineVersion SelectedMachineVersion { get; set; } + public MachinePrototype SelectedPrototype { get; set; } private bool _isNewMachine; public bool IsNewMachine @@ -35,25 +35,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _name = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } - private bool _generateDispensers; - public bool GenerateDispensers - { - get { return _generateDispensers; } - set { _generateDispensers = value; RaisePropertyChangedAuto(); } - } - - private double _dispenserFactor; - public double DispenserFactor - { - get { return _dispenserFactor; } - set { _dispenserFactor = value; RaisePropertyChangedAuto(); } - } - - public MachineCreationDialogVM() : base() - { - DispenserFactor = 2.34; - } - protected override bool CanOK() { return base.CanOK() && !String.IsNullOrWhiteSpace(SerialNumber) && !String.IsNullOrWhiteSpace(Name); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index dc29515c8..6ddf86ddb 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -287,7 +287,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public override async void OnApplicationReady() { MachinesAdapter.MachineVersions = (await MachinesAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection(); - + MachinesAdapter.MachinePrototypes = (await MachinesAdapter.Context.MachinePrototypes.ToListAsync()).ToObservableCollection(); } #endregion @@ -513,7 +513,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { IsNewMachine = true; - if (machineCreationDialogVM.SelectedMachineVersion == null) + if (machineCreationDialogVM.SelectedPrototype == null) { ActiveMachine = new Machine(); ActiveMachine.Configuration = new Configuration(); @@ -526,9 +526,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels try { initHwConfig = false; - ActiveMachine = await machineCreationDialogVM.SelectedMachineVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context); - ActiveMachine.SerialNumber = machineCreationDialogVM.SerialNumber; - ActiveMachine.Name = machineCreationDialogVM.Name; + ActiveMachine = machineCreationDialogVM.SelectedPrototype.CreateMachine(machineCreationDialogVM.SerialNumber, machineCreationDialogVM.Name); + ActiveMachine.MachineVersion = ActiveMachineAdapter.MachineVersions.FirstOrDefault(x => x.Guid == ActiveMachine.MachineVersionGuid); ActiveMachineAdapter.Context.Machines.Add(ActiveMachine); HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification); @@ -537,105 +536,13 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } catch (Exception ex) { - _notification.ShowError($"Invalid machine version prototype.\n{ex.FlattenMessage()}"); + _notification.ShowError($"Invalid machine prototype.\n{ex.FlattenMessage()}"); View.NavigateTo(MachineDesignerNavigationView.MachinesView); return; } } } - if ((newMachine || clone) && machineCreationDialogVM.GenerateDispensers) - { - for (int i = 0; i < 10; i++) - { - var serial = machineCreationDialogVM.SerialNumber + "-" + (i + 1); - - var existingDispenser = await ActiveMachineAdapter.Context.Dispensers.Include(x => x.IdsPacks).SingleOrDefaultAsync(x => x.SerialNumber == serial); - - if (existingDispenser != null) - { - if (existingDispenser.IsInstalled) - { - _notification.ShowError($"Dispenser '{serial}' already exists. Cannot create machine."); - return; - } - else - { - if (!_notification.ShowErrorQuestion($"Dispenser '{serial}' already exists and is not installed. Do you wish to assign the existing dispenser to this machine?")) - { - return; - } - } - } - - Dispenser dispenser = new Dispenser(); - - if (existingDispenser == null) - { - dispenser.SerialNumber = serial; - - if (newMachine) - { - dispenser.NlPerPulse = machineCreationDialogVM.DispenserFactor; - - if (i == 8) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.LubricantDispenser.ToInt32()).Guid; - } - else if (i == 9) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.CleanerDispenser.ToInt32()).Guid; - } - else - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.StandardDispenser.ToInt32()).Guid; - } - } - else - { - var packBefore = machineConfigBeforeClone.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i); - - if (packBefore != null) - { - dispenser.NlPerPulse = packBefore.Dispenser.NlPerPulse; - - if (i == 8) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.LubricantDispenser.ToInt32()).Guid; - } - else if (i == 9) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.CleanerDispenser.ToInt32()).Guid; - } - else - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.StandardDispenser.ToInt32()).Guid; - } - } - else - { - continue; - } - } - - dispenser.ProductionDate = DateTime.UtcNow; - - ActiveMachineAdapter.Context.Dispensers.Add(dispenser); - } - else - { - dispenser = existingDispenser; - } - - var idsPack = ActiveMachine.Configuration.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i); - - if (idsPack != null) - { - idsPack.Dispenser = dispenser; - idsPack.DispenserGuid = dispenser.Guid; - } - } - } ActiveMachine.OrganizationChanged -= ActiveMachine_OrganizationChanged; ActiveMachine.OrganizationChanged += ActiveMachine_OrganizationChanged; @@ -888,7 +795,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { MachineCreationDialogVM vm = new MachineCreationDialogVM(); vm.IsNewMachine = true; - vm.MachineVersions = MachinesAdapter.MachineVersions.ToList(); + vm.Prototypes = MachinesAdapter.MachinePrototypes.ToList(); _notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) => { if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower())) @@ -897,12 +804,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels return; } - if (vm.SelectedMachineVersion != null && String.IsNullOrWhiteSpace(vm.SelectedMachineVersion.PrototypeMachineData)) - { - _notification.ShowError("The selected version does not contain any prototype machine data."); - return; - } - LoadSelectedMachine(true, false, vm); }, () => { }); } @@ -946,36 +847,32 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels private async void MakePrototype() { - if (ActiveMachine.MachineVersion == null) - { - _notification.ShowError("Machine version must be selected in order to make a prototype."); - return; - } + String protoName = _notification.ShowTextInput("Enter prototype name", "name"); + + if (!protoName.IsNotNullOrWhiteSpace()) return; - if (_notification.ShowQuestion($"Are you sure you wish to make this machine configuration as a prototype for version '{ActiveMachine.MachineVersion.Name}' ?")) + using (_notification.PushTaskItem($"Saving machine prototype '{protoName}'...")) { - using (_notification.PushTaskItem($"Making prototype machine for '{ActiveMachine.MachineVersion.Name}'...")) + try { - try - { - IsFree = false; + IsFree = false; - using (var db = ObservablesContext.CreateDefault()) - { - var machineVersion = await db.MachineVersions.SingleOrDefaultAsync(x => x.Guid == ActiveMachine.MachineVersionGuid); - await machineVersion.ApplyPrototypeMachine(ActiveMachine, db); - await db.SaveChangesAsync(); - } - } - catch (Exception ex) + using (var db = ObservablesContext.CreateDefault()) { - _notification.ShowError($"Error making machine version prototype\n{ex.FlattenMessage()}"); - } - finally - { - IsFree = true; + MachinePrototype prototype = MachinePrototype.CreateNew(ActiveMachine, protoName, protoName); + db.MachinePrototypes.Add(prototype); + await db.SaveChangesAsync(); + MachinesAdapter.MachinePrototypes = (await MachinesAdapter.Context.MachinePrototypes.ToListAsync()).ToObservableCollection(); } } + catch (Exception ex) + { + _notification.ShowError($"Error creating machine prototype\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } } } @@ -985,7 +882,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { MachineCreationDialogVM vm = new MachineCreationDialogVM(); vm.IsNewMachine = false; - vm.MachineVersions = MachinesAdapter.MachineVersions.ToList(); + vm.Prototypes = MachinesAdapter.MachinePrototypes.ToList(); _notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) => { if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower())) diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml index 41e0fa685..f69606e29 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineCreationDialog.xaml @@ -52,28 +52,16 @@ <Grid> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20 20 0 0" Width="400"> <TextBlock TextWrapping="Wrap" Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}"> - <Run>Please specify the machine version in order to prototype the new machine with default machine settings and configuration.</Run> + <Run>Specify a machine prototype to create the new machine with default settings and configuration.</Run> </TextBlock> - <ComboBox Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}" ItemsSource="{Binding MachineVersions}" SelectedItem="{Binding SelectedMachineVersion}" DisplayMemberPath="Name" Margin="0 10 0 0" FontSize="16" materialDesign:HintAssist.Hint="NONE"></ComboBox> + <ComboBox Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}" ItemsSource="{Binding Prototypes}" SelectedItem="{Binding SelectedPrototype}" DisplayMemberPath="Name" Margin="0 10 0 0" FontSize="16" materialDesign:HintAssist.Hint="NONE"></ComboBox> <TextBlock Margin="0 20 0 0" FontSize="10">Serial Number</TextBlock> <TextBox Margin="0 2 0 0" Text="{Binding SerialNumber,UpdateSourceTrigger=PropertyChanged}"></TextBox> <TextBlock Margin="0 20 0 0" FontSize="10">Name</TextBlock> <TextBox Margin="0 2 0 0" Text="{Binding Name,UpdateSourceTrigger=PropertyChanged}"></TextBox> - - <CheckBox Margin="0 30 -200 0" IsChecked="{Binding GenerateDispensers}"> - <TextBlock> - <Run>Automatically generate 10 dispensers for this machine</Run> - <Run>(</Run><Run Foreground="{StaticResource GrayBrush}" FontSize="10" Text="{Binding SerialNumber}"></Run><Run Foreground="{StaticResource GrayBrush}" FontSize="10">-1-10</Run><Run>)</Run> - </TextBlock> - </CheckBox> - - <StackPanel Margin="20 10 0 0" Visibility="{Binding IsNewMachine,Converter={StaticResource BooleanToVisibilityConverter}}"> - <TextBlock FontSize="10">Dispenser max nl/cm</TextBlock> - <mahapps:NumericUpDown Minimum="0" StringFormat="0.00" Maximum="10" InterceptMouseWheel="True" Value="{Binding DispenserFactor,Mode=TwoWay}" HorizontalContentAlignment="Left" Width="95" HorizontalAlignment="Left" BorderThickness="0 0 0 1" Margin="0 2 0 0" HideUpDownButtons="True" HasDecimals="True" Background="Transparent"></mahapps:NumericUpDown> - </StackPanel> </StackPanel> </Grid> </DockPanel> diff --git a/Software/Visual_Studio/Tango.BL/Entities/MachinePrototype.cs b/Software/Visual_Studio/Tango.BL/Entities/MachinePrototype.cs index 58e3c861f..d83572ab6 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/MachinePrototype.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/MachinePrototype.cs @@ -20,11 +20,112 @@ using Tango.DAL.Remote.DB; using Tango.Core; using System.ComponentModel; using Tango.Core.CustomAttributes; +using System.Threading.Tasks; +using Tango.BL.Builders; +using Tango.BL.Serialization; +using System.Data.Entity; namespace Tango.BL.Entities { - public abstract class MachinePrototype : MachinePrototypeBase + public class MachinePrototype : MachinePrototypeBase { + public void SetPrototypeMachine(Machine machine) + { + PrototypeJson = machine.ToJson(new EntitySerializationStrategy() + .Include(() => machine.Configuration) + .Include(() => new IdsPack().Dispenser) + .Ignore(() => new IdsPack().Dispenser.IdsPacks) + .Ignore(() => machine.Name) + .Ignore(() => machine.MachinesEvents) + .Ignore(() => machine.Configuration.Machines) + .Ignore(() => machine.Jobs) + .Ignore(() => machine.SerialNumber) + .Ignore(() => machine.DefaultRmlGuid) + .Ignore(() => machine.DefaultColorSpaceGuid) + .Ignore(() => machine.DefaultSpoolTypeGuid) + .Ignore(() => machine.LoadedRmlGuid) + .Ignore(() => machine.DeviceId) + .Ignore(() => machine.DeviceName) + .Ignore(() => machine.IsDeviceRegistered) + .Ignore(() => machine.SiteGuid) + .Ignore(() => machine.ActivationKey), + EntitySerializationFlags.IgnoreGuids | EntitySerializationFlags.IgnoreReferenceTypes); + } + + public Machine CreateMachine(String serialNumber, String name) + { + Machine m = new Machine(); + + Machine machine = Machine.FromJson(PrototypeJson, new EntitySerializationStrategy() + .Include(() => m.Configuration) + .Include(() => new IdsPack().Dispenser) + .Ignore(() => m.Name) + .Ignore(() => m.MachinesEvents) + .Ignore(() => m.Configuration.Machines) + .Ignore(() => m.Jobs) + .Ignore(() => m.SerialNumber) + .Ignore(() => m.DefaultRmlGuid) + .Ignore(() => m.DefaultColorSpaceGuid) + .Ignore(() => m.DefaultSpoolTypeGuid) + .Ignore(() => m.LoadedRmlGuid) + .Ignore(() => m.DeviceId) + .Ignore(() => m.DeviceName) + .Ignore(() => m.IsDeviceRegistered) + .Ignore(() => m.SiteGuid) + .Ignore(() => m.ActivationKey), + + EntitySerializationFlags.IgnoreGuids | EntitySerializationFlags.IgnoreReferenceTypes); + + + machine.OrganizationGuid = null; + machine.ConfigurationGuid = null; + machine.ConfigurationGuid = machine.Configuration.Guid; + + + foreach (var cat in machine.Cats) + { + cat.MachineGuid = machine.Guid; + } + + machine.SerialNumber = serialNumber; + machine.Name = name; + machine.ProductionDate = DateTime.UtcNow; + + foreach (var idsPack in machine.Configuration.IdsPacks.OrderBy(x => x.PackIndex)) + { + if (idsPack.Dispenser != null) + { + idsPack.Dispenser.ID = 0; + idsPack.Dispenser.LastUpdated = DateTime.UtcNow; + idsPack.Dispenser.SerialNumber = $"{serialNumber}-{idsPack.PackIndex + 1}"; + idsPack.DispenserGuid = idsPack.Dispenser.Guid; + } + + idsPack.ConfigurationGuid = machine.ConfigurationGuid; + } + + foreach (var spool in machine.Spools) + { + spool.MachineGuid = machine.Guid; + } + + machine.DefaultColorSpaceGuid = null; + machine.DefaultRmlGuid = null; + machine.DefaultSpoolTypeGuid = null; + + return machine; + } + + public static MachinePrototype CreateNew(Machine machine, String name, String description) + { + MachinePrototype prototype = new MachinePrototype(); + prototype.Name = name; + prototype.Description = description; + prototype.LastUpdated = DateTime.UtcNow; + prototype.SetPrototypeMachine(machine); + return prototype; + + } } } diff --git a/Software/Visual_Studio/Tango.BL/Entities/MachineVersion.cs b/Software/Visual_Studio/Tango.BL/Entities/MachineVersion.cs index 7b90623d8..5832e8a74 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/MachineVersion.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/MachineVersion.cs @@ -11,91 +11,6 @@ namespace Tango.BL.Entities { public partial class MachineVersion : MachineVersionBase { - public async Task ApplyPrototypeMachine(Machine machine, ObservablesContext context) - { - machine = await new MachineBuilder(context) - .Set(machine) - .WithOrganization() - .WithConfiguration() - .WithSpools() - .WithCats() - .BuildAsync(); - - PrototypeMachineData = machine.ToJson(new EntitySerializationStrategy() - .Include(() => machine.Configuration) - .Ignore(() => machine.Name) - .Ignore(() => machine.MachinesEvents) - .Ignore(() => machine.Configuration.Machines) - .Ignore(() => machine.Jobs) - .Ignore(() => machine.SerialNumber) - .Ignore(() => machine.DefaultRmlGuid) - .Ignore(() => machine.DefaultColorSpaceGuid) - .Ignore(() => machine.DefaultSpoolTypeGuid) - .Ignore(() => machine.LoadedRmlGuid) - .Ignore(() => machine.DeviceId) - .Ignore(() => machine.DeviceName) - .Ignore(() => machine.IsDeviceRegistered) - .Ignore(() => machine.SiteGuid), - - EntitySerializationFlags.IgnoreGuids | EntitySerializationFlags.IgnoreReferenceTypes); - } - - public async Task<Machine> CreatePrototypeMachine(ObservablesContext context) - { - Machine m = new Machine(); - - String protoTypeData = (await context.MachineVersions.SingleOrDefaultAsync(x => x.Guid == Guid)).PrototypeMachineData; - - Machine machine = Machine.FromJson(protoTypeData, new EntitySerializationStrategy() - .Include(() => m.Configuration) - .Ignore(() => m.Name) - .Ignore(() => m.MachinesEvents) - .Ignore(() => m.Configuration.Machines) - .Ignore(() => m.Jobs) - .Ignore(() => m.SerialNumber) - .Ignore(() => m.DefaultRmlGuid) - .Ignore(() => m.DefaultColorSpaceGuid) - .Ignore(() => m.DefaultSpoolTypeGuid) - .Ignore(() => m.LoadedRmlGuid) - .Ignore(() => m.DeviceId) - .Ignore(() => m.DeviceName) - .Ignore(() => m.IsDeviceRegistered) - .Ignore(() => m.SiteGuid), - - EntitySerializationFlags.IgnoreGuids | EntitySerializationFlags.IgnoreReferenceTypes); - - - machine.OrganizationGuid = null; - machine.ConfigurationGuid = null; - machine.ConfigurationGuid = machine.Configuration.Guid; - - - foreach (var cat in machine.Cats) - { - cat.MachineGuid = machine.Guid; - } - - machine.MachineVersionGuid = Guid; - machine.ProductionDate = DateTime.UtcNow; - - foreach (var idsPack in machine.Configuration.IdsPacks) - { - idsPack.DispenserGuid = null; - idsPack.ConfigurationGuid = machine.ConfigurationGuid; - } - - foreach (var spool in machine.Spools) - { - spool.MachineGuid = machine.Guid; - } - - machine.DefaultColorSpaceGuid = null; - machine.DefaultRmlGuid = null; - machine.DefaultSpoolTypeGuid = null; - - return machine; - } - /// <summary> /// Initializes a new instance of the <see cref="MachineVersion" /> class. /// </summary> |
