Created
December 26, 2017 15:45
-
-
Save nathan130200/b7339c77df87c93a16fb8799b1b71fcd to your computer and use it in GitHub Desktop.
Program.cs
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
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