Exemplo n.º 1
0
        public static string GetConfigFilePath()
        {
            if (!_configFilePath.IsNullOrWhiteSpace())
            {
                return(_configFilePath);
            }
            else
            {
                string configFilePath;
                string appFrxFilePath = ChoAppFrxSettings.Me.AppFrxFilePath;

                if (appFrxFilePath.IsNullOrWhiteSpace())
                {
                    configFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoReservedFileName.CoreFrxConfigFileName));
                }
                else
                {
                    appFrxFilePath = ChoString.ExpandProperties(appFrxFilePath, ChoEnvironmentVariablePropertyReplacer.Instance);

                    if (ChoPath.IsDirectory(appFrxFilePath))
                    {
                        appFrxFilePath = Path.Combine(appFrxFilePath, ChoReservedFileName.CoreFrxConfigFileName);
                    }

                    configFilePath = appFrxFilePath;
                }
                return(configFilePath);
            }
        }
        private void LoadXml(XmlDocument doc)
        {
            if (doc == null)
            {
                return;
            }

            XmlNode rootNode = doc.SelectSingleNode("//sharedEnvironment");

            if (rootNode != null)
            {
                if (rootNode.Attributes["baseAppSharedConfigDirectory"] != null)
                {
                    BaseAppConfigDirectory = ChoPath.GetFullPath(ChoString.ExpandProperties(rootNode.Attributes["baseAppSharedConfigDirectory"].Value, ChoEnvironmentVariablePropertyReplacer.Instance));
                }
                if (BaseAppConfigDirectory.IsNullOrWhiteSpace())
                {
                    BaseAppConfigDirectory = ChoPath.AssemblyBaseDirectory;
                }

                if (rootNode.Attributes["defaultEnvironment"] != null)
                {
                    DefaultEnvironment = rootNode.Attributes["defaultEnvironment"].Value;
                }

                XmlNodeList envNodes = rootNode.SelectNodes("environment");
                if (envNodes != null)
                {
                    List <ChoEnvironmentDetails> environmentDetailList = new List <ChoEnvironmentDetails>();
                    foreach (XmlNode envNode in envNodes)
                    {
                        ChoEnvironmentDetails environmentDetails = new ChoEnvironmentDetails();

                        if (envNode.Attributes["name"] != null)
                        {
                            environmentDetails.Name = envNode.Attributes["name"].Value;

                            if (!environmentDetails.Name.IsNullOrWhiteSpace())
                            {
                                if (envNode.Attributes["freeze"] != null)
                                {
                                    Boolean.TryParse(envNode.Attributes["freeze"].Value, out environmentDetails.Freeze);
                                }

                                if (envNode.Attributes["appFrxFilePath"] != null)
                                {
                                    environmentDetails.AppFrxFilePath = envNode.Attributes["appFrxFilePath"].Value;
                                    if (!environmentDetails.AppFrxFilePath.IsNullOrWhiteSpace())
                                    {
                                        if (!Path.IsPathRooted(environmentDetails.AppFrxFilePath))
                                        {
                                            environmentDetails.AppFrxFilePath = ChoString.ExpandProperties(environmentDetails.AppFrxFilePath, ChoEnvironmentVariablePropertyReplacer.Instance);

                                            if (!Path.IsPathRooted(environmentDetails.AppFrxFilePath))
                                            {
                                                environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.AppFrxFilePath);
                                            }

                                            if (ChoPath.IsDirectory(environmentDetails.AppFrxFilePath))
                                            {
                                                environmentDetails.AppFrxFilePath = Path.Combine(environmentDetails.AppFrxFilePath, ChoReservedFileName.CoreFrxConfigFileName);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.Name, ChoReservedFileName.CoreFrxConfigFileName);
                                    }
                                }
                                else
                                {
                                    environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.Name, ChoReservedFileName.CoreFrxConfigFileName);
                                }

                                XmlNodeList machineNodes = envNode.SelectNodes("machine");
                                if (machineNodes != null)
                                {
                                    List <string> machines = new List <string>();
                                    foreach (XmlNode machineNode in machineNodes)
                                    {
                                        machines.Add(machineNode.InnerText);
                                    }
                                    environmentDetails.Machines = machines.ToArray();
                                }

                                environmentDetailList.Add(environmentDetails);
                            }
                        }
                    }

                    EnvironmentDetails = environmentDetailList.ToArray();

                    foreach (ChoEnvironmentDetails environmentDetail in EnvironmentDetails)
                    {
                        environmentDetail.Parent = this;
                    }
                }
            }
        }