public TrackingConfigBase LoadIfExists(IExecutionContext executionContext, string file) { Trace.Entering(); // The tracking config will not exist for a new definition. if (!File.Exists(file)) { return(null); } // Load the content and distinguish between tracking config file // version 1 and file version 2. string content = File.ReadAllText(file); string fileFormatVersionJsonProperty = StringUtil.Format( @"""{0}""", TrackingConfig.FileFormatVersionJsonProperty); if (content.Contains(fileFormatVersionJsonProperty)) { // The config is the new format. Trace.Verbose("Parsing new tracking config format."); return(JsonConvert.DeserializeObject <TrackingConfig>(content)); } // Attempt to parse the legacy format. Trace.Verbose("Parsing legacy tracking config format."); LegacyTrackingConfig config = LegacyTrackingConfig.TryParse(content); if (config == null) { executionContext.Warning(StringUtil.Loc("UnableToParseBuildTrackingConfig0", content)); } return(config); }
private TrackingConfig LoadIfExists( IExecutionContext executionContext, string file) { Trace.Entering(); Trace.Verbose($"Loading {file}"); // The tracking config will not exist for a new definition. if (!File.Exists(file)) { Trace.Verbose($"Tracking file does not exist: {file}"); return(null); } TrackingConfig result = null; // Load the content and distinguish between tracking config file // version 1 and file version 2. string content = File.ReadAllText(file); string fileFormatVersionJsonProperty = StringUtil.Format( @"""{0}""", TrackingConfig.FileFormatVersionJsonProperty); if (content.Contains(fileFormatVersionJsonProperty)) { // The config is the new format. Trace.Verbose("Parsing new tracking config format."); result = JsonConvert.DeserializeObject <TrackingConfig>(content); } else { // Attempt to parse the legacy format. Trace.Verbose("Parsing legacy tracking config format."); var legacyTrackingConfig = LegacyTrackingConfig.TryParse(content); if (legacyTrackingConfig == null) { executionContext.Warning(StringUtil.Loc("UnableToParseBuildTrackingConfig0", content)); } else { // Convert legacy format to the new format. result = ConvertToNewFormat( executionContext, legacyTrackingConfig, RepositoryUtil.GetCloneDirectory(legacyTrackingConfig.RepositoryUrl), RepositoryUtil.GuessRepositoryType(legacyTrackingConfig.RepositoryUrl)); } } if (result != null) { result.FileLocation = file; } return(result); }
private TrackingConfig LoadIfExists( IExecutionContext executionContext, string file) { Trace.Entering(); Trace.Verbose($"Loading {file}"); // The tracking config will not exist for a new definition. if (!File.Exists(file)) { Trace.Verbose($"Tracking file does not exist: {file}"); return(null); } TrackingConfig result = null; // Load the content and distinguish between tracking config file // version 1 and file version 2. string content = File.ReadAllText(file); string fileFormatVersionJsonProperty = StringUtil.Format( @"""{0}""", TrackingConfig.FileFormatVersionJsonProperty); if (content.Contains(fileFormatVersionJsonProperty)) { // The config is the new format. Trace.Verbose("Parsing new tracking config format."); result = JsonConvert.DeserializeObject <TrackingConfig>(content); if (result != null) { // if RepositoryTrackingInfo is empty, then we should create an entry so the rest // of the logic after this will act correctly if (result.RepositoryTrackingInfo.Count == 0) { result.RepositoryTrackingInfo.Add(new Build.RepositoryTrackingInfo { Identifier = RepositoryUtil.DefaultPrimaryRepositoryName, RepositoryType = result.RepositoryType, RepositoryUrl = result.RepositoryUrl, SourcesDirectory = result.SourcesDirectory, }); } } } else { // Attempt to parse the legacy format. Trace.Verbose("Parsing legacy tracking config format."); var legacyTrackingConfig = LegacyTrackingConfig.TryParse(content); if (legacyTrackingConfig == null) { executionContext.Warning(StringUtil.Loc("UnableToParseBuildTrackingConfig0", content)); } else { // Convert legacy format to the new format. result = ConvertToNewFormat( executionContext, legacyTrackingConfig, RepositoryUtil.GetCloneDirectory(legacyTrackingConfig.RepositoryUrl), RepositoryUtil.GuessRepositoryType(legacyTrackingConfig.RepositoryUrl)); } } if (result != null) { result.FileLocation = file; } return(result); }