public async Task <IActionResult> Edit(int workflowTypeId, string activityId, string returnUrl)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Forbid());
            }

            var workflowType = await _session.GetAsync <WorkflowType>(workflowTypeId);

            var activityRecord  = workflowType.Activities.Single(x => x.ActivityId == activityId);
            var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties);

            var activityEditor = await _activityDisplayManager.BuildEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew : false);

            activityEditor.Metadata.Type = "Activity_Edit";

            var viewModel = new ActivityEditViewModel
            {
                Activity       = activityContext.Activity,
                ActivityId     = activityId,
                ActivityEditor = activityEditor,
                WorkflowTypeId = workflowTypeId,
                ReturnUrl      = returnUrl
            };

            return(View("EditActivity", viewModel));
        }
        public async Task <IActionResult> Edit(string workflowsnippetname, string activityId, string returnUrl)
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Workflows.Snippets.Permissions.ManageWorkflowSnippets))
            {
                return(Forbid());
            }

            // var workflowType = await _session.GetAsync<WorkflowType>(workflowTypeId);
            var workflowSnippet = await  GetWorkFlowSnippet(workflowsnippetname);

            var activityRecord  = workflowSnippet.WorkFlowType.Activities.Single(x => x.ActivityId == activityId);
            var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties);

            var activityEditor = await _activityDisplayManager.BuildEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew : false);

            activityEditor.Metadata.Type = "ActivityWorkflowSnippets_Edit";
            ((dynamic)activityEditor).WorkflowSnippetName = workflowsnippetname;

            var viewModel = new ActivityEditViewModel
            {
                Activity       = activityContext.Activity,
                ActivityId     = activityId,
                ActivityEditor = activityEditor,
                //  WorkflowTypeId = workflowTypeId,
                ReturnUrl = returnUrl
            };

            return(View("EditActivity", viewModel));
        }
        public async Task <IActionResult> Edit(string sourcename, string localId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Workflows.Snippets.Permissions.ManageWorkflowSnippets))
            {
                return(Forbid());
            }

            var newLocalId          = string.IsNullOrWhiteSpace(localId) ? Guid.NewGuid().ToString() : localId;
            var availableActivities = _activityLibrary.ListActivities();

            var shortcodeTemplatesDocument = await _workflowSnippetsManager.GetWorkflowSnippetsDocumentAsync();

            if (!shortcodeTemplatesDocument.WorkflowSnippets.ContainsKey(sourcename))
            {
                return(RedirectToAction("EditProperties", new { sourcename = sourcename }));
            }

            var workflowSnippet = shortcodeTemplatesDocument.WorkflowSnippets[sourcename];

            var workflowType = workflowSnippet.WorkFlowType;

            if (workflowType == null)
            {
                return(NotFound());
            }

            //populate properties from source object
            workflowType.Name      = sourcename;
            workflowType.IsEnabled = workflowSnippet.IsEnabled;

            var workflow        = _workflowManager.NewWorkflow(workflowType);
            var workflowContext = await _workflowManager.CreateWorkflowExecutionContextAsync(workflowType, workflow);

            var activityContexts = await Task.WhenAll(workflowType.Activities.Select(x => _workflowManager.CreateActivityExecutionContextAsync(x, x.Properties)));

            // var workflowCount = await _session.QueryIndex<WorkflowIndex>(x => x.WorkflowTypeId == workflowType.WorkflowTypeId).CountAsync();


            var activityThumbnailShapes = new List <dynamic>();
            var index = 0;

            foreach (var activity in availableActivities)
            {
                activityThumbnailShapes.Add(await BuildActivityDisplay(activity, index++, sourcename, newLocalId, "Thumbnail"));
            }

            var activityDesignShapes = new List <dynamic>();

            index = 0;

            foreach (var activityContext in activityContexts)
            {
                activityDesignShapes.Add(await BuildActivityDisplay(activityContext, index++, sourcename, newLocalId, "Design"));
            }

            var activitiesDataQuery = activityContexts.Select(x => new
            {
                Id       = x.ActivityRecord.ActivityId,
                X        = x.ActivityRecord.X,
                Y        = x.ActivityRecord.Y,
                Name     = x.ActivityRecord.Name,
                IsStart  = x.ActivityRecord.IsStart,
                IsEvent  = x.Activity.IsEvent(),
                Outcomes = x.Activity.GetPossibleOutcomes(workflowContext, x).ToArray()
            });
            var workflowTypeData = new
            {
                Id          = sourcename,
                Name        = workflowType.Name,
                IsEnabled   = workflowType.IsEnabled,
                Activities  = activitiesDataQuery.ToArray(),
                Transitions = workflowType.Transitions
            };

            var wfVewModel = new WorkflowTypeViewModel
            {
                WorkflowType     = workflowType,
                WorkflowTypeJson = JsonConvert.SerializeObject(workflowTypeData, Formatting.None, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }),
                ActivityThumbnailShapes = activityThumbnailShapes,
                ActivityDesignShapes    = activityDesignShapes,
                ActivityCategories      = _activityLibrary.ListCategories().ToList(),
                LocalId        = newLocalId,
                LoadLocalState = !string.IsNullOrWhiteSpace(localId),
                //  WorkflowCount = workflowCount
            };

            var model = new WorkflowSnippetViewModel
            {
                Name = sourcename,
                WorkflowTypeViewModel = wfVewModel,
                //Content = template.Content,
                // WorkflowType = workflowType,
                Description = workflowSnippet.Description,
                // Categories = template.Categories
            };

            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, string localId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Unauthorized());
            }

            var newLocalId          = string.IsNullOrWhiteSpace(localId) ? Guid.NewGuid().ToString() : localId;
            var availableActivities = _activityLibrary.ListActivities();
            var workflowType        = await _session.GetAsync <WorkflowType>(id);

            if (workflowType == null)
            {
                return(NotFound());
            }

            var workflow        = _workflowManager.NewWorkflow(workflowType);
            var workflowContext = await _workflowManager.CreateWorkflowExecutionContextAsync(workflowType, workflow);

            var activityContexts = await Task.WhenAll(workflowType.Activities.Select(async x => await _workflowManager.CreateActivityExecutionContextAsync(x, x.Properties)));

            var activityThumbnailDisplayTasks = availableActivities.Select(async(x, i) => await BuildActivityDisplay(x, i, id, newLocalId, "Thumbnail"));
            var activityDesignDisplayTasks    = activityContexts.Select(async(x, i) => await BuildActivityDisplay(x, i, id, newLocalId, "Design"));
            var workflowCount = await _session.QueryIndex <WorkflowIndex>(x => x.WorkflowTypeId == workflowType.WorkflowTypeId).CountAsync();

            await Task.WhenAll(activityThumbnailDisplayTasks.Concat(activityDesignDisplayTasks));

            var activityThumbnailShapes = activityThumbnailDisplayTasks.Select(x => x.Result).ToList();
            var activityDesignShapes    = activityDesignDisplayTasks.Select(x => x.Result).ToList();
            var activitiesDataQuery     = activityContexts.Select(x => new
            {
                Id       = x.ActivityRecord.ActivityId,
                X        = x.ActivityRecord.X,
                Y        = x.ActivityRecord.Y,
                Name     = x.ActivityRecord.Name,
                IsStart  = x.ActivityRecord.IsStart,
                IsEvent  = x.Activity.IsEvent(),
                Outcomes = x.Activity.GetPossibleOutcomes(workflowContext, x).ToArray()
            });
            var workflowTypeData = new
            {
                Id          = workflowType.Id,
                Name        = workflowType.Name,
                IsEnabled   = workflowType.IsEnabled,
                Activities  = activitiesDataQuery.ToArray(),
                Transitions = workflowType.Transitions
            };
            var viewModel = new WorkflowTypeViewModel
            {
                WorkflowType     = workflowType,
                WorkflowTypeJson = JsonConvert.SerializeObject(workflowTypeData, Formatting.None, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }),
                ActivityThumbnailShapes = activityThumbnailShapes,
                ActivityDesignShapes    = activityDesignShapes,
                ActivityCategories      = _activityLibrary.ListCategories().ToList(),
                LocalId        = newLocalId,
                LoadLocalState = !string.IsNullOrWhiteSpace(localId),
                WorkflowCount  = workflowCount
            };

            return(View(viewModel));
        }
Esempio n. 5
0
        public async Task <IActionResult> Details(int id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Unauthorized());
            }

            var workflow = await _workflowStore.GetAsync(id);

            if (workflow == null)
            {
                return(NotFound());
            }

            var workflowType = await _workflowTypeStore.GetAsync(workflow.WorkflowTypeId);

            var blockingActivities = workflow.BlockingActivities.ToDictionary(x => x.ActivityId);
            var workflowContext    = await _workflowManager.CreateWorkflowExecutionContextAsync(workflowType, workflow);

            var activityContexts = await Task.WhenAll(workflowType.Activities.Select(async x => await _workflowManager.CreateActivityExecutionContextAsync(x, x.Properties)));

            var activityDesignShapes = (await Task.WhenAll(activityContexts.Select(async x => await BuildActivityDisplayAsync(x, workflowType.Id, blockingActivities.ContainsKey(x.ActivityRecord.ActivityId), "Design")))).ToList();
            var activitiesDataQuery  = activityContexts.Select(x => new
            {
                Id         = x.ActivityRecord.ActivityId,
                X          = x.ActivityRecord.X,
                Y          = x.ActivityRecord.Y,
                Name       = x.ActivityRecord.Name,
                IsStart    = x.ActivityRecord.IsStart,
                IsEvent    = x.Activity.IsEvent(),
                IsBlocking = workflow.BlockingActivities.Any(a => a.ActivityId == x.ActivityRecord.ActivityId),
                Outcomes   = x.Activity.GetPossibleOutcomes(workflowContext, x).ToArray()
            });
            var workflowTypeData = new
            {
                Id          = workflowType.Id,
                Name        = workflowType.Name,
                IsEnabled   = workflowType.IsEnabled,
                Activities  = activitiesDataQuery.ToArray(),
                Transitions = workflowType.Transitions
            };

            var jsonSerializerSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var viewModel = new WorkflowViewModel
            {
                Workflow             = workflow,
                WorkflowType         = workflowType,
                WorkflowTypeJson     = JsonConvert.SerializeObject(workflowTypeData, Formatting.None, jsonSerializerSettings),
                WorkflowJson         = JsonConvert.SerializeObject(workflow, Formatting.Indented, jsonSerializerSettings),
                ActivityDesignShapes = activityDesignShapes
            };

            return(View(viewModel));
        }