/// <summary> /// Set a time-out if the due date is greater than zero and there is a timeout transition. /// </summary> /// <param name="timeoutDays"></param> protected void SetTimeoutIfNeeded(IRunState context, decimal timeoutDays) { if (timeoutDays > 0 && GetTimeoutTransition() != null) { context.SetPostRunAction(() => TimeoutActivityHelper.Instance.ScheduleTimeout(this, context.WorkflowRun, new decimal(24.0 * 60.0) * timeoutDays)); context.HasTimeout = true; } }
/// <summary> /// Responds to an activity being started. /// </summary> /// <param name="context">The current running context of the workflow.</param> /// <param name="inputs">Any inputs that have been provided to the activity by the workflow.</param> /// <returns>True if the activity has completed, false if it is paused.</returns> public bool OnStart(IRunState context, ActivityInputs inputs) { var done = false; using (Profiler.Measure("CastActivityImplementation.OnStart")) { try { LogToRun(context, string.Format("CAST Activity '{0}' is starting.", ActivityInstance.Name)); var dbid = string.Empty; if (!string.IsNullOrEmpty(DatabaseIdInputAlias)) { dbid = GetArgumentValue <string>(inputs, DatabaseIdInputAlias); } if (string.IsNullOrEmpty(dbid)) { throw new WorkflowRunException("Unable to determine client communication key."); } var request = GetRequest(context, inputs); request.Type = request.GetType().AssemblyQualifiedName; request.DatabaseId = dbid; request.RunStep = context.StepsTakenInSession; // send the request after the workflow run has been saved context.SetPostRunAction(() => { request.RunId = context.WorkflowRunId; Sender.Request(SpecialStrings.CastClientKeyPrefix + dbid.ToLowerInvariant(), request, this); }); } catch (Exception e) { EventLog.Application.WriteError("An unexpected error occurred when starting a CAST activity. {0}", e.ToString()); done = true; LogToRun(context, string.Format("CAST Activity '{0}' failed to start.", ActivityInstance.Name)); if (string.IsNullOrEmpty(FailureExitPointAlias)) { throw; } context.ExitPointId = new EntityRef(FailureExitPointAlias); } } return(done); }
/// <summary> /// Send the notifications on a background thread. /// </summary> void SendMessagesInBackground(IRunState context, long notificationId, List <long> userIds, bool waitForReplies) { context.SetPostRunAction(() => { var runId = context.WorkflowRunId; WorkflowRunContext.Current.QueueAction(() => SecurityBypassContext.Elevate(() => { var workflowRunner = Factory.Current.Resolve <IWorkflowRunner>(); WorkflowRun run = Entity.Get <WorkflowRun>(runId);; try { var notification = Entity.Get <Notification>(notificationId); var users = Entity.Get(userIds); Factory.Current.Resolve <INotifier>().Send(notification, users, true); var sends = notification.SendRecords; var sentWithoutError = sends.Where(r => r.SrErrorMessage == null); // update the notification bool resume = true; if (waitForReplies) { notification = notification.AsWritable <Notification>(); notification.NPendingRun = run; notification.Save(); resume = notification.Complete(); // Just in case all the replies were completed while we were sending. } if (resume && run != null) { workflowRunner.ResumeWorkflow(run, new NotifyResumeEvent()); } } catch { if (run != null) { workflowRunner.ResumeWorkflow(run, new NotifyResumeFailedEvent()); } throw; } })); }); }