@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using System.Diagnostics
@using System.Threading.Tasks

@{ 
	string repository = "Secondary users";
	string indexName = "Users.index";
	string buildName = "Users";

	Dynamicweb.Indexing.IndexHelper.BuildIndexInstances(repository, indexName, buildName);

	var indexService = Dynamicweb.Extensibility.ServiceLocator.Current.GetInstance<Dynamicweb.Indexing.IIndexService>();
	var index = indexService.LoadIndex(repository, indexName);
	Stopwatch stopwatch = new Stopwatch();
	stopwatch.Start();

	Task.WaitAll(Task.Delay(250));

	while (indexService.GetActiveBuildTasks(index).Any() && stopwatch.ElapsedMilliseconds < 5000)
	{
		Task.WaitAll(Task.Delay(1000));
	}
	stopwatch.Stop();

	Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + Pageview.Page.ID + "&LayoutTemplate=Swift-v2_PageClean.cshtml&Confirmation=InvitationSent");
}

