Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment