コード例 #1
0
ファイル: TimerActivity.cs プロジェクト: adaxiong/Tomelt.CMS
        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 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 }));
        }
コード例 #3
0
ファイル: TimerActivity.cs プロジェクト: zaieda/Coevery
        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);
            }
        }
コード例 #4
0
        public ActionResult EditActivityPost(int id, string localId, string name, string clientId, FormCollection formValues)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit workflows")))
            {
                return(new HttpUnauthorizedResult());
            }

            var activity = _activitiesManager.GetActivityByName(name);

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

            // validating form values
            _formManager.Validate(new ValidatingContext {
                FormName = activity.Form, ModelState = ModelState, ValueProvider = ValueProvider
            });

            // stay on the page if there are validation errors
            if (!ModelState.IsValid)
            {
                // build the form, and let external components alter it
                var form = activity.Form == null ? null : _formManager.Build(activity.Form);

                // bind form with existing values.
                _formManager.Bind(form, ValueProvider);

                var viewModel = New.ViewModel(Id: id, LocalId: localId, Form: form);

                return(View(viewModel));
            }

            var model = new UpdatedActivityModel {
                ClientId = clientId,
                Data     = HttpUtility.JavaScriptStringEncode(FormParametersHelper.ToJsonString(formValues))
            };

            TempData["UpdatedViewModel"] = model;

            return(RedirectToAction("Edit", new {
                id,
                localId
            }));
        }
コード例 #5
0
        public ActionResult GetUserList()
        {
            var users = _userService.GetUsers();

            dynamic jObj = new JObject();

            jObj.Users = new JArray(users.Select(x =>
            {
                dynamic user = new JObject();
                user.id      = x.Id;
                user.Name    = x.UserName;

                return(user);
            }));


            return(Json(FormParametersHelper.ToJsonString(jObj), JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public ActionResult AddAssignment(int taskId)
        {
            TaskAssignment _taskAssignment = new TaskAssignment();
            var            users           = _userService.GetUsers();

            _taskAssignment.Users = users;
            dynamic jObj = new JObject();

            jObj.Users = new JArray(users.Select(x =>
            {
                dynamic user = new JObject();
                user.id      = x.Id;
                user.Name    = x.UserName;

                return(user);
            }));
            _taskAssignment.jsonData = FormParametersHelper.ToJsonString(jObj);
            return(View("AddAssignment", _taskAssignment));
        }
コード例 #7
0
        private string ProjectManagementTaskJson <T>(IEnumerable <T> _tasks) where T : TaskMgmtPart
        {
            //IEnumerable<TaskMgmtPartRecord> _tasks = _projTasks.GetTasks();
            // ProjectTaskViewModel _taskPartVM = new ProjectTaskViewModel(_tasks);
            dynamic jsonTask = new JObject();

            jsonTask.tasks = new JArray(_tasks.Select(_task =>
            {
                dynamic task          = new JObject();
                task.id               = _task.Id;
                task.name             = _task.Name;
                task.description      = _task.Description;
                task.status           = _task.Status;
                task.code             = _task.TaskCode;
                task.level            = _task.Level;
                task.duration         = _task.Duration;
                task.startIsMilestone = _task.StartIsMilestone;
                task.endIsMilestone   = _task.EndIsMilestone;
                task.progress         = _task.Progress;
                if (_task.Dependancy != null)
                {
                    task.depends = _task.Dependancy;
                }
                //task.start = DateTime.Now.AddDays(10).Millisecond;
                if (_task.ProjStartDate != null)
                {
                    DateTime start = (DateTime)_task.ProjStartDate;
                    task.start     = (long)(start - new DateTime(1970, 1, 1)).TotalMilliseconds;
                }
                if (_task.ProjEndDate != null)
                {
                    DateTime end = (DateTime)_task.ProjEndDate;
                    task.end     = (long)(end - new DateTime(1970, 1, 1)).TotalMilliseconds;
                }
                return(task);
            }));
            jsonTask.selectedRow      = 0;
            jsonTask.canWrite         = true;
            jsonTask.canWriteOnParent = true;

            return(FormParametersHelper.ToJsonString(jsonTask));
        }
コード例 #8
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);
        }
コード例 #9
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);
                }
            }
        }
コード例 #10
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 }));
        }
コード例 #11
0
 private void SerializeState()
 {
     Record.State = FormParametersHelper.ToJsonString(State);
 }