SHARE
TWEET

Untitled

a guest Jun 4th, 2017 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using ComponentFactory.Krypton.Toolkit;
  7. using FacebookMessenger.Properties;
  8. using System.ComponentModel;
  9. using agsXMPP;
  10. using FacebookMessenger.Windows;
  11.  
  12. namespace FacebookMessenger
  13. {
  14.     partial class AppController : ApplicationContext
  15.     {
  16.         //Variables
  17.         static AppController AppControllerSingleton = null;
  18.         public HiddenWindow HiddenWindow = null;
  19.         public LoginWindow LoginWindow = null;
  20.         static XmppClientConnection Connection = new XmppClientConnection();
  21.  
  22.         //Delegates
  23.         delegate void OnMessageDelegate(object sender, agsXMPP.protocol.client.Message msg);
  24.         delegate void OnPresenceDelegate(object sender, agsXMPP.protocol.client.Presence Presence);
  25.  
  26.         public AppController()
  27.         {
  28.  
  29.             HiddenWindow = new HiddenWindow();
  30.             HiddenWindow.Visible = false;
  31.             this.MainForm = HiddenWindow;
  32.  
  33.             HiddenWindow.Load += new EventHandler(HiddenWindow_Load);
  34.         }
  35.  
  36.         public void HiddenWindow_Load(Object sender, EventArgs e)
  37.         {
  38.             InitializeConnectionSettings();
  39.             ShowLoginWindow();
  40.         }
  41.  
  42.         public void ShowLoginWindow()
  43.         {
  44.             LoginWindow = new LoginWindow();
  45.             LoginWindow.FormClosed += new FormClosedEventHandler(LoginWindowExithandler);
  46.             LoginWindow.Show();
  47.         }
  48.  
  49.         public void Login(string Username, string Password) //Sent from LoginWindow
  50.         {
  51.             Connection.Username = Username;
  52.             Connection.Password = Password;
  53.             LoginWindow.ActiveForm.Text = String.Format("{0} - Logging In", Settings.Default.ApplicationTitle);
  54.             Connection.Open();
  55.         }
  56.  
  57.  
  58.         public void LoginWindowExithandler(object sender,FormClosedEventArgs Arguments)
  59.         {
  60.             Application.Exit();
  61.         }
  62.  
  63.         #region On* Callbacks
  64.         private void OnRosterStart(object Sender)
  65.         {
  66.             if (LoginWindow.ActiveForm.InvokeRequired)
  67.             {
  68.                 LoginWindow.ActiveForm.BeginInvoke(new ObjectHandler(OnRosterStart), new object[] { Sender });
  69.                 return;
  70.             }
  71.             LoginWindow.ActiveForm.Text = String.Format("{0} - Roster Started", Settings.Default.ApplicationTitle);
  72.         }
  73.  
  74.         private void XmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
  75.         {}
  76.  
  77.         private void OnRosterEnd(object Sender)
  78.         {
  79.             if (LoginWindow.ActiveForm.InvokeRequired)
  80.             {
  81.                 LoginWindow.ActiveForm.BeginInvoke(new ObjectHandler(OnRosterEnd), new object[] { Sender });
  82.                 return;
  83.             }
  84.             LoginWindow.ActiveForm.Text = String.Format("{0} - Roster Ended", Settings.Default.ApplicationTitle);
  85.         }
  86.  
  87.         private void OnLogin(object Sender)
  88.         {
  89.             if(LoginWindow.ActiveForm.InvokeRequired)
  90.             {
  91.                 LoginWindow.ActiveForm.BeginInvoke(new ObjectHandler(OnLogin), new object[] { Sender });
  92.                 return;
  93.             }
  94.             LoginWindow.ActiveForm.Text = String.Format("{0} - Fetching Contacts", Settings.Default.ApplicationTitle);
  95.         }
  96.  
  97.         private void OnAuthError(object Sender, agsXMPP.Xml.Dom.Element Element)
  98.         {
  99.             if (LoginWindow.ActiveForm.InvokeRequired)
  100.             {  
  101.                 // Windows Forms are not Thread Safe, we need to invoke this :(
  102.                 // We're not in the UI thread, so we need to call BeginInvoke              
  103.                 LoginWindow.ActiveForm.BeginInvoke(new XmppElementHandler(OnAuthError), new object[]{Sender, Element});
  104.                 return;
  105.             }
  106.            
  107.             if (Connection.XmppConnectionState != XmppConnectionState.Disconnected)
  108.             {
  109.                 Connection.Close();
  110.             }
  111.             MessageBox.Show("Authentication Error!\r\nWrong password or username.","Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
  112.             LoginWindow.EnableControlls(true);
  113.         }
  114.  
  115.         private void OnPresence(object sender, agsXMPP.protocol.client.Presence Presence)
  116.         {}
  117.  
  118.         #endregion
  119.  
  120.         public void InitializeConnectionSettings()
  121.         {
  122.             Connection.Server = Settings.Default.FacebookChatServer;
  123.             Connection.Port = 5222;
  124.  
  125.             //Assign Delegates
  126.             //Connection.OnRosterEnd += new ObjectHandler(OnRosterEnd);
  127.             //Connection.OnRosterItem += new agsXMPP.XmppClientConnection.RosterHandler(OnRosterItem);
  128.             Connection.OnRosterStart    += new ObjectHandler(OnRosterStart);
  129.             Connection.OnLogin          += new ObjectHandler(OnLogin);
  130.             //Connection.OnMessage
  131.             Connection.OnPresence       += new agsXMPP.protocol.client.PresenceHandler(OnPresence);
  132.             Connection.OnAuthError      += new XmppElementHandler(OnAuthError);
  133.  
  134.             //Uneeded Atm
  135.             //Connection.OnAgentEnd
  136.             //Connection.OnAgentItem
  137.             //Connection.OnAgentStart
  138.             //Connection.OnBinded
  139.             //Connection.OnClose
  140.             //Connection.OnError
  141.             //Connection.OnIq
  142.             //Connection.OnPasswordChanged
  143.             //Connection.OnReadSocketData
  144.             //Connection.OnReadXml
  145.             //Connection.OnRegistered
  146.             //Connection.OnRegisterError
  147.             //Connection.OnRegisterInformation
  148.             //Connection.OnSaslEnd
  149.             //Connection.OnSaslStart
  150.             //Connection.OnSocketError
  151.             //Connection.OnStreamError
  152.             //Connection.OnWriteSocketData
  153.             //Connection.OnWriteXml
  154.             //Connection.OnXmppConnectionStateChanged
  155.         }
  156.  
  157.         /*
  158.          * Used to get a static instacne of the AppController
  159.         **/
  160.         public static AppController Instance
  161.         {
  162.             get
  163.             {
  164.                 if (AppControllerSingleton == null)
  165.                 {
  166.                     AppControllerSingleton = new AppController();
  167.                 }
  168.                 return AppControllerSingleton;
  169.             }
  170.         }
  171.     }
  172. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top