// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.Tools.Heat
{
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using WixToolset.Core;
using WixToolset.Data;
using WixToolset.Extensibility;
using WixToolset.Extensibility.Data;
using WixToolset.Extensibility.Services;
using WixToolset.Harvesters;
using WixToolset.Harvesters.Data;
using WixToolset.Harvesters.Extensibility;
using WixToolset.Tools.Core;
///
/// Wix Toolset Harvester.
///
public sealed class Program
{
///
/// The main entry point for the application.
///
/// Commandline arguments for the application.
/// Returns the application error code.
[MTAThread]
public static async Task Main(string[] args)
{
var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
var listener = new ConsoleMessageListener("HEAT", "heat.exe");
try
{
var program = new Program();
return await program.Run(serviceProvider, listener, args);
}
catch (WixException e)
{
listener.Write(e.Error);
return e.Error.Id;
}
catch (Exception e)
{
listener.Write(ErrorMessages.UnexpectedException(e));
if (e is NullReferenceException || e is SEHException)
{
throw;
}
return e.HResult;
}
}
///
/// Run the application with the given arguments.
///
/// Service provider to use throughout this execution.
/// The commandline arguments.
/// Returns the application error code.
public Task Run(IServiceProvider serviceProvider, IMessageListener listener, string[] args)
{
var messaging = serviceProvider.GetService();
messaging.SetListener(listener);
var arguments = serviceProvider.GetService();
arguments.Populate(args);
var extensionManager = serviceProvider.GetService();
foreach (var extension in arguments.Extensions)
{
extensionManager.Load(extension);
}
var heatExtensions = extensionManager.GetServices();
var commandLine = HeatCommandLineFactory.CreateCommandLine(serviceProvider, heatExtensions);
var command = commandLine.ParseStandardCommandLine(arguments);
messaging.Write(HarvesterWarnings.HeatIsDeprecated());
return command?.ExecuteAsync(CancellationToken.None) ?? Task.FromResult(1);
}
}
}