//Connects to the server and logs the message. private bool logToServer(string message) { if (m_server.State != MongoServerState.Connected) m_server.Connect(); string hostName = Dns.GetHostName(); string databaseName = Settings.Store.Database; string table = Settings.Store.EventTable; string machine = Environment.MachineName; var database = m_server.GetDatabase(databaseName); var collection = database.GetCollection<Event>(table); var pGinaEvent = new Event { TimeStamp = DateTime.UtcNow, Host = hostName, Ip = getIPAddress(), Machine = machine, Message = message }; m_logger.DebugFormat("Logging: {0}", message); collection.Insert(pGinaEvent); m_logger.DebugFormat("Event logged: {1}", message); return true; }
//Tests the table based on the registry data. Returns a string indicating the table status. public string TestTable() { if (m_server == null) throw new InvalidOperationException("No MongoDB Connection present."); if (m_server.State != MongoServerState.Connected) m_server.Connect(); string databaseName = Settings.Store.Database; string table = Settings.Store.EventTable; var database = m_server.GetDatabase(databaseName); var collection = database.GetCollection<Event>(table); var pGinaEvent = new Event { Host = "test"}; collection.Insert(pGinaEvent); return "Table exists and is setup correctly."; }