Ejemplo n.º 1
0
        private static agsXMPP.XmppClientConnection CreateClient()
        {
            var client = new agsXMPP.XmppClientConnection();
            agsXMPP.Jid id = new agsXMPP.Jid("*****@*****.**");
            client.Password = "******";
            client.Username = id.User;
            client.Server = id.Server;
            client.AutoResolveConnectServer = true;

            client.OnMessage += (o, e) => { Console.WriteLine(e.Value); };
            client.OnAuthError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Value); };
            client.OnError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Message); };
            client.OnLogin += (o) =>
            {
                int i = 0;
                while (i<20)
                {
                    agsXMPP.Jid to = new agsXMPP.Jid("*****@*****.**");
                    agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(to);
                    msg.Body = "Hi how are you cmyworld";
                    msg.Type = agsXMPP.protocol.client.MessageType.chat;
                    client.Send(msg);
                    System.Threading.Thread.Sleep(2000);
                    i++;
                }
            };
            client.Open();
            return client;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void RegUser(string strUserName, string strPassword)
        {
            objXmpp = new agsXMPP.XmppClientConnection();
            objXmpp.OnRegistered          += new agsXMPP.ObjectHandler(objXmpp_OnRegistered);
            objXmpp.OnRegisterError       += new agsXMPP.XmppElementHandler(objXmpp_OnRegisterError);
            objXmpp.OnRegisterInformation += new agsXMPP.protocol.iq.register.RegisterEventHandler(objXmpp_OnRegisterInformation);

            strUserName = strUserName + "@ishow.xba.com.cn";

            agsXMPP.Jid jid = new agsXMPP.Jid(strUserName);
            objXmpp.Password        = strPassword;
            objXmpp.Username        = jid.User;
            objXmpp.Server          = jid.Server;
            objXmpp.RegisterAccount = true;
            objXmpp.Open();
        }
Ejemplo n.º 4
0
        public void Connect(Action onConnected)
        {
            _jabberClient = new agsXMPP.XmppClientConnection();
            agsXMPP.Jid id = new agsXMPP.Jid("*****@*****.**");
            _jabberClient.Password = "******";
            //client.Password="******";
            _jabberClient.Username = id.User;
            _jabberClient.Server = id.Server;
            _jabberClient.AutoResolveConnectServer = true;

            _jabberClient.OnAuthError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Value); };
            _jabberClient.OnError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Message); };
            _jabberClient.OnLogin += (o) =>
            {
                System.Diagnostics.Trace.TraceInformation("Login Successful");
                onConnected();
            };
            _jabberClient.Open();
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
        }
        private static agsXMPP.XmppClientConnection CreateClient()
        {
            var client = new agsXMPP.XmppClientConnection();
            agsXMPP.Jid id = new agsXMPP.Jid("*****@*****.**");
            client.Password = "******";
            client.Username = id.User;
            client.Server = id.Server;
            client.AutoResolveConnectServer = true;

            client.OnAuthError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Value); };
            client.OnError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Message); };
            client.OnLogin += (o) =>
            {
                System.Diagnostics.Trace.TraceInformation("Login Successful");
                //agsXMPP.Jid to = new agsXMPP.Jid("*****@*****.**");
                //agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(to);
                //msg.Body = "Hi how are you cmyworld";
                //msg.Type = agsXMPP.protocol.client.MessageType.chat;
                //client.Send(msg);
            };
            return client;
        }