-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathServiceControlEditAttachment.cs
More file actions
107 lines (92 loc) · 4.63 KB
/
ServiceControlEditAttachment.cs
File metadata and controls
107 lines (92 loc) · 4.63 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
namespace ServiceControl.Config.UI.InstanceEdit
{
using System;
using System.ServiceProcess;
using System.Threading.Tasks;
using Caliburn.Micro;
using Events;
using Framework;
using Framework.Modules;
using ReactiveUI;
using Validation;
class ServiceControlEditAttachment : Attachment<ServiceControlEditViewModel>
{
public ServiceControlEditAttachment(IServiceControlWindowManager windowManager, IEventAggregator eventAggregator, ServiceControlInstanceInstaller installer)
{
this.windowManager = windowManager;
this.installer = installer;
this.eventAggregator = eventAggregator;
}
protected override void OnAttach()
{
var validationTemplate = new ValidationTemplate(viewModel);
viewModel.ValidationTemplate = validationTemplate;
viewModel.Save = ReactiveCommand.CreateFromTask(Save);
viewModel.Cancel = Command.Create(async () =>
{
await viewModel.TryCloseAsync(false);
await eventAggregator.PublishOnUIThreadAsync(new RefreshInstances());
}, IsInProgress);
}
bool IsInProgress()
{
return viewModel != null && !viewModel.InProgress;
}
async Task Save()
{
viewModel.SubmitAttempted = true;
if (!viewModel.ValidationTemplate.Validate())
{
viewModel.NotifyOfPropertyChange(string.Empty);
viewModel.SubmitAttempted = false;
windowManager.ScrollFirstErrorIntoView(viewModel);
return;
}
var instance = viewModel.ServiceControlInstance;
if (instance.Service.Status == ServiceControllerStatus.Running)
{
var shouldProceed = await windowManager.ShowMessage("STOP INSTANCE AND MODIFY",
$"{instance.Name} needs to be stopped in order to modify the settings. Do you want to proceed.");
if (!shouldProceed)
{
return;
}
}
viewModel.InProgress = true;
instance.LogPath = viewModel.ServiceControl.LogPath;
instance.ServiceAccount = viewModel.ServiceControl.ServiceAccount;
instance.ServiceAccountPwd = viewModel.ServiceControl.Password;
instance.Description = viewModel.ServiceControl.Description;
instance.HostName = viewModel.ServiceControl.HostName;
instance.Port = Convert.ToInt32(viewModel.ServiceControl.PortNumber);
instance.DatabaseMaintenancePort = !string.IsNullOrWhiteSpace(viewModel.ServiceControl.DatabaseMaintenancePortNumber) ? Convert.ToInt32(viewModel.ServiceControl.DatabaseMaintenancePortNumber) : null;
instance.VirtualDirectory = null;
instance.ForwardErrorMessages = viewModel.ServiceControl.ErrorForwarding.Value;
instance.EnableEmbeddedServicePulse = viewModel.ServiceControl.EnableEmbeddedServicePulse.Value;
instance.ErrorQueue = viewModel.ServiceControl.ErrorQueueName;
instance.ErrorLogQueue = viewModel.ServiceControl.ErrorForwardingQueueName;
instance.ErrorRetentionPeriod = viewModel.ServiceControl.ErrorRetentionPeriod;
instance.EnableFullTextSearchOnBodies = viewModel.ServiceControl.EnableFullTextSearchOnBodies.Value;
instance.TransportPackage = viewModel.SelectedTransport;
instance.ConnectionString = viewModel.ConnectionString;
using (var progress = viewModel.GetProgressObject("SAVING INSTANCE"))
{
progress.Report(0, 0, "Updating Instance");
instance.Service.Refresh();
var isRunning = instance.Service.Status == ServiceControllerStatus.Running;
var reportCard = await Task.Run(() => installer.Update(instance, isRunning));
if (reportCard.HasErrors || reportCard.HasWarnings)
{
await windowManager.ShowActionReport(reportCard, "ISSUES MODIFYING INSTANCE", "Could not modify instance because of the following errors:", "There were some warnings while modifying the instance:");
return;
}
progress.Report(0, 0, "Update Complete");
}
await viewModel.TryCloseAsync(true);
await eventAggregator.PublishOnUIThreadAsync(new RefreshInstances());
}
readonly IServiceControlWindowManager windowManager;
readonly IEventAggregator eventAggregator;
readonly ServiceControlInstanceInstaller installer;
}
}