public static MetadataArtifactLoader Create(
     string path,
     MetadataArtifactLoader.ExtensionCheck extensionCheck,
     string validExtension,
     ICollection <string> uriRegistry)
 {
     return(MetadataArtifactLoader.Create(path, extensionCheck, validExtension, uriRegistry, (MetadataArtifactAssemblyResolver) new DefaultAssemblyResolver()));
 }
Пример #2
0
        public MetadataArtifactLoader GetArtifactLoader(
            DbConnectionOptions effectiveConnectionOptions)
        {
            string connectionOption = effectiveConnectionOptions["metadata"];

            if (string.IsNullOrEmpty(connectionOption))
            {
                return(MetadataArtifactLoader.Create(new List <MetadataArtifactLoader>()));
            }
            List <MetadataArtifactLoader> metadataArtifactLoaderList = this._artifactLoaderCache.Evaluate(connectionOption);

            return(MetadataArtifactLoader.Create(MetadataCache.ShouldRecalculateMetadataArtifactLoader((IEnumerable <MetadataArtifactLoader>)metadataArtifactLoaderList) ? MetadataCache.SplitPaths(connectionOption) : metadataArtifactLoaderList));
        }
        public static MetadataArtifactLoader CreateCompositeFromXmlReaders(
            IEnumerable <XmlReader> xmlReaders)
        {
            List <MetadataArtifactLoader> allCollections = new List <MetadataArtifactLoader>();

            foreach (XmlReader xmlReader in xmlReaders)
            {
                if (xmlReader == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(xmlReaders)));
                }
                allCollections.Add((MetadataArtifactLoader) new MetadataArtifactLoaderXmlReaderWrapper(xmlReader));
            }
            return(MetadataArtifactLoader.Create(allCollections));
        }
Пример #4
0
        public MetadataArtifactLoader GetArtifactLoader(DbConnectionOptions effectiveConnectionOptions)
        {
            DebugCheck.NotNull(effectiveConnectionOptions);

            var paths = effectiveConnectionOptions[EntityConnectionStringBuilder.MetadataParameterName];

            if (!string.IsNullOrEmpty(paths))
            {
                var loaders = _artifactLoaderCache.Evaluate(paths);

                return(MetadataArtifactLoader.Create(
                           ShouldRecalculateMetadataArtifactLoader(loaders)
                        ? SplitPaths(paths)
                        : loaders));
            }

            return(MetadataArtifactLoader.Create(new List <MetadataArtifactLoader>()));
        }
        internal static MetadataArtifactLoader CreateCompositeFromFilePaths(
            IEnumerable <string> filePaths,
            string validExtension,
            MetadataArtifactAssemblyResolver resolver)
        {
            MetadataArtifactLoader.ExtensionCheck extensionCheck = !string.IsNullOrEmpty(validExtension) ? MetadataArtifactLoader.ExtensionCheck.Specific : MetadataArtifactLoader.ExtensionCheck.All;
            List <MetadataArtifactLoader>         allCollections = new List <MetadataArtifactLoader>();
            HashSet <string> stringSet = new HashSet <string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);

            foreach (string filePath in filePaths)
            {
                if (string.IsNullOrEmpty(filePath))
                {
                    throw new MetadataException(Strings.NotValidInputPath, (Exception) new ArgumentException(Strings.ADP_CollectionParameterElementIsNullOrEmpty((object)nameof(filePaths))));
                }
                string path = filePath.Trim();
                if (path.Length > 0)
                {
                    allCollections.Add(MetadataArtifactLoader.Create(path, extensionCheck, validExtension, (ICollection <string>)stringSet, resolver));
                }
            }
            return(MetadataArtifactLoader.Create(allCollections));
        }
Пример #6
0
        //For MetadataArtifactLoader.Create method call. But the path is not created in this method.
        internal static List <MetadataArtifactLoader> SplitPaths(string paths)
        {
            DebugCheck.NotEmpty(paths);

            string[] results;

            // This is the registry of all URIs in the global collection.
            var uriRegistry = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            var 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.
            //
            var dataDirPaths = new List <string>();

            var indexStart = paths.IndexOf(s_dataDirectory, StringComparison.OrdinalIgnoreCase);

            while (indexStart != -1)
            {
                var prevSeparatorIndex = indexStart == 0
                                             ? -1
                                             : paths.LastIndexOf(
                    s_metadataPathSeparator,
                    indexStart - 1,                              // start looking here
                    StringComparison.Ordinal
                    );

                var 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.
                //
                var indexEnd = paths.IndexOf(
                    s_metadataPathSeparator,
                    indexStart + 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(s_dataDirectory, StringComparison.OrdinalIgnoreCase);
            }

            // Split the string on the separator and remove all spaces around each parameter value
            results = paths.Split(new[] { 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 (var 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);
        }
Пример #7
0
        private static List <MetadataArtifactLoader> SplitPaths(string paths)
        {
            HashSet <string> stringSet  = new HashSet <string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);
            List <string>    stringList = new List <string>();
            int num1 = paths.IndexOf("|datadirectory|", StringComparison.OrdinalIgnoreCase);
            int startIndex;

            while (true)
            {
                int num2;
                switch (num1)
                {
                case -1:
                    goto label_7;

                case 0:
                    num2 = -1;
                    break;

                default:
                    num2 = paths.LastIndexOf("|", num1 - 1, StringComparison.Ordinal);
                    break;
                }
                startIndex = num2 + 1;
                int num3 = paths.IndexOf("|", num1 + "|datadirectory|".Length, StringComparison.Ordinal);
                if (num3 != -1)
                {
                    stringList.Add(paths.Substring(startIndex, num3 - startIndex));
                    paths = paths.Remove(startIndex, num3 - startIndex);
                    num1  = paths.IndexOf("|datadirectory|", StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    break;
                }
            }
            stringList.Add(paths.Substring(startIndex));
            paths = paths.Remove(startIndex);
label_7:
            string[] strArray = paths.Split(new string[1] {
                "|"
            }, StringSplitOptions.RemoveEmptyEntries);
            if (stringList.Count > 0)
            {
                stringList.AddRange((IEnumerable <string>)strArray);
                strArray = stringList.ToArray();
            }
            List <MetadataArtifactLoader> metadataArtifactLoaderList1 = new List <MetadataArtifactLoader>();
            List <MetadataArtifactLoader> metadataArtifactLoaderList2 = new List <MetadataArtifactLoader>();
            List <MetadataArtifactLoader> metadataArtifactLoaderList3 = new List <MetadataArtifactLoader>();
            List <MetadataArtifactLoader> metadataArtifactLoaderList4 = new List <MetadataArtifactLoader>();

            for (int index = 0; index < strArray.Length; ++index)
            {
                strArray[index] = strArray[index].Trim();
                if (strArray[index].Length > 0)
                {
                    MetadataArtifactLoader metadataArtifactLoader = MetadataArtifactLoader.Create(strArray[index], MetadataArtifactLoader.ExtensionCheck.All, (string)null, (ICollection <string>)stringSet);
                    if (strArray[index].EndsWith(".csdl", StringComparison.OrdinalIgnoreCase))
                    {
                        metadataArtifactLoaderList1.Add(metadataArtifactLoader);
                    }
                    else if (strArray[index].EndsWith(".msl", StringComparison.OrdinalIgnoreCase))
                    {
                        metadataArtifactLoaderList2.Add(metadataArtifactLoader);
                    }
                    else if (strArray[index].EndsWith(".ssdl", StringComparison.OrdinalIgnoreCase))
                    {
                        metadataArtifactLoaderList3.Add(metadataArtifactLoader);
                    }
                    else
                    {
                        metadataArtifactLoaderList4.Add(metadataArtifactLoader);
                    }
                }
            }
            metadataArtifactLoaderList4.AddRange((IEnumerable <MetadataArtifactLoader>)metadataArtifactLoaderList3);
            metadataArtifactLoaderList4.AddRange((IEnumerable <MetadataArtifactLoader>)metadataArtifactLoaderList2);
            metadataArtifactLoaderList4.AddRange((IEnumerable <MetadataArtifactLoader>)metadataArtifactLoaderList1);
            return(metadataArtifactLoaderList4);
        }