private void stringSaveMessage(ChatSharp.Events.PrivateMessageEventArgs e) { try { using (var DB = new internetEntities()) { irkki testRow = new irkki { viesti = e.PrivateMessage.Message, nick = e.PrivateMessage.User.Nick, kanava = e.PrivateMessage.Source, aika = DateTime.Now, maara = 1 }; DB.irkki.Add(testRow); DB.SaveChanges(); } } catch (Exception eip) { try { using (var DB = new internetEntities()) { DB.logs.Add(new logs { message = e.ToString(), severity = 1 }); DB.SaveChanges(); } } catch (Exception se) { } } }
private irkki getRand(string channel, string like, string messageTarget = "") { try { using (var DB = new internetEntities()) { List <string> sent_rands = DB.rand_messages.Where(x => (messageTarget == "" || x.initiator == messageTarget) && x.kanava == channel).Select(x => x.message).ToList(); List <irkki> tList = null; tList = DB.irkki.Where(x => x.viesti != "x" && !x.viesti.StartsWith("!random") && (like == "" || x.viesti.Contains(like)) && x.kanava.ToLower() == channel.ToLower() && (!sent_rands.Contains(x.viesti))).OrderBy(x => Guid.NewGuid()).Take(1).ToList(); irkki mes = null; if (tList.Any()) { mes = tList.First(); storeRandMessageToBuffer(mes, null, messageTarget); return(mes); } else { return(null); } } } catch (Exception e) { return(null); } }
private string random(string channel, string like = "", bool onlyOld = false, string messageTarget = "") { string rand = ""; irkki mes = null; irkki_old oldMes = null; try { using (var DB = new internetEntities()) { double countOld = DB.irkki_old.Count(); double countNew = DB.irkki.Where(x => x.viesti != "x").Count(); double total = countOld + countNew; double limit = rnd1.NextDouble(); if (onlyOld || (limit < countOld / total)) //Old { oldMes = getOldRand(channel, like, messageTarget); if (oldMes != null) { rand = formRandomMessage(oldMes.aika.Value, oldMes.nick, oldMes.viesti); } else { mes = getRand(channel, like, messageTarget); if (mes != null) { rand = formRandomMessage(mes.aika.Value, mes.nick, mes.viesti); } } } else // new { mes = getRand(channel, like, messageTarget); if (mes != null) { rand = formRandomMessage(mes.aika.Value, mes.nick, mes.viesti); } else { oldMes = getOldRand(channel, like, messageTarget); if (oldMes != null) { rand = formRandomMessage(oldMes.aika.Value, oldMes.nick, oldMes.viesti); } } } } } catch (Exception e) { helperClass.writeLog("Virhe random()-metodissa. Virheviesti: " + e.ToString(), 4); } return(rand); }
public void updateJobs() { using (var db = new internetEntities()) { //Kannan vertaus tallessa olevaan paskaan. foreach (var s in db.timing_table) { try { //Löytyykö jo listalta? if (trigger_job_list.Where(x => x.rowid == s.rowid).Any()) { //Tarkistetaan päivityksen tarve ja jos on tarpeen, päivitetään. TriggerJobViewModel j = trigger_job_list.Where(x => x.rowid == s.rowid).First(); if (j.trigger_time != s.trigger_time) { sched.DeleteJob(j.job.Key); trigger_job_list.Remove(j); TriggerJobViewModel m = createJobAndTrigger(s); trigger_job_list.Add(m); sched.ScheduleJob(m.job, m.trigger); } } else { //Lisätään tämä TriggerJobViewModel m = createJobAndTrigger(s); trigger_job_list.Add(m); sched.ScheduleJob(m.job, m.trigger); } } catch (Exception e) { helperClass.writeLog(e.ToString(), 4); } } //Tallessa olevan paskan vertaus kantaan. List <TriggerJobViewModel> tmpList = trigger_job_list.ToList(); foreach (var s in tmpList) { try { if (!db.timing_table.Where(x => x.rowid == s.rowid).Any()) //Jos ei löydy, niin helvettiin koko paska. { sched.DeleteJob(s.job.Key); trigger_job_list.Remove(s); } } catch (Exception e) { helperClass.writeLog(e.ToString(), 4); } } } }
public static void writeLog(string message, int severity) { try { using (var DB = new internetEntities()) { DB.logs.Add(new logs { message = message, severity = severity, timestamp = DateTime.Now }); DB.SaveChanges(); } } catch (Exception e) { } }
private void sendMessagesForTrigger(Int64 timing_ID, ref IRCListener irc_bot) { using (var db = new internetEntities()) { foreach (var m in db.timed_messages.Where(x => x.timing_ID == timing_ID)) { try { irc_bot.sendMessage(m.channel, m.message); } catch (Exception e) { helperClass.writeLog(e.ToString(), 3); } } } }
private void logMessage(IrcEventArgs e) { try { using (var DB = new internetEntities()) { irkki testRow = new irkki { viesti = e.Data.Message, nick = e.Data.Nick, kanava = e.Data.Channel, aika = DateTime.Now, maara = 1 }; DB.irkki.Add(testRow); DB.SaveChanges(); } } catch (Exception eip) { } }
//Ajetaan alussa. private void fillTriggersAndJobs() { try { using (var db = new internetEntities()) { foreach (var s in db.timing_table) { try { //Jobi kullekin. IJobDetail job = createJob(s); //Samaten triggeri. ITrigger t = createTrigger(s); //Lisätään triggeri ja jobi listalle. trigger_job_list.Add(new TriggerJobViewModel { job = job, trigger = t, rowid = s.rowid, trigger_time = s.trigger_time }); } catch (Exception e) { } } } } catch (Exception e) { } }
private string get_stats(string channel, int?range, int choise = 0) { try { string insertNick = ""; List <F_Get_Stats_Result> stats = new List <F_Get_Stats_Result>(); DateTime end = DateTime.Now; DateTime start = DateTime.Now; if (range != null && range > 0) { start = end.AddDays(-1 * range.Value); } else { start = new DateTime(end.Year, end.Month, end.Day); } using (var db = new internetEntities()) { stats = db.F_Get_Stats(start, channel, choise).OrderByDescending(x => x.count).Take(10).ToList(); } string retVal = ""; foreach (var s in stats) { if (retVal.Length > 0) { retVal += ", "; } //Lisätään kontrollimerkki, jotta rivit eivät hilittaa. retVal += remove_hilite(s.nick) + ": " + s.count.ToString(); } return(retVal); } catch (Exception e) { helperClass.writeLog("Virhe haettaessa tilastoja! Viesti: " + e.ToString(), 4); return(""); } }