예제 #1
0
        public async Task CanUpdated()
        {
            var entity = new WorkflowForm(Guid.NewGuid())
            {
                Name = "Name2"
            };

            UsingDbContext(dbContext => { dbContext.Set <WorkflowForm>().Add(entity); });
            var grain  = ClusterClient.GetGrain <IWorkflowFormGrain <WorkflowFormDto> >(entity.Id);
            var result = await grain.Get();

            result.Name.ShouldBe(entity.Name);
            await grain.Update(new WorkflowFormDto()
            {
                Id   = entity.Id,
                Name = "Name3"
            });

            var updateResult = await grain.Get();

            updateResult.Name.ShouldBe("Name3");
            await Task.Delay(500);

            UsingDbContext(dbContext =>
            {
                dbContext.Set <WorkflowForm>().Any(x => x.Id == entity.Id).ShouldBeTrue();
                var workflowForm = dbContext.Set <WorkflowForm>().First(x => x.Id == entity.Id);
                workflowForm.Name.ShouldBe("Name3");
            });
        }
예제 #2
0
        public async Task <JsonResult> SaveWorkflowFromPublic(WorkflowForm form)
        {
            string fileName = form.FormId + ".cshtml";
            //生成对应文件
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(
                @"@using EIP.Common.Core.Auth;
                  @using EIP.Common.Core.Utils;
                  @{
                    PrincipalUser principalUser = FormAuthenticationExtension.Current(HttpContext.Current.Request);
                   }");
            stringBuilder.Append(form.Html);
            string formUrl = "~/Areas/Workflow/Views/Form/Designer/" + fileName;
            string file    = Server.MapPath(formUrl);

            //写入请求当前人员信息脚本

            FileUtil.WriteFile(file, stringBuilder.ToString());
            form.UpdateTime     = DateTime.Now;
            form.UpdateUserId   = CurrentUser.UserId;
            form.UpdateUserName = CurrentUser.Name;
            form.Url            = formUrl;
            OperateStatus operateStatus = await _workflowFormLogic.SaveWorkflowFromUrl(form);

            if (operateStatus.ResultSign == ResultSign.Successful)
            {
                operateStatus.Message = ResourceWorkflow.表单发布成功;
            }
            return(Json(operateStatus));
        }
예제 #3
0
 public async Task <JsonResult> SaveWorkflowFromHtml(WorkflowForm form)
 {
     form.UpdateTime     = DateTime.Now;
     form.UpdateUserId   = CurrentUser.UserId;
     form.UpdateUserName = CurrentUser.Name;
     return(Json(await _workflowFormLogic.SaveWorkflowFromHtml(form)));
 }
예제 #4
0
        public async Task CanRead()
        {
            var entity = new WorkflowForm(Guid.NewGuid())
            {
                Name = "Name2"
            };

            UsingDbContext(dbContext => { dbContext.Set <WorkflowForm>().Add(entity); });
            var grain  = ClusterClient.GetGrain <IWorkflowFormGrain <WorkflowFormDto> >(entity.Id);
            var result = await grain.Get();

            result.Name.ShouldBe(entity.Name);
        }
예제 #5
0
        public async Task <ViewResultBase> Edit(NullableIdInput input)
        {
            var form = new WorkflowForm();

            if (input != null)
            {
                if (!input.Id.IsNullOrEmptyGuid())
                {
                    form = await _workflowFormLogic.GetByIdAsync(input.Id);
                }
            }
            return(View(form));
        }
예제 #6
0
        public Workflow Upsert(WorkflowForm form)
        {
            var workflow = context.Workflows.Include("Flows").Where(t => form.Id == t.Id).FirstOrDefault();

            if (workflow == null)
            {
                form.SetCreated();
                workflow = Mapper.Map <WorkflowForm, Workflow>(form, workflow);
                workflow.Init();
                form.Flows = form.Flows ?? new List <FlowForm>();

                workflow.Flows = form.Flows.Select(t => {
                    var flow     = Mapper.Map <Flow>(t);
                    flow.DueDate = flow.DueDate?.Date;
                    //flow.Init();
                    return(flow);
                }).ToList();


                context.Workflows.Add(workflow);
            }
            else
            {
                form.SetUpdated();

                var toDelete = workflow.Flows.ToList();

                toDelete.ForEach(t => {
                    context.Flows.Remove(t);
                });

                form.Flows = form.Flows ?? new List <FlowForm>();

                form.Flows.ToList().ForEach(t => {
                    var flow = Mapper.Map <Flow>(t);
                    //flow.Init();
                    workflow.Flows.Add(flow);
                });
            }


            context.SaveChanges();

            return(workflow);
        }
예제 #7
0
        public async Task CanDeleted()
        {
            var entity = new WorkflowForm(Guid.NewGuid())
            {
                Name = "Name4"
            };

            UsingDbContext(dbContext => { dbContext.Set <WorkflowForm>().Add(entity); });
            var grain  = ClusterClient.GetGrain <IWorkflowFormGrain <WorkflowFormDto> >(entity.Id);
            var result = await grain.Get();

            result.Name.ShouldBe(entity.Name);
            await grain.Delete();

            await grain.Over();

            var updateResult = await grain.Get();

            updateResult.Id.ShouldBe(default);
예제 #8
0
        public WorkflowForm GetNextForm(Guid?workflowGuid = null, string formAction = null, List <MobileField> formFields = null)
        {
            var rockContext     = new RockContext();
            var workflowService = new WorkflowService(rockContext);

            var workflow      = LoadWorkflow(workflowGuid, rockContext);
            var currentPerson = GetCurrentPerson();

            //
            // Set initial workflow attribute values.
            //
            if (!workflowGuid.HasValue)
            {
                SetInitialWorkflowAttributes(workflow, formFields);
            }

            var action = ProcessAndGetNextAction(workflow, currentPerson, rockContext, out var message);

            if (action == null)
            {
                return(new WorkflowForm
                {
                    Message = message ?? GetCompletionMessage(workflow, string.Empty)
                });
            }

            //
            // If this is a form submittal, then complete the form and re-process.
            //
            if (!string.IsNullOrEmpty(formAction) && formFields != null)
            {
                SetFormValues(action, formFields);
                var responseText = CompleteFormAction(action, formAction, currentPerson, rockContext);

                action = ProcessAndGetNextAction(workflow, currentPerson, rockContext, out message);
                if (action == null)
                {
                    return(new WorkflowForm
                    {
                        Message = message ?? GetCompletionMessage(workflow, responseText)
                    });
                }
                else
                {
                    //
                    // If there is a second form, we need to persist.
                    //
                    workflowService.PersistImmediately(action);
                }
            }

            //
            // Begin building up the response with the form data.
            //
            var activity = action.Activity;
            var form     = action.ActionTypeCache.WorkflowForm;

            var mobileForm = new WorkflowForm
            {
                WorkflowGuid = workflow.Id != 0 ? ( Guid? )workflow.Guid : null
            };

            //
            // Populate all the form fields that should be visible on the workflow.
            //
            foreach (var formAttribute in form.FormAttributes.OrderBy(a => a.Order))
            {
                if (formAttribute.IsVisible)
                {
                    var    attribute = AttributeCache.Get(formAttribute.AttributeId);
                    string value     = attribute.DefaultValue;

                    //
                    // Get the current value from either the workflow or the activity.
                    //
                    if (workflow.AttributeValues.ContainsKey(attribute.Key) && workflow.AttributeValues[attribute.Key] != null)
                    {
                        value = workflow.AttributeValues[attribute.Key].Value;
                    }
                    else if (activity.AttributeValues.ContainsKey(attribute.Key) && activity.AttributeValues[attribute.Key] != null)
                    {
                        value = activity.AttributeValues[attribute.Key].Value;
                    }

                    var mobileField = new MobileField
                    {
                        AttributeGuid       = attribute.Guid,
                        Key                 = attribute.Key,
                        Title               = attribute.Name,
                        IsRequired          = formAttribute.IsRequired,
                        ConfigurationValues = attribute.QualifierValues.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Value),
                        RockFieldType       = attribute.FieldType.Class,
                        Value               = value
                    };

                    if (formAttribute.IsReadOnly)
                    {
                        var field = attribute.FieldType.Field;

                        string formattedValue = null;

                        // get formatted value
                        if (attribute.FieldType.Class == typeof(Rock.Field.Types.ImageFieldType).FullName)
                        {
                            formattedValue = field.FormatValueAsHtml(null, attribute.EntityTypeId, activity.Id, value, attribute.QualifierValues, true);
                        }
                        else
                        {
                            formattedValue = field.FormatValueAsHtml(null, attribute.EntityTypeId, activity.Id, value, attribute.QualifierValues);
                        }

                        mobileField.Value         = formattedValue;
                        mobileField.RockFieldType = string.Empty;

                        if (formAttribute.HideLabel)
                        {
                            mobileField.Title = string.Empty;
                        }
                    }

                    mobileForm.Fields.Add(mobileField);
                }
            }

            //
            // Build the list of form actions (buttons) that should be presented
            // to the user.
            //
            foreach (var btn in form.Actions.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var actionDetails = btn.Split(new char[] { '^' });
                if (actionDetails.Length > 0)
                {
                    DefinedValueCache btnType;

                    if (!actionDetails[1].IsNullOrWhiteSpace())
                    {
                        btnType = DefinedValueCache.Get(actionDetails[1].AsGuid());
                    }
                    else
                    {
                        btnType = DefinedTypeCache.Get(SystemGuid.DefinedType.BUTTON_HTML)
                                  .DefinedValues
                                  .OrderBy(a => a.Order)
                                  .FirstOrDefault();
                    }

                    if (btnType != null)
                    {
                        mobileForm.Buttons.Add(new WorkflowFormButton
                        {
                            Text = actionDetails[0],
                            Type = btnType.Value
                        });
                    }
                }
            }

            return(mobileForm);
        }
예제 #9
0
 public static void EventHandle(WorkflowForm entity, EnabledEvent evt)
 {
     entity.Disabled             = false;
     entity.LastModificationTime = evt.LastModificationTime;
 }