-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathServiceControlAddAttachment.cs
More file actions
198 lines (170 loc) · 10.2 KB
/
ServiceControlAddAttachment.cs
File metadata and controls
198 lines (170 loc) · 10.2 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
namespace ServiceControl.Config.UI.InstanceAdd
{
using System;
using System.Threading.Tasks;
using Caliburn.Micro;
using Events;
using Framework;
using Framework.Modules;
using ReactiveUI;
using ServiceControl.Config.Commands;
using ServiceControlInstaller.Engine.Instances;
using ServiceControlInstaller.Engine.Validation;
using Validation;
class ServiceControlAddAttachment : Attachment<ServiceControlAddViewModel>
{
public ServiceControlAddAttachment(IServiceControlWindowManager windowManager, IEventAggregator eventAggregator, ServiceControlInstanceInstaller serviceControlInstaller, ServiceControlAuditInstanceInstaller serviceControlAuditInstaller, ScmuCommandChecks commandChecks)
{
this.windowManager = windowManager;
this.serviceControlInstaller = serviceControlInstaller;
this.serviceControlAuditInstaller = serviceControlAuditInstaller;
this.eventAggregator = eventAggregator;
this.commandChecks = commandChecks;
}
protected override void OnAttach()
{
var validationTemplate = new ValidationTemplate(viewModel);
viewModel.ValidationTemplate = validationTemplate;
viewModel.Save = ReactiveCommand.CreateFromTask(Add);
viewModel.Cancel = Command.Create(async () =>
{
await viewModel.TryCloseAsync(false);
await eventAggregator.PublishOnUIThreadAsync(new RefreshInstances());
}, IsInProgress);
}
bool IsInProgress() => viewModel != null && !viewModel.InProgress;
async Task Add()
{
viewModel.SubmitAttempted = true;
if (!viewModel.ValidationTemplate.Validate())
{
viewModel.NotifyOfPropertyChange(string.Empty);
viewModel.SubmitAttempted = false;
windowManager.ScrollFirstErrorIntoView(viewModel);
return;
}
viewModel.InProgress = true;
var serviceControlNewInstance = viewModel.InstallErrorInstance ? ServiceControlNewInstance.CreateWithDefaultPersistence() : null;
if (viewModel.InstallErrorInstance)
{
serviceControlNewInstance.DisplayName = viewModel.ServiceControl.InstanceName;
serviceControlNewInstance.Name = viewModel.ServiceControl.InstanceName.Replace(' ', '.');
serviceControlNewInstance.InstanceName = viewModel.ServiceControl.InstanceName.Replace(' ', '.');
serviceControlNewInstance.ServiceDescription = viewModel.ServiceControl.Description;
serviceControlNewInstance.DBPath = viewModel.ServiceControl.DatabasePath;
serviceControlNewInstance.LogPath = viewModel.ServiceControl.LogPath;
serviceControlNewInstance.InstallPath = viewModel.ServiceControl.DestinationPath;
serviceControlNewInstance.HostName = viewModel.ServiceControl.HostName;
serviceControlNewInstance.Port = Convert.ToInt32(viewModel.ServiceControl.PortNumber);
serviceControlNewInstance.DatabaseMaintenancePort = Convert.ToInt32(viewModel.ServiceControl.DatabaseMaintenancePortNumber);
serviceControlNewInstance.VirtualDirectory = null;
serviceControlNewInstance.ErrorQueue = viewModel.ServiceControl.ErrorQueueName;
serviceControlNewInstance.ErrorLogQueue = viewModel.ServiceControl.ErrorForwarding.Value ? viewModel.ServiceControl.ErrorForwardingQueueName : null;
serviceControlNewInstance.ForwardErrorMessages = viewModel.ServiceControl.ErrorForwarding.Value;
serviceControlNewInstance.TransportPackage = viewModel.SelectedTransport;
serviceControlNewInstance.ConnectionString = viewModel.ConnectionString;
serviceControlNewInstance.ErrorRetentionPeriod = viewModel.ServiceControl.ErrorRetentionPeriod;
serviceControlNewInstance.ServiceAccount = viewModel.ServiceControl.ServiceAccount;
serviceControlNewInstance.ServiceAccountPwd = viewModel.ServiceControl.Password;
serviceControlNewInstance.EnableFullTextSearchOnBodies = viewModel.ServiceControl.EnableFullTextSearchOnBodies.Value;
serviceControlNewInstance.EnableIntegratedServicePulse = viewModel.ServiceControl.EnableIntegratedServicePulse.Value;
}
var auditNewInstance = viewModel.InstallAuditInstance ? ServiceControlAuditNewInstance.CreateWithDefaultPersistence() : null;
if (viewModel.InstallAuditInstance)
{
auditNewInstance.DisplayName = viewModel.ServiceControlAudit.InstanceName;
auditNewInstance.Name = viewModel.ServiceControlAudit.InstanceName.Replace(' ', '.');
auditNewInstance.InstanceName = viewModel.ServiceControlAudit.InstanceName.Replace(' ', '.');
auditNewInstance.ServiceDescription = viewModel.ServiceControlAudit.Description;
auditNewInstance.DBPath = viewModel.ServiceControlAudit.DatabasePath;
auditNewInstance.LogPath = viewModel.ServiceControlAudit.LogPath;
auditNewInstance.InstallPath = viewModel.ServiceControlAudit.DestinationPath;
auditNewInstance.HostName = viewModel.ServiceControlAudit.HostName;
auditNewInstance.Port = Convert.ToInt32(viewModel.ServiceControlAudit.PortNumber);
auditNewInstance.DatabaseMaintenancePort = Convert.ToInt32(viewModel.ServiceControlAudit.DatabaseMaintenancePortNumber);
auditNewInstance.AuditLogQueue = viewModel.ServiceControlAudit.AuditForwarding.Value ? viewModel.ServiceControlAudit.AuditForwardingQueueName : null;
auditNewInstance.AuditQueue = viewModel.ServiceControlAudit.AuditQueueName;
auditNewInstance.ForwardAuditMessages = viewModel.ServiceControlAudit.AuditForwarding.Value;
auditNewInstance.TransportPackage = viewModel.SelectedTransport;
auditNewInstance.ConnectionString = viewModel.ConnectionString;
auditNewInstance.AuditRetentionPeriod = viewModel.ServiceControlAudit.AuditRetentionPeriod;
auditNewInstance.ServiceAccount = viewModel.ServiceControlAudit.ServiceAccount;
auditNewInstance.ServiceAccountPwd = viewModel.ServiceControlAudit.Password;
auditNewInstance.ServiceControlQueueAddress = serviceControlNewInstance == null ? string.Empty : serviceControlNewInstance.InstanceName;
auditNewInstance.EnableFullTextSearchOnBodies = viewModel.ServiceControlAudit.EnableFullTextSearchOnBodies.Value;
}
if (!await commandChecks.ValidateNewInstance(serviceControlNewInstance, auditNewInstance))
{
viewModel.InProgress = false;
return;
}
if (viewModel.InstallAuditInstance && viewModel.InstallErrorInstance)
{
serviceControlNewInstance.AddRemoteInstance(auditNewInstance.Url);
}
if (viewModel.InstallErrorInstance)
{
using (var progress = viewModel.GetProgressObject("ADDING INSTANCE"))
{
var installationCancelled = await InstallInstance(serviceControlNewInstance, progress);
if (installationCancelled)
{
return;
}
}
}
if (viewModel.InstallAuditInstance)
{
using (var progress = viewModel.GetProgressObject("ADDING AUDIT INSTANCE"))
{
var installationCancelled = await InstallInstance(auditNewInstance, progress);
if (installationCancelled)
{
return;
}
}
}
await viewModel.TryCloseAsync(true);
await eventAggregator.PublishOnUIThreadAsync(new RefreshInstances());
}
async Task<bool> InstallInstance(ServiceControlNewInstance instanceData, IProgressObject progress)
{
var reportCard = await Task.Run(() => serviceControlInstaller.Add(instanceData, progress, PromptToProceed));
if (reportCard.HasErrors || reportCard.HasWarnings)
{
await windowManager.ShowActionReport(reportCard, "ISSUES ADDING INSTANCE", "Could not add new instance because of the following errors:", "There were some warnings while adding the instance:");
return true;
}
if (reportCard.CancelRequested)
{
return true;
}
return false;
}
async Task<bool> InstallInstance(ServiceControlAuditNewInstance instanceData, IProgressObject progress)
{
var reportCard = await Task.Run(() => serviceControlAuditInstaller.Add(instanceData, progress, PromptToProceed));
if (reportCard.HasErrors || reportCard.HasWarnings)
{
await windowManager.ShowActionReport(reportCard, "ISSUES ADDING INSTANCE", "Could not add new instance because of the following errors:", "There were some warnings while adding the instance:");
return true;
}
if (reportCard.CancelRequested)
{
return true;
}
return false;
}
async Task<bool> PromptToProceed(PathInfo pathInfo)
{
var result = false;
await Execute.OnUIThreadAsync(async () => { result = await windowManager.ShowYesNoDialog("ADDING INSTANCE QUESTION - DIRECTORY NOT EMPTY", $"The directory specified as the {pathInfo.Name} is not empty.", $"Are you sure you want to use '{pathInfo.Path}' ?", "Yes use it", "No I want to change it"); });
return result;
}
readonly IServiceControlWindowManager windowManager;
readonly IEventAggregator eventAggregator;
readonly ServiceControlInstanceInstaller serviceControlInstaller;
readonly ServiceControlAuditInstanceInstaller serviceControlAuditInstaller;
readonly ScmuCommandChecks commandChecks;
}
}