public static Profile ReadFrom(DeploymentSettings settings, string profileName, string settingsProfileName = null) { var profile = new Profile(profileName); var profileFile = settings.ProfileFileNameFor(profileName); var fileSystem = new FileSystem(); if (!fileSystem.FileExists(profileFile)) { var sb = new StringBuilder(); sb.AppendFormat("Couldn't find the profile '{0}'", profileFile); sb.AppendLine(); sb.AppendLine("Looked in:"); settings.Directories.Each(d => sb.AppendLine(" {0}".ToFormat(d))); throw new Exception(sb.ToString()); } // Settings profile goes first if (settingsProfileName != null) { profile.AddProfileDependency(settingsProfileName); } fileSystem.ReadTextFile(profileFile, profile.ReadText); profile._childProfileNames.Each(childName => { var childProfile = ReadFrom(settings, childName); profile._childProfiles.Add(childProfile); childProfile.Data.AllKeys.Each(childKey => { // do not override main profile settings from dependencies. // NOTE: Has(childKey) doesn't work here because SettingsData has a weird inner dictionary with a special key structure if (profile.Data.AllKeys.Any(k => k == childKey)) return; profile.Data[childKey] = childProfile.Data[childKey]; }); }); return profile; }
public static Profile ReadFrom(DeploymentSettings settings, string profileName) { var profile = new Profile(profileName); var profileFile = settings.ProfileFileNameFor(profileName); var fileSystem = new FileSystem(); if (!fileSystem.FileExists(profileFile)) { var sb = new StringBuilder(); sb.AppendFormat("Couldn't find the profile '{0}'", profileFile); sb.AppendLine(); sb.AppendLine("Looked in:"); settings.Directories.Each(d => sb.AppendLine(" {0}".ToFormat(d))); throw new Exception(sb.ToString()); } fileSystem.ReadTextFile(profileFile, profile.ReadText); return profile; }