private void AbortRelatedWorkflows(Node currentNode, WorkflowApplicationAbortReason reason)
        {
            //if (!StorageContext.Search.IsOuterEngineEnabled)
            IEnumerable <Node> nodes = null;

            if (RepositoryInstance.ContentQueryIsAllowed)
            {
                nodes = SenseNet.Search.ContentQuery.Query(SafeQueries.WorkflowsByRelatedContent, null, currentNode.Id).Nodes;
            }
            else
            {
                var nodeType = ActiveSchema.NodeTypes["Workflow"];
                nodes = SenseNet.ContentRepository.Storage.Search.NodeQuery.QueryNodesByReferenceAndType("RelatedContent", currentNode.Id, nodeType, false).Nodes;
            }

            foreach (WorkflowHandlerBase workflow in nodes)
            {
                if (workflow.WorkflowStatus == WorkflowStatusEnum.Running && workflow.AbortOnRelatedContentChange)
                {
                    InstanceManager.Abort(workflow, reason);
                }
            }
        }
Ejemplo n.º 2
0
        private void StartWorkflow(WorkflowHandlerBase wfTemplate, Node currentNode)
        {
            var list         = (ContentList)currentNode.LoadContentList();
            var targetFolder = list.GetWorkflowContainer(); // Node.LoadNode(targetFolderPath);

            var wfInstance = (WorkflowHandlerBase)ContentTemplate.CreateTemplated(targetFolder, wfTemplate, wfTemplate.Name).ContentHandler;

            wfInstance.RelatedContent = currentNode;
            if (!ValidateWorkflow(wfInstance, currentNode))
            {
                wfInstance.Save();
                return;
            }

            wfInstance["OwnerSiteUrl"] = PortalContext.Current.RequestedUri.GetLeftPart(UriPartial.Authority);
            using (new SystemAccount())
            {
                // We need to save the wf instance before the engine starts it to have everything persisted to the repo.
                // Please do not remove this line.
                wfInstance.Save();
            }

            InstanceManager.Start(wfInstance);
        }
Ejemplo n.º 3
0
        public static void NotifyContentChanged(WorkflowNotificationEventArgs eventArgs)
        {
            try
            {
                WorkflowNotification[] notifications = null;
                using (var dbContext = GetDataContext())
                {
                    notifications = dbContext.WorkflowNotifications.Where(notification =>
                                                                          notification.NodeId == eventArgs.NodeId).ToArray();
                }

                //Debug.WriteLine(String.Format("##WF> NotifyContentChanged: Loaded notifications {0}: {1}", notifications.Length, String.Join(", ", notifications.Select(n => n.NodeId + "|" + n.WorkflowInstanceId))));

                foreach (var notification in notifications)
                {
                    InstanceManager.FireNotification(notification, eventArgs);
                }
            }
            catch (Exception e)
            {
                WriteError("NotifyContentChanged", e);
                throw;
            }
        }
Ejemplo n.º 4
0
        protected override void OnNodeModified(object sender, NodeEventArgs e)
        {
            InstanceManager.NotifyContentChanged(new WorkflowNotificationEventArgs(e.SourceNode.Id, CONTENTCHANGEDNOTIFICATIONTYPE, null));

            AbortRelatedWorkflows(e.SourceNode, WorkflowApplicationAbortReason.RelatedContentChanged);
        }
Ejemplo n.º 5
0
 public void ReleaseWait(int notificationId)
 {
     InstanceManager.ReleaseWait(notificationId);
 }