public void ShouldFormatWithException() { DateTime dateTime; UnicastLogger logger; MockedUnicastReceiver receiver; receiver = new MockedUnicastReceiver(3023); logger = new UnicastLogger(IPAddress.Parse("127.0.0.1"), 3023); dateTime = DateTime.Now; logger.Log(1, "Component", "Method", new Exception("Message1")); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(1, receiver.Logs.Count); Assert.AreEqual("Message1", receiver.Logs[0].Message); dateTime = DateTime.Now; logger.Log(1, "Component", "Method", new Exception("Message2")); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(2, receiver.Logs.Count); Assert.AreEqual("Message2", receiver.Logs[1].Message); logger.Dispose(); receiver.Dispose(); }
public void ShouldFormatWithValidInput() { DateTime dateTime; UnicastLogger logger; MockedUnicastReceiver receiver; receiver = new MockedUnicastReceiver(3021); logger = new UnicastLogger(IPAddress.Parse("127.0.0.1"), 3021); dateTime = DateTime.Now; logger.Log(1, "Component", "Method", LogLevels.Debug, "Message0"); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(1, receiver.Logs.Count); Assert.AreEqual("Message0", receiver.Logs[0].Message); dateTime = DateTime.Now; logger.Log(1, "Component", "Method", LogLevels.Debug, "Message1"); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(2, receiver.Logs.Count); Assert.AreEqual("Message1", receiver.Logs[1].Message); dateTime = DateTime.Now; logger.Log(new Log(dateTime, 1, "Component", "Method", LogLevels.Debug, "Message2")); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(3, receiver.Logs.Count); Assert.AreEqual("Message2", receiver.Logs[2].Message); logger.Dispose(); receiver.Dispose(); }
public void ShouldFormatWithNullInput() { DateTime dateTime; UnicastLogger logger; MockedUnicastReceiver receiver; receiver = new MockedUnicastReceiver(3022); logger = new UnicastLogger(IPAddress.Parse("127.0.0.1"), 3022); dateTime = DateTime.Now; logger.Log(1, null, null, LogLevels.Debug, null); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(1, receiver.Logs.Count); Assert.AreEqual(null, receiver.Logs[0].Message); dateTime = DateTime.Now; logger.Log(1, null, null, LogLevels.Debug, null); receiver.ReceivedEvent.WaitOne(); Assert.AreEqual(2, receiver.Logs.Count); Assert.AreEqual(null, receiver.Logs[1].Message); logger.Dispose(); receiver.Dispose(); }
public void ShouldFormatWithValidInputWhenNoReceiverIsRunning() { DateTime dateTime; UnicastLogger logger; logger = new UnicastLogger(IPAddress.Parse("127.0.0.1"), 3020); dateTime = DateTime.Now; logger.Log(1, "Component", "Method", LogLevels.Debug, "Message"); logger.Dispose(); }
static void Main(string[] args) { ILogger logger; VersionControlModule versionControlModule; //ServiceHostModule serviceHostModule; //IBotsService service; RESTServer server; IRouteManager routeManager; IDatabase database; IConnectionFactory connectionFactory; ICommandBuilder commandBuilder; IDatabaseCreator databaseCreator; IBotModule botModule; IOrderModule orderModule; IOrderManagerModule orderManagerModule; IProduceOrderModule produceOrderModule; IHarvestOrderModule harvestOrderModule; IBuildOrderModule buildOrderModule; IBotSchedulerModule botSchedulerModule; PIOServiceClient client; quitEvent = new AutoResetEvent(false); Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); //logger = new ConsoleLogger(new DefaultLogFormatter()); logger = new UnicastLogger(IPAddress.Loopback, Properties.Settings.Default.UnicastPort); //logger = new FileLogger(new DefaultLogFormatter(), "PIO.Bots.ServerHost.Log"); databaseCreator = new SqlDatabaseCreator(Properties.Settings.Default.Server, Properties.Settings.Default.DatabaseName); connectionFactory = new SqlConnectionFactory(Properties.Settings.Default.Server, Properties.Settings.Default.DatabaseName); commandBuilder = new SqlCommandBuilder(); database = new Database(connectionFactory, commandBuilder); versionControlModule = new VersionControlModule(logger, databaseCreator, new BotsVersionControl(database)); if (!versionControlModule.InitializeDatabase(Properties.Settings.Default.DropDatabase)) { Console.ReadLine(); return; } client = new PIOServiceClient(new BasicHttpBinding(), new EndpointAddress($@"http://127.0.0.1:8733/PIO/Service/")); client.Open(); botModule = new BotModule(logger, database); orderModule = new OrderModule(logger, database); produceOrderModule = new ProduceOrderModule(logger, database); harvestOrderModule = new HarvestOrderModule(logger, database); buildOrderModule = new BuildOrderModule(logger, database); orderManagerModule = new OrderManagerModule(logger, client, orderModule, produceOrderModule, harvestOrderModule, buildOrderModule, 10); botSchedulerModule = new BotSchedulerModule(logger, client, botModule, orderManagerModule, 5); botSchedulerModule.Start(); routeManager = new RouteManager(new RouteParser(), new ResponseSerializer()); routeManager.AddRouteHandler(new BotRouteHandler(botModule)); routeManager.AddRouteHandler(new ProduceOrderRouteHandler(produceOrderModule)); routeManager.AddRouteHandler(new HarvestOrderRouteHandler(harvestOrderModule)); routeManager.AddRouteHandler(new BuildOrderRouteHandler(buildOrderModule)); server = new RESTServer(logger, routeManager, "http://127.0.0.1:8734/"); server.Start(); WaitHandle.WaitAny(new WaitHandle[] { quitEvent }, -1); server.Stop(); //serviceHostModule.Stop(); botSchedulerModule.Stop(); client.Close(); logger.Dispose(); Console.CancelKeyPress -= new ConsoleCancelEventHandler(Console_CancelKeyPress); }