private void DownloadNamedWorkFile(int work_id, string filename) { DBWorkFileView view = null; DBFile file = null; string compressed_mime; using (DB db = new DB()) { WebServiceLogin login = Authentication.CreateLogin(Request); view = DBWorkFileView_Extensions.Find(db, work_id, filename); if (view == null) { throw new HttpException(404, "Could not find the file."); } if (view.@internal) // internal files need admin rights { Authentication.VerifyUserInRole(Context, db, login, Roles.Administrator, false); } else { Authentication.VerifyAnonymousAccess(Context, db, login); } file = DBWork_Extensions.GetFile(db, view.work_id, filename, false); if (file == null) { throw new HttpException(404, string.Format("Could not find the filename '{0}'", filename)); } compressed_mime = file.compressed_mime; Response.ContentType = file.mime; Response.AppendHeader("Content-Disposition", "filename=\"" + Path.GetFileName(filename) + "\""); if (view.file_file_id == null) { DownloadMd5(view.md5); } else { using (Stream str = db.Download(view)) { DownloadStream(str, compressed_mime); } } } }
/// <summary> /// Returns a READ-ONLY list of files /// </summary> /// <param name="db"></param> /// <param name="work_id"></param> /// <param name="include_hidden_files">If hidden files are included in the returned list. Note that any file named 'index.html' is always returned, even if it's hidden and this parameter is false.</param> /// <returns></returns> public static List<DBWorkFileView> GetFiles (DB db, int work_id, bool include_hidden_files) { List<DBWorkFileView> result = new List<DBWorkFileView> (); using (IDbCommand cmd = db.CreateCommand ()) { if (include_hidden_files) { cmd.CommandText = "SELECT * FROM WorkFileView WHERE work_id = @work_id;"; } else { cmd.CommandText = "SELECT * FROM WorkFileView WHERE work_id = @work_id AND (hidden = false OR filename = 'index.html');"; } DB.CreateParameter (cmd, "work_id", work_id); using (IDataReader reader = cmd.ExecuteReader ()) { while (reader.Read ()) { DBWorkFileView file = new DBWorkFileView (reader); result.Add (file); } } } return result; }
private void DownloadWorkFile(int workfile_id, string md5) { DBWorkFileView view = null; DBFile file = null; string filename; string mime; string compressed_mime; using (DB db = new DB()) { WebServiceLogin login = Authentication.CreateLogin(Request); filename = Request ["filename"]; if (!string.IsNullOrEmpty(md5)) // md5 lookup needs admin rights { Authentication.VerifyUserInRole(Context, db, login, Roles.Administrator, false); file = DBFile_Extensions.Find(db, md5); if (file == null) { throw new HttpException(404, "Could not find the file."); } mime = file.mime; filename = file.filename; compressed_mime = file.compressed_mime; } else { view = DBWorkFileView_Extensions.Find(db, workfile_id); if (view == null) { throw new HttpException(404, "Could not find the file."); } if (view.@internal) // internal files need admin rights { Authentication.VerifyUserInRole(Context, db, login, Roles.Administrator, false); } else { Authentication.VerifyAnonymousAccess(Context, db, login); } if (!string.IsNullOrEmpty(filename)) { file = DBWork_Extensions.GetFile(db, view.work_id, filename, false); if (file == null) { throw new HttpException(404, string.Format("Could not find the filename '{0}'", filename)); } mime = file.mime; compressed_mime = file.compressed_mime; md5 = file.md5; view = null; } else { mime = view.mime; filename = view.filename; compressed_mime = view.compressed_mime; } } Response.ContentType = mime; Response.AppendHeader("Content-Disposition", "filename=\"" + Path.GetFileName(filename) + "\""); // any access rights verified, serve the file if (view != null) { if (view.file_file_id == null) { DownloadMd5(view.md5); } else { using (Stream str = db.Download(view)) { DownloadStream(str, compressed_mime); } } } else { DownloadFile(db, file); } } }
public string GenerateLane(GetViewWorkTableDataResponse response, DBLane lane, DBHost host, DBCommand command) { StringBuilder matrix = new StringBuilder(); List <DBWorkView2> steps; steps = response.WorkViews; matrix.AppendLine("<table class='buildstatus'>"); matrix.AppendLine("<tr>"); matrix.AppendLine("\t<th>Revision</th>"); matrix.AppendLine("\t<th>Start Time</th>"); matrix.AppendLine("\t<th>Duration</th>");; matrix.AppendLine("\t<th>Html report</th>"); matrix.AppendLine("\t<th>Summary</th>"); matrix.AppendLine("\t<th>Files</th>"); matrix.AppendLine("</tr>"); for (int i = 0; i < steps.Count; i++) { DBWorkView2 view = steps [i]; List <DBWorkFileView> files = response.WorkFileViews [i]; DBState state = (DBState)view.state; matrix.Append("<tr>"); // revision string result; switch (state) { case DBState.NotDone: result = "queued"; break; case DBState.Executing: result = "running"; break; case DBState.Failed: result = view.nonfatal ? "issues" : "failure"; break; case DBState.Success: case DBState.Aborted: case DBState.Timeout: case DBState.Paused: default: result = state.ToString().ToLowerInvariant(); break; } // result matrix.AppendFormat("\t<td class='{0}'><a href='ViewLane.aspx?lane_id={2}&host_id={3}&revision_id={4}'>{1}</a></td>", result, view.revision, lane.id, host.id, view.revision_id); if (state > DBState.NotDone && state != DBState.Paused && state != DBState.Ignore) { matrix.AppendFormat("<td>{0}</td>", view.starttime.ToString("yyyy/MM/dd HH:mm:ss UTC")); } else { matrix.AppendLine("<td>-</td>"); } // duration matrix.Append("\t<td>"); if (state >= DBState.Executing && state != DBState.Paused && state != DBState.Ignore) { matrix.Append("["); matrix.Append(MonkeyWrench.Utilities.GetDurationFromWorkView(view).ToString()); matrix.Append("]"); } else { matrix.Append("-"); } matrix.AppendLine("</td>"); // html report matrix.AppendLine("<td>"); DBWorkFileView index_html = null; foreach (DBWorkFileView file in files) { if (file.filename == "index.html") { index_html = file; break; } } if (index_html != null) { matrix.AppendFormat("<a href='ViewHtmlReport.aspx?workfile_id={0}'>View html report</a>", index_html.id); } else { matrix.AppendLine("-"); } matrix.AppendLine("</td>"); // summary matrix.AppendLine("<td>"); matrix.AppendLine(view.summary); matrix.AppendLine("</td>"); matrix.AppendLine("</tr>"); } matrix.AppendLine("</table>"); return(matrix.ToString()); }
public Stream Download(DBWorkFileView file) { return(new DBFileStream(DBFile_Extensions.Create(this, file.file_id), this)); }
public static DBWorkFileView Find(DB db, string filename, string lane, string revision, string host) { DBWorkFileView result; if (lane == null) { throw new ArgumentNullException("lane"); } using (IDbCommand cmd = db.CreateCommand()) { cmd.CommandText = @" SELECT WorkFile.id, WorkFile.work_id, WorkFile.file_id, WorkFile.filename, WorkFile.hidden, File.mime, File.compressed_mime, Command.internal FROM WorkFile INNER JOIN File ON WorkFile.file_id = File.id INNER JOIN Work ON WorkFile.work_id = Work.id INNER JOIN Command ON Work.command_id = Command.id INNER JOIN RevisionWork ON Work.revisionwork_id = RevisionWork.id INNER JOIN Revision ON RevisionWork.revision_id = Revision.id INNER JOIN Lane ON RevisionWork.lane_id = Lane.id INNER JOIN Host ON RevisionWork.host_id = Host.id WHERE Lane.lane = @lane AND Revision.revision = @revision AND WorkFile.filename = @filename AND Host.host = @host; "; DB.CreateParameter(cmd, "filename", filename); DB.CreateParameter(cmd, "lane", lane); DB.CreateParameter(cmd, "revision", revision); DB.CreateParameter(cmd, "host", host); using (IDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { return(null); } result = new DBWorkFileView(reader); int counter = 0; string ids = result.id.ToString(); while (reader.Read()) { counter++; ids += ", " + reader ["id"]; } if (counter > 0) { throw new ApplicationException(string.Format("Found more than one file ({0} too many: {1}).", counter, ids)); } } } return(result); }
public string GenerateLane(GetViewLaneDataResponse response) { StringBuilder matrix = new StringBuilder(); List <DBWorkView2> steps = response.WorkViews; DBRevision dbr = response.Revision; DBRevisionWork revisionwork = response.RevisionWork; DBLane lane = response.Lane; DBHost host = response.Host; DBRevision revision = response.Revision; StringBuilder header = new StringBuilder(); header.AppendFormat("Revision: <a href='GetRevisionLog.aspx?id={0}'>{1}</a>", dbr.id, dbr.revision); header.AppendFormat(" - Status: {0}", revisionwork.State); header.AppendFormat(" - Author: {0}", dbr.author); header.AppendFormat(" - Commit date: {0}", dbr.date.ToString("yyyy/MM/dd HH:mm:ss UTC")); if (Authentication.IsInRole(response, MonkeyWrench.DataClasses.Logic.Roles.Administrator)) { bool isExecuting = response.RevisionWork.State == DBState.Executing || (response.RevisionWork.State == DBState.Issues && !response.RevisionWork.completed) || response.RevisionWork.State == DBState.Aborted; if (isExecuting) { header.AppendFormat(" - <a href='javascript:confirmViewLaneAction (\"ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=clearrevision\", \"clear\");'>reset work</a>", lane.id, dbr.id, host.id); header.AppendFormat(" - <a href='javascript:confirmViewLaneAction (\"ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=deleterevision\", \"delete\");'>delete work</a>", lane.id, dbr.id, host.id); header.AppendFormat(" - <a href='ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=abortrevision'>abort work</a>", lane.id, dbr.id, host.id); } else if (response.RevisionWork.State == DBState.Ignore) { header.AppendFormat(" - <a href='ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=clearrevision'>build this revision</a>", lane.id, dbr.id, host.id); } else { if (response.RevisionWork.State == DBState.NotDone) { header.AppendFormat(" - <a href='ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=ignorerevision'>don't build</a>", lane.id, dbr.id, host.id); } if (response.RevisionWork.State != DBState.NoWorkYet) { header.AppendFormat(" - <a href='ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=clearrevision'>reset work</a>", lane.id, dbr.id, host.id); header.AppendFormat(" - <a href='ViewLane.aspx?lane_id={0}&host_id={2}&revision_id={1}&action=deleterevision'>delete work</a>", lane.id, dbr.id, host.id); } } } if (response.WorkHost != null) { header.AppendFormat(" - Assigned to <a href='ViewHostHistory.aspx?host_id={1}'>{0}</a>", response.WorkHost.host, response.WorkHost.id); } else { header.AppendFormat(" - Unassigned."); } if (!revisionwork.completed && revisionwork.State != DBState.NotDone && revisionwork.State != DBState.Paused && revisionwork.State != DBState.Ignore) { header.Insert(0, "<center><table class='executing'><td>"); header.Append("</td></table></center>"); } // matrix.AppendFormat ("<div class='buildstatus {0}'>Status: {0}</div>", revisionwork.State.ToString ().ToLowerInvariant ()); matrix.AppendLine("<table class='buildstatus'>"); matrix.AppendFormat("<tr class='{0}'>", revisionwork.State.ToString().ToLowerInvariant()); matrix.Append("<th colspan='9'>"); matrix.Append(header.ToString()); matrix.Append("</th>"); matrix.AppendLine("</tr>"); matrix.AppendLine("<tr>"); matrix.AppendLine("\t<th>Step</th>"); matrix.AppendLine("\t<th>Result</th>"); matrix.AppendLine("\t<th>Start Time</th>"); matrix.AppendLine("\t<th>Duration</th>"); matrix.AppendLine("\t<th>Html report</th>"); matrix.AppendLine("\t<th>Summary</th>"); matrix.AppendLine("\t<th>Files</th>"); matrix.AppendLine("\t<th>Host</th>"); matrix.AppendLine("\t<th>Misc</th>"); matrix.AppendLine("</tr>"); bool failed = false; for (int s = 0; s < steps.Count; s++) { DBWorkView2 step = steps [s]; DBState state = (DBState)step.state; bool nonfatal = step.nonfatal; string command = step.command; List <DBWorkFileView> files = response.WorkFileViews [s]; IEnumerable <DBFileLink> links = response.Links.Where <DBFileLink> ((DBFileLink link) => link.work_id == step.id); if (state == DBState.Failed && !nonfatal) { failed = true; } matrix.AppendLine("<tr>"); // step DBWorkFileView step_log = files.Find((v) => v.filename == command + ".log"); matrix.Append("\t<td>"); if (step_log != null) { matrix.AppendFormat("<a href='GetFile.aspx?id={0}'>{1}</a> ", step_log.id, command); } else { matrix.Append(command); } matrix.Append("</td>"); // result string result; switch (state) { case DBState.NotDone: result = failed ? "skipped" : "queued"; break; case DBState.Executing: result = "running"; break; case DBState.Failed: result = nonfatal ? "issues" : "failure"; break; case DBState.Success: case DBState.Aborted: case DBState.Timeout: case DBState.Paused: default: result = state.ToString().ToLowerInvariant(); break; } // result matrix.AppendFormat("\t<td class='{0}'>{0}</td>", result); if (state > DBState.NotDone && state != DBState.Paused && state != DBState.Ignore && state != DBState.DependencyNotFulfilled) { matrix.AppendFormat("<td>{0}</td>", step.starttime.ToString("yyyy/MM/dd HH:mm:ss UTC")); } else { matrix.AppendLine("<td>-</td>"); } // duration matrix.Append("\t<td>"); if (state >= DBState.Executing && state != DBState.Paused && state != DBState.Ignore && state != DBState.DependencyNotFulfilled && state != DBState.Aborted) { matrix.Append("["); matrix.Append(MonkeyWrench.Utilities.GetDurationFromWorkView(step).ToString()); matrix.Append("]"); } else { matrix.Append("-"); } matrix.AppendLine("</td>"); // html report matrix.AppendLine("<td>"); DBWorkFileView index_html = null; foreach (DBWorkFileView file in files) { if (file.filename == "index.html") { index_html = file; break; } } if (index_html != null) { matrix.AppendFormat("<a href='ViewHtmlReportEmbedded.aspx?workfile_id={0}&lane_id={1}&host_id={2}&revision_id={3}'>View html report</a>", index_html.id, lane.id, host.id, revision.id); } else { matrix.AppendLine("-"); } matrix.AppendLine("</td>"); // summary matrix.AppendLine("<td>"); matrix.AppendLine(step.summary); matrix.AppendLine("</td>"); // files matrix.AppendLine("<td style='text-align: left;'>"); var sb = new StringBuilder(); var file_count = 0; foreach (DBWorkFileView file in files.Where((v) => !v.hidden).OrderBy((v) => v.filename)) { if (file.hidden) { continue; } if (file_count > 0) { sb.Append(", "); } file_count++; sb.AppendFormat("<a href='GetFile.aspx?id={0}'>{1}</a> ", file.id, file.filename); } foreach (var link in links.OrderBy((v) => v.link)) { if (file_count > 0) { sb.Append(", "); } file_count++; sb.Append(link.link); } if (file_count > 3) { matrix.AppendFormat("<span id='files_{0}' style='display: none'>{1}</span>" + "<a href='#' id='showFiles_{0}' onclick='javascript:document.getElementById (\"files_{0}\").style.display = \"block\"; document.getElementById (\"showFiles_{0}\").style.display = \"none\";'>Show {2} files</a>", step.id, sb.ToString(), file_count); } else { matrix.Append(sb.ToString()); } matrix.AppendLine("</td>"); // host matrix.AppendFormat("<td>{0}</td>", step.workhost); // misc matrix.AppendFormat("\t<td><a href='ViewWorkTable.aspx?lane_id={1}&host_id={2}&command_id={3}'>History for '{4}'</a></td>", result, lane.id, host.id, step.command_id, command); matrix.AppendLine("</tr>"); } matrix.AppendLine("</table>"); return(matrix.ToString()); }