aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/NavigationObjects
ModeNameSize
-rw-r--r--JobNavigationObject.cs799logstatsplain
-rw-r--r--JobSummeryNavigationObject.cs357logstatsplain
-rw-r--r--TwineCatalogNavigationObject.cs360logstatsplain
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.Messages;
using Tango.PPC.Jobs.Messages;
using Tango.PPC.Jobs.Views;

namespace Tango.PPC.Jobs.ViewModels
{
    /// <summary>
    /// Represents the job summary view model.
    /// </summary>
    /// <seealso cref="Tango.PPC.Common.PPCViewModel" />
    public class JobSummeryViewVM : PPCViewModel
    {
        private ObservablesContext _context;

        private Job _job;
        /// <summary>
        /// Gets or sets the job.
        /// </summary>
        public Job Job
        {
            get { return _job; }
            set { _job = 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()
        {
            RegisterForMessage<JobSelectedMessage>(HandleJobSelectedMessage);

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

        /// <summary>
        /// Handles the job selected message.
        /// </summary>
        /// <param name="message">The message.</param>
        private void HandleJobSelectedMessage(JobSelectedMessage message)
        {
            _context = message.Context;
            Job = message.Job;
        }

        /// <summary>
        /// Edits the job.
        /// </summary>
        private void EditJob()
        {
            LogManager.Log("Edit command pressed.");
            NavigationManager.NavigateTo<JobsModule>(false, nameof(JobView));
        }

        /// <summary>
        /// Starts the job.
        /// </summary>
        private async void StartJob()
        {
            try
            {
                LogManager.Log("Start job command pressed. Starting job and navigating to job progress view...");

                Job = await new JobBuilder(_context).Set(Job.Guid)
                        .WithConfiguration()
                        .WithRML()
                        .WithUser()
                        .WithSegments()
                        .WithBrushStops()
                        .BuildAsync();

                PrintingManager.Print(Job, _context);
                await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
            }
            catch (Exception ex)
            {
                LogManager.Log(ex, "Could not start the current job.");
                await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}.");
            }
        }

        /// <summary>
        /// Called when the application has been started.
        /// </summary>
        public override void OnApplicationStarted()
        {

        }
    }
}