aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Statistics/Dialogs/JobRunStreamingViewVM.cs
blob: 1b1aea2e2acf3faa722dc5f1efde48310589e5c1 (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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.FSE.Common;
using Tango.FSE.Common.Notifications;
using Tango.FSE.Common.Storage;
using Tango.FSE.Statistics.Models;
using Tango.Settings;
using static Tango.FSE.Common.FSESettings;

namespace Tango.FSE.Statistics.Dialogs
{
    public class JobRunStreamingViewVM : FSEDialogViewVM
    {
        public StatisticsStreamingConfiguration Config { get; set; }

        public RelayCommand BrowseCsvReportsFolderCommand { get; set; }

        [TangoInject]
        private IStorageProvider StorageProvider { get; set; }

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

        public JobRunStreamingViewVM()
        {
            CanCancel = false;
            OKText = "CLOSE";

            TangoIOC.Default.Inject(this);

            Config = SettingsManager.Default.GetOrCreate<FSESettings>().StatisticsStreamingConfig;
            BrowseCsvReportsFolderCommand = new RelayCommand(BrowseCsvReportsFolder);
        }

        protected override void Accept()
        {
            if (Config.EnableCsvReports && (!Config.CsvReportsFolder.IsNotNullOrEmpty() || !Directory.Exists(Config.CsvReportsFolder)))
            {
                NotificationProvider.ShowError("Please specify a valid reports folder path.");
                return;
            }

            base.Accept();
        }

        private async void BrowseCsvReportsFolder()
        {
            var result = await StorageProvider.SelectFolder("Select CSV Reports Folder", Config.CsvReportsFolder);
            if (result)
            {
                Config.CsvReportsFolder = result.SelectedItem;
                RaisePropertyChanged(nameof(Config));
            }
        }
    }
}