public static void Start () { List<DBLaneNotification> lane_notifications = new List<DBLaneNotification> (); lock (lock_obj) { using (DB db = new DB ()) { using (IDbCommand cmd = db.CreateCommand ()) { /* Only select the notifications that are actually in use */ cmd.CommandText = "SELECT Notification.* FROM Notification WHERE id IN (SELECT DISTINCT notification_id FROM LaneNotification);"; cmd.CommandText += "SELECT * FROM LaneNotification;"; using (IDataReader reader = cmd.ExecuteReader ()) { while (reader.Read ()) { DBNotification n = new DBNotification (reader); if (n.ircidentity_id.HasValue) { log.Info ("Starting irc notification"); notifications.Add (new IrcNotification (n)); } else if (n.emailidentity_id.HasValue) { log.Info ("Starting email notification"); notifications.Add (new EMailNotification (n)); } else if (n.githubidentity_id.HasValue) { log.Info ("Starting GitHub notification"); notifications.Add (new GitHubNotification (n)); } else { log.ErrorFormat ("Unknown notification (id: {0})", n.id); } } reader.NextResult (); while (reader.Read ()) { lane_notifications.Add (new DBLaneNotification (reader)); } } } } foreach (DBLaneNotification ln in lane_notifications) { List<NotificationBase> ns; NotificationBase n; if (!notifications_per_lane.TryGetValue (ln.lane_id, out ns)) { ns = new List<NotificationBase> (); notifications_per_lane [ln.lane_id] = ns; } n = notifications.First ((v) => v.Notification.id == ln.notification_id); ns.Add (n); log.InfoFormat ("enabled notification {0} '{1}' for lane {2}", n.Notification.id, n.Notification.name, ln.lane_id); } } if (notifier_thread == null) { queued_notifications = new BlockingCollection<QueuedNotification> (); notifier_thread = new Thread (NotificationProcessor); notifier_thread.IsBackground = true; notifier_thread.Start (); } }
public GitHubNotification (DBNotification notification) : base (notification) { using (var db = new DB ()) using (var cmd = db.CreateCommand ()) { cmd.CommandText = @"SELECT username, token FROM githubidentity WHERE id = @id;"; DB.CreateParameter (cmd, "id", notification.githubidentity_id); using (var reader = cmd.ExecuteReader ()) { reader.Read (); username = reader.GetString (0); token = reader.GetString (1); } } }
public EMailNotification (DBNotification notification) : base (notification) { using (DB db = new DB ()) { using (IDbCommand cmd = db.CreateCommand ()) { cmd.CommandText = "SELECT * FROM EmailIdentity WHERE id = @id;"; DB.CreateParameter (cmd, "id", notification.emailidentity_id.Value); using (IDataReader reader = cmd.ExecuteReader ()) { if (!reader.Read ()) throw new ApplicationException (string.Format ("Could not find the email identity {0}", notification.emailidentity_id.Value)); identity = new DBEmailIdentity (reader); } } } emails = string.IsNullOrWhiteSpace (identity.email) ? new string[0] : identity.email.Split(','); }
public IrcNotification (DBNotification notification) : base (notification) { /* Connect to server and join channels */ using (DB db = new DB ()) { using (IDbCommand cmd = db.CreateCommand ()) { cmd.CommandText = "SELECT * FROM IrcIdentity WHERE id = @id;"; DB.CreateParameter (cmd, "id", notification.ircidentity_id.Value); using (IDataReader reader = cmd.ExecuteReader ()) { if (!reader.Read ()) throw new ApplicationException (string.Format ("Could not find the irc identity {0}", notification.ircidentity_id.Value)); identity = new DBIrcIdentity (reader); } } } }
public static void Start () { List<DBLaneNotification> lane_notifications = new List<DBLaneNotification> (); lock (lock_obj) { using (DB db = new DB ()) { using (IDbCommand cmd = db.CreateCommand ()) { /* Only select the notifications that are actually in use */ cmd.CommandText = "SELECT Notification.* FROM Notification WHERE id IN (SELECT DISTINCT notification_id FROM LaneNotification);"; cmd.CommandText += "SELECT * FROM LaneNotification;"; using (IDataReader reader = cmd.ExecuteReader ()) { while (reader.Read ()) { DBNotification n = new DBNotification (reader); if (n.ircidentity_id.HasValue) { Logger.Log ("Starting irc notification"); notifications.Add (new IrcNotification (n)); } else if (n.emailidentity_id.HasValue) { Logger.Log ("Starting email notification"); notifications.Add (new EMailNotification (n)); } else { Logger.Log ("Starting unknown notification"); } } if (reader.NextResult ()) { while (reader.Read ()) { lane_notifications.Add (new DBLaneNotification (reader)); } } } } } foreach (DBLaneNotification ln in lane_notifications) { List<NotificationBase> ns; NotificationBase n; if (!notifications_per_lane.TryGetValue (ln.lane_id, out ns)) { ns = new List<NotificationBase> (); notifications_per_lane [ln.lane_id] = ns; } n = notifications.First ((v) => v.Notification.id == ln.notification_id); ns.Add (n); Logger.Log ("Notifications: enabled notification {0} '{1}' for lane {2}", n.Notification.id, n.Notification.name, ln.lane_id); } } }
public WebServiceResponse EditNotification (WebServiceLogin login, DBNotification notification) { WebServiceResponse response = new WebServiceResponse (); using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); notification.Save (db); Notifications.Restart (); } return response; }
protected NotificationBase (DBNotification notification) { Notification = notification; }
public EMailNotification (DBNotification notification) : base (notification) { /* nothing to do here really */ }
protected void lnkAdd_Click (object sender, EventArgs e) { DBNotification notification = new DBNotification (); WebServiceResponse response; try { notification.mode = int.Parse (cmbMode.SelectedValue); notification.name = txtName.Text; notification.type = int.Parse (cmbNotificationType.SelectedValue); } catch (FormatException) { lblMessage.Text = "Invalid number"; return; } catch (OverflowException) { lblMessage.Text = "Invalid number"; return; } try { var match = IDENT_RE.Match (cmbIdentity.SelectedItem.Value); if (!match.Success) throw new ValidationException ("Invalid identity"); var type = match.Groups[1].Value; var id = int.Parse(match.Groups[2].Value); if (type == "IRC") notification.ircidentity_id = id; else if (type == "Email") notification.emailidentity_id = id; else if (type == "GitHub") notification.githubidentity_id = id; else throw new ValidationException ("Invalid identity"); if (string.IsNullOrEmpty (notification.name)) throw new ValidationException ("You need to specify the name of the notification"); response = Utils.LocalWebService.EditNotification (Master.WebServiceLogin, notification); } catch (ValidationException ex) { lblMessage.Text = ex.Message; return; } if (response.Exception != null) { lblMessage.Text = response.Exception.Message; } else { Response.Redirect ("Notifications.aspx", false); } }
public WebServiceResponse EditNotification (WebServiceLogin login, DBNotification notification) { WebServiceResponse response = new WebServiceResponse (); try { using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); notification.Save (db); } } catch (Exception ex) { response.Exception = new WebServiceException (ex); } return response; }