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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
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()
.WithSegmentsGroups()
.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);
}
}
}
|