private void btnRegister_Click(object sender, EventArgs e) { string[] username = ApplicationPreferences.getUsername(); var cn = new agsXMPP.XmppClientConnection(username[1]); cn.RegisterAccount = true; cn.OnRegistered += (object sender2) => { MessageBox.Show("Your account is registered now.", "Create Jabber account", MessageBoxButtons.OK, MessageBoxIcon.Information); cn.Close(); /*button2_Click(null, null);*/ }; cn.OnRegisterError += (object sender2, Element e2) => { MessageBox.Show("Error while registering account: \n" + e2.ToString(), "Create Jabber account", MessageBoxButtons.OK, MessageBoxIcon.Error); }; cn.OnLogin += (object sender2) => { MessageBox.Show("This account is already registered.", "Create Jabber account", MessageBoxButtons.OK, MessageBoxIcon.Information); cn.Close(); /*button2_Click(null, null);*/ }; cn.OnAuthError += (object sender2, agsXMPP.Xml.Dom.Element e2) => { var text = e2.SelectSingleElement("text", true); MessageBox.Show("Error while registering account: \n" + (text != null ? text.Value : e2.ToString()), "Create Jabber account", MessageBoxButtons.OK, MessageBoxIcon.Error); }; cn.OnError += (object sender2, Exception e2) => { MessageBox.Show("Error while registering account: \n" + e2.ToString(), "Create Jabber account", MessageBoxButtons.OK, MessageBoxIcon.Error); }; cn.OnSocketError += (object sender2, Exception e2) => { MessageBox.Show("Error while registering account: \n" + e2.ToString(), "Create Jabber account", MessageBoxButtons.OK, MessageBoxIcon.Error); }; cn.Open(username[0], qq_txtPrefPassword.Text); }
private void SendMessages(string message) { Exception ex = null; var waitEvent = new System.Threading.ManualResetEvent(false); var uri = new Library.Utility.Uri(m_username.Contains("://") ? m_username : "******" + m_username); var con = new agsXMPP.XmppClientConnection(uri.Host, uri.Port == -1 ? (uri.Scheme == "https" ? 5223 :5222) : uri.Port); if (uri.Scheme == "https") { con.UseSSL = true; } var resource = uri.Path ?? ""; if (resource.StartsWith("/", StringComparison.Ordinal)) { resource = resource.Substring(1); } if (string.IsNullOrWhiteSpace(resource)) { resource = "Duplicati"; } agsXMPP.ObjectHandler loginDelegate = (sender) => { try { foreach (var recipient in m_to.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { con.Send(new agsXMPP.protocol.client.Message(recipient, agsXMPP.protocol.client.MessageType.chat, message)); } } catch (Exception e) { ex = e; } finally { waitEvent.Set(); } }; agsXMPP.ErrorHandler errorHandler = (sender, e) => { ex = e; waitEvent.Set(); }; agsXMPP.XmppElementHandler loginErroHandler = (sender, e) => { ex = new Exception(string.Format("Failed to log in: {0}", e)); waitEvent.Set(); }; con.OnLogin += loginDelegate; con.OnError += errorHandler; con.OnAuthError += loginErroHandler; //con.OnBinded += (sender) => {Console.WriteLine("Binded: {0}", sender);}; //con.OnIq += (sender, iq) => {Console.WriteLine("Iq: {0}", iq);}; //con.OnReadXml += (sender, xml) => {Console.WriteLine("ReadXml: {0}", xml);}; //con.OnWriteXml += (sender, xml) => {Console.WriteLine("writeXml: {0}", xml);};; con.Open(uri.Username, string.IsNullOrWhiteSpace(m_password) ? uri.Password : m_password, resource); var timeout = !waitEvent.WaitOne(TimeSpan.FromSeconds(30), true); con.OnLogin -= loginDelegate; con.OnError -= errorHandler; con.OnAuthError -= loginErroHandler; try { con.Close(); } catch { } if (ex != null) { throw ex; } if (timeout) { throw new TimeoutException(Strings.SendJabberMessage.LoginTimeoutError); } }
private void SendMessages(string message) { Exception ex = null; var waitEvent = new System.Threading.ManualResetEvent(false); var uri = new Library.Utility.Uri(m_username.Contains("://") ? m_username : "******" + m_username); var con = new agsXMPP.XmppClientConnection(uri.Host, uri.Port == -1 ? (uri.Scheme == "https" ? 5223 :5222) : uri.Port); if (uri.Scheme == "https") con.UseSSL = true; var resource = uri.Path ?? ""; if (resource.StartsWith("/")) resource = resource.Substring(1); if (string.IsNullOrWhiteSpace(resource)) resource = "Duplicati"; agsXMPP.ObjectHandler loginDelegate = (sender) => { try { foreach(var recipient in m_to.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) con.Send(new agsXMPP.protocol.client.Message(recipient, agsXMPP.protocol.client.MessageType.chat, message)); } catch (Exception e) { ex = e; } finally { waitEvent.Set(); } }; agsXMPP.ErrorHandler errorHandler = (sender, e) => { ex = e; waitEvent.Set(); }; agsXMPP.XmppElementHandler loginErroHandler = (sender, e) => { ex = new Exception(string.Format("Failed to log in: {0}", e.ToString())); waitEvent.Set(); }; con.OnLogin += loginDelegate; con.OnError += errorHandler; con.OnAuthError += loginErroHandler; //con.OnBinded += (sender) => {Console.WriteLine("Binded: {0}", sender);}; //con.OnIq += (sender, iq) => {Console.WriteLine("Iq: {0}", iq);}; //con.OnReadXml += (sender, xml) => {Console.WriteLine("ReadXml: {0}", xml);}; //con.OnWriteXml += (sender, xml) => {Console.WriteLine("writeXml: {0}", xml);};; con.Open(uri.Username, string.IsNullOrWhiteSpace(m_password) ? uri.Password : m_password, resource); var timeout = !waitEvent.WaitOne(TimeSpan.FromSeconds(30), true); con.OnLogin -= loginDelegate; con.OnError -= errorHandler; con.OnAuthError -= loginErroHandler; try { con.Close(); } catch { } if (ex != null) throw ex; if (timeout) throw new TimeoutException(Strings.SendJabberMessage.LoginTimeoutError); }
void objXmpp_OnRegisterError(object sender, agsXMPP.Xml.Dom.Element e) { Console.WriteLine(e.ToString()); objXmpp.Close(); }