/// <summary>
        /// 添加依赖项目和被依赖项目
        /// </summary>
        /// <param name="flowItem"></param>
        /// <param name="dependId"></param>
        private void AddDependAndBedepend(FlowItem flowItem, int dependId)
        {
            FlowItem dependItem = GetFlowItem(dependId);

            if (dependItem != null)
            {
                if (dependItem.Item.Property.Disable)
                {
                    if (!string.IsNullOrEmpty(dependItem.Item.Property.Depend))
                    {
                        string[] dependArray = dependItem.Item.Property.Depend.Split(' ');
                        foreach (string depend in dependArray)
                        {
                            int id = Convert.ToInt32(depend);
                            AddDependAndBedepend(flowItem, id);
                        }
                    }
                }
                else
                {
                    flowItem.AddDepend(dependId);
                    dependItem.AddBedepend(flowItem.Id);
                }
            }
            else
            {
                flowItem.AddDepend(dependId);
            }
        }
        /// <summary>
        /// 测试脚本加载
        /// </summary>
        /// <param name="filename"></param>
        private void LoadFlowFile(string filename)
        {
            XmlReaderSettings settings = new XmlReaderSettings(); //测试脚本初始化的一些设定

            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace             = true;
            try
            {
                using (XmlReader reader = XmlReader.Create(filename, settings))
                {
                    reader.MoveToContent();//移动到文本正确内容
                    while (reader.Read())
                    {
                        if (reader.IsStartElement("Item"))
                        {
                            FlowItem flowItem = ParseFlowItem(reader);
                            AddFlowItem(flowItem);
                            UpdateDependAndBedepend(flowItem);
                        }
                    }
                }
            }
            catch (System.IO.FileNotFoundException)
            {
            }
        }
        /// <summary>
        /// 添加测试脚本
        /// </summary>
        /// <param name="flowItem"></param>
        private void AddFlowItem(FlowItem flowItem)
        {
            if (flowItemList_ == null)
            {
                flowItemList_ = new List <FlowItem>();
            }

            flowItemList_.Add(flowItem);
        }
 /// <summary>
 /// 跟新依赖项目和被依赖项目
 /// </summary>
 /// <param name="flowItem"></param>
 private void UpdateDependAndBedepend(FlowItem flowItem)
 {
     if (!string.IsNullOrEmpty(flowItem.Item.Property.Depend))
     {
         string[] dependArray = flowItem.Item.Property.Depend.Split(' ');
         foreach (string depend in dependArray)
         {
             int id = Convert.ToInt32(depend);
             AddDependAndBedepend(flowItem, id);
         }
     }
 }
 public FlowItemExecutor(FlowItem flowItem)
 {
     flowItem_ = flowItem;
     cmdDict_  = new Dictionary <string, ExecuteMatchCmd>();
     cmdDict_.Add(CMD_EQUIPMENT, new ExecuteMatchCmd(ExecuteEquipmentCmd));
     cmdDict_.Add(CMD_DELAY, new ExecuteMatchCmd(ExecuteDelayCmd));
     cmdDict_.Add(CMD_ASSISTANT, new ExecuteMatchCmd(Assistant.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_PHONE, new ExecuteMatchCmd(PhoneCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_COMMANDLINE, new ExecuteMatchCmd(CommandLineCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_EQUIPMENT1, new ExecuteMatchCmd(RemoteEquipmentCmd1.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_EQUIPMENT2, new ExecuteMatchCmd(RemoteEquipmentCmd2.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_EQUIPMENT3, new ExecuteMatchCmd(RemoteEquipmentCmd3.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_EQUIPMENT4, new ExecuteMatchCmd(RemoteEquipmentCmd4.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_EQUIPMENT5, new ExecuteMatchCmd(RemoteEquipmentCmd5.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_EQUIPMENT6, new ExecuteMatchCmd(RemoteEquipmentCmd6.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_FILE, new ExecuteMatchCmd(FileCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_RSTECH, new ExecuteMatchCmd(RStechCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_AUDIO, new ExecuteMatchCmd(AudioCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_RESULT, new ExecuteMatchCmd(ResultCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_IMAGE_PROCESS, new ExecuteMatchCmd(ImageProcessCmd.Instance.ExecuteCmd));
     cmdDict_.Add(CMD_IMAGE, new ExecuteMatchCmd(ImageCmd.Instance.ExecuteCmd));
 }
        /// <summary>
        /// 解析Item
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private FlowItem ParseFlowItem(XmlReader reader)
        {
            if (!reader.IsStartElement("Item"))
            {
                return(null);
            }

            FlowItem flowItem = new FlowItem();
            Item     item     = new Item();

            item.Id = Convert.ToInt32(reader.GetAttribute("id"));
            while (reader.Read() && reader.IsStartElement("Method"))
            {
                item.AddMethod(ParseMethod(reader));
            }

            item.Property = ParseProperty(reader);

            flowItem.Item = item;

            return(flowItem);
        }
 public ExecuteFinishEventArgs(FlowItem flowItem)
 {
     flowItem_ = flowItem;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 是否需要跳过测试
        /// 如果跳过测试指令,则直接将实测值赋值为Skip,测试结果赋值为失败
        /// </summary>
        /// <returns></returns>
        public bool IsSkip()
        {
            if (!String.IsNullOrEmpty(Item.Property.Condition))
            {
                string condition = Item.Property.Condition.Replace(" ", String.Empty);

                string expression = String.Empty;
                string operand    = String.Empty;
                bool   not        = false;
                foreach (char c in condition)
                {
                    if (c == '+' || c == '-' || c == '(' || c == ')')
                    {
                        if (!String.IsNullOrEmpty(operand))
                        {
                            int id = Int32.Parse(operand);

                            FlowItem flowItem = FlowControl.Instance.GetFlowItem(id);

                            bool pass = false;
                            if (flowItem != null && flowItem.IsPass())
                            {
                                pass = true;
                            }

                            if (not)
                            {
                                pass = !pass;
                            }

                            expression += pass ? Boolean.TrueString : Boolean.FalseString;

                            operand = String.Empty;
                            not     = false;
                        }

                        expression += c;
                    }
                    else if (c == '!')
                    {
                        not = true;
                    }
                    else
                    {
                        operand += c;
                    }
                }

                if (!String.IsNullOrEmpty(operand))
                {
                    int id = Int32.Parse(operand);

                    FlowItem flowItem = FlowControl.Instance.GetFlowItem(id);

                    bool pass = false;
                    if (flowItem != null && flowItem.IsPass())
                    {
                        pass = true;
                    }

                    if (not)
                    {
                        pass = !pass;
                    }

                    expression += pass ? Boolean.TrueString : Boolean.FalseString;
                    operand     = String.Empty;
                    not         = false;
                }

                return(!Utils.IsTrue(expression));
            }

            return(false);
        }