/// <summary>
 /// Instantiantes an instanceof the driver with it's configuration parameters
 /// </summary>
 /// <param name="allAdapters"></param>
 /// <param name="device"></param>
 public BuildWatchDriver(List<TfsBuildAdapter> allAdapters, IBuildIndicatorDevice device,
     int pollPauseBetweenRequestsInMilliseconds,
     int exceptionPauseInMilliseconds,
     HttpListenerWrapper httpListenerWrapper)
 {
     this.allAdapters = allAdapters;
     this.device = device;
     this.pollPauseBetweenRequestsInMilliseconds = pollPauseBetweenRequestsInMilliseconds;
     this.exceptionPauseInMilliseconds = exceptionPauseInMilliseconds;
     this.httpListenerWrapper = httpListenerWrapper;
 }
Beispiel #2
0
        //// from MSDN examples
        public static void ListenerCallback(IAsyncResult result)
        {
            log.Debug("received http listener callback");
            HttpListenerWrapper listener = (HttpListenerWrapper)result.AsyncState;
            // Call EndGetContext to complete the asynchronous operation.
            HttpListenerContext context = listener.myListener.EndGetContext(result);
            HttpListenerRequest request = context.Request;
            // Obtain a response object.
            HttpListenerResponse response = context.Response;
            // Construct a response.
            string responseString = "<HTML>";

            responseString += "<head>";
            responseString += "<META HTTP-EQUIV='REFRESH' CONTENT='10'>";
            responseString += "<title>Build Status last shown on " + DateTime.Now.ToShortTimeString() + "</title>";
            responseString += "</head>";
            responseString += "<BODY>";
            responseString += "<table cellspacing='0' border='1'>";
            foreach (String buildName in listener.buildResults.Keys)
            {
                responseString += "<tr><td bgcolor='silver' colspan='2'>" + buildName + "</td></tr>";
                TfsLastTwoBuildResults[] theBuildSet = listener.buildResults[buildName];
                foreach (TfsLastTwoBuildResults aResultPair in theBuildSet)
                {
                    if (aResultPair.LastBuild != null)
                    {
                        IBuildDetail lastBuild = aResultPair.LastBuild;
                        String       bgcolor   = "white";
                        if (lastBuild.Status == BuildStatus.Succeeded)
                        {
                            bgcolor = "green";
                        }
                        else if (lastBuild.Status == BuildStatus.PartiallySucceeded)
                        {
                            bgcolor = "yellow";
                        }
                        else if (lastBuild.Status == BuildStatus.Failed)
                        {
                            bgcolor = "red";
                        }
                        else
                        {
                            bgcolor = "gray";
                        }
                        responseString += "<tr>";
                        responseString += "<td bgcolor='" + bgcolor + "' >" + lastBuild.BuildDefinition.Name + "</td>";
                        responseString += "<td bgcolor='" + bgcolor + "' >" + lastBuild.Status + "</td>";
                        responseString += "</tr>";
                    }
                }
            }
            responseString += "</table>";
            responseString += "</BODY></HTML>";
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            // Get a response stream and write the response to it.
            response.ContentLength64 = buffer.Length;
            System.IO.Stream output = response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            // You must close the output stream.
            output.Close();
            // reenable the listener so we will be ready for another request
            listener.myListener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
        }