Quit() public method

Quits the server, giving the specified comment. Waits the specified duration of time before forcibly disconnecting.
The current instance has already been disposed.
public Quit ( int timeout, string comment = null ) : void
timeout int The number of milliseconds to wait before forcibly disconnecting.
comment string
return void
        public ActionResult Irc()
        {
            var api = new AppHarborApi(new AuthInfo { AccessToken = ConfigurationManager.AppSettings["authToken"] });

            var latestBuild = api.GetBuilds(Constants.AppHarborAppName).First();
            var testResults = api.GetTests(Constants.AppHarborAppName, latestBuild.ID);
            List<AppHarbor.Model.Test> allTests = new List<AppHarbor.Model.Test>();

            foreach (var testresult in testResults)
            {
                FillTests(allTests, testresult);
            }

            AutoResetEvent are = new AutoResetEvent(false);
            IrcDotNet.IrcClient client = new IrcDotNet.IrcClient();

            try
            {
                client.Connect("irc.gamesurge.net", false, new IrcUserRegistrationInfo() { NickName = "crymono-build", RealName = "crymono", UserName = "******" });

                client.ClientInfoReceived += (s, e) => are.Set();

                are.WaitOne();

                client.Channels.Join(new string[] { "#crymono" });

                Thread.Sleep(200);
                string msg = latestBuild.Commit.Message.Replace("\n", "").Replace("\r", "");

                client.LocalUser.SendMessage("#crymono", "Build finished, latest commit: " + msg);
                Thread.Sleep(200);

                int numPassedTests = allTests.Count(t => t.Status == "Passed");
                float percentage = (float)numPassedTests / allTests.Count * 100;
                client.LocalUser.SendMessage("#crymono", String.Format("Test results: {0} of {1} passed ({2:0}%) - http://crymono.apphb.com/#!/{3} - AppHB: https://appharbor.com/applications/crymonobuild/builds/{3}/tests",
                    numPassedTests,
                    allTests.Count,
                    percentage,
                    latestBuild.ID
                    ));
                Thread.Sleep(200);

            }
            finally
            {
                if (client != null && client.IsConnected)
                {
                    client.Quit("to the hills!");
                    Thread.Sleep(200);
                    client.Disconnect();
                }
            }

            return Content("OK");
        }
示例#2
0
        public void Listen(IrcClient.IrcMessage ircMessage)
        {
            string message = ircMessage.Parameters[1];

            if (message.ToLower().StartsWith(this.Nick.ToLower()))
            {
                string receivedMessageNick = ircMessage.Parameters[0];
                Regex  reg     = new Regex(@"[\w]+");
                int    outvar  = 0;
                string zipCode = string.Empty;
                foreach (Match m in reg.Matches(message))
                {
                    switch (m.Value.ToLower())
                    {
                    case "weather":
                        Match zip = m.NextMatch();
                        if (zip != null)
                        {
                            if (zip.Length == 5 && int.TryParse(zip.Value, out outvar))
                            {
                                zipCode = outvar.ToString();
                            }
                            else if (zip.Length == 3)
                            {
                                zipCode = zip.ToString();
                            }
                        }
                        Weather w = new Weather(zipCode);
                        ParameterizedThreadStart pts = new ParameterizedThreadStart(ProcessRequest);
                        Thread t = new Thread(pts);
                        t.Start(w);
                        break;

                    case "leave":
                        if (ircMessage.Source.Name.ToLower().Equals("syrfox"))
                        {
                            SendMessage(":<");
                            client.Quit();
                        }
                        break;
                    }
                }
                return;
            }
        }
        //
        // GET: /Notify/
        public ActionResult TravisCi()
        {
            var payload = Request.Form["payload"];

            JObject jsonPayload = null;

            if (payload != null)
            {jsonPayload = (JObject)JsonConvert.DeserializeObject(payload);}

            TimeSpan buildDuration;
            bool buildSuccess = true;
            int buildId = 0;

            HttpWebRequest webRequest =
                (HttpWebRequest)HttpWebRequest.Create("http://www.travis-ci.org/repositories.json?slug=inkdev%2FCryMono");

            using (StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream()))
            {
                string result = sr.ReadToEnd();

                var jsonResult = ((JArray)JsonConvert.DeserializeObject(result))[0];

                buildDuration = TimeSpan.FromSeconds(jsonResult["last_build_duration"].Value<double>());
                buildSuccess = jsonResult["last_build_status"].Value<int>() == 0;
                buildId = jsonResult["last_build_id"].Value<int>();

                var type = jsonResult.GetType();
            }

            // Get build log
            webRequest = (HttpWebRequest)HttpWebRequest.Create(String.Format("http://www.travis-ci.org/jobs/{0}.json", buildId + 1));

            using (StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream()))
            {
                string result = sr.ReadToEnd();

                var jsonResult = ((JObject)JsonConvert.DeserializeObject(result));

                string log = jsonResult["log"].Value<string>();

                bool buildResult = false;
                using (StringReader stringReader = new StringReader(log))
                {
                    string line = stringReader.ReadLine();

                    string summary = "No tests run";
                    while (line != null)
                    {

                        if (line.Equals("-- START TEST RUN --"))
                        {
                            buildResult = true;
                        }  else if (line.StartsWith("Tests run: "))
                        {
                            summary = line + " - " + stringReader.ReadLine();
                        }
                        else if (line.Equals("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>"))
                        {
                            string xmlContents = stringReader.ReadToEnd();

                            xmlContents = xmlContents.Substring(0, xmlContents.IndexOf("</test-results>")+15);

                            XDocument doc = XDocument.Parse(xmlContents);

                            AutoResetEvent are = new AutoResetEvent(false);
                            IrcDotNet.IrcClient client = new IrcDotNet.IrcClient();

                            try
                            {
                                client.Connect("irc.gamesurge.net", false, new IrcUserRegistrationInfo() { NickName = "inkdev-build", RealName = "crymono", UserName = "******" });

                                client.ClientInfoReceived += (s, e) => are.Set();

                                are.WaitOne();

                                //client.Channels.Join(new string[] { "#crymono" });

                                Thread.Sleep(200);
                                //string msg = latestBuild.Commit.Message.Replace("\n", "").Replace("\r", "");
                                string msg = "hello";
                                string buildStatus = buildResult ? "OK" : "FAILED";

                                client.LocalUser.SendMessage("#crymonobuild", String.Format("Travis build completed. Build: {0} - http://travis-ci.org/inkdev/CryMono/builds/{1}", buildStatus,buildId));
                                Thread.Sleep(200);
                                var testResultsElement = doc.Element("test-results");
                                client.LocalUser.SendMessage("#crymonobuild", String.Format("Tests run: {0}, Errors: {1}, Failures: {2}, Inconclusive: {3}, Not run: {4}, Invalid: {5}, Ignored: {6}, Skipped: {7}, Time: {8}s",
                                    testResultsElement.Attribute("total").Value,
                                    testResultsElement.Attribute("errors").Value,
                                    testResultsElement.Attribute("failures").Value,
                                    testResultsElement.Attribute("inconclusive").Value,
                                    testResultsElement.Attribute("not-run").Value,
                                    testResultsElement.Attribute("invalid").Value,
                                    testResultsElement.Attribute("ignored").Value,
                                    testResultsElement.Attribute("skipped").Value,
                                    doc.Descendants("test-suite").First().Attribute("time").Value

                                    ));
                                Thread.Sleep(500);

                                var failingTests =
                                    doc.Descendants("test-case").Where(
                                        x =>
                                        x.Attribute("success").Value == "False" &&
                                        x.Descendants().Any(d => d.Name == "failure")).Take(3);

                                foreach (var item in failingTests)
                                {
                                    client.LocalUser.SendMessage("#crymonobuild", String.Format("{0}: {1}",
                                        item.Attribute("name").Value,
                                        item.Element("failure").Element("message").Value.Replace("\n","")));
                                    Thread.Sleep(500);
                                }

                                if (payload == null)
                                {
                                    client.LocalUser.SendMessage("#crymonobuild", "Something wrong: " + String.Join(",",Request.Form.AllKeys));
                                }
                                else
                                {

                                    client.LocalUser.SendMessage("#crymonobuild",
                                                                 "Debug for ins\\: " + payload);
                                }
                                Thread.Sleep(5000);

                            }
                            finally
                            {
                                if (client != null && client.IsConnected)
                                {
                                    client.Quit("to the hills!");
                                    Thread.Sleep(200);
                                    client.Disconnect();
                                }
                            }

                            break;
                        }

                        line = stringReader.ReadLine();

                    }
                }

            }

            return Content("What?");
        }