// Protected methods for abstract classes and public methods for concrete classes to ensure proper roll up and no // redundant execution. Only leaves of the class diagram should have public methods and be called outside this class protected void ConsumeEnvVarsAndInterpretOptions(CommonOptionsBase commonOptionsBase) { IEnumerable <OptionallyEmittedData> toInsertFromEnvVar = GetOptionEnumFromEnvVar <OptionallyEmittedData>(nameof(commonOptionsBase.DataToInsert)); IEnumerable <OptionallyEmittedData> toRemoveFromEnvVar = GetOptionEnumFromEnvVar <OptionallyEmittedData>(nameof(commonOptionsBase.DataToRemove)); commonOptionsBase.DataToInsert = NullCheckAndDistinctUnionLists(commonOptionsBase.DataToInsert, toInsertFromEnvVar); commonOptionsBase.DataToRemove = NullCheckAndDistinctUnionLists(commonOptionsBase.DataToRemove, toRemoveFromEnvVar); }
public static IDictionary <string, Uri> ConstructUriBaseIdsDictionary(this CommonOptionsBase options) { if (options.UriBaseIds == null) { return(null); } IDictionary <string, Uri> uriBaseIdsDictionary = new Dictionary <string, Uri>(); foreach (string uriBaseId in options.UriBaseIds) { string[] tokens = uriBaseId.Split('='); string key = tokens[0]; Uri value = new Uri(tokens[1], UriKind.Absolute); uriBaseIdsDictionary[key] = value; } return(uriBaseIdsDictionary); }
public static IDictionary<string, ArtifactLocation> ConstructUriBaseIdsDictionary(this CommonOptionsBase options) { if (options.UriBaseIds == null || options.UriBaseIds.Count() == 0) { return null; } var uriBaseIdsDictionary = new Dictionary<string, ArtifactLocation>(); foreach (string uriBaseId in options.UriBaseIds) { string[] tokens = uriBaseId.Split('='); string key = tokens[0]; string uriToken = tokens[1]; Uri value = null; try { value = new Uri(uriToken, UriKind.RelativeOrAbsolute); if (!value.IsAbsoluteUri) { value = null; // Command-line tools may be required to provide relative paths for // various operations. We will help resolve these to absolute paths // where we can. try { uriToken = Path.GetFullPath(uriToken); Uri.TryCreate(uriToken, UriKind.Absolute, out value); } catch (ArgumentException) { } // illegal file path characters throw this catch (PathTooLongException) { } } } catch (UriFormatException) { } if (value == null) { throw new InvalidOperationException("Could not construct absolute URI from specified value: " + tokens[1]); } uriBaseIdsDictionary[key] = new ArtifactLocation { Uri = value }; } return uriBaseIdsDictionary; }