-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmJobManager.axaml.cs
More file actions
122 lines (103 loc) · 4.01 KB
/
frmJobManager.axaml.cs
File metadata and controls
122 lines (103 loc) · 4.01 KB
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
using Avalonia.Controls;
using Avalonia.Interactivity;
using S3_SimpleBackup.Models;
using SharedMethods;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Threading.Tasks;
namespace S3_SimpleBackup
{
public partial class JobManager : Window
{
private bool InEditMode { get; set; }
private string OldJobName;
private BackupJobModel JobInfo { get; set; }
public JobManager()
{
InitializeComponent();
}
public JobManager(string formMode, BackupJobModel jobInfo, List<string> AvailableProfiles) : base()
{
InitializeComponent();
AvailableProfiles.Add("Create New Profile");
switch (formMode)
{
case "edit":
InEditMode = true;
cmbxProfileSelector.Items = AvailableProfiles;
cmbxProfileSelector.SelectedItem = jobInfo.JobProfile;
OldJobName = jobInfo.JobName;
edtJobName.Text = jobInfo.JobName;
edtSource.Text = jobInfo.SourceFileFolder;
edtDestination.Text = jobInfo.S3Destination;
edtS3Bucket.Text = jobInfo.S3BucketName;
chckbxRunwithProfile.IsChecked = jobInfo.RunWithProfile;
rbtnSyncUp.IsChecked = jobInfo.JobParameters.Contains("/su") ? true : false;
chckbxRecursiveSync.IsChecked = jobInfo.JobParameters.Contains("/r") ? true : false;
break;
case "new":
InEditMode = false;
cmbxProfileSelector.Items = AvailableProfiles;
edtJobName.Text = "";
edtSource.Text = "";
edtDestination.Text = "";
chckbxRunwithProfile.IsChecked = false;
rbtnSyncUp.IsChecked = true;
break;
default:
break;
}
}
private async void btnSaveJob_ClickedAsync(object? sender, RoutedEventArgs args)
{
BackupJobModel jobInfo = new BackupJobModel();
if (cmbxProfileSelector.SelectedItem.ToString() != "Create New Profile")
{
jobInfo.JobProfile = cmbxProfileSelector.SelectedItem.ToString();
}
else
{
jobInfo.JobProfile = edtNewProfileName.Text;
}
jobInfo.JobName = edtJobName.Text;
jobInfo.SourceFileFolder = edtSource.Text;
jobInfo.S3Destination = edtDestination.Text;
jobInfo.S3BucketName = edtS3Bucket.Text;
jobInfo.JobParameters = rbtnSyncUp.IsChecked ?? false ? "/su" : "";
jobInfo.JobParameters = jobInfo.JobParameters + (chckbxRecursiveSync.IsChecked ?? false ? " /r" : "");
jobInfo.RunWithProfile = chckbxRunwithProfile.IsChecked ?? false;
if (InEditMode)
{
//We are editing a job, so we will update it
//Not in Edit mode so we will create a new job
if (await DoInputOutput.UpdateJobAsync(OldJobName, jobInfo, this))
{
this.Close();
}
}
else
{
//Not in Edit mode so we will create a new job
if (await DoInputOutput.CreateNewJobAsync(jobInfo, this))
{
this.Close();
}
}
}
private void btnCancel_Clicked(object? sender, RoutedEventArgs args)
{
this.Close();
}
private void cmbxProfileSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cmbxProfileSelector.SelectedItem == "Create New Profile")
{
edtNewProfileName.IsVisible = true;
}
else
{
edtNewProfileName.IsVisible = false;
}
}
}
}