/// <summary> /// /// </summary> /// <param name="job"></param> /// <param name="stage"></param> /// <param name="regex"></param> /// <param name="priority"></param> /// <param name="request"></param> /// <returns></returns> public static int Watch(IJob job, PipeLineStages stage, Regex regex, int priority, Func <int, HttpApplication, WatchResponse> request) { Environ environ = null; if (EnvironLock.Write(() => { if (!Environs.TryGetValue(job.Environment.SortOrder, out environ)) { Environs.Add(job.Environment.SortOrder, environ = new Environ(job.Environment)); } })) { return(EnvironLock.Read(() => { return environ.WatchLocks[(int)stage].Write(() => { var watchList = environ.Watchers[(int)stage]; var count = Interlocked.Increment(ref _requestCount); EnvironHasWatches[(int)stage] = true; watchList.Add(new Watcher { Priority = priority, AppId = job.App.Id, Regex = regex, Request = request }); watchList.Sort(new WatchComparer()); return count; }); })); } return(-1); }
private bool IgnoresProcess() { return(UrlIgnoresLock.Write <bool?>(() => { foreach (var ignore in UrlIgnores.Where(x => x.CalculatedUrl == false && x.Url != null)) { if (!UrlProcess(ignore)) { return false; } } return true; }).Value); }
private bool ExceptionsProcess() { return(UrlExceptionLock.Write <bool?>(() => { foreach (var exception in UrlExceptions.Where(x => x.CalculatedUrl == false && x.Url != null)) { if (!UrlProcess(exception)) { return false; } } return true; }).Value); }
/// <summary> /// /// </summary> public void Poll() { if (DateTime.UtcNow.Ticks < _ranTick) { return; } if (Interlocked.CompareExchange(ref Instance._runningPoll, 0, 1) != 0) { return; } try { //System.Diagnostics.Debug.WriteLine("START running poll with " + ranTick.ToString()); _ranTick = RanNow; if (JobLock.Write(() => { foreach (var reg in Jobs.Value) { var ct = new CancellationTokenSource(); var task = new Task <bool>(() => Execute(reg.Value), ct.Token, TaskCreationOptions.PreferFairness); reg.Value.CancelToken = ct; reg.Value.Task = task; } })) { if (JobLock.Read(() => { foreach (var reg in Jobs.Value) { reg.Value.Task.Start(); } })) { if (Interlocked.CompareExchange(ref _ranTick, RanRepeat, RanNow) != RanRepeat) { _ranTick = DateTime.UtcNow.AddSeconds(PollSecs).Ticks; } } } //System.Diagnostics.Debug.WriteLine("END running poll with " + ranTick.ToString()); } finally { _runningPoll = 0; } }
private bool MakeSureAllUrlExceptionsHaveBeenCalculated() { return(UrlExceptionLock.Write(() => { foreach (var exception in UrlExceptions.Where(x => x.CalculatedUrl == false)) { var url = new UmbracoUrlService().Url(exception.Url); exception.CalculatedUrl = true; if (string.IsNullOrWhiteSpace(url)) { continue; } var query = url.IndexOf('?'); if (query == 0) { exception.CalculatedUrlWithoutSlash = url; exception.CalculatedUrlWithSlash = "/" + url; continue; } var point = (query == -1 ? url.Length : query) - 1; var builder = new StringBuilder(url.Length); if (url[point] == '/') { exception.CalculatedUrlWithSlash = url; for (var i = 0; i != url.Length; i++) { if (i != point) { builder.Append(url[i]); } } exception.CalculatedUrlWithoutSlash = builder.ToString(); continue; } exception.CalculatedUrlWithoutSlash = url; for (var i = 0; i != url.Length; i++) { builder.Append(url[i]); if (i == point) { builder.Append('/'); } } exception.CalculatedUrlWithSlash = builder.ToString(); } })); }