Exemplo n.º 1
0
        //从XML文件中读取MeasClsInfo的信息
        public static List <TestStepInfo> GetTestStepInfoFromXml()
        {
            List <TestStepInfo> stepInfoListFromXml = new List <TestStepInfo>();

            try
            {
                XElement rooEl = XElement.Load(@"./configfiles/MeasClsInfo.xml");

                var xmlStepInfoList = rooEl.Elements("TestStepInfo");
                foreach (var xmlstepInfo in xmlStepInfoList)
                {
                    string       typeName    = GetAttibute(xmlstepInfo, "TypeName");
                    string       displayName = GetAttibute(xmlstepInfo, "DisplayName");
                    TestStepInfo stepInfo    = new TestStepInfo()
                    {
                        TypeName = typeName, DisplayName = displayName
                    };
                    try
                    {
                        var xmlMeasClsInfolist = xmlstepInfo.Elements("MeasClsInfo");
                        foreach (var xmlMeasClsInfo in xmlMeasClsInfolist)
                        {
                            string      measTypeName    = GetAttibute(xmlMeasClsInfo, "TypeName");
                            string      measDisplayName = GetAttibute(xmlMeasClsInfo, "DisplayName");
                            string      measInfo        = GetAttibute(xmlMeasClsInfo, "Info");
                            MeasClsInfo measClsInfo     = new MeasClsInfo()
                            {
                                TypeName = measTypeName, DisplayName = measDisplayName, Info = measInfo
                            };
                            stepInfo.MeasClsInfoList.Add(measClsInfo);
                            //添加所有InstruInfo配置
                            var xmlInstruInfolist            = xmlMeasClsInfo.Elements("InstruInfo");
                            List <InstruInfo> instruInfolist = new List <InstruInfo>();
                            foreach (var xmlInstruInfo in xmlInstruInfolist)
                            {
                                string instruName        = GetAttibute(xmlInstruInfo, "Name");
                                string instruDispalyName = GetAttibute(xmlInstruInfo, "DisplayName");
                                bool   isManualInit      = false;
                                try
                                {
                                    string isManualInitStr = GetAttibute(xmlInstruInfo, "IsManualInit");
                                    isManualInit = Symtant.GeneFunLib.StringExtensions.ScpiResToBool(isManualInitStr);
                                }
                                catch
                                {
                                }
                                bool isCal = false;
                                try
                                {
                                    string isCalStr = GetAttibute(xmlInstruInfo, "IsCal");
                                    isCal = Symtant.GeneFunLib.StringExtensions.ScpiResToBool(isCalStr);
                                }
                                catch
                                {
                                }
                                InstruInfo instruInfo = new InstruInfo()
                                {
                                    Name = instruName, DisplayName = instruDispalyName, IsManuallyInit = isManualInit, IsCal = isCal
                                };
                                instruInfolist.Add(instruInfo);
                            }
                            measClsInfo.InstruInfoList = instruInfolist.ToArray();
                            //添加所有ConfigInfo配置
                            var xmlConfiglist = xmlMeasClsInfo.Elements("ConfigInfo");
                            List <PathConfigInfo> configList = new List <PathConfigInfo>();
                            foreach (var xmlConfig in xmlConfiglist)
                            {
                                string         configName     = GetAttibute(xmlConfig, "Name");
                                string         configValue    = GetAttibute(xmlConfig, "Path");
                                string         configInfo     = GetAttibute(xmlConfig, "Info");
                                PathConfigInfo pathConfigInfo = new PathConfigInfo()
                                {
                                    Name = configName, Path = configValue, Info = configInfo
                                };

                                var xmlConfigSettings = xmlConfig.Elements("set");
                                foreach (var xmlConfigSet in xmlConfigSettings)
                                {
                                    var k = xmlConfigSet.Attribute("key");
                                    if (k != null && k.Value != null)
                                    {
                                        var v = xmlConfigSet.Attribute("value");
                                        if (v != null && v.Value != null)
                                        {
                                            pathConfigInfo.Settings.Add(k.Value.Trim(), v.Value.Trim());
                                        }
                                    }
                                }
                                configList.Add(pathConfigInfo);
                            }
                            measClsInfo.PathConfigInfoList = configList.ToArray();
                            //添加所有其他配置
                            measClsInfo.Settings.Clear();
                            var xmlClsSettings = xmlMeasClsInfo.Elements("set");
                            foreach (var xmlClsSet in xmlClsSettings)
                            {
                                var k = xmlClsSet.Attribute("key");
                                if (k != null && k.Value != null)
                                {
                                    var v = xmlClsSet.Attribute("value");
                                    if (v != null && v.Value != null)
                                    {
                                        measClsInfo.Settings.Add(k.Value.Trim(), v.Value.Trim());
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        stepInfo.MeasClsInfoList = null;
                    }
                    try
                    {
                        stepInfo.Settings.Clear();
                        var xmlStepSettings = xmlstepInfo.Elements("set");
                        foreach (var xmlStepSet in xmlStepSettings)
                        {
                            var k = xmlStepSet.Attribute("key");
                            if (k != null && k.Value != null)
                            {
                                var v = xmlStepSet.Attribute("value");
                                if (v != null && v.Value != null)
                                {
                                    stepInfo.Settings.Add(k.Value.Trim(), v.Value.Trim());
                                }
                            }
                        }
                    }
                    catch
                    { stepInfo.Settings = null; }
                    try
                    {
                        var xmlLocalSettingViewStr = xmlstepInfo.Element("LocalSettingView");
                        stepInfo.LocalSettingViewStr = GetAttibute(xmlLocalSettingViewStr, "value");
                    }
                    catch
                    {
                        stepInfo.LocalSettingViewStr = null;
                    }
                    stepInfoListFromXml.Add(stepInfo);
                }
            }
            catch
            {
            }
            return(stepInfoListFromXml);
        }
Exemplo n.º 2
0
 public void SetCurrentPathConfig()
 {
     PathConfigInfo pathConfig = GetCurrentPathConfigInfo();
 }