public override void GetNotification(DBNotification _notification) { //TODO if (!_notification.IsSentBySelf) { } }
public static async Task SaveNotificationToDBAsync(int rspHttpCode, string MessageId, Notification rspNotification, string AppIdUri, string ClientUrl, string BearerToken, bool Success) { var DBNotification = new DBNotification { MessageId = MessageId, HttpCode = rspHttpCode, AppIdUri = AppIdUri, ClientUrl = ClientUrl, BearerToken = string.Empty, Success = Success, Notification = rspNotification, Timestamp = DateTime.UtcNow }; var documentDbProvider = new DocumentDBProvider(); try { await documentDbProvider.CreateNotificationAsync(DBNotification); } catch (Exception) { throw; } }
/// <summary> /// Effectue la sauvegarde des proipriétés modifiées des objets représentés /// dans le <see cref="ShContext"/>. /// </summary> public bool Exe() { string _saveChangesQuery = SaveChangesQuery(); if (__connection.ExecuteNonQuery(new NpgsqlCommand(_saveChangesQuery))) { foreach (KeyValuePair <Guid, ClassProxy> _kvp in __inserteds) { _kvp.Value.IsNew = false; } foreach (KeyValuePair <Guid, ClassProxy> _kvp in __updateds) { _kvp.Value.UpdateProxyValues();// suprime le fait qu'un PropertyProxy se dise changé. } if (__connection.NotifyChanges && (__inserteds.Count != 0 || __updateds.Count != 0)) { DBNotification _notification = new DBNotification(); foreach (KeyValuePair <Guid, ClassProxy> _kvp in __inserteds) { _notification.AddEntity(_kvp.Value.TypeName.ToLower(), _kvp.Key); } foreach (KeyValuePair <Guid, ClassProxy> _kvp in __updateds) { _notification.AddEntity(_kvp.Value.TypeName.ToLower(), _kvp.Key); } __connection.Notify(_notification); } return(true); } return(false); }
private void OnNotification(object sender, NpgsqlNotificationEventArgs e) { if (NotificationEvent != null) { DBNotification _notification = DBNotification.Factory(this, e); NotificationEvent.Invoke(_notification); } }
public NotificationPageNotificationViewModel(NotificationsViewModel Page, DBNotification notification) { this.Page = Page; Notification = notification; TypeBox = Notification.Type; MessageBox = Notification.Message; DateBox = Notification.Date.ToString(); }
/// <summary> /// Envoie une notification à tous les utilisateurs connectés à cette db, /// y compris à l'envoyeur. /// <see cref="DBSaveChanges"/> invoque cette méthode lors d'une sauvegarde /// si <see cref="NotifyChanges"/> est mis à true. /// </summary> public bool Notify(DBNotification _notification) { return(true); //if(_notification == null) // throw new ArgumentNullException("_notification"); //_notification.TimeOfDispatch = DateTime.Now; //return ExecuteNonQuery(new NpgsqlCommand("NOTIFY applinotification," + // "'" + _notification.Notification + "';")); }
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 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 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 IActionResult CreateNotification([FromBody] JObject notification) { using (var context = new RevojiDataContext()) { DBNotification dBNotification = new DBNotification(notification); if (dBNotification.AppUserId == -1) { return(BadRequest("app_user_id_required")); } dBNotification.Created = DateTime.Now; context.Add(dBNotification); context.Save(); return(Ok(new Notification(dBNotification))); } }
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(','); }
protected void lnkAdd_Click(object sender, EventArgs e) { WebServiceResponse response; try { DBNotification notification = new DBNotification(); notification.mode = int.Parse(cmbMode.SelectedValue); notification.name = txtName.Text; notification.type = int.Parse(cmbNotificationType.SelectedValue); if (cmbIdentity.SelectedItem.Text.StartsWith("IRC: ")) { notification.ircidentity_id = int.Parse(cmbIdentity.SelectedItem.Value); } else if (cmbIdentity.SelectedItem.Text.StartsWith("Email: ")) { notification.emailidentity_id = int.Parse(cmbIdentity.SelectedItem.Value); } if (string.IsNullOrEmpty(notification.name)) { throw new Exception("You need to specify the name of the notification"); } response = Master.WebService.EditNotification(Master.WebServiceLogin, notification); if (response.Exception != null) { lblMessage.Text = response.Exception.Message; } else { Response.Redirect("Notifications.aspx", false); } } catch (Exception ex) { lblMessage.Text = ex.Message; } }
protected override void OnInit(EventArgs e) { base.OnInit(e); try { TableRow row; GetLaneForEditResponse response; txtID.Attributes ["readonly"] = "readonly"; string action = Request ["action"]; string command_id = Request ["command_id"]; int id; int sequence; int timeout; tblCommands.Visible = true; tblFiles.Visible = true; int.TryParse(Request ["lane_id"], out id); response = Master.WebService.GetLaneForEdit(Master.WebServiceLogin, id, Request ["lane"]); lane = response.Lane; if (lane == null) { Response.Redirect("EditLanes.aspx", false); return; } lblH2.Text = "Lane: " + lane.lane; lblDeletionDirectiveErrors.Visible = false; // find possible parent lanes lstParentLane.Items.Clear(); lstParentLane.Items.Add(new ListItem("None", "0")); foreach (DBLane l in response.Lanes) { if (l.id == lane.id) { continue; } if (Utils.IsDescendentLaneOf(response.Lanes, lane, l, 0)) { continue; // our descendents can't be our parents too. } lstParentLane.Items.Add(new ListItem(l.lane, l.id.ToString())); if (!IsPostBack) { if (lane.parent_lane_id.HasValue && lane.parent_lane_id.Value == l.id) { lstParentLane.SelectedIndex = lstParentLane.Items.Count - 1; } } } if (!IsPostBack) { for (int i = 0; i < cmbSourceControl.Items.Count; i++) { cmbSourceControl.Items [i].Selected = lane.source_control == cmbSourceControl.Items [i].Text; } txtRepository.Text = lane.repository; txtCommitFilter.Text = lane.commit_filter; txtMinRevision.Text = lane.min_revision; txtMaxRevision.Text = lane.max_revision; txtLane.Text = lane.lane; txtID.Text = lane.id.ToString(); // find (direct) child lanes foreach (DBLane l in response.Lanes) { if (l.parent_lane_id.HasValue && l.parent_lane_id.Value == lane.id) { if (!string.IsNullOrEmpty(lblChildLanes.Text)) { lblChildLanes.Text += ", "; } lblChildLanes.Text += string.Format("<a href='EditLane.aspx?lane_id={0}'>{1}</a>", l.id, l.lane); } } chkTraverseMerges.Checked = lane.traverse_merge; chkEnabled.Checked = lane.enabled; } if (!string.IsNullOrEmpty(action)) { switch (action) { case "createFile": Master.WebService.CreateLanefile(Master.WebServiceLogin, lane.id, Request ["filename"]); break; case "addFile": if (int.TryParse(Request ["lanefile_id"], out id)) { Master.WebService.AttachFileToLane(Master.WebServiceLogin, lane.id, id); } break; case "deleteFile": if (int.TryParse(Request ["file_id"], out id)) { Master.WebService.DeattachFileFromLane(Master.WebServiceLogin, lane.id, id); } break; case "editCommandFilename": if (int.TryParse(command_id, out id)) { Master.WebService.EditCommandFilename(Master.WebServiceLogin, id, Request ["filename"]); } break; case "editCommandSequence": if (int.TryParse(command_id, out id)) { if (int.TryParse(Request ["sequence"], out sequence)) { Master.WebService.EditCommandSequence(Master.WebServiceLogin, id, sequence); } } break; case "editCommandArguments": if (int.TryParse(command_id, out id)) { Master.WebService.EditCommandArguments(Master.WebServiceLogin, id, Request ["arguments"]); } break; case "editCommandTimeout": if (int.TryParse(command_id, out id)) { if (int.TryParse(Request ["timeout"], out timeout)) { Master.WebService.EditCommandTimeout(Master.WebServiceLogin, id, timeout); } } break; case "editCommandWorkingDirectory": if (int.TryParse(command_id, out id)) { Master.WebService.EditCommandWorkingDirectory(Master.WebServiceLogin, id, Request ["working_directory"]); } break; case "editCommandUploadFiles": if (int.TryParse(command_id, out id)) { Master.WebService.EditCommandUploadFiles(Master.WebServiceLogin, id, Request ["upload_files"]); } break; case "deletecommand": if (int.TryParse(command_id, out id)) { Master.WebService.DeleteCommand(Master.WebServiceLogin, id); } break; case "switchNonFatal": if (int.TryParse(command_id, out id)) { Master.WebService.SwitchCommandNonFatal(Master.WebServiceLogin, id); } break; case "switchAlwaysExecute": if (int.TryParse(command_id, out id)) { Master.WebService.SwitchCommandAlwaysExecute(Master.WebServiceLogin, id); } break; case "switchInternal": if (int.TryParse(command_id, out id)) { Master.WebService.SwitchCommandInternal(Master.WebServiceLogin, id); } break; case "addCommand": if (!int.TryParse(Request ["sequence"], out sequence)) { sequence = -1; } Master.WebService.AddCommand(Master.WebServiceLogin, lane.id, Request ["command"], false, false, 60, sequence); break; case "switchHostEnabled": if (int.TryParse(Request ["host_id"], out id)) { Master.WebService.SwitchHostEnabledForLane(Master.WebServiceLogin, lane.id, id); } break; case "switchHostHidden": if (int.TryParse(Request ["host_id"], out id)) { Master.WebService.SwitchHostHiddenForLane(Master.WebServiceLogin, lane.id, id); } break; case "removeHost": if (int.TryParse(Request ["host_id"], out id)) { Master.WebService.RemoveHostForLane(Master.WebServiceLogin, lane.id, id); } break; case "addHost": if (int.TryParse(Request ["host_id"], out id)) { Master.WebService.AddHostToLane(Master.WebServiceLogin, lane.id, id); } break; case "addDependency": if (int.TryParse(Request ["dependent_lane_id"], out id)) { int condition; int host_id; if (int.TryParse(Request ["condition"], out condition)) { if (int.TryParse(Request ["dependent_host_id"], out host_id)) { Master.WebService.AddDependencyToLane(Master.WebServiceLogin, lane.id, id, host_id > 0 ? (Nullable <int>)host_id : (Nullable <int>)null, (DBLaneDependencyCondition)condition); } } } break; case "editDependencyFilename": if (int.TryParse(Request ["lanedependency_id"], out id)) { Master.WebService.EditLaneDependencyFilename(Master.WebServiceLogin, id, Request ["filename"]); } break; case "deleteDependency": if (int.TryParse(Request ["dependency_id"], out id)) { Master.WebService.DeleteLaneDependency(Master.WebServiceLogin, id); } break; case "editDependencyDownloads": if (int.TryParse(Request ["lanedependency_id"], out id)) { Master.WebService.EditLaneDependencyDownloads(Master.WebServiceLogin, id, Request ["downloads"]); } break; case "editEnvironmentVariableValue": { int host_id, lane_id; if (int.TryParse(Request ["host_id"], out host_id)) { if (int.TryParse(Request ["lane_id"], out lane_id)) { if (int.TryParse(Request ["id"], out id)) { DBEnvironmentVariable ev = new DBEnvironmentVariable(); ev.id = id; ev.host_id = host_id == 0 ? (int?)null : host_id; ev.lane_id = lane_id == 0 ? (int?)null : lane_id; ev.name = Request ["name"]; ev.value = Request ["value"]; Master.WebService.EditEnvironmentVariable(Master.WebServiceLogin, ev); } } } } break; case "moveCommandToParentLane": { if (int.TryParse(command_id, out id)) { if (response.Lane.parent_lane_id != null) { DBCommand cmd = response.Commands.Find((v) => v.id == id); if (cmd != null) { cmd.lane_id = response.Lane.parent_lane_id.Value; Master.WebService.EditCommand(Master.WebServiceLogin, cmd); } } } } break; default: break; } RedirectToSelf(); return; } // Files var shown_files = new HashSet <int> (); foreach (DBLanefile file in response.Files) { if (shown_files.Contains(file.id)) { continue; } shown_files.Add(file.id); string text = file.name; if (!string.IsNullOrEmpty(file.mime)) { text += " (" + file.mime + ")"; } bool is_inherited = !response.LaneFiles.Exists((v) => v.lane_id == lane.id && v.lanefile_id == file.id); tblFiles.Rows.Add(Utils.CreateTableRow( string.Format("<a href='EditLaneFile.aspx?lane_id={1}&file_id={0}'>{2}</a>", file.id, lane.id, file.name), file.mime, (is_inherited ? string.Empty : string.Format("<a href='EditLane.aspx?lane_id={1}&action=deleteFile&file_id={0}'>Delete</a> ", file.id, lane.id)) + string.Format("<a href='ViewLaneFileHistory.aspx?id={0}'>View history</a>", file.id), string.Join(", ", GetLanesWhereFileIsUsed(file, response).Where((l) => l.id != lane.id).Select((l, s) => string.Format("<a href='EditLane.aspx?lane_id={0}'>{1}</a>", l.id, l.lane)).ToArray()))); if (is_inherited) { tblFiles.Rows [tblFiles.Rows.Count - 1].BackColor = System.Drawing.Color.LightGray; } } tblFiles.Rows.Add(Utils.CreateTableRow( "<input type='text' value='filename' id='txtCreateFileName'></input>", "text/plain", string.Format("<a href='javascript:createFile ({0})'>Add</a>", lane.id), "-" )); StringBuilder existing_files = new StringBuilder(); existing_files.AppendLine("<select id='cmbExistingFiles'>"); response.ExistingFiles.Sort((a, b) => string.Compare(a.name, b.name)); shown_files.Clear(); foreach (DBLanefile file in response.ExistingFiles) { if (shown_files.Contains(file.id)) { continue; } shown_files.Add(file.id); existing_files.AppendFormat("<option value='{1}' title='Used in: {2}'>{0}</option>\n", file.name, file.id, string.Join(", ", GetLanesWhereFileIsUsed(file, response).Select((l, s) => l.lane).ToArray())); } existing_files.AppendLine("</select>"); tblFiles.Rows.Add(Utils.CreateTableRow( existing_files.ToString(), "N/A", string.Format("<a href='javascript:addFile ({0})'>Add</a>", lane.id), "-" )); tblFiles.Visible = true; // commands foreach (DBCommand command in response.Commands) { string filename = command.command; DBLanefile file = Utils.FindFile(response.Files, f => f.name == filename); if (file != null) { filename = string.Format("<a href='EditLaneFile.aspx?lane_id={1}&file_id={0}'>{2}</a>", file.id, lane.id, file.name); } string working_directory = "<em>modify</em>"; if (!string.IsNullOrEmpty(command.working_directory)) { working_directory = command.working_directory; } string upload_files = "<em>modify</em>"; if (!string.IsNullOrEmpty(command.upload_files)) { upload_files = command.upload_files; } bool is_inherited = command.lane_id != lane.id; tblCommands.Rows.Add(Utils.CreateTableRow( string.Format("<a href='javascript:editCommandSequence ({2}, {0}, true, \"{1}\")'>{1}</a>", command.id, command.sequence, lane.id), filename, string.Format("<a href='EditLane.aspx?lane_id={0}&command_id={3}&action=switchAlwaysExecute'>{2}</a>", lane.id, (!command.alwaysexecute).ToString(), command.alwaysexecute ? "yes" : "no", command.id), string.Format("<a href='EditLane.aspx?lane_id={0}&command_id={3}&action=switchNonFatal'>{2}</a>", lane.id, (!command.nonfatal).ToString(), command.nonfatal ? "yes" : "no", command.id), string.Format("<a href='EditLane.aspx?lane_id={0}&command_id={1}&action=switchInternal'>{2}</a>", lane.id, command.id, (command.@internal ? "yes" : "no")), string.Format("<a href='javascript:editCommandFilename ({2}, {0}, true, \"{1}\")'>{1}</a>", command.id, command.filename, lane.id), string.Format("<a href='javascript:editCommandArguments ({2}, {0}, true, \"{1}\")'>{3}</a>", command.id, command.arguments.Replace("\"", "\\\""), lane.id, command.arguments), string.Format("<a href='javascript:editCommandTimeout ({2}, {0}, true, \"{1}\")'>{1} minutes</a>", command.id, command.timeout, lane.id), string.Format("<a href='javascript:editCommandWorkingDirectory ({2}, {0}, true, \"{1}\")'>{3}</a>", command.id, command.working_directory, lane.id, working_directory), string.Format("<a href='javascript:editCommandUploadFiles ({2}, {0}, true, \"{1}\")'>{3}</a>", command.id, command.upload_files, lane.id, upload_files), is_inherited ? "-" : string.Format("<a href='EditLane.aspx?lane_id={0}&action=deletecommand&command_id={1}'>Delete</a>", lane.id, command.id), is_inherited ? string.Format("Inherited from <a href='EditLane.aspx?lane_id={1}'>{0}</a>", response.Lanes.Find((v) => v.id == command.lane_id).lane, command.lane_id) : (lane.parent_lane_id == null ? "-" : string.Format("<a href='EditLane.aspx?lane_id={0}&command_id={1}&action=moveCommandToParentLane'>Move</a> to parent lane", lane.id, command.id, lane.parent_lane_id.Value)))); if (is_inherited) { tblCommands.Rows [tblCommands.Rows.Count - 1].BackColor = System.Drawing.Color.LightGray; } } tblCommands.Rows.Add(Utils.CreateTableRow( (response.Commands.Count * 10).ToString(), string.Format("<input type='text' value='command' id='txtCreateCommand_name'></input>"), "no", "no", "no", "bash", "-ex {0}", "60 minutes", "-", "-", string.Format("<a href='javascript:addCommand ({0}, {1})'>Add</a>", lane.id, response.Commands.Count > 0 ? (response.Commands [response.Commands.Count - 1].sequence + 10) : 0), "-")); // Show all the hosts List <string> current_hosts = new List <string> (); string html; foreach (DBHostLaneView view in response.HostLaneViews) { string ed = view.enabled ? "enabled" : "disabled"; string hid = view.hidden ? "hidden" : "visible"; string @class = ed + " " + hid; row = new TableRow(); row.Cells.Add(Utils.CreateTableCell(string.Format("<a href='EditHost.aspx?host_id={0}'>{1}</a>", view.host_id, view.host), @class)); html = string.Format("<a href='EditLane.aspx?lane_id={0}&host_id={1}&action=removeHost'>Remove</a> ", lane.id, view.host_id); html = html + string.Format("<a href='EditLane.aspx?lane_id={0}&host_id={1}&action=switchHostEnabled'>{2}</a> ", lane.id, view.host_id, (view.enabled ? "Disable" : "Enable")); html = html + string.Format("<a href='EditLane.aspx?lane_id={0}&host_id={1}&action=switchHostHidden'>{2}</a>", lane.id, view.host_id, (view.hidden ? "Show" : "Hide")); row.Cells.Add(Utils.CreateTableCell(html, @class)); tblHosts.Rows.Add(row); current_hosts.Add(view.host); } if (response.Hosts.Count != current_hosts.Count) { row = new TableRow(); html = "<select id='lstHosts'>"; foreach (DBHost host in response.Hosts) { if (!current_hosts.Contains(host.host)) { html += "<option value='" + host.id + "'>" + host.host + "</option>"; } } html += "</select>"; row.Cells.Add(Utils.CreateTableCell(html)); row.Cells.Add(Utils.CreateTableCell(string.Format("<a href='javascript:addHost({0})'>Add</a>", lane.id))); tblHosts.Rows.Add(row); } // dependencies foreach (DBLaneDependency dependency in response.Dependencies) { row = new TableRow(); for (int i = 0; i < response.Lanes.Count; i++) { if (response.Lanes [i].id == dependency.dependent_lane_id) { row.Cells.Add(Utils.CreateTableCell(response.Lanes [i].lane)); break; } } row.Cells.Add(Utils.CreateTableCell(dependency.Condition.ToString())); row.Cells.Add(Utils.CreateTableCell(dependency.dependent_host_id.HasValue ? Utils.FindHost(response.Hosts, dependency.dependent_host_id.Value).host : "Any")); switch (dependency.Condition) { case DBLaneDependencyCondition.DependentLaneSuccessWithFile: row.Cells.Add(Utils.CreateTableCell(string.Format("<a href='javascript: editDependencyFilename ({0}, {1}, \"{2}\")'>{2}</a>", lane.id, dependency.id, string.IsNullOrEmpty(dependency.filename) ? "(edit)" : dependency.filename))); break; case DBLaneDependencyCondition.DependentLaneSuccess: case DBLaneDependencyCondition.DependentLaneIssuesOrSuccess: default: row.Cells.Add(Utils.CreateTableCell("-")); break; } row.Cells.Add(Utils.CreateTableCell(string.Format("<a href='javascript: editDependencyDownloads ({0}, {1}, \"{2}\")'>{3}</a>", lane.id, dependency.id, string.IsNullOrEmpty(dependency.download_files) ? string.Empty : dependency.download_files.Replace("\"", "\\\""), string.IsNullOrEmpty(dependency.download_files) ? "(edit)" : HttpUtility.HtmlEncode(dependency.download_files)))); row.Cells.Add(Utils.CreateTableCell(string.Format("<a href='javascript: deleteDependency ({0}, {1})'>Delete</a>", lane.id, dependency.id))); tblDependencies.Rows.Add(row); } // Create new dependency row row = new TableRow(); html = "<select id='lstDependentLanes'>"; foreach (DBLane l in response.Lanes) { if (l.id == lane.id) { continue; } html += string.Format("<option value='{0}'>{1}</option>", l.id, l.lane); } html += "</select>"; row.Cells.Add(Utils.CreateTableCell(html)); html = "<select id='lstDependencyConditions'>"; foreach (object value in Enum.GetValues(typeof(DBLaneDependencyCondition))) { if ((int)value == 0) { continue; } html += string.Format("<option value='{0}'>{1}</option>", (int)value, value.ToString()); } html += "</select>"; row.Cells.Add(Utils.CreateTableCell(html)); // host html = "<select id='lstDependentHosts'>"; html += "<option value='0'>Any</option>"; foreach (DBHost h in response.Hosts) { html += string.Format("<option value='{0}'>{1}</option>", h.id, h.host); } html += "</select>"; row.Cells.Add(Utils.CreateTableCell(html)); row.Cells.Add(Utils.CreateTableCell(string.Empty)); row.Cells.Add(Utils.CreateTableCell(string.Empty)); row.Cells.Add(Utils.CreateTableCell(string.Format("<a href='javascript:addDependency ({0})'>Add</a>", lane.id))); tblDependencies.Rows.Add(row); // deletion directives foreach (DBLaneDeletionDirectiveView directive in response.LaneDeletionDirectives) { AddDeletionDirectiveRow(directive); } if (response.FileDeletionDirectives != null && response.FileDeletionDirectives.Count > 0) { foreach (DBFileDeletionDirective directive in response.FileDeletionDirectives) { lstDeletionDirectives2.Items.Add(new ListItem(directive.name, directive.id.ToString())); } } else { rowDeletionDirectives2.Visible = false; } foreach (DBDeleteCondition condition in Enum.GetValues(typeof(DBDeleteCondition))) { lstDeletionDirectiveCondition1.Items.Add(new ListItem(condition.ToString(), ((int)condition).ToString())); } foreach (DBMatchMode mode in Enum.GetValues(typeof(DBMatchMode))) { lstDeletionDirectiveGlobs1.Items.Add(new ListItem(mode.ToString(), ((int)mode).ToString())); } editorVariables.Lane = response.Lane; editorVariables.Master = Master; editorVariables.Variables = response.Variables; // notifications foreach (DBLaneNotification ln in response.LaneNotifications.FindAll((v) => v.lane_id == response.Lane.id)) { DBNotification notification = response.Notifications.Find((v) => v.id == ln.notification_id); tblNotifications.Rows.AddAt(tblNotifications.Rows.Count - 1, Utils.CreateTableRow(Utils.CreateTableCell(notification.name), Utils.CreateTableCell(Utils.CreateLinkButton("remove_notification_" + ln.id.ToString(), "Remove", "RemoveNotification", ln.id.ToString(), OnLinkButtonCommand)))); } foreach (DBNotification notification in response.Notifications.FindAll((v) => !response.LaneNotifications.Exists((ln) => ln.notification_id == v.id && ln.lane_id == response.Lane.id))) { cmbNotifications.Items.Add(new ListItem(notification.name, notification.id.ToString())); } } catch (Exception ex) { lblMessage.Text = ex.ToString().Replace("\n", "<br/>"); } }
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 EMailNotification(DBNotification notification) : base(notification) { /* nothing to do here really */ }
public override void GetNotification(DBNotification _notification) { /* pas de notification utile à form_accueil */ }
public PostgreSQLNotification(DBNotification <T> notification) { Notification = notification; }
public override void GetNotification(DBNotification _notification) { // }
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(); } }
// handle notifications of a change in one of the monitored table private void _conn_Notification(object sender, NpgsqlNotificationEventArgs e) { JObject json = JObject.Parse(e.Payload); // get the name of the table that changed, if it's not the one this listener is watching, ignore it string table = (string)json["table"]; if (table.ToLower() != _table) { return; } // get the change type (update, delete, insert) string operation = (string)json["operation"]; DBNotification <T> notificationData = new DBNotification <T>(); notificationData.operation = operation; notificationData.table = (string)json["table"]; notificationData.schema = (string)json["schema"]; notificationData.Timestamp = (DateTime)json["timestamp"]; // get the key column name(s), and the key value(s) of the row that set off the trigger string key_columns = ((string)json["keycolumns"]).ToUpper(); string key_values = (string)json["keyvalues"]; string[] keycolsarray = key_columns.Split(","); string[] keyvalsarray = key_values.Split(","); PropertyInfo propInfo; if (operation == "DELETE") { notificationData.row = new T(); for (int i = 0; i < keycolsarray.Length; i++) { propInfo = notificationData.row.GetType().GetProperty(keycolsarray[i]); if (propInfo.PropertyType == typeof(Guid)) { propInfo.SetValue(notificationData.row, Guid.Parse(keyvalsarray[i])); } if (propInfo.PropertyType == typeof(Int32)) { propInfo.SetValue(notificationData.row, Int32.Parse(keyvalsarray[i])); } if (propInfo.PropertyType == typeof(string)) { propInfo.SetValue(notificationData.row, keyvalsarray[i]); } } } else { string where = " where "; for (int i = 0; i < keycolsarray.Length; i++) { if (i > 0) { where += " and "; } where += keycolsarray[i] + " = '" + keyvalsarray[i] + "'"; } // query for the row that changed or was inserted string query = "select row_to_json(t) from( select * from " + table + where + ") t;"; string jsonResult; using (NpgsqlConnection conn = new NpgsqlConnection(_connstring)) { conn.Open(); using (NpgsqlCommand command = conn.CreateCommand()) { command.CommandText = query; jsonResult = (string)command.ExecuteScalar(); } } // convert the row into an object of type T (very cool! I could use this elsewhere, like in DatabaseManager.LoadConfig() ) notificationData.row = JsonConvert.DeserializeObject <T>(jsonResult, new CustomJsonConvert()); } // raise an event to notify the app that the monitored table has changed, include the row data and operation type Notification?.Invoke(this, new PostgreSQLNotification(notificationData)); }
protected NotificationBase(DBNotification notification) { Notification = notification; }
/// <summary> /// Lorsqu'une notification est reçue par <seealso cref="CFLDBConnection"/>, cette notification est passée /// aux classes system concernées(ex <seealso cref="CFL_global"/>) /// et à <seealso cref="CFL_forms"/> qui la propage à toutes les CFL_form. /// </summary> /// <param name="_notification"></param> public abstract void GetNotification(DBNotification _notification);
public void UpdateDB(DBNotification dBNotification) { dBNotification.Created = Created; dBNotification.AppUserId = AppUserId; dBNotification.data = Data; }
public Notification(DBNotification dBNotification) { Created = dBNotification.Created; AppUserId = dBNotification.AppUserId; Data = dBNotification.data; }
public void GetNotification(DBNotification _notification) { }