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 += l.lane; } } } 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 "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; default: break; } RedirectToSelf (); } // Files foreach (DBLanefile file in response.Files) { string text = file.name; if (!string.IsNullOrEmpty (file.mime)) text += " (" + file.mime + ")"; 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, string.Format ("<a href='EditLane.aspx?lane_id={1}&action=deleteFile&file_id={0}'>Delete</a> <a href='ViewLaneFileHistory.aspx?id={0}'>View history</a>", file.id, lane.id))); } 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'>"); foreach (DBLanefile file in response.ExistingFiles) { existing_files.AppendFormat ("<option value='{1}'>{0}</option>\n", file.name, file.id); } 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; 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), string.Format ("<a href='EditLane.aspx?lane_id={0}&action=deletecommand&command_id={1}'>Delete</a>", lane.id, command.id))); } 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 * 10)))); // 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"; row = new TableRow (); row.Cells.Add (Utils.CreateTableCell (string.Format ("<a href='EditHost.aspx?host_id={0}'>{1}</a>", view.host_id, view.host), view.enabled ? "enabled" : "disabled")); 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")); row.Cells.Add (Utils.CreateTableCell (html, ed)); 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: 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/>"); } }
public void EditEnvironmentVariable (WebServiceLogin login, DBEnvironmentVariable variable) { using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); variable.Save (db); } }
public GetBuildInfoResponse GetBuildInfoMultiple (WebServiceLogin login, string host, bool multiple_work) { List<DBHost> hosts = new List<DBHost> (); // list of hosts to find work for List<DBHostLane> hostlanes = new List<DBHostLane> (); List<DBLane> lanes = new List<DBLane> (); GetBuildInfoResponse response = new GetBuildInfoResponse (); response.Work = new List<List<BuildInfoEntry>> (); using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.BuildBot, true); response.Host = FindHost (db, null, host); if (!response.Host.enabled) return response; // find the master hosts for this host (if any) response.MasterHosts = FindMasterHosts (db, response.Host); // get the hosts to find work for if (response.MasterHosts != null && response.MasterHosts.Count > 0) { foreach (DBMasterHost mh in response.MasterHosts) hosts.Add (DBHost_Extensions.Create (db, mh.master_host_id)); } else { hosts.Add (response.Host); } // find the enabled hostlane combinations for these hosts using (IDbCommand cmd = db.CreateCommand ()) { cmd.CommandText = "SELECT HostLane.* FROM HostLane INNER JOIN Lane ON Lane.id = HostLane.lane_id WHERE Lane.enabled = TRUE AND HostLane.enabled = TRUE AND ("; for (int i = 0; i < hosts.Count; i++) { if (i > 0) cmd.CommandText += " OR "; cmd.CommandText += " HostLane.host_id = " + hosts [i].id; } cmd.CommandText += ")"; using (IDataReader reader = cmd.ExecuteReader ()) { while (reader.Read ()) hostlanes.Add (new DBHostLane (reader)); } } if (hostlanes.Count == 0) return response; // nothing to do here lanes = db.GetAllLanes (); switch (response.Host.QueueManagement) { case DBQueueManagement.OneRevisionWorkAtATime: if (hostlanes.Count > 1) { int latest = -1; DateTime latest_date = DateTime.MaxValue; // we need to find the latest revisionwork each hostlane has completed. // we want to work on the hostlane which has waited the longest amount // of time without getting work done (but which has pending work to do). for (int i = 0; i < hostlanes.Count; i++) { DBHostLane hl = hostlanes [i]; // check if this hostlane has pending work. // this would ideally be included in the query below, but I'm not sure // how to do that while still distinguising the case where nothing has // been done ever for a hostlane. using (IDbCommand cmd = db.CreateCommand ()) { cmd.CommandText = @" SELECT RevisionWork.id FROM RevisionWork WHERE RevisionWork.host_id = @host_id AND (RevisionWork.workhost_id = @workhost_id OR RevisionWork.workhost_id IS NULL) AND RevisionWork.completed = false AND RevisionWork.state <> 9 AND RevisionWork.state <> 10 AND RevisionWork.state <> 11 AND lane_id = @lane_id LIMIT 1; "; DB.CreateParameter (cmd, "lane_id", hl.lane_id); DB.CreateParameter (cmd, "host_id", hl.host_id); DB.CreateParameter (cmd, "workhost_id", response.Host.id); object obj = cmd.ExecuteScalar (); if (obj == DBNull.Value || obj == null) { // there is nothing to do for this hostlane continue; } } // find the latest completed (this may not be correct, maybe find the latest unstarted?) // revisionwork for this hostlane. using (IDbCommand cmd = db.CreateCommand ()) { cmd.CommandText = @" SELECT RevisionWork.endtime FROM RevisionWork WHERE RevisionWork.host_id = @host_id AND (RevisionWork.workhost_id = @workhost_id OR RevisionWork.workhost_id IS NULL) AND RevisionWork.completed = true AND lane_id = @lane_id ORDER BY RevisionWork.endtime DESC LIMIT 1; "; DB.CreateParameter (cmd, "lane_id", hl.lane_id); DB.CreateParameter (cmd, "host_id", hl.host_id); DB.CreateParameter (cmd, "workhost_id", response.Host.id); object obj = cmd.ExecuteScalar (); if (obj is DateTime) { DateTime dt = (DateTime) obj; if (dt < latest_date) { latest_date = dt; latest = i; } } else { // nothing has ever been done for this hostlane. latest_date = DateTime.MinValue; latest = i; } } } if (latest >= 0) { DBHostLane tmp = hostlanes [latest]; hostlanes.Clear (); hostlanes.Add (tmp); } else { hostlanes.Clear (); // there is nothing to do at all } } break; } foreach (DBHostLane hl in hostlanes) { int counter = 10; DBRevisionWork revisionwork; DBLane lane = null; DBHost masterhost = null; foreach (DBLane l in lanes) { if (l.id == hl.lane_id) { lane = l; break; } } foreach (DBHost hh in hosts) { if (hh.id == hl.host_id) { masterhost = hh; break; } } do { revisionwork = db.GetRevisionWork (lane, masterhost, response.Host); if (revisionwork == null) break; } while (!revisionwork.SetWorkHost (db, response.Host) && counter-- > 0); if (revisionwork == null) continue; if (!revisionwork.workhost_id.HasValue || revisionwork.workhost_id != response.Host.id) continue; // couldn't lock this revisionwork. log.DebugFormat ("Found work for host {0} {4}: {1} (lane: {2} {3})", response.Host.id, revisionwork.id, revisionwork.lane_id, lane.lane, response.Host.host); DBRevision revision = DBRevision_Extensions.Create (db, revisionwork.revision_id); List<DBWorkFile> files_to_download = null; List<DBLane> dependent_lanes = null; // get dependent files List<DBLaneDependency> dependencies = lane.GetDependencies (db); if (dependencies != null && dependencies.Count > 0) { foreach (DBLaneDependency dep in dependencies) { DBLane dependent_lane; DBHost dependent_host; DBRevisionWork dep_revwork; List<DBWorkFile> work_files; if (string.IsNullOrEmpty (dep.download_files)) continue; dependent_lane = DBLane_Extensions.Create (db, dep.dependent_lane_id); dependent_host = dep.dependent_host_id.HasValue ? DBHost_Extensions.Create (db, dep.dependent_host_id.Value) : null; DBRevision dep_lane_rev = dependent_lane.FindRevision (db, revision.revision); if (dep_lane_rev == null) continue; /* Something bad happened: the lane we're dependent on does not have the same revisions we have */ dep_revwork = DBRevisionWork_Extensions.Find (db, dependent_lane, dependent_host, dep_lane_rev); work_files = dep_revwork.GetFiles (db); foreach (DBWorkFile file in work_files) { bool download = true; foreach (string exp in dep.download_files.Split (new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { if (!System.Text.RegularExpressions.Regex.IsMatch (file.filename, FileUtilities.GlobToRegExp (exp))) { download = false; break; } } if (!download) continue; if (files_to_download == null) { files_to_download = new List<DBWorkFile> (); dependent_lanes = new List<DBLane> (); } files_to_download.Add (file); dependent_lanes.Add (dependent_lane); } } } List<DBWorkView2> pending_work = revisionwork.GetNextWork (db, lane, masterhost, revision, multiple_work); if (pending_work == null || pending_work.Count == 0) continue; List<DBEnvironmentVariable> environment_variables = null; using (IDbCommand cmd = db.CreateCommand ()) { foreach (int li in db.GetLaneHierarchy (lane.id)) { cmd.CommandText += string.Format (@" SELECT * FROM EnvironmentVariable WHERE (host_id = {0} OR host_id = {1} OR host_id IS NULL) AND (lane_id = {2} OR lane_id IS NULL) ORDER BY id; ;", revisionwork.workhost_id, revisionwork.host_id, li); } using (IDataReader reader = cmd.ExecuteReader ()) { var set = new HashSet<string> (); do { while (reader.Read ()) { if (environment_variables == null) environment_variables = new List<DBEnvironmentVariable> (); var ev = new DBEnvironmentVariable (reader); if (!set.Contains (ev.name)) { environment_variables.Add (ev); set.Add (ev.name); } } } while (reader.NextResult ()); } } DBHost host_being_worked_for = hosts.Find (h => h.id == revisionwork.host_id); foreach (DBWorkView2 work in pending_work) { BuildInfoEntry entry = new BuildInfoEntry (); entry.Lane = lane; entry.HostLane = hl; entry.Revision = revision; entry.Command = DBCommand_Extensions.Create (db, work.command_id); entry.FilesToDownload = files_to_download; entry.DependentLaneOfFiles = dependent_lanes; entry.Work = DBWork_Extensions.Create (db, work.id); entry.LaneFiles = lane.GetFiles (db, lanes); entry.EnvironmentVariables = environment_variables; entry.Host = host_being_worked_for; // TODO: put work with the same sequence number into one list of entries. List<BuildInfoEntry> entries = new List<BuildInfoEntry> (); entries.Add (entry); response.Work.Add (entries); } // Notify that the revision is assigned var notifyInfo = new GenericNotificationInfo (); notifyInfo.laneID = revisionwork.lane_id; notifyInfo.hostID = revisionwork.host_id; notifyInfo.revisionID = revisionwork.revision_id; notifyInfo.message = String.Format("Assigned to host '{0}' ({1})", response.Host.host, response.Host.id); notifyInfo.state = DBState.Executing; Notifications.NotifyGeneric (notifyInfo); } } return response; }
protected override void OnInit (EventArgs e) { base.OnInit (e); TableRow row; GetLaneForEditResponse response; txtID.Attributes ["readonly"] = "readonly"; string action = Request ["action"]; string command_id = Request ["command_id"]; int id; int sequence; int timeout; int? deadlock_timeout; tblCommands.Visible = true; tblFiles.Visible = true; int.TryParse (Request ["lane_id"], out id); response = Utils.LocalWebService.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; if (response.Tags != null) txtTags.Text = string.Join (",", response.Tags.ConvertAll<string> ((DBLaneTag tag) => tag.tag).ToArray ()); 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": Utils.LocalWebService.CreateLanefile (Master.WebServiceLogin, lane.id, Request ["filename"]); break; case "addFile": if (int.TryParse (Request ["lanefile_id"], out id)) Utils.LocalWebService.AttachFileToLane (Master.WebServiceLogin, lane.id, id); break; case "deleteFile": if (int.TryParse (Request ["file_id"], out id)) Utils.LocalWebService.DeattachFileFromLane (Master.WebServiceLogin, lane.id, id); break; case "editCommandFilename": if (int.TryParse (command_id, out id)) Utils.LocalWebService.EditCommandFilename (Master.WebServiceLogin, id, Request ["filename"]); break; case "editCommandSequence": if (int.TryParse (command_id, out id)) { if (int.TryParse (Request ["sequence"], out sequence)) Utils.LocalWebService.EditCommandSequence (Master.WebServiceLogin, id, sequence); } break; case "editCommandArguments": if (int.TryParse (command_id, out id)) Utils.LocalWebService.EditCommandArguments (Master.WebServiceLogin, id, Request ["arguments"]); break; case "editCommandTimeout": if (int.TryParse (command_id, out id)) { if (int.TryParse (Request ["timeout"], out timeout)) Utils.LocalWebService.EditCommandTimeout (Master.WebServiceLogin, id, timeout); } break; case "editCommandDeadlockTimeout": if (int.TryParse (command_id, out id) && Request.Params.AllKeys.Contains ("deadlock_timeout")) { if (string.IsNullOrEmpty (Request ["deadlock_timeout"])) { deadlock_timeout = null; } else if (int.TryParse (Request ["deadlock_timeout"], out timeout)) { deadlock_timeout = timeout; } else { break; } Utils.LocalWebService.EditCommandDeadlockTimeout (Master.WebServiceLogin, id, deadlock_timeout); } break; case "editCommandWorkingDirectory": if (int.TryParse (command_id, out id)) Utils.LocalWebService.EditCommandWorkingDirectory (Master.WebServiceLogin, id, Request ["working_directory"]); break; case "editCommandUploadFiles": if (int.TryParse (command_id, out id)) Utils.LocalWebService.EditCommandUploadFiles (Master.WebServiceLogin, id, Request ["upload_files"]); break; case "deletecommand": if (int.TryParse (command_id, out id)) Utils.LocalWebService.DeleteCommand (Master.WebServiceLogin, id); break; case "switchNonFatal": if (int.TryParse (command_id, out id)) Utils.LocalWebService.SwitchCommandNonFatal (Master.WebServiceLogin, id); break; case "switchAlwaysExecute": if (int.TryParse (command_id, out id)) Utils.LocalWebService.SwitchCommandAlwaysExecute (Master.WebServiceLogin, id); break; case "switchInternal": if (int.TryParse (command_id, out id)) Utils.LocalWebService.SwitchCommandInternal (Master.WebServiceLogin, id); break; case "switchTimestamp": if (int.TryParse (command_id, out id)) Utils.LocalWebService.SwitchCommandTimestamp (Master.WebServiceLogin, id); break; case "addCommand": if (!int.TryParse (Request ["sequence"], out sequence)) sequence = -1; Utils.LocalWebService.AddCommand (Master.WebServiceLogin, lane.id, Request ["command"], false, false, 60, sequence); break; case "switchHostEnabled": if (int.TryParse (Request ["host_id"], out id)) Utils.LocalWebService.SwitchHostEnabledForLane (Master.WebServiceLogin, lane.id, id); break; case "switchHostHidden": if (int.TryParse (Request ["host_id"], out id)) Utils.LocalWebService.SwitchHostHiddenForLane (Master.WebServiceLogin, lane.id, id); break; case "removeHost": if (int.TryParse (Request ["host_id"], out id)) Utils.LocalWebService.RemoveHostForLane (Master.WebServiceLogin, lane.id, id); break; case "addHost": if (int.TryParse (Request ["host_id"], out id)) Utils.LocalWebService.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)) { Utils.LocalWebService.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)) Utils.LocalWebService.EditLaneDependencyFilename (Master.WebServiceLogin, id, Request ["filename"]); break; case "deleteDependency": if (int.TryParse (Request ["dependency_id"], out id)) Utils.LocalWebService.DeleteLaneDependency (Master.WebServiceLogin, id); break; case "editDependencyDownloads": if (int.TryParse (Request ["lanedependency_id"], out id)) Utils.LocalWebService.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"]; Utils.LocalWebService.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; Utils.LocalWebService.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); var file_used_list = 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 (); var file_list = string.Format ( @" <div id=""hideFileList{2}"" style=""display: none;"" onclick=""document.getElementById('fileList{2}').style.display = 'none'; document.getElementById('hideFileList{2}').style.display = 'none'; document.getElementById('showFileList{2}').style.display = 'block';"" >[Hide]</div> <div id=""showFileList{2}"" style=""display: block;"" onclick=""document.getElementById('fileList{2}').style.display = 'block'; document.getElementById('hideFileList{2}').style.display = 'block'; document.getElementById('showFileList{2}').style.display = 'none' ; "" >Used by {0} other lanes [Show]</div> <div id=""fileList{2}"" style=""display: none;"">{1}</div> ", file_used_list.Length, string.Join (", ", file_used_list), 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), file_list.ToString ())); 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 (); // build dictionary of lanes var laneDictionary = new Dictionary<int, DBLane> (); foreach (var l in response.Lanes) laneDictionary.Add (l.id, l); // build table of lanes where each file is used var lanesUsedByFile = new Dictionary<int, HashSet<string>> (); foreach (var lf in response.LaneFiles) { HashSet<string> f; if (!lanesUsedByFile.TryGetValue (lf.lanefile_id, out f)) { f = new HashSet<string> (); lanesUsedByFile [lf.lanefile_id] = f; } f.Add (laneDictionary [lf.lane_id].lane); } // list all the files, with a tooltip saying where each file is used foreach (DBLanefile file in response.ExistingFiles) { if (shown_files.Contains (file.id)) continue; shown_files.Add (file.id); existing_files.AppendFormat ("<option value='{0}'", file.id); HashSet<string> lanes_for_file; if (lanesUsedByFile.TryGetValue (file.id, out lanes_for_file)) { existing_files.Append (" title='Used in: "); var any = false; foreach (var l in lanes_for_file) { if (any) { existing_files.Append (", "); } else { any = true; } existing_files.Append (l); } existing_files.Append ("'"); } existing_files.Append (">"); existing_files.Append (file.name); existing_files.Append ("</option>\n"); // existing_files.AppendFormat ("<option value='{1}' title='Used in: {2}'>{0}</option>\n", file.name, file.id, "somewhere else"); } 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:editCommandDeadlockTimeout ({2}, {0}, true, \"{3}\")'>{1}</a>", command.id, command.deadlock_timeout == null ? "wrench default" : (command.deadlock_timeout.Value == 0 ? "disabled" : command.deadlock_timeout.Value.ToString () + " minutes"), lane.id, command.deadlock_timeout.HasValue ? command.deadlock_timeout.Value.ToString () : string.Empty), 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), string.Format ("<a href='EditLane.aspx?lane_id={0}&command_id={1}&action=switchTimestamp'>{2}</a>", lane.id, command.id, (command.timestamp ? "yes" : "no")), 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", "wrench default", "-", "-", "no", 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 ())); } }
public int AddEnvironmentVariable (WebServiceLogin login, int? lane_id, int? host_id, string name, string value) { using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); DBEnvironmentVariable var = new DBEnvironmentVariable (); var.name = name; var.value = value; var.host_id = host_id; var.lane_id = lane_id; var.Save (db); return var.id; } }
public DBLane CloneLane (int lane_id, string new_name, bool copy_files) { DBLane result = null; DBLane master = DBLane_Extensions.Create (this, lane_id); if (this.LookupLane (new_name, false) != null) throw new Exception (string.Format ("The lane '{0}' already exists.", new_name)); try { using (IDbTransaction transaction = BeginTransaction ()) { result = new DBLane (); result.lane = new_name; result.max_revision = master.max_revision; result.min_revision = master.min_revision; result.repository = master.repository; result.source_control = master.source_control; result.parent_lane_id = master.parent_lane_id; result.enabled = master.enabled; result.Save (this); foreach (DBLanefile filemaster in master.GetFiles (this, null)) { int fid; if (copy_files) { DBLanefile clone = new DBLanefile (); clone.contents = filemaster.contents; clone.mime = filemaster.mime; clone.name = filemaster.name; clone.Save (this); fid = clone.id; } else { fid = filemaster.id; } DBLanefiles lane_files = new DBLanefiles (); lane_files.lane_id = result.id; lane_files.lanefile_id = fid; lane_files.Save (this); } foreach (DBCommand cmdmaster in GetCommands (master.id)) { DBCommand clone = new DBCommand (); clone.lane_id = result.id; clone.alwaysexecute = cmdmaster.alwaysexecute; clone.arguments = cmdmaster.arguments; clone.command = cmdmaster.command; clone.filename = cmdmaster.filename; clone.nonfatal = cmdmaster.nonfatal; clone.sequence = cmdmaster.sequence; clone.timeout = cmdmaster.timeout; clone.working_directory = cmdmaster.working_directory; clone.upload_files = cmdmaster.upload_files; clone.Save (this); } foreach (DBHostLaneView hostlanemaster in master.GetHosts (this)) { DBHostLane clone = new DBHostLane (); clone.enabled = false; clone.lane_id = result.id; clone.host_id = hostlanemaster.host_id; clone.Save (this); } foreach (DBEnvironmentVariable env in master.GetEnvironmentVariables (this)) { DBEnvironmentVariable clone = new DBEnvironmentVariable (); clone.host_id = env.host_id; clone.lane_id = result.id; clone.name = env.name; clone.value = env.value; clone.Save (this); } foreach (DBLaneNotification notification in master.GetNotifications (this)) { DBLaneNotification clone = new DBLaneNotification (); clone.lane_id = result.id; clone.notification_id = notification.notification_id; clone.Save (this); } foreach (var tag in master.GetTags (this)) { var clone = new DBLaneTag (); clone.lane_id = result.id; clone.tag = tag.tag; clone.Save (this); } transaction.Commit (); } } catch { result = null; throw; } return result; }
public void DeleteEnvironmentVariableInLane (WebServiceLogin login, DBEnvironmentVariable variable, int lane_id) { using (DB db = new DB ()) { var lane = DBLane_Extensions.Create (db, lane_id); VerifyUserInRoles (db, login, lane.additional_roles, false); VerifyEnvironmentVariableIsForLane (variable, lane_id); DBRecord_Extensions.Delete (db, variable.id, DBEnvironmentVariable.TableName); } }
public void EditEnvironmentVariableInLane (WebServiceLogin login, DBEnvironmentVariable variable, int lane_id) { using (DB db = new DB ()) { var lane = DBLane_Extensions.Create (db, lane_id); VerifyUserInRoles (db, login, lane.additional_roles, false); VerifyEnvironmentVariableIsForLane (variable, lane_id); variable.Save (db); } }
public void VerifyEnvironmentVariableIsForLane(DBEnvironmentVariable variable, int lane_id) { if (variable.lane_id != lane_id) { throw new UnauthorizedException ("You don't have the required permissions."); } }
public int AddEnvironmentVariableInLane (WebServiceLogin login, int lane_id, int? host_id, string name, string value) { using (DB db = new DB ()) { var lane = DBLane_Extensions.Create (db, lane_id); VerifyUserInRoles (db, login, lane.additional_roles, false); DBEnvironmentVariable var = new DBEnvironmentVariable (); var.name = name; var.value = value; var.host_id = host_id; var.lane_id = lane_id; var.Save (db); return var.id; } }