SIM.Pipelines.Agent.AgentHelper.Request C# (CSharp) Method

Request() private method

private Request ( [ url, [ pageName ) : string
url [
pageName [
return string
        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}", url);
            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}", result);
              return result;
        }

Usage Example

        private static void ExecuteAgent(string statusFileName, string statusUrl, string agentName, string operationUrl)
        {
            // Call agent main operation
            string status = AgentHelper.Request(operationUrl, agentName);

            // If the package installation process takes more than http timeout, retrieve status
            if (!IsCompleted(status))
            {
                // Retrieve status while the previous request timed out, status is in progress or package is already being installed
                while (!IsCompleted(status) && !status.StartsWith("Failed", StringComparison.OrdinalIgnoreCase))
                {
                    Thread.Sleep(2000);
                    status = AgentHelper.Request(statusUrl, statusFileName);
                }

                // Break the process if something went wrong and the package is not installed
                Assert.IsTrue(IsCompleted(status), status);
            }
        }