Example #1
0
        /// <summary>
        /// 当前条件是否通过
        /// </summary>
        /// <param name="scope">作用域</param>
        /// <returns>
        ///   <c>true</c> if the specified scope is passed; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool IsPassed(ModuleRunScope scope)
        {
            if (ExpressionLeft != null && ExpressionRight != null)
            {
                string result      = ExpressionLeft.Invoke(scope);
                string resultRight = ExpressionRight.Invoke(scope);

                if (!string.IsNullOrEmpty(BooleanCompareDelegate))
                {
                    return(ConditionalElement.GetBooleanDelegate(BooleanCompareDelegate)(result, resultRight));
                }
                else
                {
                    return(string.Equals(result, resultRight, ComparisonMode));
                }
            }

            object boolKey = scope.GetVaraible(Key);

            if (boolKey == null)
            {
                return(false);
            }
            else
            {
                return(Convert.ToBoolean(boolKey));
            }
        }
        /// <summary>
        /// 从对象的 XML 表示形式生成该对象。
        /// </summary>
        /// <param name="reader">从中对对象进行反序列化的 <see cref="T:System.Xml.XmlReader" /> 流。</param>
        public override void ReadXml(XmlReader reader)
        {
            int entDepth = reader.Depth;

            //处理开始节点
            if (reader.NodeType == XmlNodeType.Element && reader.Name == "when")
            {
                reader.ReadToElement("match");
                if (reader.Name == "match")
                {
                    ConditionalElement myWhen = new ConditionalElement();
                    myWhen.ReadXml(reader);
                    Match = myWhen;

                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "match")
                    {
                        reader.ReadEndElement();
                    }
                }

                reader.ReadToElement("invoke");
                if (reader.Name == "invoke")
                {
                    reader.ReadToElement(null);
                    while (reader.NodeType == XmlNodeType.Element)
                    {
                        _innerSteps.ReadXmlEx <ModuleBuildStepElement>(reader);
                    }
                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "invoke")
                    {
                        reader.ReadEndElement();
                    }
                }

                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "when")
                {
                    reader.ReadEndElement();
                }
            }
        }
Example #3
0
        /// <summary>
        /// 从对象的 XML 表示形式生成该对象。
        /// </summary>
        /// <param name="reader">从中对对象进行反序列化的 <see cref="T:System.Xml.XmlReader" /> 流。</param>
        public override void ReadXml(XmlReader reader)
        {
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.Name == "moduleId")
                    {
                        ModuleId = reader.Value;
                    }
                    else if (reader.Name == "type")
                    {
                        Type = reader.Value;
                    }
                    else if (reader.Name == "isInstance")
                    {
                        BuildInstance = Convert.ToBoolean(reader.Value);
                    }
                    else if (reader.Name == "target")
                    {
                        Target = (BuildTarget)Enum.Parse(typeof(BuildTarget), reader.Value);
                    }
                    else if (reader.Name == "enumerator")
                    {
                        ScopeIEnumerableInstance = reader.Value;
                    }
                }
            }

            int entDepth = reader.Depth;

            while (reader.Read() && reader.Depth >= entDepth)
            {
                //处理开始节点
                while (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "match")
                    {
                        ConditionalElement myWhen = new ConditionalElement();
                        myWhen.ReadXml(reader);
                        Match = myWhen;
                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "match")
                        {
                            reader.ReadEndElement();
                        }
                    }

                    if (reader.Name == "invoke")
                    {
                        reader.Read();
                        while (reader.NodeType == XmlNodeType.Element)
                        {
                            _innerSteps.ReadXmlEx <ModuleBuildStepElement>(reader);
                        }
                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "invoke")
                        {
                            reader.ReadEndElement();
                        }
                    }
                }
            }
        }