예제 #1
0
파일: Program.cs 프로젝트: vsrz/desbot_vsrz
        static void Main()
        {
            //set up environment
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //ask for token
            Token token;
            using (ConnectDialog dialog = new ConnectDialog(Token.LocalHostToken()))
            {
                DialogResult result = dialog.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }
                token = dialog.ConnectToken;
            }

            //reset handling
            State.OnReset += new OnStateReset(OnReset);

            //init watcher
            Watcher.Init();

            //create form
            Form = new MainForm();

            //set up connection
            Bot = new Connection(new Listener.LogDelegate(Program.Log), token);
            Bot.OnReceive += new Connection.OnReceiveEventHandler(Fetcher.OnBotObject);

            //run application
            Form.Run();

            //kill bot
            try
            {
                Thread.Sleep(100);
                Bot.Stop();
                Thread.Sleep(100);
            }
            catch (Exception ex)
            {
                Log("Exception during connection shutdown: " + ex.Message);
            }

            //display messagebox on error
            if (Bot.State == ConnectionState.Error)
            {
                MessageBox.Show("The connection to desBot failed:\n" + Bot.GetError(), "Connection failed");
            }
        }
예제 #2
0
 /// <summary>
 /// Removes a connection from the listener (used internally)
 /// </summary>
 /// <param name="connection">The connection to remove</param>
 void RemoveConnection(Connection connection)
 {
     lock (this)
     {
         if (connections.Contains(connection))
         {
             connections.Remove(connection);
         }
         log("Removing connection with state " + connection.State.ToString() + " and error: " + connection.GetError());
     }
 }