aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/ThreadBreakView.xaml
blob: 71c4ced07d533f2a1b509eb1f661072d278a6477 (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
<UserControl x:Class="Tango.PPC.Events.EventsViews.ThreadBreakView"
             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:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL"
             xmlns:local="clr-namespace:Tango.PPC.Events.EventsViews"
             mc:Ignorable="d" 
             d:DesignHeight="220" d:DesignWidth="750" d:DataContext="{d:DesignInstance Type=entities:MachinesEvent, IsDesignTimeCreatable=False}">
    <Grid Background="{StaticResource TangoPrimaryBackgroundBrush}">
        <DockPanel>
            <Image Stretch="None" Margin="20" DockPanel.Dock="Right" Source="../Images/machine_small.png" RenderOptions.BitmapScalingMode="Fant" />
            <DockPanel Margin="35 20 20 20">
                <TextBlock FontSize="{StaticResource TangoTitleFontSize}" FontWeight="SemiBold" DockPanel.Dock="Top" Text="{Binding EventType.Title,FallbackValue='Unknown Event'}"></TextBlock>

                <StackPanel Margin="0 30 0 0">
                    <TextBlock TextWrapping="Wrap" FontWeight="SemiBold" Text="{Binding EventType.Description,FallbackValue='No Description'}"></TextBlock>
                    <Rectangle Margin="0 5 0 10" StrokeThickness="2" Stroke="{StaticResource TangoDividerBrush}" />

                    <touch:TouchButton x:Name="btnLoadThreadBreakWizard" Margin="0 10 0 0" Height="55" Style="{StaticResource TangoHollowButton}" Width="280" HorizontalAlignment="Left">LOAD THREAD BREAK WIZARD</touch:TouchButton>
                </StackPanel>
            </DockPanel>
        </DockPanel>
    </Grid>
</UserControl>
ound-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #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.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Integration.Operation;
using Tango.Logging;
using Tango.PMR.Printing;
using Tango.PPC.Jobs.ViewModels;
using Tango.SharedUI;

namespace Tango.JobProgressTester.UI
{
    public class MainWindowVM : ViewModel
    {
        private DataSource _dataSource;

        private List<Job> _jobs;
        public List<Job> Jobs
        {
            get { return _jobs; }
            set { _jobs = value; RaisePropertyChangedAuto(); }
        }

        private Job _selectedJob;
        public Job SelectedJob
        {
            get { return _selectedJob; }
            set { _selectedJob = value; RaisePropertyChangedAuto(); OnSelectedJobChanged(); }
        }

        private Job _activeJob;
        public Job ActiveJob
        {
            get { return _activeJob; }
            set { _activeJob = value; RaisePropertyChangedAuto(); }
        }

        private JobProgressViewVM _jobProgressViewVM;
        public JobProgressViewVM JobProgressViewVM
        {
            get { return _jobProgressViewVM; }
            set { _jobProgressViewVM = value; RaisePropertyChangedAuto(); }
        }

        private JobHandler2 _jobHandler;
        public JobHandler2 JobHandler
        {
            get { return _jobHandler; }
            set { _jobHandler = value; RaisePropertyChangedAuto(); }
        }

        private double _progress;
        public double Progress
        {
            get { return _progress; }
            set { _progress = value; RaisePropertyChangedAuto(); OnProgressChanged(); }
        }

        public MainWindowVM()
        {
            Application.Current.MainWindow.ContentRendered += (_, __) => Init();
        }

        private async void Init()
        {
            LogManager.RegisterLogger(new VSOutputLogger());

            _dataSource = new DataSource()
            {
                Address = "localhost\\SQLPPC",
                Catalog = "Tango",
                IntegratedSecurity = true
            };

            try
            {
                IsFree = false;
                ObservablesContext.OverrideSettingsDataSource(_dataSource);

                using (ObservablesContext db = ObservablesContext.CreateDefault())
                {
                    Jobs = await db.Jobs.ToListAsync();
                }
            }
            catch (Exception ex)
            {
                ShowError(ex.FlattenMessage());
            }
            finally
            {
                IsFree = true;
            }
        }

        private async void OnSelectedJobChanged()
        {
            if (SelectedJob != null)
            {
                try
                {
                    IsFree = false;

                    using (ObservablesContext db = ObservablesContext.CreateDefault())
                    {
                        ActiveJob = await new JobBuilder(db)
                            .Set(SelectedJob)
                            .WithConfiguration()
                            .WithBrushStops()
                            .WithRML()
                            .WithSegments()
                            .WithUser()
                            .BuildAsync();

                        JobHandler = new JobHandler2(() => { }, ActiveJob, null, ActiveJob.Rml.GetActiveProcessGroup().ProcessParametersTables.First(), JobHandlerModes.SettingUp);

                        JobProgressViewVM = new JobProgressViewVM()
                        {
                            Job = ActiveJob,
                            RunningJobStatus = JobHandler.Status,
                        };

                        Progress = 0.1;
                    }
                }
                catch (Exception ex)
                {
                    ShowError(ex.FlattenMessage());
                }
                finally
                {
                    IsFree = true;
                }
            }
        }

        private void OnProgressChanged()
        {
            if(JobHandler != null)
            {
                JobHandler.RaiseStatusReceived(new JobStatus()
                {
                    Progress = Progress,
                });
            }
            
        }

        private void ShowError(String message)
        {
            MessageBox.Show(Application.Current.MainWindow, message, "Job Progress Tester", MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
}