Esempio n. 1
0
        public bool StartNewConnection(string userName, string password, string address, int port)
        {
            // Reset the connection if it is already open
            ResetConnection();
            hubConfig = null;

            // We can't connect if these have not been set
            if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(address) || port == 0)
            {
                return(false);
            }

            // Get an auth token if we dont have one
            var harmonyAuthToken = GetUserAuthToken(userName, password);

            if (harmonyAuthToken == null)
            {
                return(false);
            }

            OpenConnection(address, port);

            // Start pinging the harmony to keep the connection alive
            if (_pingThread == null)
            {
                _pingThread      = new Thread(new ThreadStart(PingHarmony));
                _pingThread.Name = "Ping_Harmony";
                _pingThread.Start();
            }

            // Get the config info
            GetConfig();

            return(true);
        }
Esempio n. 2
0
        public void GetConfig()
        {
            var iqCmd    = $"<iq type='get' from='1' to='guest' id='j64Harmony_4'><oa xmlns='connect.logitech.com' mime='vnd.logitech.harmony/vnd.logitech.harmony.engine?config'/></iq>";
            var response = SendReceiveSocketData(iqCmd, 2);

            // Turn the config into a strongly typed document
            string config = response.DocumentElement.FirstChild.NextSibling.InnerText;

            hubConfig = JsonConvert.DeserializeObject <HubConfig>(config);

            // Save the config to a file for debugging purposes
            File.WriteAllText("myHubConfig.json", JsonConvert.SerializeObject(hubConfig, Formatting.Indented));
        }