private void AbortRelatedWorkflows(Node currentNode, WorkflowApplicationAbortReason reason)
        {
            //TODO: WF: Testing StorageContext.Search.IsOuterEngineEnabled flag hack
            if (!StorageContext.Search.IsOuterEngineEnabled)
                return;

            var query = String.Format("+TypeIs:Workflow +RelatedContent:{0} .AUTOFILTERS:OFF", currentNode.Id);
            var result = SenseNet.Search.ContentQuery.Query(query);

            foreach (WorkflowHandlerBase workflow in result.Nodes)
                if (workflow.WorkflowStatus == WorkflowStatusEnum.Running && workflow.AbortOnRelatedContentChange)
                    InstanceManager.Abort(workflow, reason);
        }
Beispiel #2
0
 private static string GetAbortMessage(WorkflowApplicationAbortReason reason, WorkflowHandlerBase workflow)
 {
     switch (reason)
     {
         case WorkflowApplicationAbortReason.ManuallyAborted:
             return String.Concat(ABORTEDBYUSERMESSAGE, AccessProvider.Current.GetCurrentUser().Username);
         case WorkflowApplicationAbortReason.StateContentDeleted:
             return "Workflow deleted" + (workflow == null ? "." : (": " + workflow.Path));
         case WorkflowApplicationAbortReason.RelatedContentChanged:
             return "Aborted because the related content was changed.";
         case WorkflowApplicationAbortReason.RelatedContentDeleted:
             return "Aborted because the related content was moved or deleted.";
         default:
             return reason.ToString();
     }
 }
Beispiel #3
0
 private static void WriteBackAbortMessage(WorkflowHandlerBase stateContent, WorkflowApplicationAbortReason reason)
 {
     var abortMessage = GetAbortMessage(reason, stateContent);
     if (reason == WorkflowApplicationAbortReason.StateContentDeleted)
         Logger.WriteInformation("Workflow aborted. Reason: " + abortMessage);
     else
         WriteBackAbortMessage(stateContent, abortMessage);
 }
Beispiel #4
0
        public static void Abort(WorkflowHandlerBase workflowInstance, WorkflowApplicationAbortReason reason)
        {
            //check permissions
            if (reason == WorkflowApplicationAbortReason.ManuallyAborted && !workflowInstance.Security.HasPermission(PermissionType.Save))
            {
                Logger.WriteVerbose(String.Concat("InstanceManager cannot abort the instance: ", workflowInstance.Path, ", because the user doesn't have the sufficient permissions (Save)."));
Debug.WriteLine(String.Concat("##WF> ############ ERROR: InstanceManager cannot abort the instance: ", workflowInstance.Path, ", because the user doesn't have the sufficient permissions (Save)."));
                throw new SenseNetSecurityException(workflowInstance.Path, PermissionType.Save, AccessProvider.Current.GetCurrentUser());
            }

            //abort the workflow
            try
            {
                var wfApp = CreateWorkflowApplication(workflowInstance, WorkflowApplicationCreationPurpose.Abort, null);
                
                wfApp.Load(Guid.Parse(workflowInstance.WorkflowInstanceGuid));
                //wfApp.Abort();
                wfApp.Cancel(); //.Terminate(string.Format("#### Aborted. Reason {0}, Path: {1}", reason, workflowInstance.Path));
            }
            catch(Exception e)
            {
                Logger.WriteVerbose(String.Concat("InstanceManager cannot abort the instance: ", workflowInstance.Path, ". Exception message: ", e.Message));
Debug.WriteLine("##WF> ERROR: " + e.Message);
            }

            //write back workflow state
            WriteBackAbortMessage(workflowInstance, reason);
        }