private ObservableCollection <OSInfo> LoadOSSet(AsfRoleInfo e)
        {
            ObservableCollection <OSInfo> osList = new ObservableCollection <OSInfo>();

            if (e.RoleName.Contains("TSVDA") || e.RoleName.Contains("DC") || e.RoleName.Contains("SF"))
            {
                if (string.IsNullOrEmpty(e.TemplateName))
                {
                    osList = new ObservableCollection <OSInfo>(_OSList.Where(o => o.OSType == OSInfo.OperatingSystemType.win_server && !e.TemplateBlackList.Contains(o.DisplayName)).ToList());
                }
                else
                {
                    osList = new ObservableCollection <OSInfo>(_OSList.Where(o => o.DisplayName == e.TemplateName).ToList());
                }
            }
            else if (e.RoleName.Contains("VDA"))
            {
                if (string.IsNullOrEmpty(e.TemplateName))
                {
                    osList = new ObservableCollection <OSInfo>(_OSList.Where(o => o.OSType == OSInfo.OperatingSystemType.win_desktop && !e.TemplateBlackList.Contains(o.DisplayName)).ToList());
                }
                else
                {
                    osList = new ObservableCollection <OSInfo>(_OSList.Where(o => o.DisplayName == e.TemplateName).ToList());
                }
            }
            else
            {
                if (string.IsNullOrEmpty(e.TemplateName))
                {
                    osList = new ObservableCollection <OSInfo>(_OSList.Where(o => o.OSType != OSInfo.OperatingSystemType.linux && !e.TemplateBlackList.Contains(o.DisplayName)).ToList());
                }
                else
                {
                    osList = new ObservableCollection <OSInfo>(_OSList.Where(o => o.DisplayName == e.TemplateName).ToList());
                }
            }
            return(osList);
        }
        public static ObservableCollection <AsfRoleInfo> LoadRoleInfo(string FilePath)
        {
            ObservableCollection <AsfRoleInfo> RolesInfo = new ObservableCollection <AsfRoleInfo>();
            XElement root = XElement.Load(FilePath);
            Dictionary <string, ObservableCollection <string> > BuildSchemaList = new Dictionary <string, ObservableCollection <string> >();
            string EnvNumber;
            string SchemaFolderPath;

            // a bug here. Appdisk support multi seq env xml
            if (root.Element("TestConfig").Element("Name") != null)
            {
                string EnvTypeName = root.Element("TestConfig").Element("Name").Value.ToString();
                if (EnvTypeName.Length > 5)
                {
                    string tmpTestsPath        = FilePath.Remove(FilePath.IndexOf(@"\Regression"));
                    string EnvTemplateJsonFile = tmpTestsPath + @"\environments\BasicEnvs\" + EnvTypeName + @"\EnvTemplate.json";
                    //we fix the env naming rule bug here. As we do not support mapping between envNumber and envName from Env4.
                    // For fix the bug with the latest code modification. we jsut take this way.
                    if (!File.Exists(EnvTemplateJsonFile))
                    {
                        log.DebugFormat("the setupConfigureFile not found under: {0}", EnvTemplateJsonFile);
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            MessageBox.Show("Do not find File:" + EnvTemplateJsonFile + "Try to get latest build & this app. Try again", "Error", MessageBoxButton.OK);
                        }));
                        return(null);
                    }
                    string SchemaName = JsonAccess.GetSchemaName(EnvTemplateJsonFile);
                    EnvNumber = SchemaName.Remove(0, 6);
                    //string setupConfigureFile = tmpTestsPath + @"\environments\Setup\SetupRS\SetupRS.Config.xml";
                    //if(!File.Exists(setupConfigureFile))
                    //{
                    //    log.DebugFormat("the setupConfigureFile not found under: {0}", setupConfigureFile);
                    //    Application.Current.Dispatcher.Invoke(new Action(() =>
                    //    {
                    //        MessageBox.Show("Do not find File:" + setupConfigureFile + "Try to get latest build & this app. Try again", "Error", MessageBoxButton.OK);

                    //    }));
                    //    return null;
                    //}
                    //log.DebugFormat("parse the setuprs.config.xml file at {0}", setupConfigureFile);
                    //XElement configureRoot = XElement.Load(setupConfigureFile);
                    //XElement targetEnv = configureRoot.Element("envmapping").Elements("env")
                    //    .Where(e => e.Element("name").Value.ToString() == EnvTypeName)
                    //    .FirstOrDefault();
                    //if(targetEnv ==null)
                    //{
                    //    //As from Env4, we do not support EnvNumber mapping to EnvName. Fix bugs here.
                    //    log.DebugFormat("the envname in the envfile is neither name nor number");
                    //    log.DebugFormat("we take the schema name from EnvTemplate.json directly ");
                    //    if (File.Exists())
                    //    Application.Current.Dispatcher.Invoke(new Action(() =>
                    //    {
                    //        MessageBox.Show("this sequence is not supported by Env0 or you need to get the latest build", "Error", MessageBoxButton.OK);

                    //    }));
                    //    return null;
                    //}
                    //EnvNumber = targetEnv.Element("mapping").Value.ToString().Remove(0, 3);
                }
                else
                {
                    EnvNumber = EnvTypeName.Remove(0, 3);
                }
                log.DebugFormat("load env0 type info from env xml, env0 type: {0}", EnvNumber);
            }
            else
            {
                EnvNumber = "1";
                log.DebugFormat("not get env0type from env xml,default value is 1");
            }
            SchemaFolderPath = FilePath.Remove(FilePath.IndexOf(@"Regression\")) + @"environments\Schemas\Schema" + EnvNumber;
            if (Directory.Exists(SchemaFolderPath))
            {
                var tmp = Directory.EnumerateFiles(SchemaFolderPath, "*.json").Select(e =>
                {
                    JObject Jroot   = JObject.Parse(File.ReadAllText(e));
                    string roleName = Jroot["Versions"][0]["Role"].Value <string>();
                    ObservableCollection <string> products = new ObservableCollection <string>();//(Jroot["Versions"].Select(t=>t["Version"].Values<string>()).ToArray());
                    // here, we fix jira ticket WADA-2137
                    var tmpSaver = Jroot["Versions"].Select(t => {
                        t["Version"].Values <string>().ToList().ForEach(products.Add);
                        log.DebugFormat("These product will be added for role: {0}", roleName);
                        t["Version"].Values <string>().ToList().ForEach(log.Debug);
                        return(t);
                    }).ToArray();
                    BuildSchemaList.Add(roleName, products);
                    log.DebugFormat("Load build info done. Add Key {0}, supported builds are: ", roleName);
                    var tmpBuildLog = products.Select(p =>
                    {
                        log.Debug(p);
                        return(p);
                    }).ToArray();
                    return(e);
                }).ToArray();
            }
            if (root.Descendants("Env0Host").ToList().Count != 0)
            {
                ObservableCollection <string> reusedRoles = new ObservableCollection <string>(root.Descendants("Env0Host").Elements("Roles").FirstOrDefault().Value.ToString().Split(','));
                var tmp = reusedRoles.Select(e =>
                {
                    ObservableCollection <string> supportedBuild = SelectTargetBuild(e.Trim(), BuildSchemaList);
                    RolesInfo.Add(new AsfRoleInfo(e.Trim(), supportedBuild));
                    log.DebugFormat("reuse env0 machine. role {1}  supported Build List {1}", e.Trim(), supportedBuild == null ? string.Empty : supportedBuild.ToString());
                    return(e);
                }).ToArray();
            }
            var tmp1 = root.Descendants("Hosts").Elements("Host").Select(e =>
            {
                string role = e.Elements("Role").FirstOrDefault().Value.ToString();
                AsfRoleInfo existingRole = RolesInfo.Where(t => t.RoleName.IndexOf(role, StringComparison.CurrentCultureIgnoreCase) == 0).FirstOrDefault();
                if (e.Elements("UnsupportedOS").FirstOrDefault() != null)
                {
                    ObservableCollection <string> templateBlackList = new ObservableCollection <string>(e.Element("UnsupportedOS").Value.ToString().Split(','));
                    string ProductVersion = e.Elements("ProductVersion").FirstOrDefault() == null ? "" : e.Elements("ProductVersion").FirstOrDefault().Value.ToString();
                    ObservableCollection <string> supportedBuild = SelectTargetBuild(role, BuildSchemaList);
                    log.InfoFormat("the role name is {0}", role);
                    log.Info("the os blacklist is ");
                    if (templateBlackList != null)
                    {
                        var tmpBlackList = templateBlackList.Select(t =>
                        {
                            log.Info(t);
                            return(t);
                        }).ToArray();
                    }
                    log.Info("the supported builds list is");
                    if (supportedBuild != null)
                    {
                        var tmpSupportedBuilds = supportedBuild.Select(b =>
                        {
                            log.Info(b);
                            return(b);
                        }).ToArray();
                    }
                    if (existingRole != null)
                    {
                        log.InfoFormat("using the existing Role: {0}", role);
                        existingRole.TemplateBlackList        = templateBlackList;
                        existingRole.ProductVersion           = ProductVersion;
                        existingRole.SupportedBuildCollection = supportedBuild;
                    }
                    else
                    {
                        log.InfoFormat("creating a new role: {0}", role);
                        RolesInfo.Add(new AsfRoleInfo(role, templateBlackList, ProductVersion, supportedBuild));
                    }
                }
                else if (e.Elements("TemplateName").FirstOrDefault() != null)
                {
                    string templateName   = e.Element("TemplateName").Value.ToString();
                    string ProductVersion = e.Elements("ProductVersion").FirstOrDefault() == null ? "" : e.Elements("ProductVersion").FirstOrDefault().Value.ToString();
                    ObservableCollection <string> supportedBuild = SelectTargetBuild(role, BuildSchemaList);
                    log.InfoFormat("the role name is {0}, os template is {1}", role, templateName);
                    log.Info("the supported builds list is");
                    if (supportedBuild != null)
                    {
                        var tmpSupportedBuilds = supportedBuild.Select(b =>
                        {
                            log.Info(b);
                            return(b);
                        }).ToArray();
                    }
                    if (existingRole != null)
                    {
                        log.InfoFormat("using the existing Role: {0}", role);
                        existingRole.TemplateName             = templateName;
                        existingRole.ProductVersion           = ProductVersion;
                        existingRole.SupportedBuildCollection = supportedBuild;
                    }
                    else
                    {
                        log.InfoFormat("creating a new role: {0}", role);
                        RolesInfo.Add(new AsfRoleInfo(role, templateName, ProductVersion, supportedBuild));
                    }
                }
                else
                {
                    string ProductVersion = e.Elements("ProductVersion").FirstOrDefault() == null ? "" : e.Elements("ProductVersion").FirstOrDefault().Value.ToString();
                    ObservableCollection <string> supportedBuild = SelectTargetBuild(role, BuildSchemaList);
                    log.InfoFormat("the role name is {0}", role);
                    log.Info("the supported builds list is");
                    if (supportedBuild != null)
                    {
                        var tmpSupportedBuilds = supportedBuild.Select(b =>
                        {
                            log.Info(b);
                            return(b);
                        }).ToArray();
                    }
                    if (existingRole != null)
                    {
                        log.InfoFormat("using the existing Role: {0}", role);
                        existingRole.ProductVersion           = ProductVersion;
                        existingRole.SupportedBuildCollection = supportedBuild;
                    }
                    else
                    {
                        log.DebugFormat("creating a new role: {0}", role);
                        RolesInfo.Add(new AsfRoleInfo(role, ProductVersion, supportedBuild));
                    }
                }
                return(e);
            }
                                                                         ).ToArray();

            return(RolesInfo);
        }