Пример #1
0
        /// <summary><![CDATA[
        /// Wrapper method for building CSS from SCSS files, with partial injection.
        /// Will check and build every "Scss.BuildCheck.Seconds" when debug=true if there are file changes (production).
        /// Will check and build every page load when debug=true if there are file changes.
        /// Requires the following Carbide config items:
        /// ]]></summary>
        /// <example>
        /// <code><![CDATA[
        /// <add key="Scss.BuildCheck.Seconds" value="3600" />
        /// <add key="Scss.Root" value="/scss/" />
        /// <add key="Scss.Partials.Root" value="/scss/custom/" />
        /// <add key="Scss.Filename.Base" value="application" />
        /// <add key="Scss.Output.Root" value="/css/" />
        /// ]]></code>
        /// </example>
        public static void RunConfiguredScssBuild()
        {
            var scssPath         = Config.GetKeyValue("Scss.Root", "/scss/", "Fynydd.Carbide");
            var scssPartialsPath = Config.GetKeyValue("Scss.Partials.Root", "/scss/custom/", "Fynydd.Carbide");
            var scssFilenameBase = Config.GetKeyValue("Scss.Filename.Base", "application", "Fynydd.Carbide");
            var scssOutputPath   = Config.GetKeyValue("Scss.Output.Root", "/css/", "Fynydd.Carbide");

            var debugging = AppStateHelpers.IsDebugging();
            var buildScss = debugging; // Always run in debug mode

            if (debugging == false)
            {
                // Only run the check periodically on production unless the file doesn't exist

                if (FileExists(scssOutputPath + scssFilenameBase + ".css") == false)
                {
                    buildScss = true;
                }

                TemporalHelpers.TaskIntervalInit("ScssProductionBuild", Config.GetKeyValue <double>("Scss.BuildCheck.Seconds", 60 * 60 * 24, "Fynydd.Carbide"));

                if (TemporalHelpers.TaskShouldBeRun("ScssProductionBuild"))
                {
                    buildScss = true;
                }
            }

            if (buildScss == true)
            {
                if (debugging == false)
                {
                    TemporalHelpers.TaskIntervalStart("ScssProductionBuild");
                }

                StorageHelpers.InjectScssPartials(scssPath, scssFilenameBase + ".scss", scssPartialsPath);
                StorageHelpers.BuildScss(scssPath + scssFilenameBase + ".scss", scssOutputPath + scssFilenameBase + ".css", debugMode: debugging);

                if (debugging == false)
                {
                    TemporalHelpers.TaskIntervalStop("ScssProductionBuild");
                }
            }
        }
Пример #2
0
        /// <summary><![CDATA[
        /// Task Interval methods help manage scheduled activities triggered by web page views.
        /// These methods only track status and time. They do not execute anything.
        ///
        /// Check to see if a task should be run again. It ensures that the task is not currently running
        /// and that the task time in seconds set in TimeIntervalInit() has elapsed.
        /// ]]></summary>
        /// <param name="activityName">Name of the activity, like "TwitterImport".</param>
        /// <param name="context">Manually set the context if running the method from a thread.</param>
        public static bool TaskShouldBeRun(string activityName, HttpContext context = null)
        {
            bool result = true;

            if (context == null)
            {
                context = HttpContext.Current;
            }

            if (CacheHelpers.CacheExists(activityName + "_Waiting", context) == false)
            {
                try
                {
                    if (TaskIsRunning(activityName, context) == true)
                    {
                        result = false;

                        Debug.WriteLine("Carbide.TemporalHelpers.TaskShouldBeRun (" + activityName + ") - ALREADY RUNNING");
                    }
                }

                catch (Exception e)
                {
                    Debug.WriteLine("Carbide.Temporal EXCEPTION: TaskShouldBeRun (" + activityName + ") - " + e.Message);
                }
            }

            else
            {
                result = false;

                Debug.WriteLine("Carbide.TemporalHelpers.TaskShouldBeRun (" + activityName + ") - TOO SOON; " + FormatTimer((int)(TemporalHelpers.DateDiff <double>(DateTime.Now, CacheHelpers.Cache <DateTime>(activityName + "_Waiting", context), DateDiffComparisonType.Seconds)), " ") + " to go");
            }

            Debug.WriteLine("Carbide.TemporalHelpers.TaskShouldBeRun (" + activityName + ") - " + (result == true ? "YES" : "NO"));

            return(result);
        }
Пример #3
0
        public HttpResponseMessage PrerenderPages() // /umbraco/api/carbidesupport/prerenderpages/
        {
            string result = "";

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                Thread workerThread = new Thread(new ThreadStart(() =>
                {
                    StopWatch timer  = new StopWatch();
                    StopWatch timer2 = new StopWatch();

                    try
                    {
                        timer.Start();
                        context.Server.ScriptTimeout = 100000;

                        context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Pre-rendering templates... ";
                        timer2.Reset();
                        timer2.Start();

                        var umbracoHelper    = new UmbracoHelper(Carbide.ContextHelpers.EnsureUmbracoContext());
                        int pageCounter      = 0;
                        List <int> templates = new List <int>();

                        foreach (var node in umbracoHelper.TypedContentAtRoot())
                        {
                            ListChildNodes(node, ref pageCounter, ref context, ref templates);
                        }

                        if (pageCounter > 1)
                        {
                            var msg = context.Application["RebuildCacheHistory"].ToString();
                            msg     = msg.Substring(0, msg.LastIndexOf("..."));
                            context.Application["RebuildCacheHistory"] = msg + "... ";
                        }

                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>" + pageCounter + " template" + (pageCounter != 1 ? "s" : "") + " in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        timer.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] += "</ol>";

                        context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                    }

                    catch (Exception e)
                    {
                        timer.Stop();
                        timer2.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] = "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                        result = context.Application["RebuildCacheHistory"].ToString();
                    }
                }))
                {
                    IsBackground = true
                };
                workerThread.Start();

                while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                {
                    // Wait for worker thread to start up and initialize
                    System.Threading.Thread.Sleep(50);
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");
            return(response);
        }
Пример #4
0
        public HttpResponseMessage CompactDatabase(string days = "30")         // /umbraco/api/carbidesupport/compactdatabase/
        {
            string result   = "";
            var    response = new HttpResponseMessage(HttpStatusCode.OK);

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                if (days.IsPureNumeric() == true)
                {
                    int _days = int.Parse(days);

                    Thread workerThread = new Thread(new ThreadStart(() =>
                    {
                        StopWatch timer  = new StopWatch();
                        StopWatch timer2 = new StopWatch();

                        try
                        {
                            timer.Start();
                            context.Server.ScriptTimeout = 100000;

                            context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                            var daterange = "DATEADD(d, " + (_days * -1) + ", getdate())";
                            var ageText   = "> " + _days + " days old";



                            // Truncate log

                            timer2.Start();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Truncating log (" + ageText + ")... ";

                            var commands = @"DECLARE @out int = (SELECT COUNT(*) FROM umbracoLog WHERE Datestamp < " + daterange + @");
DELETE FROM umbracolog WHERE Datestamp < " + daterange + @";
SELECT @out;";
                            context.Application["RebuildCacheHistory"] += Carbide.SqlHelpers.Lookup <int>(commands, "umbracoDbDSN").FormatNumber(NumberFormats.Proper) + " deleted... ";

                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";



                            // Delete unused property data

                            timer2.Start();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Delete unused property data (" + ageText + ")... ";

                            commands = @"DECLARE @out int = (SELECT COUNT(*) FROM cmsPropertyData WHERE
	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > "     + daterange + @" OR newest = 1) AND
	contentNodeId IN (SELECT DISTINCT nodeID FROM cmsDocument));
DELETE FROM cmsPropertyData WHERE
	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > "     + daterange + @" OR newest = 1) AND
	contentNodeId IN (SELECT DISTINCT nodeID FROM cmsDocument);
SELECT @out;";
                            context.Application["RebuildCacheHistory"] += Carbide.SqlHelpers.Lookup <int>(commands, "umbracoDbDSN").FormatNumber(NumberFormats.Proper) + " deleted... ";

                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";



                            // Delete preview XML (pass 1)

                            timer2.Start();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Delete XML previews (" + ageText + ")... ";

                            commands = @"DECLARE @out int = (SELECT COUNT(*) FROM cmsPreviewXml WHERE
	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > "     + daterange + @" OR newest = 1) AND
	nodeId IN (SELECT DISTINCT nodeID FROM cmsDocument));
DELETE FROM cmsPreviewXml WHERE
	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > "     + daterange + @" OR newest = 1) AND
	nodeId IN (SELECT DISTINCT nodeID FROM cmsDocument);
SELECT @out;";
                            context.Application["RebuildCacheHistory"] += Carbide.SqlHelpers.Lookup <int>(commands, "umbracoDbDSN").FormatNumber(NumberFormats.Proper) + " deleted... ";

                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";



                            // Delete content versions

                            timer2.Start();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Delete content versions (" + ageText + ")... ";

                            commands = @"DECLARE @out int = (SELECT COUNT(*) FROM cmsContentVersion WHERE
	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > "     + daterange + @" OR newest = 1) AND
	ContentId  IN (SELECT DISTINCT nodeID FROM cmsDocument));
DELETE FROM cmsContentVersion WHERE
	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > "     + daterange + @" OR newest = 1) AND
	ContentId  IN (SELECT DISTINCT nodeID FROM cmsDocument);
SELECT @out;";
                            context.Application["RebuildCacheHistory"] += Carbide.SqlHelpers.Lookup <int>(commands, "umbracoDbDSN").FormatNumber(NumberFormats.Proper) + " deleted... ";

                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";



                            // Delete unpublished content

//						timer2.Start();
//							context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Delete unpublished content (" + ageText + ")... ";

//							commands = @"DECLARE @out int = (SELECT COUNT(*) FROM cmsDocument WHERE
//	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > " + daterange + @" OR newest = 1) AND
//	nodeId IN (SELECT DISTINCT nodeID FROM cmsDocument));
//DELETE FROM cmsDocument WHERE
//	versionId NOT IN (SELECT versionId FROM cmsDocument WHERE updateDate > " + daterange + @" OR newest = 1) AND
//	nodeId IN (SELECT DISTINCT nodeID FROM cmsDocument);
//SELECT @out;";
//							context.Application["RebuildCacheHistory"] += Carbide.SqlHelpers.Lookup<int>(commands, "umbracoDbDSN").FormatNumber(NumberFormats.Proper) + " deleted... ";

//							timer2.Stop();
//							context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds<int>() + " seconds</strong></li>";



                            // Delete preview XML (pass 2)

                            timer2.Start();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Delete XML previews (pass 2)... ";

                            commands = @"DECLARE @out int = (SELECT COUNT(*) FROM cmsPreviewXml WHERE
	versionId IN (SELECT cmsPreviewXml.versionId FROM cmsPreviewXml JOIN cmsDocument ON cmsPreviewXml.versionId=cmsDocument.versionId WHERE cmsDocument.newest <> 1));
DELETE FROM cmsPreviewXml WHERE
	versionId IN (SELECT cmsPreviewXml.versionId FROM cmsPreviewXml JOIN cmsDocument ON cmsPreviewXml.versionId=cmsDocument.versionId WHERE cmsDocument.newest <> 1);
SELECT @out;";
                            context.Application["RebuildCacheHistory"] += Carbide.SqlHelpers.Lookup <int>(commands, "umbracoDbDSN").FormatNumber(NumberFormats.Proper) + " deleted... ";

                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";



                            // REBUILD CONTENT CACHE

                            timer2.Reset();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Republishing all content... ";
                            timer2.Start();
                            Services.ContentService.RePublishAll();
                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                            timer2.Reset();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Refreshing XML cache... ";
                            timer2.Start();
                            umbraco.library.RefreshContent();
                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                            timer2.Reset();
                            context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Rebuilding Examine indexes... ";
                            timer2.Start();

                            foreach (var index in ExamineManager.Instance.IndexProviderCollection.ToList())
                            {
                                context.Application["RebuildCacheHistory"] += index.Name.Replace("Indexer", "") + "... ";
                                index.RebuildIndex();
                            }

                            timer2.Stop();
                            context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";


                            timer.Stop();

                            context.Application.SafeRemove("RebuildCacheStatus");

                            context.Application["RebuildCacheHistory"] += "</ol>";
                            context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                        }

                        catch (Exception e)
                        {
                            timer.Stop();
                            timer2.Stop();

                            context.Application.SafeRemove("RebuildCacheStatus");

                            context.Application["RebuildCacheHistory"] += "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                            result = context.Application["RebuildCacheHistory"].ToString();
                        }
                    }))
                    {
                        IsBackground = true
                    };
                    workerThread.Start();

                    while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                    {
                        // Wait for worker thread to start up and initialize
                        System.Threading.Thread.Sleep(50);
                    }
                }

                else
                {
                    context.Application.SafeRemove("RebuildCacheStatus");

                    context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";
                    context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Days is not a numeric value.</li>";
                    context.Application["RebuildCacheHistory"] += "</ol>";
                    context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Aborted</h4>";

                    result = context.Application["RebuildCacheHistory"].ToString();
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");

            return(response);
        }
Пример #5
0
        public HttpResponseMessage RebuildImageCache() // /umbraco/api/carbidesupport/rebuildimagecache/
        {
            string result = "";

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                Thread workerThread = new Thread(new ThreadStart(() =>
                {
                    StopWatch timer  = new StopWatch();
                    StopWatch timer2 = new StopWatch();

                    try
                    {
                        timer.Start();
                        context.Server.ScriptTimeout = 100000;

                        context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Clearing cached images... ";
                        timer2.Start();

                        foreach (var folder in StorageHelpers.GetFolders("/App_Data/cache/"))
                        {
                            StorageHelpers.DeleteDirectory("/App_Data/cache/" + folder);

                            if (StorageHelpers.DirectoryExists("/App_Data/cache/" + folder))
                            {
                                // Retry up to 5 times after pausing...

                                int retry = 0;

                                string original = context.Application["RebuildCacheHistory"].ToString();

                                while (retry < 5)
                                {
                                    retry++;

                                    context.Application["RebuildCacheHistory"] = original + "cache/" + folder + " retry " + retry;

                                    TemporalHelpers.PauseExecution(1);

                                    if (StorageHelpers.DirectoryExists("/App_Data/cache/" + folder))
                                    {
                                        StorageHelpers.DeleteDirectory("/App_Data/cache/" + folder);
                                    }

                                    if (!StorageHelpers.DirectoryExists("/App_Data/cache/" + folder))
                                    {
                                        retry = 5;
                                    }
                                }

                                context.Application["RebuildCacheHistory"] = original;

                                if (StorageHelpers.DirectoryExists("/App_Data/cache/" + folder))
                                {
                                    context.Application["RebuildCacheHistory"] += "<strong style='color:#b94a48;'>cache/" + folder + " locked...</strong> ";
                                }
                            }
                        }

                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        timer.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] += "</ol>";

                        context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                    }

                    catch (Exception e)
                    {
                        timer.Stop();
                        timer2.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] = "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                        result = context.Application["RebuildCacheHistory"].ToString();
                    }
                }))
                {
                    IsBackground = true
                };
                workerThread.Start();

                while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                {
                    // Wait for worker thread to start up and initialize
                    System.Threading.Thread.Sleep(50);
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");
            return(response);
        }
Пример #6
0
        public HttpResponseMessage RebuildCache() // /umbraco/api/carbidesupport/rebuildcache/
        {
            string result = "";

            if (HttpContext.Current.Application["RebuildCacheStatus"] == null)
            {
                var context = HttpContext.Current;

                context.Application["RebuildCacheStatus"]  = "running";
                context.Application["RebuildCacheHistory"] = "<h4 style=\"font-size: 1.1rem; margin-bottom: 1.5rem;\">Started " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</h4>";

                result = context.Application["RebuildCacheHistory"].ToString();

                Thread workerThread = new Thread(new ThreadStart(() =>
                {
                    StopWatch timer  = new StopWatch();
                    StopWatch timer2 = new StopWatch();

                    try
                    {
                        timer.Start();
                        context.Server.ScriptTimeout = 100000;

                        context.Application["RebuildCacheHistory"] += "<ol style=\"padding: 0.25rem 0 0 1rem;\">";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Republishing all content... ";
                        timer2.Reset();
                        timer2.Start();
                        Services.ContentService.RePublishAll();
                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Refreshing XML cache... ";
                        timer2.Reset();
                        timer2.Start();
                        umbraco.library.RefreshContent();
                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        context.Application["RebuildCacheHistory"] += "<li style=\"padding-bottom: 1rem;\">Rebuilding Examine indexes... ";
                        timer2.Reset();
                        timer2.Start();

                        foreach (var index in ExamineManager.Instance.IndexProviderCollection.ToList())
                        {
                            context.Application["RebuildCacheHistory"] += index.Name.Replace("Indexer", "") + "... ";
                            index.RebuildIndex();
                        }

                        timer2.Stop();
                        context.Application["RebuildCacheHistory"] += "<strong>completed in " + timer2.GetSeconds <int>() + " seconds</strong></li>";

                        timer.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] += "</ol>";

                        context.Application["RebuildCacheHistory"] += "<h4 style=\"font-size: 1.1rem;\">Finished in " + timer.GetSeconds <int>() + " seconds</h4>";
                    }

                    catch (Exception e)
                    {
                        timer.Stop();
                        timer2.Stop();

                        context.Application.SafeRemove("RebuildCacheStatus");

                        context.Application["RebuildCacheHistory"] = "</li></ol><p><strong>Error in " + timer.GetSeconds <int>() + " seconds on " + TemporalHelpers.DateFormat(DateTime.Now, DateFormats.European).ToUpper() + " @ " + TemporalHelpers.TimeFormat(DateTime.Now, TimeFormats.SqlMilitary) + "</strong></p>" + e.Message;

                        result = context.Application["RebuildCacheHistory"].ToString();
                    }
                }))
                {
                    IsBackground = true
                };
                workerThread.Start();

                while (HttpContext.Current.Application["RebuildCacheStatus"] == null)
                {
                    // Wait for worker thread to start up and initialize
                    System.Threading.Thread.Sleep(50);
                }
            }

            else
            {
                result = HttpContext.Current.Application["RebuildCacheHistory"].ToString();
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(result, Encoding.UTF8, "text/plain");
            return(response);
        }