aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpView.xaml
blob: 08177843448b1a3c076a19d0c5421b3e98ad6b06 (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
<UserControl x:Class="Tango.PPC.UI.Dialogs.PowerUpView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch"
             xmlns:local="clr-namespace:Tango.PPC.UI.Dialogs"
             mc:Ignorable="d" 
             Background="{StaticResource TangoPrimaryBackgroundBrush}"  d:DesignHeight="555" d:DesignWidth="560" Width="600" Height="800" d:DataContext="{d:DesignInstance Type=local:PowerUpViewVM, IsDesignTimeCreatable=False}">
    <Grid>
        <StackPanel Margin="0 100 0 0" HorizontalAlignment="Center">
            <touch:TouchGifAnimation Source="../Images/powerup.gif" EnableAnimation="{Binding IsVisible}" />
            <TextBlock HorizontalAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}" Margin="0 30 0 0">Continue getting ready for:</TextBlock>
            <DockPanel HorizontalAlignment="Center" Margin="0 40 0 0">
                <touch:TouchRadioButton IsChecked="{Binding IsSelectedRml}" />
                <touch:TouchComboBox Margin="20 0 0 0" Width="300" ItemsSource="{Binding Rmls}" SelectedItem="{Binding SelectedRml}" DisplayMemberPath="Name" Title="Select thread type"></touch:TouchComboBox>
            </DockPanel>
            <DockPanel HorizontalAlignment="Left" Margin="0 40 0 0">
                <touch:TouchRadioButton IsChecked="{Binding IsMinimalTemperature}" />
                <TextBlock VerticalAlignment="Center" Margin="20 0 0 0">Minimal temperature</TextBlock>
            </DockPanel>

            <touch:TouchButton Command="{Binding OKCommand}" Margin="0 150 0 0" Style="{StaticResource TangoHollowButton}" HorizontalAlignment="Center" Padding="60 15" CornerRadius="25">CONTINUE</touch:TouchButton>

            <TextBlock HorizontalAlignment="Center" Margin="0 10 0 0" Visibility="{Binding IsTimeoutEnabled,Converter={StaticResource BooleanToVisibilityConverter}}">
                <Run>auto select in</Run>
                <Run Text="{Binding RemainingSeconds}"></Run>
                <Run>sec</Run>
            </TextBlock>
        </StackPanel>
    </Grid>
</UserControl>
lor: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.Integration.Operation;
using Tango.PMR.Printing;
using Tango.PPC.Common;
using Tango.PPC.Common.Connection;
using Tango.PPC.Common.Notifications;
using Tango.Settings;
using Tango.SharedUI;

namespace Tango.PPC.Maintenance.Dialogs
{
    public class HeadCleaningViewVM : DialogViewVM
    {
        private HeadCleaningHandler _handler;

        [TangoInject]
        private IMachineProvider MachineProvider { get; set; }

        [TangoInject]
        private INotificationProvider NotificationProvider { get; set; }

        private bool _isStarted;
        public bool IsStarted
        {
            get { return _isStarted; }
            set { _isStarted = value; RaisePropertyChangedAuto(); }
        }

        private bool _isCompleted;
        public bool IsCompleted
        {
            get { return _isCompleted; }
            set { _isCompleted = value; RaisePropertyChangedAuto(); }
        }

        private bool _isAborting;
        public bool IsAborting
        {
            get { return _isAborting; }
            set { _isAborting = value; RaisePropertyChangedAuto(); }
        }

        private bool _isFailed;
        public bool IsFailed
        {
            get { return _isFailed; }
            set { _isFailed = value; RaisePropertyChangedAuto(); }
        }

        private StartHeadCleaningResponse _status;
        public StartHeadCleaningResponse Status
        {
            get { return _status; }
            set { _status = value; RaisePropertyChangedAuto(); }
        }

        public RelayCommand StartCommand { get; set; }
        public RelayCommand AbortCommand { get; set; }

        public HeadCleaningViewVM()
        {
            CanClose = true;
            TangoIOC.Default.Inject(this);
            StartCommand = new RelayCommand(Start);
            AbortCommand = new RelayCommand(Abort);
        }

        private async void Start()
        {
            try
            {
                CanClose = false;
                IsStarted = true;
                _handler = await MachineProvider.MachineOperator.PerformHeadCleaning();
                _handler.Completed += _handler_Completed;
                _handler.Failed += _handler_Failed;
                _handler.StatusChanged += _handler_StatusChanged;
            }
            catch (Exception ex)
            {
                _handler_Failed(this, ex);
            }
        }

        private void _handler_StatusChanged(object sender, HeadCleaningStatusChangedEventArgs e)
        {
            Status = e.Status;
        }

        private void _handler_Failed(object sender, Exception e)
        {
            IsStarted = false;
            IsFailed = true;
            InvokeUI(() =>
            {
                CanClose = true;
                Cancel();
                NotificationProvider.ShowError($"Error occurred while trying to perform the head cleaning.\n{e.FlattenMessage()}");
            });
        }

        private void _handler_Completed(object sender, EventArgs e)
        {
            IsStarted = false;
            IsCompleted = true;
            InvokeUI(() =>
            {
                Accept();
                NotificationProvider.ShowSuccess("Head cleaning completed successfully.");
            });
        }

        protected override void Cancel()
        {
            if (CanClose)
            {
                base.Cancel();
            }
        }

        private async void Abort()
        {
            IsAborting = true;
            try
            {
                await _handler.Abort();
                CanClose = true;
                Cancel();
                await NotificationProvider.ShowInfo("Head cleaning aborted.");
            }
            catch (Exception ex)
            {
                if (!IsCompleted)
                {
                    CanClose = true;
                    IsAborting = false;
                    await NotificationProvider.ShowError($"Error occurred while trying to abort the head cleaning.\n{ex.FlattenMessage()}");
                }
            }
        }
    }
}