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; } } }
public ActionResult Schedule(Uri serviceBaseUri, DateTimeOffset callbackTime, Uri callbackUri) { DateTimeOffset now = DateTimeOffset.Now; Interlocked.Increment(ref _TotalRequestCount); Guid callbackId = RevaleeRegistrar.ScheduleCallback(serviceBaseUri, callbackTime, callbackUri); _Log.Add(callbackId, callbackTime, callbackUri, now); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public static void SendNewEventEmailToAllSubscribers() { // Schedule your callback 10 minutes from now DateTimeOffset callbackTime = DateTimeOffset.Now.AddMinutes(Convert.ToInt16(CallbackTime)); // Your web service's Uri Uri callbackUrl = new Uri(MyHostURL + "Subscribe/SendNewEventEmailToSubscribers"); // Register the callback request with the Revalee service RevaleeRegistrar.ScheduleCallback(callbackTime, callbackUrl); previousCallbackTime = callbackTime; }
private void Schedule(CallbackRequest callbackDetails) { Task.Factory.StartNew(() => { try { RevaleeRegistrar.ScheduleCallback(callbackDetails.CallbackTime, callbackDetails.CallbackUri); } catch (RevaleeRequestException exception) { this.OnDeactivate(exception); } }); }
/// <summary> /// Called when a process requests authorization for the marked callback action. /// </summary> /// <param name="filterContext">The filter context, which encapsulates information for using <see cref="T:Revalee.Client.Mvc.CallbackActionAttribute" />.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="filterContext" /> parameter is null.</exception> public void OnAuthorization(AuthorizationContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } if (filterContext.HttpContext == null || filterContext.HttpContext.Request == null || !RevaleeRegistrar.ValidateCallback(filterContext.HttpContext.Request)) { filterContext.Result = new HttpUnauthorizedResult(); } }
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; } } }
protected internal void Start() { if (this.CallbackBaseUri != null) { if (!this.IsActive) { if (_HeartbeatTimer == null) { // Schedule a heartbeat on a timer lock (_TaskCollection) { if (_HeartbeatTimer == null) { _HeartbeatTimer = new Timer(delegate(object self) { try { if (this.IsActive) { lock (_TaskCollection) { if (_HeartbeatTimer != null) { _HeartbeatTimer.Dispose(); _HeartbeatTimer = null; } } } else { if (_HeartbeatTimer == null || AppDomain.CurrentDomain.IsFinalizingForUnload()) { return; } int failureCount = Interlocked.Increment(ref _HeartbeatCount) - 1; lock (_TaskCollection) { if (_HeartbeatTimer != null) { if (_HeartbeatCount > 20) { // Leave current timer setting in-place } else if (_HeartbeatCount > 13) { _HeartbeatTimer.Change(3600000, 14400000); } else if (_HeartbeatCount > 3) { _HeartbeatTimer.Change(60000, 60000); } else if (_HeartbeatCount > 2) { _HeartbeatTimer.Change(49750, 60000); } } } if (failureCount > 0) { OnActivationFailure(failureCount); } try { RevaleeRegistrar.ScheduleCallback(_ClockSource.Now, this.GenerateHeartbeatCallbackUri()); } catch (RevaleeRequestException) { // Ignore network errors and retry based on the timer schedule } } } catch (AppDomainUnloadedException) { // Ignore errors when already shutting down } catch (ObjectDisposedException) { // Ignore errors when already shutting down } catch (ThreadAbortException) { // Ignore errors when already shutting down } }, null, 250, 10000); } } } else { // Schedule an on-demand heartbeat this.Schedule(this.PrepareHeartbeat()); } } } }