Ejemplo n.º 1
0
        /// <summary>
        /// This is helper method to provide well-known defaults for some parameters of <see cref="FrameworkMonikerInfo.ReadAssemblyInformationFromRedistXMLFile"/> method.
        /// </summary>
        /// <param name="redistXMLFilePath">The location of the <c>FrameworkList.xml</c> file.</param>
        /// <param name="msCorLibName">This will hold the detected assembly name that acts as <c>mscorlib</c> assembly of the framework-</param>
        /// <param name="frameworkDisplayName">This will hold the detected display name of the framework.</param>
        /// <param name="targetFWDir">This will hold the detected full path to the target framework assemblies.</param>
        /// <param name="defaultTargetFWPath">The default target framework path, if the XML file does not define target framework path. If none provider, a directory up one level from the given XML path will be used.</param>
        /// <returns>The result of <see cref="FrameworkMonikerInfo.ReadAssemblyInformationFromRedistXMLFile"/> method.</returns>
        public static IDictionary <String, Tuple <Version, Byte[]> > ReadAssemblyInformationFromRedistXMLFile(
            String redistXMLFilePath,
            out String msCorLibName,
            out String frameworkDisplayName,
            out String targetFWDir,
            String defaultTargetFWPath = null
            )
        {
            var redistListDir = Path.GetDirectoryName(redistXMLFilePath);

            if (defaultTargetFWPath == null)
            {
                defaultTargetFWPath = Directory.GetParent(redistListDir).FullName;
            }

            IDictionary <String, Tuple <Version, Byte[]> > retVal;

            using (var stream = File.Open(redistXMLFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                retVal = FrameworkMonikerInfo.ReadAssemblyInformationFromRedistXMLFile(
                    defaultTargetFWPath,
                    stream,
                    targetFWPathArg =>
                {
                    var targetFWDirInner = ProcessTargetFWDir(redistListDir, targetFWPathArg);
                    return(Directory.EnumerateFiles(targetFWDirInner, "*.dll").Select(curFN => Path.Combine(targetFWDirInner, curFN)));
                },
                    () => DotNETReflectionContext.CreateDotNETContext(),
                    assFN => File.Open(assFN, FileMode.Open, FileAccess.Read, FileShare.Read),
                    (targetFWPathArg, simpleAssemblyName) =>
                {
                    return(File.Exists(Path.Combine(targetFWPathArg, simpleAssemblyName + ".dll")));
                },
                    out msCorLibName,
                    out frameworkDisplayName,
                    out targetFWDir
                    );
            }
            targetFWDir = ProcessTargetFWDir(redistListDir, targetFWDir);
            return(retVal);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of <see cref="DotNETCILAssemblyLoaderCallbacks"/> with given reference assemblies directory.
 /// </summary>
 /// <param name="referenceAssembliesDir">The directory containing reference assemblies information. See <see cref="DotNETReflectionContext.GetDefaultReferenceAssemblyPath"/> for more info.</param>
 public DotNETCILAssemblyLoaderCallbacks(String referenceAssembliesDir)
 {
     this._referenceAssembliesRes = Path.GetFullPath(String.IsNullOrEmpty(referenceAssembliesDir) ? DotNETReflectionContext.GetDefaultReferenceAssemblyPath() : referenceAssembliesDir);
     this._monikers            = new ConcurrentDictionary <FrameworkMonikerID, FrameworkMonikerInfo>();
     this._explicitDirectories = new ConcurrentDictionary <FrameworkMonikerInfo, String>();
 }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public Boolean TryGetFrameworkMoniker(String fwName, String fwVersion, String fwProfile, out FrameworkMonikerInfo moniker)
        {
            var retVal = !String.IsNullOrEmpty(fwName) && !String.IsNullOrEmpty(fwVersion);

            if (retVal)
            {
                var key = new FrameworkMonikerID(fwName, fwVersion, fwProfile);
                retVal = this._monikers.TryGetValue(key, out moniker);
                if (!retVal)
                {
                    var dir = this.GetDirectory(fwName, fwVersion, fwProfile);
                    retVal = Directory.Exists(dir);
                    if (retVal)
                    {
                        var    redistListDir = Path.Combine(dir, "RedistList");
                        var    fn = Path.Combine(redistListDir, "FrameworkList.xml");
                        String msCorLibName; String fwDisplayName; String targetFWDir;
                        moniker = new FrameworkMonikerInfo(fwName, fwVersion, fwProfile, DotNETReflectionContext.ReadAssemblyInformationFromRedistXMLFile(
                                                               fn,
                                                               out msCorLibName,
                                                               out fwDisplayName,
                                                               out targetFWDir
                                                               ), msCorLibName, fwDisplayName);
                        if (!String.IsNullOrEmpty(targetFWDir))
                        {
                            this._explicitDirectories.TryAdd(moniker, targetFWDir);
                        }
                    }
                }
            }
            else
            {
                moniker = null;
            }
            return(retVal);
        }