Example #1
0
        public bool Command(string cmd, string parameter)
        {
            HttpWebRequest request;
            var            returnContent = false;

            var uri = @"http://" + _parent.IP + ":" + _parent.MpcHcPort + "/command.html?wm_command=" + cmd;

            if (!String.IsNullOrEmpty(parameter))
            {
                uri += "&" + parameter;
            }
            try
            {
                request         = (HttpWebRequest)WebRequest.Create(new Uri(uri));
                request.Method  = "GET";
                request.Timeout = 1000;
                _parent.Log("MPCCOMMAND : " + cmd);
                _parent.Trace(uri);
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var reader = new StreamReader(stream, Encoding.UTF8))
                            {
                                var reqContent = reader.ReadToEnd();
                                _parent.Trace(reqContent);
                                returnContent = true;
                            }
                        }
                    }
                }
            }
            catch (WebException e)
            {
                _parent.Log("ERROR - MPCCOMMAND : " + cmd + " - " + e.Message);
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    _parent.MpcLoaded = false;
                }
            }
            return(returnContent);
        }