/// <summary> /// Helper method that wraps a collection of XmlReader objects in MetadataArtifactLoader /// instances. /// </summary> /// <param name="filePaths">The collection of XmlReader objects to wrap</param> /// <returns>An instance of MetadataArtifactLoader</returns> public static MetadataArtifactLoader CreateCompositeFromXmlReaders(IEnumerable <XmlReader> xmlReaders) { List <MetadataArtifactLoader> loaders = new List <MetadataArtifactLoader>(); foreach (XmlReader reader in xmlReaders) { if (reader == null) { throw EntityUtil.CollectionParameterElementIsNull("xmlReaders"); } loaders.Add(new MetadataArtifactLoaderXmlReaderWrapper(reader)); } return(MetadataArtifactLoader.Create(loaders)); }
[ResourceConsumption(ResourceScope.Machine)] //For Create method call. But the paths are not created in this method. internal static MetadataArtifactLoader CreateCompositeFromFilePaths(IEnumerable <string> filePaths, string validExtension, MetadataArtifactAssemblyResolver resolver) { ExtensionCheck extensionCheck; if (string.IsNullOrEmpty(validExtension)) { extensionCheck = ExtensionCheck.All; } else { extensionCheck = ExtensionCheck.Specific; } List <MetadataArtifactLoader> loaders = new List <MetadataArtifactLoader>(); // The following set is used to remove duplicate paths from the incoming array HashSet <string> uriRegistry = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (string path in filePaths) { if (string.IsNullOrEmpty(path)) { throw EntityUtil.Metadata(System.Data.Entity.Strings.NotValidInputPath, EntityUtil.CollectionParameterElementIsNullOrEmpty("filePaths")); } string trimedPath = path.Trim(); if (trimedPath.Length > 0) { loaders.Add(MetadataArtifactLoader.Create( trimedPath, extensionCheck, validExtension, uriRegistry, resolver) ); } } return(MetadataArtifactLoader.Create(loaders)); }
[ResourceConsumption(ResourceScope.Machine)] //For MetadataArtifactLoader.Create method call. But the path is not created in this method. internal static List <MetadataArtifactLoader> SplitPaths(string paths) { Debug.Assert(!string.IsNullOrEmpty(paths), "paths cannot be empty or null"); string[] results; // This is the registry of all URIs in the global collection. HashSet <string> uriRegistry = new HashSet <string>(StringComparer.OrdinalIgnoreCase); List <MetadataArtifactLoader> loaders = new List <MetadataArtifactLoader>(); // If the argument contains one or more occurrences of the macro '|DataDirectory|', we // pull those paths out so that we don't lose them in the string-splitting logic below. // Note that the macro '|DataDirectory|' cannot have any whitespace between the pipe // symbols and the macro name. Also note that the macro must appear at the beginning of // a path (else we will eventually fail with an invalid path exception, because in that // case the macro is not expanded). If a real/physical folder named 'DataDirectory' needs // to be included in the metadata path, whitespace should be used on either or both sides // of the name. // List <string> dataDirPaths = new List <string>(); int indexStart = paths.IndexOf(MetadataCache.s_dataDirectory, StringComparison.OrdinalIgnoreCase); while (indexStart != -1) { int prevSeparatorIndex = indexStart == 0 ? -1 : paths.LastIndexOf( MetadataCache.s_metadataPathSeparator, indexStart - 1, // start looking here StringComparison.Ordinal ); int macroPathBeginIndex = prevSeparatorIndex + 1; // The '|DataDirectory|' macro is composable, so identify the complete path, like // '|DataDirectory|\item1\item2'. If the macro appears anywhere other than at the // beginning, splice out the entire path, e.g. 'C:\item1\|DataDirectory|\item2'. In this // latter case the macro will not be expanded, and downstream code will throw an exception. // int indexEnd = paths.IndexOf(MetadataCache.s_metadataPathSeparator, indexStart + MetadataCache.s_dataDirectory.Length, StringComparison.Ordinal); if (indexEnd == -1) { dataDirPaths.Add(paths.Substring(macroPathBeginIndex)); paths = paths.Remove(macroPathBeginIndex); // update the concatenated list of paths break; } dataDirPaths.Add(paths.Substring(macroPathBeginIndex, indexEnd - macroPathBeginIndex)); // Update the concatenated list of paths by removing the one containing the macro. // paths = paths.Remove(macroPathBeginIndex, indexEnd - macroPathBeginIndex); indexStart = paths.IndexOf(MetadataCache.s_dataDirectory, StringComparison.OrdinalIgnoreCase); } // Split the string on the separator and remove all spaces around each parameter value results = paths.Split(new string[] { MetadataCache.s_metadataPathSeparator }, StringSplitOptions.RemoveEmptyEntries); // Now that the non-macro paths have been identified, merge the paths containing the macro // into the complete list. // if (dataDirPaths.Count > 0) { dataDirPaths.AddRange(results); results = dataDirPaths.ToArray(); } for (int i = 0; i < results.Length; i++) { // Trim out all the spaces for this parameter and add it only if it's not blank results[i] = results[i].Trim(); if (results[i].Length > 0) { loaders.Add(MetadataArtifactLoader.Create( results[i], MetadataArtifactLoader.ExtensionCheck.All, // validate the extension against all acceptable values null, uriRegistry )); } } return(loaders); }