/// <summary> /// Logs a message to the workflow run. /// </summary> /// <param name="context">The workflow run context.</param> /// <param name="message">The message to log.</param> private void LogToRun(IRunState context, string message) { var activityName = string.Empty; var wf = context != null?context.GetSafeWorkflowDescription() : ""; EventLog.Application.WriteTrace(wf + message); if (context == null || context.WorkflowRun == null) { return; } if (context.CurrentActivity != null) { activityName = context.CurrentActivity.Name; } var logEntry = new LogActivityLogEntry { Name = activityName, Description = message }; ActivityLogWriter.WriteLogEntry(logEntry.As <TenantLogEntry>()); }
private string GetSafeWfDescription(IRunState runState) { return(runState != null?runState.GetSafeWorkflowDescription() : ""); }
void MarkRunFailedTriggerDepth(IRunState runState) { using (new SecurityBypassContext()) { const string msg = "Failed to start because the trigger depth has been exceeded. Check triggers on workflow for looping."; var logEntry = new WorkflowRunFailedLogEntry { Name = "Workflow exceeded trigger depth", Description = msg, }; // error in how the workflow is configured by the user. EventLog.Application.WriteInformation(string.Format("Workflow: {0}. {1}", runState.GetSafeWorkflowDescription(), msg)); if (runState != null) { runState.RunStatus = WorkflowRunState_Enumeration.WorkflowRunFailed; runState.LogError(logEntry); } } }
void MarkRunFailedHasErrors(IRunState runState) { using (new SecurityBypassContext()) { string msg = $"Failed to start because it is misconfigured: \n{string.Join(", \n", runState.Metadata.ValidationMessages)}"; var logEntry = new WorkflowRunFailedLogEntry { Name = "Workflow misconfigured", Description = msg, }; // error in how the workflow is configured by the user. EventLog.Application.WriteInformation(string.Format("Workflow: {0}. {1}", runState.GetSafeWorkflowDescription(), msg)); if (runState != null) { runState.RunStatus = WorkflowRunState_Enumeration.WorkflowRunFailed; runState.LogError(logEntry); } } }
private WorkflowRun FinalizeRun(IRunState runState) { WorkflowRun run; using (Profiler.Measure("WorkflowRunner.Instance.FinalizeRun")) { using (new SecurityBypassContext()) { try { run = runState.WorkflowRun; runState.CompletedAt = DateTime.UtcNow; if (!run.IsTemporaryId) { run = Entity.Get <WorkflowRun>(runState.WorkflowRun, true, WorkflowRun.WorkflowRunExitPoint_Field, WorkflowRun.HasTimeout_Field, WorkflowRun.PendingActivity_Field, WorkflowRun.RunStepCounter_Field, WorkflowRun.WorkflowRunStatus_Field, WorkflowRun.RunCompletedAt_Field, WorkflowRun.StateInfo_Field); } var deferredRun = run as WorkflowRunDeferred; if (deferredRun != null) { deferredRun.Sync(); } runState.SyncToRun(run); WorkflowRunContext.Current.DeferSave(run); // // Raise a completed child event // if (run != null && run.ParentRun != null && IsRunCompleted(run)) { // This should be hooked into an eventing system. As we don't have one, just run the resume async. runState.WorkflowInvoker.PostEvent(new ChildWorkflowCompletedEvent(run)); } // // Add a restore message to the queue if we are suspended // if (run != null && run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunSuspended) { WorkflowRunContext.Current.DeferAction(() => { // This should be hooked into an eventing system. As we don't have one, just run the resume async. var restoreTask = ResumeWorkflowHandler.CreateBackgroundTask(run, new WorkflowRestoreEvent()); Factory.BackgroundTaskManager.EnqueueTask(restoreTask); }); } // // Let the world know we have finished WorkflowRunContext.Current.DeferAction(() => { if (run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunPaused || run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunCompleted || run.WorkflowRunStatus_Enum == WorkflowRunState_Enumeration.WorkflowRunFailed) { Factory.WorkflowRunTaskManager.RegisterComplete(run.TaskId, run.Id.ToString(CultureInfo.InvariantCulture)); } else { Factory.WorkflowRunTaskManager.SetResult(run.TaskId, run.Id.ToString(CultureInfo.InvariantCulture)); } HandleDiagnostics(run, run.WorkflowRunStatus_Enum.ToString()); }); } catch (Exception ex) { Workflow workflow = runState != null?Entity.Get <Workflow>(runState.WorkflowRunId) : null; var msg = string.Format("Workflow: {0}. Unexpected error when finalizing the workflow run ({1}), version ({2}).", runState != null ? runState.GetSafeWorkflowDescription() : "", runState != null ? runState.WorkflowRunId : -1L, workflow != null ? workflow.WorkflowVersion : 0); var log = msg + Environment.NewLine + ex.Message; #if DEBUG log += Environment.NewLine + ex.StackTrace; #endif EventLog.Application.WriteError(log); throw new Exception(msg, ex); } } } return(run); }
/// <summary> /// Runs when the activity is run by the workflow. /// </summary> /// <param name="context">The run state.</param> /// <param name="inputs">The inputs.</param> void IRunNowActivity.OnRunNow(IRunState context, ActivityInputs inputs) { var text = GetArgumentValue <string>(inputs, "inLogActivityMessage"); var refencedObject = GetArgumentEntity <UserResource>(inputs, "inLogActivityObject"); IEntity logEntry; if (refencedObject != null) { logEntry = new LogActivityResourceLogEntry { ObjectReferencedInLog = refencedObject, ReferencedObjectName = refencedObject.Name }; } else { logEntry = new LogActivityLogEntry(); } logEntry.SetField(WorkflowRunLogEntry.Name_Field, ActivityInstance.Name); logEntry.SetField(WorkflowRunLogEntry.Description_Field, text); context.Log(logEntry); // Provide some context information to the log message EventLog.Application.WriteInformation(string.Format("Log | {1} | Message: {2}", DateTime.UtcNow.Ticks, context.GetSafeWorkflowDescription(), text)); }