Exemplo n.º 1
0
        public static string Request([NotNull] string url, [NotNull] string pageName)
        {
            Assert.ArgumentNotNull(url, "url");
            Assert.ArgumentNotNullOrEmpty(pageName, "pageName");

            string result;
            string errorPrefix = pageName + " returned an error: ";

            try
            {
                Log.Info("Requesting URL {0}".FormatWith(url), typeof(string));
                result = WebRequestHelper.DownloadString(url).Trim();
                if (result.ToLower().StartsWith("error:"))
                {
                    throw new InvalidOperationException(errorPrefix + result);
                }
            }
            catch (WebException ex)
            {
                bool error500 = ex.Status == WebExceptionStatus.ProtocolError && ex.Message.Contains("(500)");
                Assert.IsTrue(!error500, errorPrefix + ex);
                result = TimedOut;
            }


            Log.Info("Install status: {0}".FormatWith(result), typeof(AgentHelper));
            return(result);
        }
        public static void StartInstance(Instance instance, int?timeout = null, string reason = null)
        {
            Assert.ArgumentNotNull(instance, "instance");

            string url = instance.GetUrl(@"/sitecore/service/keepalive.aspx?ts=" + DateTime.Now.Ticks + "&reason=" + (reason ?? "default"));

            Assert.IsNotNullOrEmpty(url, "url");
            try
            {
                WebRequestHelper.DownloadString(url, timeout);
            }
            catch (WebException ex)
            {
                string text        = "There is an issue with requesting '" + url + "'. ";
                var    webResponse = ex.Response;
                if (webResponse != null)
                {
                    using (var s = webResponse.GetResponseStream())
                    {
                        if (s != null)
                        {
                            using (StreamReader streamReader = new StreamReader(s))
                            {
                                text = streamReader.ReadToEnd();
                            }
                        }
                        else
                        {
                            text += "No error response stream provided.";
                        }
                    }
                }
                else
                {
                    text += "No error response provided.";
                }

                string text2 = string.Empty;
                try
                {
                    text2 = text.Substring(text.IndexOf("<title>") + "<title>".Length);
                    text2 = text2.Substring(0, text2.IndexOf("</title>"));
                }
                catch (Exception)
                {
                    text2 = text.Substring(0, Math.Min(text.Length, 200));
                }

                throw new WebException("{0} \r\nStatus: {1} \r\n{2}".FormatWith(ex.Message, ex.Status.ToString(), text2));
            }
        }
Exemplo n.º 3
0
        private string GetLatestVersion()
        {
            var latestVersion = string.Empty;
            var url           = BaseUrl.TrimEnd('/') + "/latest-version.txt";

            try
            {
                latestVersion = WebRequestHelper.DownloadString(url).Trim();
            }
            catch (Exception ex)
            {
                Log.Warn(ex, $"The {url} URL is unavailable");
            }

            return(latestVersion);
        }
 private static void GetLatestVersion(string path)
 {
     try
     {
         var folder = Path.GetDirectoryName(path);
         FileSystem.FileSystem.Local.Directory.Ensure(folder);
         var downloadUrl    = WebRequestHelper.DownloadString(BaseUrl + "download.txt");
         var packageZipPath = Path.Combine(folder, "package.zip");
         WebRequestHelper.DownloadFile(downloadUrl, packageZipPath);
         FileSystem.FileSystem.Local.Zip.UnpackZip(packageZipPath, folder);
     }
     catch (Exception ex)
     {
         WindowHelper.HandleError("Couldn't get latest version of Sitecore ConfigBuilder", true, ex, typeof(ConfigBuilderButton));
     }
 }
        private static string GetLatestVersion()
        {
            var latestVersion = string.Empty;
            var url           = BaseUrl + "latest-version.txt";

            try
            {
                latestVersion = WebRequestHelper.DownloadString(url).Trim();
            }
            catch (Exception ex)
            {
                Log.Warn("The {0} URL is unavailable".FormatWith(url), typeof(ConfigBuilderButton), ex);
            }

            return(latestVersion);
        }
Exemplo n.º 6
0
 private void GetLatestVersion(string path)
 {
     try
     {
         var folder = Path.GetDirectoryName(path);
         FileSystem.FileSystem.Local.Directory.Ensure(folder);
         var downloadTxtUrl = BaseUrl.TrimEnd('/') + "/download.txt";
         var downloadUrl    = WebRequestHelper.DownloadString(downloadTxtUrl).TrimEnd(" \r\n".ToCharArray());
         var packageZipPath = Path.Combine(folder, "package.zip");
         WebRequestHelper.DownloadFile(downloadUrl, packageZipPath);
         FileSystem.FileSystem.Local.Zip.UnpackZip(packageZipPath, folder);
     }
     catch (Exception ex)
     {
         WindowHelper.HandleError("Couldn't get latest version of " + AppName, true, ex);
     }
 }