public IEnumerable <C3poConfig> GetC3poConfigurations() { string basePath = settings.RepositoryPath ?? ""; string srcPath = Path.Combine(basePath, settings.Software, "src"); var appDirectories = Directory.GetDirectories(srcPath, "*.c3po", SearchOption.TopDirectoryOnly); foreach (var appDir in appDirectories) { if (Directory.Exists(appDir)) { var files = Directory.GetFiles(appDir, "c3po*", SearchOption.AllDirectories); foreach (var c3po in files) { var cfgRaw = File.ReadAllText(c3po); var jar = JsonConvert.DeserializeObject <Jar>(cfgRaw); var box = Box.Mistranslate(jar); PandoraBoxOpener opener = new PandoraBoxOpener(box); foreach (var environment in box.Clusters) { var configurations = opener.Open(new PandoraOptions(environment.Name, Machine.NotSpecified)); var cfg = new C3poConfig(configurations.AsDictionary()); cfg.Environment = environment.Name; cfg.HostName = box.Name; cfg.SoftwareName = settings.Software; yield return(cfg); } } } } }
public static bool IsValid(this C3poConfig cfg) { var requiredSettingsKeysPropNames = new string[] { "ClientIdKey", "ApplicationKey", "GitRemoteKey", "GitBranchKey", "PipelineNameKey", "PipelineGroupKey", "PipelineTemplateKey", "NugetApiKeyKey", "C3poTypeKey" }; try { foreach (var keyPropName in requiredSettingsKeysPropNames) { var keyPropValue = cfg.GetType().GetField(keyPropName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetRawConstantValue(); var cfgValue = cfg.GetType().GetMethod("GetSetting", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(cfg, new[] { keyPropValue }); if (string.IsNullOrEmpty((string)cfgValue)) { return(false); } } return(true); } catch (System.Exception ex) { return(false); } }