/// <summary> /// Save events / exceptions on this page /// </summary> private void SaveExceptions(string message, string method) { using (var db = new PersistedRepository()) { var evlog = new EventLog { EventLogTime = DateTime.Now, Message = message, PlayerId = 0, AccessCode = LblAccessCode.Text, Page = "default", PageStep = 0, Method = method }; db.Add(evlog); } }
/// <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> /// 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 entry to questions /// </summary> private void AddResponse(string accessCode) { using (var db = new PersistedRepository()) { var question = db.Questionnaires.FirstOrDefault(q => q.AccessCode.Equals(LblAccessCode.Text)); if (question == null) { db.Add(new Questionnaire { AccessCode = accessCode }); db.Save(); } } }
/// <summary> /// Generate new code for the debug / testing / auto mode /// </summary> /// <returns></returns> public string AutoAccessCode() { // Genereate a new access code var ac = System.Guid.NewGuid().ToString().Replace("-", ""); // Exit code must be invalid on auto code var ec = "invalid"; // Add the code to the database using (var db = new PersistedRepository()) { var code = new Code { AccessCode = ac, ExitCode = ec }; db.Add(code); db.Save(); } // Return the access code return ac; }