当前位置: 首页>>代码示例>>C#>>正文


C# IrcClient.Disconnect方法代码示例

本文整理汇总了C#中IrcDotNet.IrcClient.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# IrcClient.Disconnect方法的具体用法?C# IrcClient.Disconnect怎么用?C# IrcClient.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IrcDotNet.IrcClient的用法示例。


在下文中一共展示了IrcClient.Disconnect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleEventLoop

        private static void HandleEventLoop(IrcClient client)
        {
            _ircLocaluser = client.LocalUser;
              _hostNameToWebSockets.Add("", new WebSocketListenerClient(PrivateConstants.TestAccountWebsocketAuth));
              _hostNameToWebSockets[""].Run(sendToIrcProcessor);

              bool isExit = false;
              while (!isExit) {
            Console.Write("> ");
            var command = Console.ReadLine();
            switch (command) {
              case "exit":
            isExit = true;
            break;
              default:
            if (!string.IsNullOrEmpty(command)) {
              if (command.StartsWith("/") && command.Length > 1) {
                client.SendRawMessage(command.Substring(1));
              } else {
                Console.WriteLine($"Unknown command '{command}'");
              }
            }
            break;
            }
              }
              client.Disconnect();
        }
开发者ID:destinygg,项目名称:bot,代码行数:27,代码来源:Program.cs

示例2: Irc

        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 = "crymono" });

                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");
        }
开发者ID:PoppermostProductions,项目名称:CryMono-web,代码行数:55,代码来源:NotifyController.cs

示例3: Bot

        public Bot()
        {
            commands = Command.GetCommands(this);
            IsInChannel = false;
            IsIdentified = false;
            IsRunning = true;

            // Initialize commands
            foreach(Command command in commands)
                command.Initialize();

            client = new IrcClient
            {
                FloodPreventer = new IrcStandardFloodPreventer(4, 2000)
            };

            // TODO Nasty...
            connectedEvent = new ManualResetEventSlim(false);
            client.Connected += (sender, e) => connectedEvent.Set();

            client.Connected += (sender, args) => Console.WriteLine("Connected!");
            client.Disconnected += (sender, args) =>
            {
                const int MaxRetries = 16;
                int tries = 0;

                if (!IsRunning)
                {
                    Console.WriteLine("Disconnected and IsRunning == false, assuming graceful shutdown...");
                    return;
                }

                IsInChannel = false;
                IsIdentified = false;

                // Wait a little so the server doesn't block us from rejoining (flood control)
                Console.WriteLine("Lost connection, attempting to reconnect in 6 seconds...");
                client.Disconnect();
                Thread.Sleep(6000);

                // Reconnect
                Console.Write("Reconnecting... ");
                while (!Connect(Configuration.Server) && tries++ < MaxRetries)
                {
                    Console.Write("\rReconnecting, attempt {0}...", tries);
                    Thread.Sleep(1);
                }

                if (tries == MaxRetries)
                {
                    Console.WriteLine("Failed.");
                    Quit("Failed to reconnect.");
                    return;
                }

                Console.WriteLine("Connected");
                Console.Write("Joining channel... ");

                if (JoinChannel(Configuration.Channel))
                    Console.WriteLine("Success");
                else
                {
                    Console.WriteLine("Failed");
                    Quit("Failed to rejoin channel.");
                }
            };

            client.Registered += (sender, args) =>
            {
                IrcClient localClient = (IrcClient)sender;

                // Identify with server
                client.SendRawMessage(String.Format("ns identify {0}", Configuration.Password));

                localClient.LocalUser.NoticeReceived += (o, eventArgs) =>
                {
                    if (eventArgs.Text.StartsWith("Password accepted"))
                        IsIdentified = true;

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(eventArgs.Text);
                    Console.ForegroundColor = ConsoleColor.Gray;
                };

                localClient.LocalUser.JoinedChannel += (o, eventArgs) =>
                {
                    IrcChannel channel = localClient.Channels.FirstOrDefault();
                    if (channel == null)
                        return;

                    Console.WriteLine("Joined channel!");

                    channel.MessageReceived += HandleMessage;
                    channel.UserJoined += (sender1, userEventArgs) =>
                    {
                        string joinMessage = String.Format("Used joined: {0}", userEventArgs.Comment ?? "No comment");

                        foreach (Command command in commands)
                            command.HandlePassive(joinMessage, userEventArgs.ChannelUser.User.NickName);
                    };
//.........这里部分代码省略.........
开发者ID:ponglesesquire,项目名称:Assbot,代码行数:101,代码来源:Bot.cs

示例4: TravisCi


//.........这里部分代码省略.........

                        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 = "crymono" });

                                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?");
        }
开发者ID:PoppermostProductions,项目名称:CryMono-web,代码行数:101,代码来源:NotifyController.cs


注:本文中的IrcDotNet.IrcClient.Disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。