コード例 #1
0
ファイル: TemplateEngine.cs プロジェクト: stonezhu870/never
        public void Startup()
        {
            if (this.ready)
            {
                return;
            }

            this.ready = true;
            var eventArgs = new CompliantEventArgs();

            this.TestCompliant?.Invoke(this, eventArgs);

            /*有注册兼容性检查的才检查*/
            if (eventArgs.collections.Any())
            {
                foreach (var tmpl in this.addlist)
                {
                    var steps = tmpl.Steps.ToArray();
                    if (steps.Length <= 3)
                    {
                        continue;
                    }

                    /*从第三个步骤开始,因为第二个步骤的消息参数是从begin那里得来的*/
                    for (var i = 2; i < steps.Length - 1; i++)
                    {
                        foreach (var step in steps[i].Steps)
                        {
                            var type = TemplateWorkStep.Find(step);
                            if (!eventArgs.collections.ContainsKey(type))
                            {
                                throw new TemplateNotCompliantException("步骤{0}所需要上一步骤的消息结果没有注册,无法确定是否与当前步骤兼容", type.FullName);
                            }

                            var elements = steps[i - 1];
                            foreach (var ele in elements.Steps)
                            {
                                if (!eventArgs.collections.ContainsKey(TemplateWorkStep.Find(ele)))
                                {
                                    throw new TemplateNotCompliantException("步骤{0}所需要上一步骤的消息结果没有注册,无法确定是否与当前步骤兼容", type.FullName);
                                }

                                var preAction = eventArgs.collections[TemplateWorkStep.Find(ele)];
                                var curAction = eventArgs.collections[type];
                                if (curAction.Value.Invoke(type, preAction.Key))
                                {
                                    break;
                                }

                                throw new TemplateNotCompliantException("步骤{0}所需要上一步骤的消息结果与当前步骤不兼容", type.FullName);
                            }
                        }
                    }
                }
            }

            this.templateRepository.SaveAndChange(this.workflowengine.JsonSerializer, this.addlist.ToArray(), this.changeList.ToArray());

            return;
        }
コード例 #2
0
ファイル: StartupService.cs プロジェクト: stonezhu870/never
        /// <summary>
        ///
        /// </summary>
        /// <param name="application"></param>
        /// <param name="type"></param>
        public void Processing(IApplicationStartup application, Type type)
        {
            if (type == null || type.IsAbstract || !type.IsClass || type.IsInterface || type.IsGenericTypeDefinition || type.IsValueType)
            {
                return;
            }

            if (!ObjectExtension.IsAssignableToType(typeof(IWorkStep), type))
            {
                return;
            }

            TemplateWorkStep.AddStep(type);

            application.ServiceRegister.RegisterType(type, type, string.Empty, IoC.ComponentLifeStyle.Transient);
        }
コード例 #3
0
        /// <summary>
        /// 从json内容中转换为模板对象
        /// </summary>
        /// <param name="jsonSerializer"></param>
        /// <param name="json">The json.</param>
        /// <returns></returns>
        public static Template FromJson(IJsonSerializer jsonSerializer, string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            var temp = jsonSerializer.Deserialize <TemplateJson>(json);

            if (temp == null)
            {
                return(null);
            }

            var template = new Template(temp.Name);

            foreach (var ele in temp.Collection)
            {
                template.Next(ele.Steps.Select(ta => TemplateWorkStep.Find(ta)).ToArray(), ele.Mode);
            }

            return(template.End());
        }
コード例 #4
0
        /// <summary>
        /// 移动到下一容器中,这个容器可以有多个工作单位,并且只有所有的工作步骤完成后才能移动到下一节点
        /// </summary>
        /// <param name="workSteps">The work steps.</param>
        /// <param name="mode">是否为同时完成才算完成当前步骤</param>
        /// <returns></returns>
        public Template Next(Type[] workSteps, CoordinationMode mode = CoordinationMode.Any)
        {
            if (workSteps == null)
            {
                return(this);
            }

            if (workSteps.All(o => o == null))
            {
                return(this);
            }

            if (this.Ending)
            {
                throw new ArgumentException("该模板已经结束了");
            }

            var step = TemplateWorkStep.New(workSteps, mode);

            step.Order = this.workSteps.Count;
            this.workSteps.Add(step);

            return(this);
        }