/// <summary> /// Save hub message and sends it to admin /// </summary> /// <param name="gridId">GridId</param> /// <param name="accessCode">Access Code</param> /// <param name="message">The message</param> /// <returns></returns> private async Task HubMessageAsync(int gridId, string accessCode, string message, string method, long runtime, int verbosity) { using (var db = new PersistedRepository()) { // Add to message log var messageLog = new MessageLog(gridId, accessCode, message, method, runtime); db.Add(messageLog); db.Save(); } if(_segregLoop.Engine.Verbosity >= verbosity) { // Send to admin await AdminMessageAsync(message); } }
/// <summary> /// Adds message to log and broadcasts to admin /// </summary> /// <param name="g">The calling grid.</param> /// <param name="message">The message to save to the log file.</param> /// <param name="method">The method that called the grid message.</param> /// <param name="runtime">Runtime of the calling method.</param> /// <param name="verbosity">Verbosity level</param> private async Task GridMessageAsync(Grid g, string message, string method, long runtime, int verbosity) { using (var db = new PersistedRepository()) { // Add to message log var messageLog = new MessageLog(g, message, method, runtime); db.Add(messageLog); await db.SaveAsync(); } if(_engine.Verbosity >= verbosity) { // Send to admin string adminMessage = string.Format("Grid {0} : {1} : {2} : {3} [{4}]", g.GridId, g.GridState, g.Round, message, runtime); if (verbosity < 2) AdminMessage(adminMessage); } }
/// <summary> /// Remove a message log entry from database /// </summary> public void Remove(MessageLog messageLog) { db.MessageLogs.Remove(messageLog); db.SaveChanges(); }
/// <summary> /// Send Message to Console and Log /// </summary> /// <param name="g"></param> /// <param name="message"></param> /// <param name="method"></param> /// <param name="runtime"></param> public void GridMessageAsync(Grid g, string message, string method, long runtime, int debugLevel) { if (debugLevel <= DebugLevel) { if (DebugMethod.Length > 0) { if (DebugMethod == method) { // Send to admin string adminMessage = string.Format("Grid {0} : {1} : {2} : {3} [{4}]", g.GridId, g.GridState, g.Round, message, runtime); Console.WriteLine(adminMessage); } } else { // Send to admin string adminMessage = string.Format("Grid {0} : {1} : {2} : {3} [{4}]", g.GridId, g.GridState, g.Round, message, runtime); Console.WriteLine(adminMessage); } if (Logging) { using (var db = new PersistedRepository(Connect)) { // Add to message log var messageLog = new MessageLog(g, message, method, runtime); db.Add(messageLog); db.Save(); } } } }
/// <summary> /// Add a message log entry to the database /// </summary> public void Add(MessageLog messageLog) { db.MessageLogs.Add(messageLog); db.SaveChanges(); }