Пример #1
0
        /// <summary>
        /// 获取作用域共享的子集模块构建,不再构建新实例
        /// </summary>
        /// <param name="type">子模块类型</param>
        /// <returns></returns>
        public static SubModuleBuildElement GetScopeSharedModule(string type)
        {
            SubModuleBuildElement module = new SubModuleBuildElement()
            {
                BuildInstance = false,
                Type          = type,
                Target        = BuildTarget.ScopeResult
            };

            return(module);
        }
Пример #2
0
        /// <summary>
        /// 通过节点配置构建对象并执行
        /// </summary>
        /// <typeparam name="TInstance">对象类型</typeparam>
        /// <param name="moduleCfg">The module CFG.</param>
        /// <returns></returns>
        public static TInstance BuildAndInvoke <TInstance>(ClientModuleElement moduleCfg, string subModuleId)
        {
            Type      taregetType = TypeCache.GetRuntimeType(moduleCfg.Type);
            TInstance instance    = default(TInstance);

            SubModuleBuildElement sub = null;

            if (moduleCfg.MoubleBuild != null && moduleCfg.MoubleBuild.Any())
            {
                sub = moduleCfg.MoubleBuild.FirstOrDefault(m => m.ModuleId == subModuleId);
            }
            return(instance);
        }
Пример #3
0
        /// <summary>
        /// 从对象的 XML 表示形式生成该对象。
        /// </summary>
        /// <param name="reader">从中对对象进行反序列化的 <see cref="T:System.Xml.XmlReader" /> 流。</param>
        public override void ReadXml(XmlReader reader)
        {
            int entDepth = reader.Depth;

            reader.ReadToElement("when");
            List <ModuleWhen> wList = new List <ModuleWhen>();

            while (reader.Name == "when" || reader.NodeType == XmlNodeType.Comment)
            {
                if (reader.NodeType == XmlNodeType.Comment)
                {
                    reader.ReadToElement("when");
                    continue;
                }

                ModuleWhen myWhen = new ModuleWhen();
                myWhen.ReadXml(reader);
                wList.Add(myWhen);

                if (reader.Name == "when" && reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
            }
            Conditions = wList.ToArray();

            while (reader.NodeType != XmlNodeType.Element && reader.Depth > entDepth)
            {
                reader.Read();
            }

            if (reader.NodeType == XmlNodeType.Element && reader.Name == "else")
            {
                SubModuleBuildElement myElse = new SubModuleBuildElement();
                myElse.ReadXml(reader);
                Else = myElse;
            }
        }
Пример #4
0
 /// <summary>
 /// 在模块执行作用域执行(调用)模块代码
 /// </summary>
 /// <param name="sub">构建配置项</param>
 /// <param name="scope">执行作用域</param>
 public static void BuildAndInvoke(SubModuleBuildElement sub, ModuleRunScope scope)
 {
     sub.InvokeInScope(scope);
 }
        /// <summary>
        /// Invokes the builder in scope.
        /// </summary>
        /// <param name="sub">The sub.</param>
        /// <param name="scope">执行作用域</param>
        /// <param name="ignoreException">是否忽略执行异常</param>
        /// <returns></returns>
        protected static object InvokeBuilderInScope(SubModuleBuildElement sub, ModuleRunScope scope, bool ignoreException = false)
        {
            Type taregetType = TypeCache.GetRuntimeType(sub.Type);
            ModuleConstructorElement constr = sub.Steps.FirstOrDefault(s => s.GetType().Equals(typeof(ModuleConstructorElement))) as ModuleConstructorElement;
            object instance = null;

            #region 构建对象
            if (constr == null)
            {
                if (sub.BuildInstance)
                {
                    //if (taregetType.IsValueType)
                    if (taregetType == typeof(string))
                    {
                        instance = string.Empty;
                    }
                    else
                    {
                        instance = Activator.CreateInstance(taregetType);
                    }
                }
                else
                {
                    instance = default(Target);
                }
            }
            else
            {
                if (scope != null)
                {
                    scope.AddStackFrame(constr.ToString());
                }
                constr.InvokeInScope(taregetType, null, scope);
                instance = scope.StepSwap;
            }

            if (sub.BuildInstance && instance == null)
            {
                throw new ConfigurationErrorsException("创建实例:(" + taregetType.FullName + ")失败,请确保系统配置正确!");
            }

            #endregion

            try
            {
                foreach (var step in sub.Steps)
                {
                    if (scope != null)
                    {
                        scope.AddStackFrame(step.ToString());
                    }
                    step.InvokeInScope(taregetType, instance, scope);
                }
            }
            catch (Exception ivkError)
            {
                scope.LastError = ivkError;
                if (!ignoreException)
                {
                    throw ivkError;
                }
            }

            if (sub.Target == BuildTarget.Instance)
            {
                return(instance);
            }
            else
            {
                return(scope.StepSwap);
            }
        }
 /// <summary>
 /// 从对象的 XML 表示形式生成该对象。
 /// </summary>
 /// <param name="reader">从中对对象进行反序列化的 <see cref="T:System.Xml.XmlReader" /> 流。</param>
 public virtual void ReadXml(XmlReader reader)
 {
     reader.ReadToElement("Builder");
     Builder = reader.ObjectReadXml <SubModuleBuildElement>();
 }