Exemplo n.º 1
0
		private void menuItem4_Click(object sender, System.EventArgs e)
		{
			if(session == null || session.State != SessionState.LoggedIn)
			{
				// Get login information
				SignInForm s = new SignInForm();
				s.ShowDialog();

				// Open the session
				if(s.DialogResult == DialogResult.OK)
				{
					// Show status bar
					statForm.Show();

					//Reinitialize chats
					chats = new Hashtable();

					// Close the old session
					if(session != null) session.Close();
					
					// Create TCP connection
					//SecurableTcpClient tcpClient = new MentalisTcpClient(s.Server, s.Port);
					SecurableTcpClient tcpClient = new MonoTcpClient(s.Server, s.Port);

					// Create a new session
					session = new Session(tcpClient);
					session.OnAnyReceive += new XmlProtocolElementHandler(session_OnAnyReceive);
					session.OnAnySend += new XmlProtocolElementHandler(session_OnAnySend);
					session.OnError += new SessionEventHandler(session_OnError);
					session.OnStateChange += new SessionEventHandler(session_OnStateChange);
					session.OnStanzaReceive += new StanzaHandler(session_OnStanzaReceive);

					// Open the session
					bool loggedIn = session.Open(s.Domain, s.Resource, s.Username, s.Password, 30000);
					statForm.Hide();

					// Retrieve the roster and send presence information
					if(loggedIn)
					{
						session.SendStanza(StanzaFactory.GetRosterStanza(session.JabberID));
						session.SendStanza(StanzaFactory.GetPresenceBroadcastStanza("online", "en"));
						menuItem4.Text = "Sign Out";
					}
					else
					{
						session.Close();
						MessageBox.Show("Login failure!");
					}
				}
			}
			else
			{
				session.Close();
				rosterView.Nodes.Clear();
				menuItem4.Text = "Sign In";
			}
		}
Exemplo n.º 2
0
		private void button1_Click(object sender, System.EventArgs e)
		{
			SecurableTcpClient tcpClient = new MonoTcpClient(serverBox.Text, int.Parse(portBox.Text));
			AccountManager manager = new AccountManager(tcpClient);

			manager.OnRegistrationFieldsReceived += new AccountRegistrationHandler(manager_OnRegistrationFieldsReceived);
			manager.OnSuccess += new EventHandler(manager_OnSuccess);
			manager.OnFailure += new EventHandler(manager_OnFailure);
			manager.OnAnyReceive += new XmlProtocolElementHandler(manager_OnAnyReceive);
			manager.OnAnySend += new XmlProtocolElementHandler(manager_OnAnySend);
			manager.OnError += new SessionEventHandler(manager_OnError);

			manager.RequestAccountRegistration(domainBox.Text, 30000);
		}