public static void Publish(Instance instance)
        {
            Assert.ArgumentNotNull(instance, "instance");

            string publishUrl = AgentHelper.GetUrl(instance, PublishAgentFiles.PublishFileName);

            string statusUrl = AgentHelper.GetUrl(instance, PublishAgentFiles.StatusFileName);

            ExecuteAgent(AgentFiles.StatusFileName, statusUrl, PublishAgentFiles.PublishFileName, publishUrl);
        }
        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);
            }
        }