Skip to content

Instantly share code, notes, and snippets.

@wictorwilen
Created September 30, 2015 13:36
Show Gist options
  • Save wictorwilen/9ef361b7d510c229d8fc to your computer and use it in GitHub Desktop.
Save wictorwilen/9ef361b7d510c229d8fc to your computer and use it in GitHub Desktop.
SPO Create Site
SpoOperation op = _tenant.CreateSite(_newsite);
ctx.Load(_tenant);
ctx.Load(op, i => i.IsComplete);
try {
ctx.ExecuteQuery();
}
catch (ServerException se)
{
if(se.ServerErrorCode != -2146233083)
{
throw;
}
timeout_detected = true;
}
catch (WebException we)
{
if(we.Status != WebExceptionStatus.Timeout)
{
throw;
}
timeout_detected = true;
}
while (timeout_detected || !op.IsObjectPropertyInstantiated("IsComplete") || !op.IsComplete )
{
op.RefreshLoad();
timeout_detected = false;
try
{
// Use this as a keep alive (instead of increasing WEBJOBS_IDLE_TIMEOUT), also cannot have Infinite timeout
Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
"Waiting for Site Collection to be created....");
ctx.ExecuteQuery();
}
catch (ServerException se)
{
if (se.ServerErrorCode != -2146233083)
{
throw;
}
timeout_detected = true;
}
catch (WebException we)
{
if (we.Status != WebExceptionStatus.Timeout)
{
throw;
}
timeout_detected = true;
}
//wait 30seconds and try again
System.Threading.Thread.Sleep(30000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment