Guest User

Untitled

a guest
Dec 31st, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using SkyLar.Config;
  2. using System;
  3. using System.IO;
  4. using System.Xml.Serialization;
  5. using SkyLar.Extensions;
  6. using Autofac.Core;
  7. using Autofac;
  8. using SkyLar.Services;
  9.  
  10. namespace SkyLar
  11. {
  12. public class Program
  13. {
  14. public static IContainer Services {
  15. private set;
  16. get;
  17. }
  18.  
  19. static SkyLarConfig Config {
  20. set;
  21. get;
  22. }
  23.  
  24. static void Main(string[] args)
  25. {
  26. if (File.Exists(Directory.GetCurrentDirectory() + @"\Config.xml"))
  27. {
  28. using (var fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config.xml", FileMode.Open))
  29. {
  30. XmlSerializer xs = new XmlSerializer(typeof(SkyLarConfig));
  31. Config = xs.Deserialize<SkyLarConfig>(fs);
  32.  
  33. if (Config != null)
  34. {
  35. var builder = new ContainerBuilder();
  36. {
  37. builder.RegisterInstance(Config).SingleInstance();
  38. builder.RegisterType<SkyLarLogBack>().SingleInstance();
  39. builder.RegisterType<SkyLarBot>().SingleInstance();
  40. }
  41. Services = builder.Build();
  42.  
  43. Services.Resolve<SkyLarBot>().StartAsync().ContinueWith(task =>
  44. {
  45. if (task.IsCompleted)
  46. {
  47. while (true);
  48. }
  49. }).Wait();
  50. }
  51. }
  52. }
  53. else
  54. {
  55. using (var fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config.xml", FileMode.Create))
  56. {
  57. var config = new SkyLarConfig
  58. {
  59. Token = "",
  60. TokenType = DSharpPlus.TokenType.Bot,
  61. AutoReconnect = true,
  62. LogLevel = DSharpPlus.LogLevel.Debug,
  63. DatabaseConfig = new DatabaseConfig
  64. {
  65. Host = "127.0.0.1",
  66. Port = 6969,
  67. Username = "",
  68. Password = "",
  69. Database = "",
  70. }
  71. };
  72.  
  73. XmlSerializer xs = new XmlSerializer(typeof(SkyLarConfig));
  74. xs.Serialize(fs, config);
  75.  
  76. Environment.Exit(3);
  77. }
  78. }
  79. }
  80.  
  81. /// <summary>
  82. /// Constructor
  83. /// </summary>
  84. public Program()
  85. {
  86.  
  87. }
  88. }
  89. }
Add Comment
Please, Sign In to add comment