aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs
blob: 93cea9485109161950563f8e6194bf5e28c6e156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Jobs.Messages;
using Tango.PPC.Jobs.Views;

namespace Tango.PPC.Jobs.ViewModels
{
    public class JobSummeryViewVM : PPCViewModel
    {
        private Job _job;
        /// <summary>
        /// Gets or sets the job.
        /// </summary>
        public Job Job
        {
            get { return _job; }
            set { _job = value; RaisePropertyChangedAuto(); }
        }

        public RelayCommand DyeCommand { get; set; }

        public RelayCommand EditCommand { get; set; }

        public JobSummeryViewVM()
        {
            RegisterForMessage<JobSelectedMessage>(HandleJobSelectedMessage);

            DyeCommand = new RelayCommand(StartJob);
            EditCommand = new RelayCommand(EditJob);
        }

        private void HandleJobSelectedMessage(JobSelectedMessage message)
        {
            Job = message.Job;
        }

        private void EditJob()
        {
            NavigationManager.NavigateTo<JobsModule>(false, nameof(JobView));
        }

        private void StartJob()
        {
            MachineProvider.MachineOperator.Print(Job);
            NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
        }

        public override void OnApplicationStarted()
        {

        }
    }
}
/span> private bool _startingJob; private bool _isPreparingJob; /// <summary> /// Gets or sets a value indicating whether the job is currently preparing. /// </summary> public bool IsPreparingJob { get { return _isPreparingJob; } set { _isPreparingJob = value; RaisePropertyChangedAuto(); } } private Job _job; /// <summary> /// Gets or sets the job. /// </summary> public Job Job { get { return _job; } set { _job = value; RaisePropertyChangedAuto(); } } private TimeSpan _estimatedDuration; /// <summary> /// Gets or sets the duration of the estimated. /// </summary> public TimeSpan EstimatedDuration { get { return _estimatedDuration; } set { _estimatedDuration = value; RaisePropertyChangedAuto(); } } private int _btsrSpoolTension; public int BtsrSpoolTension { get { return _btsrSpoolTension; } set { _btsrSpoolTension = value; RaisePropertyChangedAuto(); } } /// <summary> /// Gets or sets the dye command. /// </summary> public RelayCommand DyeCommand { get; set; } /// <summary> /// Gets or sets the edit command. /// </summary> public RelayCommand EditCommand { get; set; } /// <summary> /// Initializes a new instance of the <see cref="JobSummeryViewVM"/> class. /// </summary> public JobSummeryViewVM() { DyeCommand = new RelayCommand(StartJob, () => { return _canStartJob; }); EditCommand = new RelayCommand(EditJob); } /// <summary> /// Edits the job. /// </summary> private void EditJob() { LogManager.Log("Edit command pressed."); NavigationManager.NavigateTo<JobsV2Module>(false, nameof(JobView)); } /// <summary> /// Starts the job. /// </summary> private async void StartJob() { if (_startingJob) return; _startingJob = true; _canStartJob = false; InvalidateRelayCommands(); NavigationManager.IsBackEnabled = false; try { LogManager.Log("Start job command pressed. Starting job and navigating to job progress view..."); await PrintingManager.Print(Job, _context); await NavigationManager.NavigateTo<JobsV2Module>(false, nameof(JobProgressView)); _startingJob = false; } catch (InsufficientLiquidQuantityException) { //Ignore.. } catch (OperationCanceledException) { //Ignore.. } catch (Exception ex) { LogManager.Log(ex, "Could not start the current job."); await NotificationProvider.ShowError($"{ex.Message}"); } finally { _startingJob = false; _canStartJob = true; NavigationManager.IsBackEnabled = true; InvalidateRelayCommands(); } } /// <summary> /// Called when the application has been started. /// </summary> public override void OnApplicationStarted() { } public async void OnNavigatedToWithObject(JobSummeryNavigationObject obj) { _canStartJob = false; InvalidateRelayCommands(); _context = obj.Context; Job = obj.Job; IsPreparingJob = true; Job = await new JobBuilder(_context).Set(Job.Guid) .WithConfiguration() .WithRML() .WithUser() .WithSegments() .WithBrushStops() .WithSegmentsGroups() .BuildAsync(); if (Job.Rml != null && _context != null) { BtsrSpoolTension = await Job.Rml.GetRequiredBtsrSpoolTension(_context, Job.SpoolType); } await Task.Factory.StartNew(() => { try { var stops = Job.OrderedSegmentsWithGroups.SelectMany(x => x.BrushStops).ToList(); if(stops.Count > 0) { IColorConverter _converter = new DefaultColorConverter(); EstimatedDuration = Job.GetEstimatedDuration(_converter.GetRecommendedProcessParameters(Job, true)); } } catch (Exception ex) { LogManager.Log(ex, "Error calculating recommended process parameters."); } }); IsPreparingJob = false; if(Job.Segments.Where( x=>x.BrushStops.Count == 0).ToList().Count == 0) { _canStartJob = true; } InvalidateRelayCommands(); } } }