Commit 24910861 authored by Michael Herndon's avatar Michael Herndon

WORK: add Agent.Core project, update program.

The bulk of logic for the agent application will go in here for now
parent 66244a3a
......@@ -44,6 +44,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{07B4A7C1-5
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NerdyMishka.Agent", "src\Apps\Agent\NerdyMishka.Agent.csproj", "{9A92EBB7-F59F-46A3-A956-FA00C4093EEC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NerdyMishka.Agent.Core", "src\Apps\Agent.Core\NerdyMishka.Agent.Core.csproj", "{9AB3DAE3-D669-42D4-A3BB-50187F94CDE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -94,6 +96,10 @@ Global
{9A92EBB7-F59F-46A3-A956-FA00C4093EEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A92EBB7-F59F-46A3-A956-FA00C4093EEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A92EBB7-F59F-46A3-A956-FA00C4093EEC}.Release|Any CPU.Build.0 = Release|Any CPU
{9AB3DAE3-D669-42D4-A3BB-50187F94CDE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AB3DAE3-D669-42D4-A3BB-50187F94CDE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AB3DAE3-D669-42D4-A3BB-50187F94CDE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AB3DAE3-D669-42D4-A3BB-50187F94CDE1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -118,6 +124,7 @@ Global
{85DF8D0D-09CC-4C22-94AF-FFBBC6ED37D1} = {6444BF0F-2EED-404A-AC00-CC756F4F4ED0}
{07B4A7C1-57E6-48D2-810D-BB8F234EECFF} = {DB042499-08A3-4C34-9231-1372043915F2}
{9A92EBB7-F59F-46A3-A956-FA00C4093EEC} = {07B4A7C1-57E6-48D2-810D-BB8F234EECFF}
{9AB3DAE3-D669-42D4-A3BB-50187F94CDE1} = {07B4A7C1-57E6-48D2-810D-BB8F234EECFF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {16666A01-3CC0-4111-8A58-9A6CA34CD76C}
......
using System.Threading;
using System.Threading.Tasks;
namespace NerdyMishka.Console
{
/// <summary>
/// Representings a possible command line action.
/// </summary>
public interface IAction
{
/// <summary>
/// Gets a description on what the action does. This is used for
/// help documentation.
/// </summary>
/// <value></value>
string Description { get; }
/// <summary>
/// Executes a command line action.
/// </summary>
/// <param name="parameters">The parameters passed to the command.</param>
/// <param name="token">A cancellation token.</param>
/// <returns>The last exit code.</returns>
Task<int> ExecuteAsync(object parameters, CancellationToken token = default);
}
}
\ No newline at end of file
using System.Collections.Generic;
namespace NerdyMishka.Console
{
/// <summary>
/// Allows console parameters/arguments to added as a service for
/// Dependency Injection purposes.
/// </summary>
public interface IConsoleArgs
{
/// <summary>
/// Gets or sets the console arguments.
/// </summary>
/// <value></value>
IReadOnlyCollection<string> Args { get; }
}
/// <summary>
///
/// </summary>
public class ConsoleArgs
{
/// <summary>
/// Initializes a new instance of <see cref="ConsoleArgs" />
/// </summary>
/// <param name="args">the arguments</param>
public ConsoleArgs(IReadOnlyCollection<string> args)
{
this.Args = args;
}
/// <summary>
/// Gets or sets the console arguments.
/// </summary>
/// <value></value>
public IReadOnlyCollection<string> Args { get; private set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>NerdyMishka</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Microsoft.Graph" Version="1.21.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
<PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.2" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.7.1" />
<PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.30.0" />
<PackageReference Include="CommandLineParser" Version="2.7.82" />
<PackageReference Include="ConsoleTables" Version="2.4.0" />
<PackageReference Include="System.Composition" Version="1.4.0" />
<PackageReference Include="Twilio" Version="5.37.2" />
<PackageReference Include="Sendgrid" Version="9.12.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Bcl\Proto\NerdyMishka.Proto.csproj" />
</ItemGroup>
</Project>
......@@ -4,22 +4,45 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.IO;
namespace NerdyMishka.Agent
{
public class Program
{
public static void Main(string[] args)
public static async Task<int> Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
IHost host = null;
try {
host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
})
.ConfigureHostConfiguration((cb) => {
cb.SetBasePath(Directory.GetCurrentDirectory());
cb.AddEnvironmentVariables("NERDY_");
cb.AddJsonFile("agent.json", optional: true);
})
.Build();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
});
await host.WaitForShutdownAsync();
return 0;
} catch(Exception ex) {
var logger = host?.Services?.GetService<ILogger>();
if(logger == null)
await Console.Error.WriteLineAsync($"Agent failure: {ex.Message} \n {ex.StackTrace}");
else
logger?.LogError(ex, "Agent failure");
return 1;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment