<%@ Page Language="c#" %> <%@ OutputCache Duration="1" Location="Server" VaryByParam="TeamProject" VaryByHeader="Accept-Language" %> <% // This posting is provided "AS IS" with no warranties of any kind and confers no rights. // Use of samples included in this posting is subject to the terms specified // at http://www.microsoft.com/info/cpyright.htm. %> <%@ Assembly Name="Microsoft.TeamFoundation.Build.common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Collections" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Xml" %> <%@ Import Namespace="Microsoft.TeamFoundation" %> <%@ Import Namespace="Microsoft.TeamFoundation.Build.Server" %> <%@ Import Namespace="Microsoft.TeamFoundation.Build.Common" %> <%@ Import Namespace="System.Xml.Serialization" %> <% // Generate an RSS feed for Team Foundation Source Code Control checkins // // Note: Only one request per "pester interval" from each system will be honored. See // pesterInterval below. // %> <% string teamProject = Request.Params["TeamProject"]; string buildType = Request.Params["BuildType"]; if (string.IsNullOrEmpty(teamProject)) { Response.StatusCode = 400; Response.End(); } if (string.IsNullOrEmpty(buildType)) buildType = null; // The maximum number of changes to return per query const int maxBuilds = 50; const string rssVersion = "2.0"; const string rssLanguage = "en-US"; string rssTitle = "Team Build " + teamProject + " " + buildType; const string rssGenerator = "Sample RSS Feed Generator for Team Foundation"; const string rssDescription = "This feed provides information on Team Builds"; const string rssItemTitle = "{0} Build {1}"; const string rssItemDescription = "

Build {0} was fired by {1} on {2}. You can view the details of the build by selecting the provided link.

"; const string buildUriFormat = "{0}://{1}:{2}/Build/Build.aspx?TeamProject={3}&BuildNumber={4}"; Response.ContentType = "application/xhtml+xml"; XmlWriterSettings set = new XmlWriterSettings(); set.Indent = true; //XmlTextWriter xt = new XmlTextWriter(Response.OutputStream, null); //xt.Formatting = Formatting.Indented; using (XmlWriter xt = XmlWriter.Create(Response.OutputStream, set)) { xt.WriteProcessingInstruction("xml-stylesheet", @"href=""http://feeds.feedburner.com/~d/styles/rss2full.xsl"" type=""text/xsl"" media=""screen"""); xt.WriteProcessingInstruction("xml-stylesheet", @"href=""http://feeds.feedburner.com/~d/styles/itemcontent.css"" type=""text/css"" media=""screen"""); try { xt.WriteStartElement("rss"); xt.WriteAttributeString("version", rssVersion); xt.WriteStartElement("channel"); xt.WriteElementString("tile", rssTitle); xt.WriteElementString("link", Request.Url.ToString()); xt.WriteElementString("description", rssDescription); xt.WriteElementString("language", rssLanguage); xt.WriteElementString("generator", rssGenerator); BuildStore buildInfo = new BuildStore(); BuildData[] listOfBuilds = buildInfo.GetListOfBuilds(teamProject, buildType); XmlSerializer ser = new XmlSerializer(typeof(BuildData)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); int startIndex = Math.Max(listOfBuilds.Length - maxBuilds - 1, 0); for (int index = startIndex; index < listOfBuilds.Length; index++) { BuildData build = listOfBuilds[index]; DateTime pubDate = build.FinishTime; if (pubDate == DateTime.MinValue) continue; string extAddrLink = string.Format(buildUriFormat, Request.Url.Scheme, Request.Url.Host, Request.Url.Port, teamProject, build.BuildNumber); xt.WriteStartElement("item"); xt.WriteElementString("title", string.Format(rssItemTitle, build.BuildStatus, build.BuildNumber)); xt.WriteElementString("link", extAddrLink); xt.WriteElementString("pubDate", pubDate.ToUniversalTime().ToString(@"ddd, dd MMM yyyy HH:mm:ss G\MT")); xt.WriteStartElement("description"); xt.WriteString(string.Format(rssItemDescription, build.BuildNumber, build.RequestedBy, build.StartTime, extAddrLink)); // Pull full log data for failed builds. if (build.BuildStatusId == 200 && Directory.Exists(build.DropLocation)) { string html = "

Release build log

";
                    string logFile = Path.Combine(build.DropLocation, "Release.txt");
                    html += File.ReadAllText(logFile);
                    html += "

"; html = "

Full MSBuild log

";
                    logFile = Path.Combine(build.DropLocation, "BuildLog.txt");
                    html += File.ReadAllText(logFile);
                    html += "

"; xt.WriteString(HttpUtility.HtmlEncode(html)); } set.OmitXmlDeclaration = true; MemoryStream mem = new MemoryStream(); XmlWriter w = XmlWriter.Create(mem, set); ser.Serialize(w, build, ns); w.Flush(); mem.Position = 0; xt.WriteString( "
" + HttpUtility.HtmlEncode(new StreamReader(mem).ReadToEnd()) + "
"); xt.WriteEndElement(); xt.WriteEndElement(); } } catch (Exception ex) { //Response.StatusCode = 404; Response.Write(ex); Response.End(); } } %>