private void context_BeginRequest(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; if (application != null && application.Context != null && application.Request != null && _Manifest != null) { HttpRequest request = application.Request; RequestAnalysis analysis = _Manifest.AnalyzeRequest(request); if (analysis.IsRecurringTask) { ConfiguredTask taskConfig; if (_Manifest.TryGetTask(analysis.TaskIdentifier, out taskConfig)) { if (RevaleeRegistrar.ValidateCallback(new HttpRequestWrapper(request))) { if (taskConfig.SetLastOccurrence(analysis.Occurrence)) { application.Context.Items.Add(_InProcessContextKey, BuildCallbackDetails(request)); application.Context.RewritePath(taskConfig.Url.AbsolutePath, true); _Manifest.Reschedule(taskConfig); return; } } } application.Context.Response.StatusCode = (int)HttpStatusCode.OK; application.Context.Response.SuppressContent = true; application.CompleteRequest(); return; } } }
internal RequestAnalysis AnalyzeRequest(HttpRequest request) { string absolutePath = request.Url.AbsolutePath; if (absolutePath.StartsWith(_RecurringTaskHandlerAbsolutePath, StringComparison.Ordinal)) { var analysis = new RequestAnalysis(); analysis.IsRecurringTask = true; int parameterStartingIndex = _RecurringTaskHandlerAbsolutePath.Length; if (absolutePath.Length > parameterStartingIndex) { // AbsolutePath format: // task -> ~/__RevaleeRecurring.axd/{identifier}/{occurrence} // heartbeat -> ~/__RevaleeRecurring.axd/{heartbeatId} int taskParameterDelimiterIndex = absolutePath.IndexOf('/', parameterStartingIndex); if (taskParameterDelimiterIndex < 0) { // no task parameter delimiter if ((absolutePath.Length - parameterStartingIndex) == 32) { Guid heartbeatId; if (Guid.TryParseExact(absolutePath.Substring(parameterStartingIndex), "N", out heartbeatId)) { if (heartbeatId.Equals(_Id)) { this.OnActivate(); } } } } else { // task parameter delimiter present if ((absolutePath.Length - taskParameterDelimiterIndex) > 1) { if (long.TryParse(absolutePath.Substring(taskParameterDelimiterIndex + 1), NumberStyles.None, CultureInfo.InvariantCulture, out analysis.Occurrence)) { analysis.TaskIdentifier = absolutePath.Substring(parameterStartingIndex, taskParameterDelimiterIndex - parameterStartingIndex); } } } } // If the TaskIdentifier is not set the default will be string.Empty, which will be discarded by the HttpModule return(analysis); } return(NonRecurringRequest); }
private void context_BeginRequest(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; if (application != null && application.Context != null && application.Request != null && _Manifest != null) { HttpRequest request = application.Request; RequestAnalysis analysis = _Manifest.AnalyzeRequest(request); if (analysis.IsRecurringTask) { ConfiguredTask taskConfig; HttpStatusCode statusCode; if (_Manifest.TryGetTask(analysis.TaskIdentifier, out taskConfig)) { if (request.HttpMethod == "POST") { if (RevaleeRegistrar.ValidateCallback(new HttpRequestWrapper(request))) { if (taskConfig.SetLastOccurrence(analysis.Occurrence)) { _Manifest.Reschedule(taskConfig); application.Context.Items.Add(_InProcessContextKey, BuildCallbackDetails(request)); application.Context.RewritePath(taskConfig.Url.AbsolutePath, true); return; } else { statusCode = HttpStatusCode.Accepted; } } else { statusCode = HttpStatusCode.Unauthorized; } } else { if (request.HttpMethod == "GET" || request.HttpMethod == "HEAD") { if (request.Headers["Expect"] == "100-continue") { application.Context.Response.StatusCode = (int)HttpStatusCode.Continue; return; } else { statusCode = HttpStatusCode.MethodNotAllowed; } } else { statusCode = HttpStatusCode.NotImplemented; } } } else { statusCode = HttpStatusCode.NoContent; } application.Context.Response.StatusCode = (int)statusCode; application.Context.Response.SuppressContent = true; application.CompleteRequest(); return; } } }
internal RequestAnalysis AnalyzeRequest(HttpRequest request) { string absolutePath = request.Url.AbsolutePath; if (absolutePath.StartsWith(_RecurringTaskHandlerAbsolutePath, StringComparison.Ordinal)) { var analysis = new RequestAnalysis(); analysis.IsRecurringTask = true; int parameterStartingIndex = _RecurringTaskHandlerAbsolutePath.Length; if (absolutePath.Length > parameterStartingIndex) { // AbsolutePath format: // task -> ~/__RevaleeRecurring.axd/{identifier}/{occurrence} // heartbeat -> ~/__RevaleeRecurring.axd/{heartbeatId} int taskParameterDelimiterIndex = absolutePath.IndexOf('/', parameterStartingIndex); if (taskParameterDelimiterIndex < 0) { // no task parameter delimiter if ((absolutePath.Length - parameterStartingIndex) == 32) { Guid heartbeatId; if (Guid.TryParseExact(absolutePath.Substring(parameterStartingIndex), "N", out heartbeatId)) { if (heartbeatId.Equals(_Id)) { this.OnActivate(); } } } } else { // task parameter delimiter present if ((absolutePath.Length - taskParameterDelimiterIndex) > 1) { if (long.TryParse(absolutePath.Substring(taskParameterDelimiterIndex + 1), NumberStyles.None, CultureInfo.InvariantCulture, out analysis.Occurrence)) { analysis.TaskIdentifier = absolutePath.Substring(parameterStartingIndex, taskParameterDelimiterIndex - parameterStartingIndex); } } } } // If the TaskIdentifier is not set the default will be string.Empty, which will be discarded by the HttpModule return analysis; } return NonRecurringRequest; }