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));
        }
        public ActionResult Index(AuthModels.Index model)
        {
            if (ModelState.IsValid)
            {
                var model2 = new AuthModels.Network
                {
                    State    = model.State,
                    Hostname = Request.UserHostAddress
                };

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

            return(View(model));
        }