Exemplo n.º 1
0
        protected void EnsureConnection()
        {
            if (Xmpp.XmppConnectionState == XmppConnectionState.Disconnected)
            {
                Xmpp.Open(_username, _token);

                WaitForData(5);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor with standard settings for a new HarmonyClient
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="port"></param>
        /// <param name="token"></param>
        public HarmonyClient(string ipAddress, int port, string token)
        {
            Xmpp = new HarmonyClientConnection(ipAddress, port);
            Xmpp.OnLogin += delegate { Wait = false; };

            SessionToken = token;
            string username = string.Format("{0}@x.com", token);

            Xmpp.OnIq += OnIq;
            Xmpp.Open(username, token);

            WaitForData(5);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor with standard settings for a new HarmonyClient
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="port"></param>
        /// <param name="token"></param>
        public HarmonyClient(string ipAddress, int port, string token)
        {
            Xmpp          = new HarmonyClientConnection(ipAddress, port);
            Xmpp.OnLogin += delegate { Wait = false; };

            SessionToken = token;
            string username = $"{token}@x.com";

            Xmpp.OnIq += OnIq;
            Xmpp.Open(username, token);

            WaitForData(5);
        }
Exemplo n.º 4
0
        protected void EnsureConnection()
        {
            if (Xmpp.XmppConnectionState == XmppConnectionState.Disconnected)
            {
                Xmpp.Open(_username, _token);

                try
                {
                    Wait.WaitOne(5000);
                }
                finally { Wait.Reset(); }
            }
        }
Exemplo n.º 5
0
        public ActionResult Network(AuthModels.Network model)
        {
            if (ModelState.IsValid)
            {
                bool success = false;
                try
                {
                    var conn = new HarmonyClientConnection(model.Hostname, 5222);
                    var manualEvent = new ManualResetEvent(false);
                    conn.ClientSocket.OnConnect += (obj) =>
                    {
                        success = true;
                        manualEvent.Set();
                    };
                    conn.OnSocketError += (obj, ex) =>
                    {
                        manualEvent.Set();
                    };
                    try
                    {
                        conn.Open();
                        manualEvent.WaitOne(5000);
                    }
                    finally
                    {
                        try { conn.Close(); } catch { }
                    }
                }
                catch { }

                if (!success)
                {
                    ModelState.AddModelError("Hostname", "Your Harmony Hub could not be reached");
                }

                if (ModelState.IsValid)
                {
                    var model2 = new AuthModels.Login
                    {
                        State = model.State,
                        Hostname = Request.UserHostAddress
                    };

                    return View("Login", model2);
                }
            }

            return View(model);
        }