Skip to content

Instantly share code, notes, and snippets.

@mrichman
Created August 27, 2014 19:43
Show Gist options
  • Save mrichman/7465c9394430744ee307 to your computer and use it in GitHub Desktop.
Save mrichman/7465c9394430744ee307 to your computer and use it in GitHub Desktop.
Component Graph
#region
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Cmc.Core.ComponentModel;
using Cmc.Core.Diagnostics;
#endregion
namespace Cmc.Installer.Core
{
public abstract class Component
{
protected readonly ILogger Logger;
private readonly Lazy<Task> _task;
private readonly CancellationTokenSource _cancellationTokenSource;
protected Component(string name, string targetMachine, IProgress<InstallProgress> progress, CancellationTokenSource cancellationTokenSource)
{
Logger = ServiceLocator.Default.GetInstance<ILoggerFactory>().GetLogger(this);
Dependencies = new List<Component>();
Name = name;
TargetMachine = targetMachine;
Progress = progress;
_cancellationTokenSource = cancellationTokenSource;
_task = new Lazy<Task>(() => StartTask(_cancellationTokenSource));
}
private string Name { get; set; }
public string TargetMachine { get; set; }
public List<Component> Dependencies { get; set; }
public Task InstallationCompletion { get { return _task.Value; } }
public IProgress<InstallProgress> Progress { get; set; }
protected abstract Task StartTask(CancellationTokenSource cancellationTokenSource);
public override string ToString()
{
return string.Format("[{0} on {1}]", Name, TargetMachine);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment