//Insert Daily Log public void insertLog(string description, string logType, string stID, int LogID) { try { using (var context = new STHookEntities()) { var STHookLog = context.STHookLog.Find(LogID); var DailyLog = context.DailyLog.Add(new DailyLog { ServiceTradeId = stID, Description = description, TimeStamp = System.DateTime.Now, logType = logType }); STHookLog.DailyLog.Add(DailyLog); context.SaveChanges(); } } catch { } }
//Update SMTP Settings public bool updateSMTPSettings(int Id, bool enableSSL, string port, string host, string username, string email, string password) { bool success = false; STHookEntities context = new STHookEntities(); var smtpSettings = context.SMTPSettings.SingleOrDefault(s => s.id == Id); try { if (smtpSettings != null) { smtpSettings.SMTPEnableSSL = enableSSL; smtpSettings.SMTPPort = port; smtpSettings.SMTPHost = host; smtpSettings.SMTPUsername = username; smtpSettings.SMTPNotificationEmail = email; smtpSettings.SMTPPassword = password; context.SaveChanges(); success = true; } } catch { success = false; } return(success); }
//Get the SMTP Settings Detail public SMTPSettings getSMTPDetail() { STHookEntities context = new STHookEntities(); var smtpSettings = (from s in context.SMTPSettings select s ).FirstOrDefault(); return(smtpSettings); }
//Get current connection String for JDE public HookCredentials ServiceTradeSettings() { STHookEntities context = new STHookEntities(); var hook = (from h in context.HookCredentials select h ).FirstOrDefault(); return(hook); }
//Get Log by Date public void getLogByDate(DateTime date, RadGridView rdLog) { STHookEntities context = new STHookEntities(); var logs = (from l in context.DailyLog where DbFunctions.TruncateTime(l.TimeStamp) == date.Date select new { l.ServiceTradeId, l.TimeStamp, l.Description, l.logType }).ToList(); rdLog.DataSource = logs; bestFitRadGridView(rdLog); }
//Query Top 7 Main Log entry public void getMainLog(RadGridView rdg) { STHookEntities context = new STHookEntities(); var log = (from l in context.STHookLog.Take(7) orderby l.LogID descending select new { l.LogID, l.TimeStamp }).ToList(); rdg.DataSource = log; bestFitRadGridView(rdg); }
//get Hook Credentials public HookCredentials getHookSettings() { STHookEntities context = new STHookEntities(); var hookSettings = (from h in context.HookCredentials select h ).FirstOrDefault(); return(hookSettings); }
//Get ID of logs that ran last public int getLogIDforLastRun() { STHookEntities context = new STHookEntities(); var log = (from l in context.STHookLog orderby l.LogID descending select l ).FirstOrDefault(); return(log.LogID); }
private void Form1_Load(object sender, EventArgs e) { STHookEntities context = new STHookEntities(); var query = from l in context.DailyLog select l; var logs = query.ToList(); rdLog.DataSource = logs; // dataGridView1.DataSource = logs; }
//Get Logs by log ID public List <DailyLog> getLogsByLogIdManual(int logId) { STHookEntities context = new STHookEntities(); var logs = (from l in context.DailyLog where (l.STHookLog.LogID) == logId select l ).ToList(); return(logs); }
//Check the Operation Mode for the Service Trade Hook public bool CheckOperationMode() { bool runProductionMode = false; STHookEntities context = new STHookEntities(); var hook = (from h in context.HookCredentials select h ).FirstOrDefault(); if (hook != null) { runProductionMode = Convert.ToBoolean(hook.runProductionMode); } return(runProductionMode); }
public int getExceptionLog() { var count = 0; try { STHookEntities context = new STHookEntities(); var logs = (from l in context.DailyLog where (DbFunctions.TruncateTime(l.TimeStamp) == DateTime.Today.Date) && (l.logType == "Exception Error") select new { l.ServiceTradeId, l.TimeStamp, l.Description, l.logType }).ToList(); count = logs.Count; } catch { } return(count); }
//Get current connection String for JDE public string AS400ConnectionString() { string connectionString = ""; STHookEntities context = new STHookEntities(); var hook = (from h in context.HookCredentials select h ).FirstOrDefault(); if (hook.runProductionMode == true) { connectionString = hook.AS400ConnectionString; } else { connectionString = hook.AS400ConnectionStringTest; } return(connectionString); }
//Get Logs by log ID public void getLogsByLogId(int logId, RadGridView rdLog, Label lblmain) { STHookEntities context = new STHookEntities(); var logs = (from l in context.DailyLog where (l.STHookLog.LogID) == logId select new { l.ServiceTradeId, l.TimeStamp, l.Description, l.logType }).ToList(); var mainLog = (from ml in context.STHookLog where ml.LogID == logId select ml).FirstOrDefault(); if (mainLog != null) { lblmain.Text = "Log ID (" + mainLog.LogID.ToString() + ") / " + mainLog.TimeStamp.ToString(); lblmain.Refresh(); } rdLog.DataSource = logs; bestFitRadGridView(rdLog); }
//Insert Main Log Entry public int insertSTHookLog() { int LogID = 0; try { STHookEntities context = new STHookEntities(); var STHookLog = context.STHookLog.Add(new STHookLog { TimeStamp = System.DateTime.Now }); context.SaveChanges(); //Return LogID LogID = STHookLog.LogID; } catch { } return(LogID); }
//Update Hook Settings public bool updateHookCredentials(int Id, bool runProductionMode, string uri, string username, string password, string connectionstring, string uriTest, string usernameTest, string passwordTest, string connectionstringTest) { bool success = false; STHookEntities context = new STHookEntities(); var hookSettings = context.HookCredentials.SingleOrDefault(h => h.id == Id); try { if (hookSettings != null) { hookSettings.runProductionMode = runProductionMode; hookSettings.ServiceTradeURI = uri; hookSettings.ServiceTradeUserName = username; hookSettings.ServiceTradePassword = password; hookSettings.AS400ConnectionString = connectionstring; hookSettings.ServiceTradeURITest = uriTest; hookSettings.ServiceTradeUserNameTest = usernameTest; hookSettings.ServiceTradePasswordTest = passwordTest; hookSettings.AS400ConnectionStringTest = connectionstringTest; context.SaveChanges(); success = true; } } catch { success = false; } return(success); }
//Send notification after the hook run is completed. public void sendEmail() { string message = ""; string subject = "ST Hook alerts"; //Get SMTP Settings Information STHookEntities context = new STHookEntities(); try { //Get Smtp Settings var smtpSettings = (from s in context.SMTPSettings select s ).FirstOrDefault(); MailMessage mail = new MailMessage("*****@*****.**", smtpSettings.SMTPNotificationEmail); SmtpClient client = new SmtpClient(); client.Port = Convert.ToInt32(smtpSettings.SMTPPort); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = smtpSettings.SMTPHost; client.EnableSsl = Convert.ToBoolean(smtpSettings.SMTPEnableSSL); client.Credentials = new System.Net.NetworkCredential(smtpSettings.SMTPUsername, smtpSettings.SMTPPassword); mail.Subject = subject; //Get Main Log var mainLog = (from l in context.STHookLog orderby l.LogID descending select l ).FirstOrDefault(); if (mainLog != null) { var logs = (from l in context.DailyLog where l.STHookLog.LogID == mainLog.LogID && (l.logType.Contains("Error")) select new { l.ServiceTradeId, l.TimeStamp, l.Description, l.logType }).ToList(); string exceptionLines = " " + Environment.NewLine; if (logs != null) { message = "The ST Migration completed with " + logs.Count.ToString() + " Exceptions" + Environment.NewLine; if (logs.Count >= 1) { // message = "The Migration completed with " + logs.Count.ToString() + " Exceptions" + Environment.NewLine; foreach (var item in logs) { exceptionLines = exceptionLines + string.Format("Service Trade ID: {0} " + Environment.NewLine + "Description: {1}" + Environment.NewLine + "Time Stamp: {2} " + Environment.NewLine + "Log Type: {3}", item.ServiceTradeId.ToString(), item.Description, item.TimeStamp, item.logType.ToString()) + Environment.NewLine + Environment.NewLine; // message = message + item.Description + Environment.NewLine; } } } message = message + exceptionLines; } else { // message = "Migration completed successfully."; } mail.Body = message; mail.BodyEncoding = UTF8Encoding.UTF8; client.Send(mail); } catch { } }