Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using ComponentFactory.Krypton.Toolkit;
- using FacebookMessenger.Properties;
- using System.ComponentModel;
- using agsXMPP;
- using FacebookMessenger.Windows;
- namespace FacebookMessenger
- {
- partial class AppController : ApplicationContext
- {
- //Variables
- static AppController AppControllerSingleton = null;
- public HiddenWindow HiddenWindow = null;
- public LoginWindow LoginWindow = null;
- static XmppClientConnection Connection = new XmppClientConnection();
- //Delegates
- delegate void OnMessageDelegate(object sender, agsXMPP.protocol.client.Message msg);
- delegate void OnPresenceDelegate(object sender, agsXMPP.protocol.client.Presence Presence);
- public AppController()
- {
- HiddenWindow = new HiddenWindow();
- HiddenWindow.Visible = false;
- this.MainForm = HiddenWindow;
- HiddenWindow.Load += new EventHandler(HiddenWindow_Load);
- }
- public void HiddenWindow_Load(Object sender, EventArgs e)
- {
- InitializeConnectionSettings();
- ShowLoginWindow();
- }
- public void ShowLoginWindow()
- {
- LoginWindow = new LoginWindow();
- LoginWindow.FormClosed += new FormClosedEventHandler(LoginWindowExithandler);
- LoginWindow.Show();
- }
- public void Login(string Username, string Password) //Sent from LoginWindow
- {
- Connection.Username = Username;
- Connection.Password = Password;
- LoginWindow.ActiveForm.Text = String.Format("{0} - Logging In", Settings.Default.ApplicationTitle);
- Connection.Open();
- }
- public void LoginWindowExithandler(object sender,FormClosedEventArgs Arguments)
- {
- Application.Exit();
- }
- #region On* Callbacks
- private void OnRosterStart(object Sender)
- {
- if (LoginWindow.ActiveForm.InvokeRequired)
- {
- LoginWindow.ActiveForm.BeginInvoke(new ObjectHandler(OnRosterStart), new object[] { Sender });
- return;
- }
- LoginWindow.ActiveForm.Text = String.Format("{0} - Roster Started", Settings.Default.ApplicationTitle);
- }
- private void XmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
- {}
- private void OnRosterEnd(object Sender)
- {
- if (LoginWindow.ActiveForm.InvokeRequired)
- {
- LoginWindow.ActiveForm.BeginInvoke(new ObjectHandler(OnRosterEnd), new object[] { Sender });
- return;
- }
- LoginWindow.ActiveForm.Text = String.Format("{0} - Roster Ended", Settings.Default.ApplicationTitle);
- }
- private void OnLogin(object Sender)
- {
- if(LoginWindow.ActiveForm.InvokeRequired)
- {
- LoginWindow.ActiveForm.BeginInvoke(new ObjectHandler(OnLogin), new object[] { Sender });
- return;
- }
- LoginWindow.ActiveForm.Text = String.Format("{0} - Fetching Contacts", Settings.Default.ApplicationTitle);
- }
- private void OnAuthError(object Sender, agsXMPP.Xml.Dom.Element Element)
- {
- if (LoginWindow.ActiveForm.InvokeRequired)
- {
- // Windows Forms are not Thread Safe, we need to invoke this :(
- // We're not in the UI thread, so we need to call BeginInvoke
- LoginWindow.ActiveForm.BeginInvoke(new XmppElementHandler(OnAuthError), new object[]{Sender, Element});
- return;
- }
- if (Connection.XmppConnectionState != XmppConnectionState.Disconnected)
- {
- Connection.Close();
- }
- MessageBox.Show("Authentication Error!\r\nWrong password or username.","Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
- LoginWindow.EnableControlls(true);
- }
- private void OnPresence(object sender, agsXMPP.protocol.client.Presence Presence)
- {}
- #endregion
- public void InitializeConnectionSettings()
- {
- Connection.Server = Settings.Default.FacebookChatServer;
- Connection.Port = 5222;
- //Assign Delegates
- //Connection.OnRosterEnd += new ObjectHandler(OnRosterEnd);
- //Connection.OnRosterItem += new agsXMPP.XmppClientConnection.RosterHandler(OnRosterItem);
- Connection.OnRosterStart += new ObjectHandler(OnRosterStart);
- Connection.OnLogin += new ObjectHandler(OnLogin);
- //Connection.OnMessage
- Connection.OnPresence += new agsXMPP.protocol.client.PresenceHandler(OnPresence);
- Connection.OnAuthError += new XmppElementHandler(OnAuthError);
- //Uneeded Atm
- //Connection.OnAgentEnd
- //Connection.OnAgentItem
- //Connection.OnAgentStart
- //Connection.OnBinded
- //Connection.OnClose
- //Connection.OnError
- //Connection.OnIq
- //Connection.OnPasswordChanged
- //Connection.OnReadSocketData
- //Connection.OnReadXml
- //Connection.OnRegistered
- //Connection.OnRegisterError
- //Connection.OnRegisterInformation
- //Connection.OnSaslEnd
- //Connection.OnSaslStart
- //Connection.OnSocketError
- //Connection.OnStreamError
- //Connection.OnWriteSocketData
- //Connection.OnWriteXml
- //Connection.OnXmppConnectionStateChanged
- }
- /*
- * Used to get a static instacne of the AppController
- **/
- public static AppController Instance
- {
- get
- {
- if (AppControllerSingleton == null)
- {
- AppControllerSingleton = new AppController();
- }
- return AppControllerSingleton;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement