Ejemplo n.º 1
0
        internal void TimerTicked()
        {
            if (ApplicationModel.Current.Server.Value.CreateNewDatabase)
            {
                ApplicationModel.Current.Server.Value.CreateNewDatabase = false;
                ApplicationModel.Current.Server.Value.DocumentStore
                .AsyncDatabaseCommands
                .ForDefaultDatabase()
                .GetAsync("Raven/StudioConfig")
                .ContinueOnSuccessInTheUIThread(doc =>
                {
                    if (doc != null && doc.DataAsJson.ContainsKey("WarnWhenUsingSystemDatabase"))
                    {
                        if (doc.DataAsJson.Value <bool>("WarnWhenUsingSystemDatabase") == false)
                        {
                            return;
                        }
                    }
                    Command.ExecuteCommand(new CreateDatabaseCommand());
                });
            }

            ApplicationModel.Current.UpdateAlerts();

            if (currentTask != null)
            {
                return;
            }

            lock (this)
            {
                if (currentTask != null)
                {
                    return;
                }

                var timeFromLastRefresh = SystemTime.UtcNow - lastRefresh;
                var refreshRate         = GetRefreshRate();
                if (timeFromLastRefresh < refreshRate)
                {
                    return;
                }

                using (OnWebRequest(request => request.Headers["Raven-Timer-Request"] = "true"))
                    currentTask = TimerTickedAsync();

                if (currentTask == null)
                {
                    return;
                }

                currentTask
                .Catch()
                .Finally(() =>
                {
                    lastRefresh = SystemTime.UtcNow;
                    IsForced    = false;
                    currentTask = null;
                });
            }
        }