Пример #1
0
        public void Sweep()
        {
            var awaiting = _awaitingActivityRepository.Table.Where(x => x.ActivityRecord.Name == "Timer").ToList();


            foreach (var action in awaiting)
            {
                try {
                    var contentItem = action.WorkflowRecord.ContentItemRecord != null?_contentManager.Get(action.WorkflowRecord.ContentItemRecord.Id, VersionOptions.Latest) : null;

                    var tokens = new Dictionary <string, object> {
                        { "Content", contentItem }
                    };
                    var workflowState = FormParametersHelper.FromJsonString(action.WorkflowRecord.State);
                    workflowState.TimerActivity_StartedUtc = null;
                    action.WorkflowRecord.State            = FormParametersHelper.ToJsonString(workflowState);
                    _workflowManager.TriggerEvent("Timer", contentItem, () => tokens);
                }
                catch (Exception ex) {
                    if (ex.IsFatal())
                    {
                        throw;
                    }
                    Logger.Error(ex, "TimerBackgroundTask: Error while processing background task \"{0}\".", action.ActivityRecord.Name);
                }
            }
        }
Пример #2
0
        public ActionResult RenderActivity(ActivityViewModel model)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
            {
                return(new HttpUnauthorizedResult());
            }

            var activity = _activitiesManager.GetActivityByName(model.Name);

            if (activity == null)
            {
                return(HttpNotFound());
            }

            dynamic shape = New.Activity(activity);

            if (model.State != null)
            {
                var state = FormParametersHelper.ToDynamic(FormParametersHelper.ToString(model.State));
                shape.State(state);
            }
            else
            {
                shape.State(FormParametersHelper.FromJsonString("{}"));
            }

            shape.Metadata.Alternates.Add("Activity__" + activity.Name);

            return(new ShapeResult(this, shape));
        }
Пример #3
0
        // returns all the actions associated with a specific state
        private static IEnumerable <string> ListAction(AwaitingActivityRecord x)
        {
            var    state       = FormParametersHelper.FromJsonString(x.ActivityRecord.State);
            string actionState = state.Actions ?? "";

            return(actionState.Split(',').Select(action => action.Trim()));
        }
Пример #4
0
        public ActionResult EditPost(int id, string localId, string data)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
            {
                return(new HttpUnauthorizedResult());
            }

            var workflowDefinitionRecord = _workflowDefinitionRecords.Get(id);

            if (workflowDefinitionRecord == null)
            {
                return(HttpNotFound());
            }

            workflowDefinitionRecord.Enabled = true;

            var state           = FormParametersHelper.FromJsonString(data);
            var activitiesIndex = new Dictionary <string, ActivityRecord>();

            workflowDefinitionRecord.ActivityRecords.Clear();
            workflowDefinitionRecord.WorkflowRecords.Clear();

            foreach (var activity in state.Activities)
            {
                ActivityRecord activityRecord;

                workflowDefinitionRecord.ActivityRecords.Add(activityRecord = new ActivityRecord {
                    Name  = activity.Name,
                    X     = activity.Left,
                    Y     = activity.Top,
                    Start = activity.Start,
                    State = FormParametersHelper.ToJsonString(activity.State),
                    WorkflowDefinitionRecord = workflowDefinitionRecord
                });

                activitiesIndex.Add((string)activity.ClientId, activityRecord);
            }

            workflowDefinitionRecord.TransitionRecords.Clear();

            foreach (var connection in state.Connections)
            {
                workflowDefinitionRecord.TransitionRecords.Add(new TransitionRecord {
                    SourceActivityRecord      = activitiesIndex[(string)connection.SourceId],
                    DestinationActivityRecord = activitiesIndex[(string)connection.TargetId],
                    SourceEndpoint            = connection.SourceEndpoint,
                    WorkflowDefinitionRecord  = workflowDefinitionRecord
                });
            }

            Services.Notifier.Information(T("Workflow saved successfully"));

            return(RedirectToAction("Edit", new { id, localId }));
        }
Пример #5
0
        private dynamic GetState(string state)
        {
            if (!String.IsNullOrWhiteSpace(state))
            {
                var formatted  = JsonConvert.DeserializeXNode(state, "Root").ToString();
                var serialized = String.IsNullOrEmpty(formatted) ? "{}" : JsonConvert.SerializeXNode(XElement.Parse(formatted));
                return(FormParametersHelper.FromJsonString(serialized).Root);
            }

            return(FormParametersHelper.FromJsonString("{}"));
        }
Пример #6
0
        private dynamic GetState(string state, IDictionary <string, object> tokens)
        {
            if (!String.IsNullOrWhiteSpace(state))
            {
                var formatted  = JsonConvert.DeserializeXNode(state, "Root").ToString();
                var tokenized  = _tokenizer.Replace(formatted, tokens);
                var serialized = String.IsNullOrEmpty(tokenized) ? "{}" : JsonConvert.SerializeXNode(XElement.Parse(tokenized));
                return(FormParametersHelper.FromJsonString(serialized).Root);
            }

            return(FormParametersHelper.FromJsonString("{}"));
        }
Пример #7
0
        // whether a user is in an accepted role for this state
        private static bool UserIsInRole(AwaitingActivityRecord x, IUser user)
        {
            var    state      = FormParametersHelper.FromJsonString(x.ActivityRecord.State);
            string rolesState = state.Roles ?? "";

            // "Any" if string is empty
            if (string.IsNullOrWhiteSpace(rolesState))
            {
                return(true);
            }
            var roles = rolesState.Split(',').Select(role => role.Trim());

            return(UserTaskActivity.UserIsInRole(user, roles));
        }
Пример #8
0
        public void Sweep()
        {
            var awaiting = _awaitingActivityRepository.Table.Where(x => x.ActivityRecord.Name == "Timer").ToList();


            foreach (var action in awaiting)
            {
                var contentItem = _contentManager.Get(action.WorkflowRecord.ContentItemRecord.Id, VersionOptions.Latest);
                var tokens      = new Dictionary <string, object> {
                    { "Content", contentItem }
                };
                var workflowState = FormParametersHelper.FromJsonString(action.WorkflowRecord.State);
                workflowState.TimerActivity_StartedUtc = null;
                action.WorkflowRecord.State            = FormParametersHelper.ToJsonString(workflowState);
                _workflowManager.TriggerEvent("Timer", contentItem, () => tokens);
            }
        }
Пример #9
0
        private WorkflowDefinitionViewModel CreateWorkflowDefinitionViewModel(WorkflowDefinitionRecord workflowDefinitionRecord)
        {
            if (workflowDefinitionRecord == null)
            {
                throw new ArgumentNullException("workflowDefinitionRecord");
            }

            var workflowDefinitionModel = new WorkflowDefinitionViewModel {
                Id   = workflowDefinitionRecord.Id,
                Name = workflowDefinitionRecord.Name
            };

            dynamic workflow = new JObject();

            workflow.Activities = new JArray(workflowDefinitionRecord.ActivityRecords.Select(x => {
                dynamic activity  = new JObject();
                activity.Name     = x.Name;
                activity.Id       = x.Id;
                activity.ClientId = x.Name + "_" + x.Id;
                activity.Left     = x.X;
                activity.Top      = x.Y;
                activity.Start    = x.Start;
                activity.State    = FormParametersHelper.FromJsonString(x.State);

                return(activity);
            }));

            workflow.Connections = new JArray(workflowDefinitionRecord.TransitionRecords.Select(x => {
                dynamic connection        = new JObject();
                connection.Id             = x.Id;
                connection.SourceId       = x.SourceActivityRecord.Name + "_" + x.SourceActivityRecord.Id;
                connection.TargetId       = x.DestinationActivityRecord.Name + "_" + x.DestinationActivityRecord.Id;
                connection.SourceEndpoint = x.SourceEndpoint;
                return(connection);
            }));

            workflowDefinitionModel.JsonData = FormParametersHelper.ToJsonString(workflow);

            return(workflowDefinitionModel);
        }
Пример #10
0
        public void Sweep()
        {
            var awaiting = _awaitingActivityRepository.Table.Where(x => x.ActivityRecord.Name == OrchardCollaborationTimerActivity.ActionName).ToList();


            foreach (var action in awaiting)
            {
                try
                {
                    var contentItem = _contentManager.Get(action.WorkflowRecord.ContentItemRecord.Id, VersionOptions.Latest);
                    var tokens      = new Dictionary <string, object> {
                        { "Content", contentItem }
                    };
                    var workflowState = FormParametersHelper.FromJsonString(action.WorkflowRecord.State);
                    workflowState.TimerActivity_StartedUtc = null;
                    action.WorkflowRecord.State            = FormParametersHelper.ToJsonString(workflowState);
                    _workflowManager.TriggerEvent(OrchardCollaborationTimerActivity.ActionName, contentItem, () => tokens);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "OrchardCollaborationTimerBackgroundTask: Error while processing background task \"{0}\" on tenant \"{1}\".", action.ActivityRecord.Name, _shellName);
                }
            }
        }
Пример #11
0
        public ActionResult EditPost(int id, string localId, string data, bool clearWorkflows)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
            {
                return(new HttpUnauthorizedResult());
            }

            var workflowDefinitionRecord = _workflowDefinitionRecords.Get(id);

            if (workflowDefinitionRecord == null)
            {
                return(HttpNotFound());
            }

            workflowDefinitionRecord.Enabled = true;

            var state           = FormParametersHelper.FromJsonString(data);
            var activitiesIndex = new Dictionary <string, ActivityRecord>();

            workflowDefinitionRecord.ActivityRecords.Clear();

            foreach (var activity in state.Activities)
            {
                ActivityRecord activityRecord;

                workflowDefinitionRecord.ActivityRecords.Add(activityRecord = new ActivityRecord {
                    Name  = activity.Name,
                    X     = activity.Left,
                    Y     = activity.Top,
                    Start = activity.Start,
                    State = FormParametersHelper.ToJsonString(activity.State),
                    WorkflowDefinitionRecord = workflowDefinitionRecord
                });

                activitiesIndex.Add((string)activity.ClientId, activityRecord);
            }

            workflowDefinitionRecord.TransitionRecords.Clear();

            foreach (var connection in state.Connections)
            {
                workflowDefinitionRecord.TransitionRecords.Add(new TransitionRecord {
                    SourceActivityRecord      = activitiesIndex[(string)connection.SourceId],
                    DestinationActivityRecord = activitiesIndex[(string)connection.TargetId],
                    SourceEndpoint            = connection.SourceEndpoint,
                    WorkflowDefinitionRecord  = workflowDefinitionRecord
                });
            }

            if (clearWorkflows)
            {
                workflowDefinitionRecord.WorkflowRecords.Clear();
            }
            else
            {
                var removeWorkflows = new List <WorkflowRecord>();
                foreach (var workflowRecord in workflowDefinitionRecord.WorkflowRecords)
                {
                    var removeAwaitingActivites = new List <AwaitingActivityRecord>();
                    // Update any awaiting activity records with the new activity record.
                    foreach (var awaitingActivityRecord in workflowRecord.AwaitingActivities)
                    {
                        var clientId = awaitingActivityRecord.ActivityRecord.GetClientId();
                        if (activitiesIndex.ContainsKey(clientId))
                        {
                            awaitingActivityRecord.ActivityRecord = activitiesIndex[clientId];
                        }
                        else
                        {
                            removeAwaitingActivites.Add(awaitingActivityRecord);
                        }
                    }

                    foreach (var item in removeAwaitingActivites)
                    {
                        workflowRecord.AwaitingActivities.Remove(item);
                    }

                    // Remove any workflows with no awaiting activities.
                    if (!workflowRecord.AwaitingActivities.Any())
                    {
                        removeWorkflows.Add(workflowRecord);
                    }
                }

                foreach (var item in removeWorkflows)
                {
                    workflowDefinitionRecord.WorkflowRecords.Remove(item);
                }
            }

            Services.Notifier.Success(T("Workflow saved successfully"));

            // Don't pass the localId to force the activites to refresh and use the deterministic clientId.
            return(RedirectToAction("Edit", new { id }));
        }