-
-
Save ReedCopsey/8361bc1b887f5e5b0079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region | |
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using Cmc.Core.ComponentModel; | |
using Cmc.Core.Diagnostics; | |
using Cmc.Installer.Core.Tasks; | |
#endregion | |
namespace Cmc.Installer.Core | |
{ | |
public abstract class Component | |
{ | |
protected readonly ILogger Logger; | |
protected readonly IProgress<InstallProgress> Progress; | |
private readonly Lazy<Task> _task; | |
private readonly CancellationTokenSource cts; | |
protected Component(string name, string targetMachine, IProgress<InstallProgress> progress, CancellationTokenSource cts) | |
{ | |
Logger = ServiceLocator.Default.GetInstance<ILoggerFactory>().GetLogger(this); | |
Dependencies = new List<Component>(); | |
Name = name; | |
TargetMachine = targetMachine; | |
Progress = progress; | |
this.cts = cts; | |
_task = new Lazy<Task>(() => this.StartTask(this.cts)); | |
} | |
protected string Name { get; set; } | |
protected string TargetMachine { get; set; } | |
protected IEnumerable<Component> Dependencies { get; set; } | |
public Task InstallationCompletion { get { return _task.Value; } } | |
protected abstract Task StartTask(CancellationTokenSource cts); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region | |
using System; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Cmc.Installer.Agent.Client; | |
using Cmc.Installer.Core; | |
#endregion | |
namespace Cmc.Installer.Modules.Crm.Components | |
{ | |
public class TalismaServerComponent : Component | |
{ | |
public TalismaServerComponent(string targetMachine, IProgress<InstallProgress> progress) | |
: base("Talisma Server", targetMachine, progress) | |
{ | |
} | |
protected override async Task StartTask(CancellationTokenSource cts) | |
{ | |
// Dont' start if we're cancelled already... | |
cts.Token.ThrowIfCancellationRequested(); | |
// Wait for dependencies to complete | |
await Task.WhenAll(Dependencies.Select(c => c.InstallationCompletion)); | |
// cts.Cancel() can cancel us in here - | |
// cts.Token.Throw... can abort if anything else was cancelled | |
// Install this component | |
try | |
{ | |
var filename = string.Format(@"{0}\SetupFiles\Crm\TalismaCRM\Server\setup.exe", Config.BootstrapPath); | |
var arguments = | |
string.Format( | |
@"-s -f2""{0}\Cmc.Installer.Modules.Crm.CrmInstallModule.Install.log"" /debuglog INIPATH={0}\SetupFiles\Crm\Cmc.Installer.Modules.Crm.Server-{1}.ini", | |
Config.BootstrapPath, TargetMachine); | |
//var agent = new InstallerAgentServiceClient(this, endpointAddress, progress, targetMachine, _logger); | |
var agent = new InstallerAgentServiceClient(null, null, null, null, null); | |
// Bubble progress events back up to desktop app | |
agent.ProgressChanged += (sender, args) => | |
{ | |
Logger.Debug(string.Format("InstallerAgentServiceClient.ProgressChanged: {0}% [{1}]", | |
args.ProgressPercentage, TargetMachine)); | |
var ip = new InstallProgress(TargetMachine, args.ProgressPercentage, "Installing"); | |
Progress.Report(ip); | |
}; | |
await agent.StartProcess(filename, arguments); | |
} | |
catch (Exception ex) | |
{ | |
Logger.Error(ex.Message); | |
throw; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment