Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Created December 26, 2017 15:45
Show Gist options
  • Save nathan130200/b7339c77df87c93a16fb8799b1b71fcd to your computer and use it in GitHub Desktop.
Save nathan130200/b7339c77df87c93a16fb8799b1b71fcd to your computer and use it in GitHub Desktop.
Program.cs
using SkyLar.Config;
using System;
using System.IO;
using System.Xml.Serialization;
using SkyLar.Extensions;
using Autofac.Core;
using Autofac;
using SkyLar.Services;
namespace SkyLar
{
public class Program
{
public static IContainer Services {
private set;
get;
}
static SkyLarConfig Config {
set;
get;
}
static void Main(string[] args)
{
if (File.Exists(Directory.GetCurrentDirectory() + @"\Config.xml"))
{
using (var fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config.xml", FileMode.Open))
{
XmlSerializer xs = new XmlSerializer(typeof(SkyLarConfig));
Config = xs.Deserialize<SkyLarConfig>(fs);
if (Config != null)
{
var builder = new ContainerBuilder();
{
builder.RegisterInstance(Config).SingleInstance();
builder.RegisterType<SkyLarLogBack>().SingleInstance();
builder.RegisterType<SkyLarBot>().SingleInstance();
}
Services = builder.Build();
Services.Resolve<SkyLarBot>().StartAsync().ContinueWith(task =>
{
if (task.IsCompleted)
{
while (true);
}
}).Wait();
}
}
}
else
{
using (var fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config.xml", FileMode.Create))
{
var config = new SkyLarConfig
{
Token = "",
TokenType = DSharpPlus.TokenType.Bot,
AutoReconnect = true,
LogLevel = DSharpPlus.LogLevel.Debug,
DatabaseConfig = new DatabaseConfig
{
Host = "127.0.0.1",
Port = 6969,
Username = "",
Password = "",
Database = "",
}
};
XmlSerializer xs = new XmlSerializer(typeof(SkyLarConfig));
xs.Serialize(fs, config);
Environment.Exit(3);
}
}
}
/// <summary>
/// Constructor
/// </summary>
public Program()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment