Skip to content

Instantly share code, notes, and snippets.

@sitefinitySDK
Last active November 30, 2022 15:02
SF_10.1, SF_10.2, SF_11.0, SF_11.1, SF_11.2, SF_12.0, SF_12.1, SF_12.2, SF_13.0, SF_13.1, SF_13.2, SF_13.3, SF_14.0, SF_14.1, SF_14.2, SF_14.3 - https://docs.sitefinity.com/application-status-page-in-continuous-integration-scenarios
using Microsoft.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Web;
namespace CiUtilities
{
public static class SitefinityStatusHelper
{
/// <summary>
/// Waits for sitefintiy to start.
/// </summary>
/// <param name="testingInstanceUrl">The testing Sitefinity instance url.</param>
/// <param name="totalWaitSeconds">the maximum wait time in seconds.</param>
public static void WaitForSitefinityToStart(string testingInstanceUrl, double totalWaitSeconds)
{
// While /appstatus service is responding, Sitefinity is either in Initialize or Upgrade state.
// Since Sitefinity Bootstrap is running on a different than main thread, getting of the tests is postoned until Sitefinity is up and running
DateTime startTime = DateTime.UtcNow;
TimeSpan elapsedTime = new TimeSpan();
HttpResponseMessage response;
HttpClient client = new HttpClient();
do
{
response = client.Get(testingInstanceUrl + "/appstatus");
Thread.Sleep(1000);
elapsedTime = DateTime.UtcNow.Subtract(startTime);
} while (response.StatusCode == HttpStatusCode.OK && elapsedTime.TotalSeconds < totalWaitSeconds);
if (elapsedTime.TotalSeconds > totalWaitSeconds)
{
throw new Exception("Sitefinity did not start in less than " + totalWaitSeconds / 60 + " minultes.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment