static void Main(string[] args) { bool dontConnectToTwitch = false; bool isDebug = false; string customConfigurationPath = null; string customSoundsPath = null; string logPath = "log/"; string port = null; foreach (var arg in args) { if (arg == "-notwitch") { dontConnectToTwitch = true; continue; } if (arg == "-debug") { isDebug = true; continue; } if (arg.StartsWith("-ccp:")) { customConfigurationPath = arg.Split(':')[1]; continue; } if (arg.StartsWith("-csp:")) { customSoundsPath = arg.Split(':')[1]; continue; } if (arg.StartsWith("-l:")) { logPath = arg.Split(':')[1]; } if (arg.StartsWith("-port:")) { port = arg.Split(':')[1]; } } var botArguments = new BotArguments(isDebug, dontConnectToTwitch, port, customConfigurationPath, customSoundsPath, logPath); using (var bot = new Bot()) { bot.Execute(botArguments); LookForExit(bot); } }
private void RegisterSoundPathProvider(BotArguments botArguments) { if (botArguments.HasCustomSoundsPath) { CustomSoundPathProvider custom = new CustomSoundPathProvider(botArguments.CustomSoundsPath); container.Register(Component.For <ISoundPathProvider>().Instance(custom).Named("_CustomSound").IsDefault().Interceptors <LoggingInterceptor>()); } else { container.Register(Component.For <ISoundPathProvider>().ImplementedBy <DefaultSoundPathProvider>().Named("_CustomSound").IsDefault().Interceptors <LoggingInterceptor>()); } }
private void RegisterLogger(BotArguments botArguments) { var configuration = new LoggerConfiguration().MinimumLevel.Verbose() .WriteTo.RollingFile( Path.Combine(botArguments.LogPath, "botbrown-{Date}.log"), botArguments.IsDebug ? Serilog.Events.LogEventLevel.Debug : Serilog.Events.LogEventLevel.Verbose, "({Timestamp:HH:mm:ss.fff}|{Level:u3}|{SourceContext}) {Message}{NewLine}{Exception}" ).WriteTo.Console( botArguments.IsDebug ? Serilog.Events.LogEventLevel.Debug : Serilog.Events.LogEventLevel.Verbose, "({Timestamp:HH:mm:ss.fff}|{Level:u3}|{SourceContext}) {Message}{NewLine}{Exception}"); Log.Logger = configuration.CreateLogger(); AppDomain.CurrentDomain.ProcessExit += (s, e) => Log.CloseAndFlush(); container.Register(Component.For <ILogger>().LifestyleSingleton().Instance(Log.Logger)); }
public void Execute(BotArguments botArguments) { container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel)); container.Register(Classes.FromThisAssembly().InNamespace("BotBrown", true) .Unless(type => type == typeof(LoggingInterceptor)) .WithServiceAllInterfaces() .Configure(x => x.Interceptors <LoggingInterceptor>())); container.Register(Component.For <LoggingInterceptor>().ImplementedBy <LoggingInterceptor>().IsDefault()); container.Register(Classes.FromThisAssembly().BasedOn(typeof(IConfigurationFileFactory <>)).WithService.Base().Configure(x => x.Interceptors <LoggingInterceptor>())); container.Register(Classes.FromThisAssembly().BasedOn(typeof(IChatCommand)).WithService.Base().Configure(x => x.Interceptors <LoggingInterceptor>())); RegisterConfigurationPathProvider(botArguments); RegisterSoundPathProvider(botArguments); RegisterLogger(botArguments); workerHost = container.Resolve <IWorkerHost>(); workerHost.Container = container; workerHost.Execute(cancellationTokenSource.Token, botArguments); }
protected static void Run(BotArguments botArguments) { using (var bot = new Bot()) using (var window = new Window()) { bot.Execute(botArguments); window.UseBrowserTitle = false; window.Title = "Bot Brown"; window.CanResize = true; window.SetWindowState(WindowState.Maximized); window.Icon = AppIcon.FromFile("botbrown", "."); window.EnableDevTools = false; // this relates to the path defined in the .csproj file Application.ContentProvider = new EmbeddedContentProvider("App"); string port = botArguments.Port ?? (botArguments.IsDebug ? WebserverConstants.DebugPort : WebserverConstants.ProductivePort); Application.Run(window, $"http://localhost:{port}"); } }