diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-02-16 14:48:33 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-02-16 14:48:33 +0200 |
| commit | e2fbc8e6047fef09681b994efe2ca1043d25ac9d (patch) | |
| tree | d51c5787ec50711361d557bb060c976a5b278dcb /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | |
| parent | 1ae720e9052b2419200c113ad1fa42550382e6c7 (diff) | |
| download | Tango-e2fbc8e6047fef09681b994efe2ca1043d25ac9d.tar.gz Tango-e2fbc8e6047fef09681b994efe2ca1043d25ac9d.zip | |
Implement Job Runs View. Create 2 views in Statistics. Implements Part of JobRunsView.
Related Work Items: #2509
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs new file mode 100644 index 000000000..f03e7f67d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -0,0 +1,209 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Core.Commands; +using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Statistics.Models; +using Tango.SharedUI; +using Tango.SharedUI.Components; + +namespace Tango.MachineStudio.Statistics.ViewModels +{ + public class JobRunsViewVM : ViewModel + { + private INotificationProvider _notification; + private List<Machine> _allMachines; + private List<User> _allUsers; + + #region Properties + + private List<JobRunModel> _jobRuns; + public List<JobRunModel> JobRuns + { + get { return _jobRuns; } + set + { + _jobRuns = value; + RaisePropertyChangedAuto(); + } + } + + private JobRunModel _selectedJobRun = null; + public JobRunModel SelectedJobRun + { + get { return _selectedJobRun; } + set + { + _selectedJobRun = value; + RaisePropertyChangedAuto(); + } + } + + private SelectedObjectCollection<Machine> _selectedMachines; + public SelectedObjectCollection<Machine> SelectedMachines + { + get { return _selectedMachines; } + set + { + _selectedMachines = value; + RaisePropertyChangedAuto(); + } + } + + private DateTime _startSelectedDate; + public DateTime StartSelectedDate + { + get { return _startSelectedDate; } + set { _startSelectedDate = value; RaisePropertyChangedAuto(); } + } + + private DateTime _endSelectedDate; + public DateTime EndSelectedDate + { + get { return _endSelectedDate; } + set { _endSelectedDate = value; RaisePropertyChangedAuto(); } + } + + protected Double _length; + public Double Length + { + get { return _length; } + set + { + _length = value; + RaisePropertyChangedAuto(); + } + } + + private JobSource _jobRunSource; + + public JobSource JobRunSource + { + get { return _jobRunSource; } + set { _jobRunSource = value; RaisePropertyChangedAuto(); } + } + + private JobRunStatus _jobRunStatus; + + public JobRunStatus JobRunStatus + { + get { return _jobRunStatus; } + set { _jobRunStatus = value; RaisePropertyChangedAuto(); } + } + + private bool? _isGradient; + + public bool? IsGradient + { + get { return _isGradient; } + set { + _isGradient = value; + RaisePropertyChangedAuto(); } + } + + private string _jobName; + + public string JobName + { + get { return _jobName; } + set { _jobName = value; } + } + + + #endregion + + public RelayCommand LoadJobRunsCommand { get; set; } + + public JobRunsViewVM(INotificationProvider notificationProvider) + { + _notification = notificationProvider; + JobRuns = new List<JobRunModel>(); + LoadJobRunsCommand = new RelayCommand( GetJobRuns); + } + + + public async void Init() + { + using (_notification.PushTaskItem("Loading job runs...")) + { + try + { + IsFree = false; + + using (var db = ObservablesContext.CreateDefault()) + { + _allMachines = await db.Machines.ToListAsync(); + _allUsers = await db.Users.ToListAsync(); + SelectedMachines = new SelectedObjectCollection<Machine>(_allMachines.ToObservableCollection(), new ObservableCollection<Machine>()); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading job runs."); + } + finally + { + IsFree = true; + } + } + } + + private async void GetJobRuns() + { + await LoadJobRuns(); + } + + private async Task LoadJobRuns() + { + using (_notification.PushTaskItem("Loading job runs...")) + { + try + { + IsFree = false; + + using (var db = ObservablesContext.CreateDefault()) + { + DateTime startUtc = StartSelectedDate.ToUniversalTime(); + TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); + DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; + + var runs = await db.JobRuns.Select(x => new JobRunModel() + { + JobRun = x, + Machine = _allMachines.FirstOrDefault(y => y.Guid == x.MachineGuid), + User = _allUsers.SingleOrDefault(y => y.Guid == x.UserGuid), + }).ToListAsync(); + + // .Query(y => y.Where + //(x => JobName == null || + //(x.JobName.ToString().ToLower().StartsWith(JobName) + //|| Length == null || (x.JobLength == Length) + //|| IsGradient == null || (x.IsGradient != null && x.IsGradient == IsGradient) + //|| ( x.JobRunSource == JobRunSource)))) + //.BuildAsync(); + + runs.ForEach(x => x.Init()); + + JobRuns = runs; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading job runs."); + } + finally + { + IsFree = true; + } + } + } + } +} |
