Ejemplo n.º 1
0
        private static void WriteBackAbortMessage(WorkflowHandlerBase stateContent, string abortMessage)
        {
            try
            {
                var state = stateContent.WorkflowStatus;
                if (state == WorkflowStatusEnum.Completed)
                {
                    return;
                }

                // if a system message has already been persisted to the workflow content, don't overwrite it
                if (!string.IsNullOrEmpty(stateContent.SystemMessages))
                {
                    return;
                }

                var times = 3;
                while (true)
                {
                    try
                    {
                        stateContent.SystemMessages = abortMessage;
                        stateContent.DisableObserver(typeof(WorkflowNotificationObserver));
                        Debug.WriteLine("##WF> Workflow aborted. Reason: " + abortMessage + ". InstanceId: " + stateContent.WorkflowInstanceGuid);
                        using (new SystemAccount())
                            stateContent.Save(ContentRepository.SavingMode.KeepVersion);
                        break;
                    }
                    catch (NodeIsOutOfDateException ne)
                    {
                        if (--times == 0)
                        {
                            throw new NodeIsOutOfDateException("Node is out of date after 3 trying", ne);
                        }
                        var msg = "InstanceManager: Saving system message caused NodeIsOutOfDateException. Trying again.";
                        Logger.WriteVerbose(msg);
                        Debug.WriteLine("##WF> ERROR " + msg);
                        stateContent = (WorkflowHandlerBase)Node.LoadNodeByVersionId(stateContent.VersionId);
                    }
                    catch (Exception e)
                    {
                        var msg = String.Format("InstanceManager:  Cannot write back a system message to the workflow state content. InstanceId: {0}. Path: {1}. Message: {2}. InstanceId: {3}."
                                                , stateContent.Id, stateContent.Path, abortMessage, stateContent.WorkflowInstanceGuid);
                        Debug.WriteLine("##WF> ERROR " + msg);
                        Logger.WriteWarning(Logger.EventId.NotDefined, msg, properties: new Dictionary <string, object> {
                            { "Exception", e }
                        });
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                WriteError("WriteBackAbortMessage#2", e);
                throw;
            }
        }
Ejemplo n.º 2
0
        //=========================================================================================================== Operations

        public static Guid Start(WorkflowHandlerBase workflowInstance)
        {
            try
            {
                var wfApp = CreateWorkflowApplication(workflowInstance, WorkflowApplicationCreationPurpose.StartNew, null);
                var id    = wfApp.Id;
                workflowInstance.WorkflowStatus = WorkflowStatusEnum.Running;
                workflowInstance.DisableObserver(typeof(WorkflowNotificationObserver));
                using (new SystemAccount())
                    workflowInstance.Save();
                wfApp.Run();
                return(id);
            }
            catch (Exception e)
            {
                WriteError("Start", e);
                throw;
            }
        }