private Image GetImage(string url, string user, string pass)
        {
            var req = new DigestHttpWebRequest(user, pass);

            Uri uri = new Uri(url);

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    return(Image.FromStream(responseStream));
                }
        }
        private Image GetImage(string url, ConfigModel options)
        {
            var req = new DigestHttpWebRequest(options.User, options.Pass);

            Uri uri = new Uri(url);

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    return(Image.FromStream(responseStream));
                }
        }
        private void DeployZip(string zipFile)
        {
            var responseString = string.Empty;

            var req = new DigestHttpWebRequest(UserName, Password);

            req.Method = WebRequestMethods.Http.Post;

            var formData = new MultipartFormData();

            formData.Add("mysubmit", "Install");
            formData.AddFile("archive", zipFile, "application/x-zip-compressed");
            req.PostData    = formData.GetMultipartFormData();
            req.ContentType = formData.ContentType;


            Uri uri = new Uri(string.Format(URL, BoxIP));

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            responseString = streamReader.ReadToEnd();

                            string          pattern = "<font color=\"red\">(.*?)<\\/font>";
                            MatchCollection matches = Regex.Matches(responseString, pattern);

                            foreach (Match m in matches)
                            {
                                if (m.Groups[1].Value.Contains("Install Success"))
                                {
                                    LogTaskMessage($"Deploy result: {m.Groups[1]}");
                                }
                                else
                                {
                                    Log.LogError($"Deploy result: {m.Groups[1]}");
                                }
                            }
                        }
                    }
                }
        }
        private static string GetImageUrl(string ip, string user, string pass)
        {
            var req = new DigestHttpWebRequest(user, pass);

            req.Method = WebRequestMethods.Http.Post;

            var formData = new MultipartFormData();

            formData.AddFile("archive", "", "application/octet-stream");
            formData.Add("passwd", "");
            formData.Add("mysubmit", "Screenshot");
            req.PostData    = formData.GetMultipartFormData();
            req.ContentType = formData.ContentType;

            Uri uri = new Uri(string.Format(URL, ip));

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            var responseString = streamReader.ReadToEnd();

                            var             pattern = "<img src=\"(.*?)\">";
                            MatchCollection matches = Regex.Matches(responseString, pattern);

                            foreach (Match m in matches)
                            {
                                return(String.Format("http://{0}/{1}", ip, m.Groups[1]));
                            }
                        }
                    }
                }

            return(null);
        }
Esempio n. 5
0
        private void DeployZip(string zipFile, string ip, ConfigModel options)
        {
            var responseString = string.Empty;

            var req = new DigestHttpWebRequest(options.User, options.Pass);

            req.Method = WebRequestMethods.Http.Post;

            var formData = new MultipartFormData();

            formData.Add("mysubmit", "Install");
            formData.AddFile("archive", zipFile, "application/x-zip-compressed");
            req.PostData    = formData.GetMultipartFormData();
            req.ContentType = formData.ContentType;


            Uri uri = new Uri(string.Format(URL, ip));

            using (HttpWebResponse webResponse = req.GetResponse(uri))
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            responseString = streamReader.ReadToEnd();

                            string          pattern = "<font color=\"red\">(.*?)<\\/font>";
                            MatchCollection matches = Regex.Matches(responseString, pattern);

                            foreach (Match m in matches)
                            {
                                Console.WriteLine("Deploy result: {0}", m.Groups[1]);
                            }
                        }
                    }
                }
        }