Пример #1
0
    List <DBRevisionWorkView2> FindRevisionWorkViews(FrontPageResponse data, int hostlane_id)
    {
        for (int k = 0; k < data.RevisionWorkHostLaneRelation.Count; k++)
        {
            if (data.RevisionWorkHostLaneRelation [k] == hostlane_id)
            {
                return(data.RevisionWorkViews [k]);
            }
        }

        return(null);
    }
Пример #2
0
        public static StatusStripRow GetRow(int hostlane, FrontPageResponse data, string header)
        {
            DBHostLane dbhostlane;
            DBLane dblane;
            DBHost dbhost;

            try {
                dbhostlane = data.HostLanes.Where (p => p.id == hostlane).FirstOrDefault ();
                dblane = data.Lanes.Where (p => p.id == dbhostlane.lane_id).FirstOrDefault ();
                dbhost = data.Hosts.Where (p => p.id == dbhostlane.host_id).FirstOrDefault ();
            } catch {
                // This generally means we couldn't find the host/lane
                return null;
            }

            StatusStripRow row = new StatusStripRow ();

            int index = data.RevisionWorkHostLaneRelation.ToList ().IndexOf (dbhostlane.id);

            DBRevisionWorkView2[] revs = data.RevisionWorkViews[index];
            IEnumerable<DBRevisionWorkView2> revisions = revs.Take (10);

            foreach (DBRevisionWorkView2 r in revisions) {
                StatusStripCell cell = new StatusStripCell ();
                cell.Text = r.revision;
                cell.Status = ConvertState (r.state);

                if ((r.state == 3 || r.state == 8) && !r.completed)
                    cell.Status = 1;

                cell.Url = string.Format (rev_link, dblane.id, dbhost.id, r.revision_id);

                row.Cells.Add (cell);
            }

            if (header == "LOOKUP")
                row.HeaderText = dbhost.host;
            else
                row.HeaderText = header;

            row.HeaderUrl = string.Format (host_link, dblane.id, dbhost.id);

            while (row.Cells.Count < 10)
                row.Cells.Add ((new StatusStripCell () { Text = string.Empty, Status = 0 }));

            return row;
        }
Пример #3
0
 private Dictionary <string, object> RevisionWorkToDict(FrontPageResponse data, DBLane l, DBRevisionWorkView2 w)
 {
     return(new Dictionary <string, object> {
         { "id", w.id },
         { "author", w.author },
         { "host_id", w.host_id },
         { "host", data.Hosts.Find(h => h.id == w.host_id).host },
         { "revision", w.revision },
         { "revision_id", w.revision_id },
         { "completed", w.completed },
         { "status", w.state },
         { "endtime", w.endtime },
         { "date", w.date },
         { "lane", l.lane },
         { "repository", l.repository },
         { "branch", l.max_revision }
     });
 }
Пример #4
0
        private string GetTagInfo()
        {
            using (var db = new DB()) {
                string[] tags    = null;
                var      results = new List <object>();

                if (!string.IsNullOrEmpty(Request ["tags"]))
                {
                    tags = Request ["tags"].Split(',');
                }

                MonkeyWrench.WebServices.Authentication.Authenticate(Context, db, login, null, true);
                FrontPageResponse data = Utils.LocalWebService.GetFrontPageDataWithTags(login, limit, 0, null, null, 30, tags);

                for (int i = 0; i < data.SelectedLanes.Count; i++)
                {
                    var lane      = data.SelectedLanes [i];
                    var hostlanes = data.HostLanes.FindAll((hl) => hl.lane_id == lane.id);

                    foreach (var hostlane in hostlanes)
                    {
                        var work_views = FindRevisionWorkViews(data, hostlane.id);

                        for (int r = 0; r < work_views.Count; r++)
                        {
                            results.Add(new Dictionary <string, object> {
                                { "id", work_views[r].id },
                                { "author", work_views[r].author },
                                { "host_id", work_views[r].host_id },
                                { "host", data.Hosts.First(h => h.id == work_views[r].host_id).host },
                                { "lane", lane.lane },
                                { "lane_id", lane.id },
                                { "revision", work_views[r].revision },
                                { "revision_id", work_views[r].revision_id },
                                { "completed", work_views[r].completed },
                                { "status", work_views[r].state.ToString().ToLowerInvariant() },
                            });
                        }
                    }
                }

                return(JsonConvert.SerializeObject(results, Formatting.Indented));
            }
        }
Пример #5
0
    private LaneTreeNode BuildTree(FrontPageResponse data)
    {
        LaneTreeNode result = LaneTreeNode.BuildTree(data.Lanes, data.HostLanes);

        if (data.Lane != null)
        {
            result = result.Find(v => v.Lane != null && v.Lane.id == data.Lane.id);
        }
        else if (data.SelectedLanes.Count > 1)
        {
            for (int i = result.Children.Count - 1; i >= 0; i--)
            {
                LaneTreeNode ltn = result.Children [i];
                if (!data.SelectedLanes.Exists((DBLane l) => l.id == ltn.Lane.id))
                {
                    result.Children.RemoveAt(i);
                }
            }
        }
        return(result);
    }
Пример #6
0
    public string GenerateOverview(FrontPageResponse data)
    {
        StringBuilder        matrix         = new StringBuilder();
        LaneTreeNode         tree           = BuildTree(data);
        List <StringBuilder> header_rows    = new List <StringBuilder> ();
        List <int>           hostlane_order = new List <int> ();

        if (tree == null)
        {
            return(string.Empty);
        }

        // This renders all the host header lanes
        WriteLanes(header_rows, tree, 0, tree.Depth);

        matrix.AppendLine("<table class='buildstatus'>");
        for (int i = 0; i < header_rows.Count; i++)
        {
            if (header_rows [i].Length == 0)
            {
                continue;
            }

            matrix.Append("<tr>");
            matrix.Append(header_rows [i]);
            matrix.AppendLine("</tr>");
        }

        // Renders all the hosts
        matrix.AppendLine("<tr>");
        WriteHostLanes(matrix, tree, data.Hosts, hostlane_order);
        matrix.AppendLine("</tr>");

        // Renders all the builds
        int           counter = 0;
        int           added   = 0;
        StringBuilder row     = new StringBuilder();

        do
        {
            added      = 0;
            row.Length = 0;

            for (int i = 0; i < hostlane_order.Count; i++)
            {
                int hl_id = hostlane_order [i];

                var rev = FindRevisionWorkViews(data, hl_id);
                DBRevisionWorkView2 work = null;

                if (rev != null && rev.Count > counter)
                {
                    work = rev [counter];
                    added++;
                }

                WriteWorkCell(row, work);
            }

            if (added > 0 && row.Length > 0)
            {
                matrix.Append("<tr>");
                matrix.Append(row.ToString());
                matrix.Append("</tr>");
            }

            counter++;
        } while (counter <= limit && added > 0);

        matrix.AppendLine("</table>");

        return(matrix.ToString());
    }
Пример #7
0
    public string GenerateTaggedOverview(FrontPageResponse data)
    {
        StringBuilder matrix = new StringBuilder();

        var lane_row = new StringBuilder();
        var hl_row   = new StringBuilder();
        var rows     = new List <StringBuilder> ();

        // First pass to get the total ammount of rows needed.
        for (int i = 0; i < data.SelectedLanes.Count; i++)
        {
            var lane = data.SelectedLanes [i];
            var hls  = data.HostLanes.FindAll((hl) => hl.lane_id == lane.id);
            foreach (var hl in hls)
            {
                var work_views = FindRevisionWorkViews(data, hl.id);
                // Create more rows if needed.
                if (rows.Count < work_views.Count)
                {
                    rows.Capacity = work_views.Count;
                    for (int r = rows.Count; r < work_views.Count; r++)
                    {
                        rows.Add(new StringBuilder());
                    }
                }
            }
        }

        // Render pass
        matrix.AppendLine("<table class='buildstatus'>");

        for (int i = 0; i < data.SelectedLanes.Count; i++)
        {
            var lane = data.SelectedLanes [i];
            var hls  = data.HostLanes.FindAll((hl) => hl.lane_id == lane.id);
            lane_row.AppendFormat("<td colspan='{1}'>{0}</td>", data.SelectedLanes [i].lane, hls.Count == 0 ? 1 : hls.Count).AppendLine();
            foreach (var hl in hls)
            {
                // This renders all the host header lanes
                WriteHostLane(hl_row, data.Hosts, hl);

                // Find all the builds
                var work_views = FindRevisionWorkViews(data, hl.id);

                // Create more rows if needed.
                if (rows.Count < work_views.Count)
                {
                    rows.Capacity = work_views.Count;
                    for (int r = rows.Count; r < work_views.Count; r++)
                    {
                        rows.Add(new StringBuilder());
                    }
                }

                for (int r = 0; r < work_views.Count; r++)
                {
                    WriteWorkCell(rows [r], work_views [r]);
                }

                // Fix the staggering, add the empty cells.
                if (work_views.Count < rows.Count)
                {
                    for (int r = work_views.Count; r < rows.Count; r++)
                    {
                        WriteWorkCell(rows [r], null);
                    }
                }
            }
        }

        matrix.Append("<tr>").Append(lane_row).AppendLine("</tr>");
        matrix.Append("<tr>").Append(hl_row).AppendLine("</tr>");
        for (int r = 0; r < rows.Count; r++)
        {
            matrix.Append("<tr>").Append(rows [r]).AppendLine("</tr>");
        }
        matrix.AppendLine("</table>");

        return(matrix.ToString());
    }
Пример #8
0
 private List <Dictionary <string, object> > RenderHostList(FrontPageResponse data, DBLane l, DBHostLane hl)
 {
     return(FindRevisionWorkViews(data, hl.id).Select(w => RevisionWorkToDict(data, l, w)).ToList());
 }
Пример #9
0
    public string GenerateOverview(FrontPageResponse data)
    {
        StringBuilder        matrix         = new StringBuilder();
        LaneTreeNode         tree           = BuildTree(data);
        List <StringBuilder> header_rows    = new List <StringBuilder> ();
        List <int>           hostlane_order = new List <int> ();

        if (tree == null)
        {
            return(string.Empty);
        }

        WriteLanes(header_rows, tree, 0, tree.Depth);

        matrix.AppendLine("<table class='buildstatus'>");
        for (int i = 0; i < header_rows.Count; i++)
        {
            if (header_rows [i].Length == 0)
            {
                continue;
            }

            matrix.Append("<tr>");
            matrix.Append(header_rows [i]);
            matrix.AppendLine("</tr>");
        }

        matrix.AppendLine("<tr>");
        WriteHostLanes(matrix, tree, data.Hosts, hostlane_order);
        matrix.AppendLine("</tr>");

        int           counter = 0;
        int           added   = 0;
        StringBuilder row     = new StringBuilder();

        do
        {
            added      = 0;
            row.Length = 0;

            for (int i = 0; i < hostlane_order.Count; i++)
            {
                int hl_id = hostlane_order [i];

                List <DBRevisionWorkView2> rev  = null;
                DBRevisionWorkView2        work = null;

                for (int k = 0; k < data.RevisionWorkHostLaneRelation.Count; k++)
                {
                    if (data.RevisionWorkHostLaneRelation [k] == hl_id)
                    {
                        rev = data.RevisionWorkViews [k];
                        break;
                    }
                }

                if (rev != null && rev.Count > counter)
                {
                    work = rev [counter];
                    added++;
                }

                if (work != null)
                {
                    string  revision    = work.revision;
                    int     lane_id     = work.lane_id;
                    int     host_id     = work.host_id;
                    int     revision_id = work.revision_id;
                    DBState state       = work.State;
                    bool    completed   = work.completed;
                    string  state_str   = state.ToString().ToLowerInvariant();
                    bool    is_working;
                    string  str_date = string.Empty;

                    if (work.endtime.Year > 2000)
                    {
                        str_date = "<br/>" + TimeDiffToString(work.endtime, DateTime.UtcNow);
                    }

                    switch (state)
                    {
                    case DBState.Executing:
                        is_working = true;
                        break;

                    case DBState.NotDone:
                    case DBState.Paused:
                    case DBState.DependencyNotFulfilled:
                    case DBState.Ignore:
                        is_working = false;
                        break;

                    default:
                        is_working = !completed;
                        break;
                    }

                    long dummy;
                    if (revision.Length > 16 && !long.TryParse(revision, out dummy))
                    {
                        revision = revision.Substring(0, 8);
                    }

                    if (is_working)
                    {
                        row.AppendFormat(
                            @"<td class='{1}'>
								<center>
									<table class='executing'>
										<td>
											<a href='ViewLane.aspx?lane_id={2}&amp;host_id={3}&amp;revision_id={4}' title='{5}'>{0}{6}</a>
										</td>
									</table>
								<center>
							  </td>"                            ,
                            revision, state_str, lane_id, host_id, revision_id, "", str_date);
                    }
                    else
                    {
                        row.AppendFormat("<td class='{1}'><a href='ViewLane.aspx?lane_id={2}&amp;host_id={3}&amp;revision_id={4}' title='{5}'>{0}{6}</a></td>",
                                         revision, state_str, lane_id, host_id, revision_id, "", str_date);
                    }
                }
                else
                {
                    row.Append("<td>-</td>");
                }
            }

            if (added > 0 && row.Length > 0)
            {
                matrix.Append("<tr>");
                matrix.Append(row.ToString());
                matrix.Append("</tr>");
            }

            counter++;
        } while (counter <= limit && added > 0);

        matrix.AppendLine("</table>");

        return(matrix.ToString());
    }
Пример #10
0
 public static StatusStripRow GetRow(int hostlane, FrontPageResponse data)
 {
     return GetRow (hostlane, data, "LOOKUP");
 }
Пример #11
0
        public static void ListWorkItems(FrontPageResponse data)
        {
            foreach (int item in data.RevisionWorkHostLaneRelation) {
                DBHostLane dbhostlane = data.HostLanes.Where (p => p.id == item).FirstOrDefault ();
                DBLane dblane = data.Lanes.Where (p => p.id == dbhostlane.lane_id).FirstOrDefault ();
                DBHost dbhost = data.Hosts.Where (p => p.id == dbhostlane.host_id).FirstOrDefault ();

                System.Diagnostics.Debug.WriteLine (string.Format ("HostLane: {0} - Lane: {1} [{3}] - Host: {2} [{4}]", dbhostlane.id, dblane.lane, dbhost.host, dblane.id, dbhost.id));
            }
        }
Пример #12
0
        private void AddRowsToStrip(StatusStrip strip, string projectLink, int[] hosts, FrontPageResponse data)
        {
            string new_rev_link = "~/builds/{0}/{1}/{2}";

            foreach (int i in hosts) {
                StatusStripRow row = MonkeyWrenchHelper.GetRow (i, data);

                if (row != null)
                    strip.Rows.Add (row);
            }

            // Update each cell's link to the wrench URL, not the old MW URL
            foreach (var row in strip.Rows) {
                foreach (var cell in row.Cells) {
                    if (cell.IsHeader || cell.Text == "msvc: windows")
                        continue;

                    if (!string.IsNullOrEmpty (projectLink))
                        cell.Url = string.Format (new_rev_link, projectLink, row.HeaderText.Replace (": ", "-"), cell.Text.TrimStart ('r'));

                    cell.Text = Utilities.FormatRevision (cell.Text);
                }
            }
        }