Exemplo n.º 1
0
        void RegisterSystemAssemblies(TargetFramework fx)
        {
            Dictionary <string, List <SystemAssembly> > assemblies = new Dictionary <string, List <SystemAssembly> > ();
            Dictionary <string, SystemPackage>          packs      = new Dictionary <string, SystemPackage> ();

            IEnumerable <string> dirs = GetFrameworkFolders(fx);

            foreach (AssemblyInfo assembly in fx.Assemblies)
            {
                foreach (string dir in dirs)
                {
                    string file = Path.Combine(dir, assembly.Name) + ".dll";
                    if (File.Exists(file))
                    {
                        if (assembly.Version == null && IsRunning)
                        {
                            try {
                                System.Reflection.AssemblyName aname = SystemAssemblyService.GetAssemblyNameObj(file);
                                assembly.Update(aname);
                            } catch {
                                // If something goes wrong when getting the name, just ignore the assembly
                            }
                        }
                        string        pkg = assembly.Package ?? string.Empty;
                        SystemPackage package;
                        if (!packs.TryGetValue(pkg, out package))
                        {
                            packs [pkg]      = package = new SystemPackage();
                            assemblies [pkg] = new List <SystemAssembly> ();
                        }
                        List <SystemAssembly> list = assemblies [pkg];
                        list.Add(assemblyContext.AddAssembly(file, assembly, package));
                        break;
                    }
                }
            }

            foreach (string pkg in packs.Keys)
            {
                SystemPackage         package = packs [pkg];
                List <SystemAssembly> list    = assemblies [pkg];
                SystemPackageInfo     info    = GetFrameworkPackageInfo(fx, pkg);
                if (!info.IsCorePackage)
                {
                    corePackages.Add(info.Name);
                }
                package.Initialize(info, list.ToArray(), false);
                assemblyContext.InternalAddPackage(package);
            }
        }
Exemplo n.º 2
0
        void CreateFrameworks()
        {
            if ((SystemAssemblyService.UpdateExpandedFrameworksFile || !SystemAssemblyService.UseExpandedFrameworksFile))
            {
                // Read the assembly versions
                foreach (TargetFramework fx in Runtime.SystemAssemblyService.GetTargetFrameworks())
                {
                    if (IsInstalled(fx))
                    {
                        IEnumerable <string> dirs = GetFrameworkFolders(fx);
                        foreach (AssemblyInfo assembly in fx.Assemblies)
                        {
                            foreach (string dir in dirs)
                            {
                                string file = Path.Combine(dir, assembly.Name) + ".dll";
                                if (File.Exists(file))
                                {
                                    if ((assembly.Version == null || SystemAssemblyService.UpdateExpandedFrameworksFile) && IsRunning)
                                    {
                                        System.Reflection.AssemblyName aname = SystemAssemblyService.GetAssemblyNameObj(file);
                                        assembly.Update(aname);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (TargetFramework fx in Runtime.SystemAssemblyService.GetTargetFrameworks())
            {
                // A framework is installed if the assemblies directory exists and the first
                // assembly of the list exists.
                if (IsInstalled(fx))
                {
                    timer.Trace("Registering assemblies for framework " + fx.Id);
                    RegisterSystemAssemblies(fx);
                }
            }

            if (SystemAssemblyService.UpdateExpandedFrameworksFile && IsRunning)
            {
                Runtime.SystemAssemblyService.SaveGeneratedFrameworkInfo();
            }
        }
Exemplo n.º 3
0
        internal protected SystemPackage RegisterPackage(SystemPackageInfo pinfo, bool isInternal, params string[] assemblyFiles)
        {
            List <PackageAssemblyInfo> pinfos = new List <PackageAssemblyInfo> (assemblyFiles.Length);

            foreach (string afile in assemblyFiles)
            {
                try {
                    PackageAssemblyInfo pi = new PackageAssemblyInfo();
                    pi.File = afile;
                    pi.Update(SystemAssemblyService.GetAssemblyNameObj(pi.File));
                    pinfos.Add(pi);
                }
                catch {
                    // Ignore
                }
            }
            return(RegisterPackage(pinfo, isInternal, pinfos.ToArray()));
        }
Exemplo n.º 4
0
        static List <AssemblyInfo> ScanAssemblyDirectory(TargetFrameworkMoniker tfm, FilePath dir)
        {
            var assemblies = new List <AssemblyInfo> ();

            foreach (var f in Directory.EnumerateFiles(dir, "*.dll"))
            {
                try {
                    var an    = SystemAssemblyService.GetAssemblyNameObj(dir.Combine(f));
                    var ainfo = new AssemblyInfo();
                    ainfo.Update(an);
                    assemblies.Add(ainfo);
                } catch (BadImageFormatException ex) {
                    LoggingService.LogError("Invalid assembly in framework '{0}': {1}{2}{3}", tfm, f, Environment.NewLine, ex.ToString());
                } catch (Exception ex) {
                    LoggingService.LogError("Error reading assembly '{0}' in framework '{1}':{2}{3}",
                                            f, tfm, Environment.NewLine, ex.ToString());
                }
            }
            return(assemblies);
        }
Exemplo n.º 5
0
 public void UpdateFromFile(string file)
 {
     Update(SystemAssemblyService.GetAssemblyNameObj(file));
 }
Exemplo n.º 6
0
        public static TargetFramework FromFrameworkDirectory(TargetFrameworkMoniker moniker, FilePath dir)
        {
            var fxList = dir.Combine("RedistList", "FrameworkList.xml");

            if (!File.Exists(fxList))
            {
                return(null);
            }

            var fx = new TargetFramework(moniker);

            using (var reader = System.Xml.XmlReader.Create(fxList)) {
                if (!reader.ReadToDescendant("FileList"))
                {
                    throw new Exception("Missing FileList element");
                }

                //not sure what this is for
                //if (reader.MoveToAttribute ("Redist") && reader.ReadAttributeValue ())
                //	redist = reader.ReadContentAsString ();

                if (reader.MoveToAttribute("Name") && reader.ReadAttributeValue())
                {
                    fx.name = reader.ReadContentAsString();
                }

                if (reader.MoveToAttribute("RuntimeVersion") && reader.ReadAttributeValue())
                {
                    string runtimeVersion = reader.ReadContentAsString();
                    switch (runtimeVersion)
                    {
                    case "2.0":
                        fx.clrVersion = ClrVersion.Net_2_0;
                        break;

                    case "4.0":
                        fx.clrVersion = ClrVersion.Net_4_0;
                        break;

                    case "4.5":
                    case "4.5.1":
                        fx.clrVersion = ClrVersion.Net_4_5;
                        break;

                    default:
                        LoggingService.LogInfo("Framework {0} has unknown RuntimeVersion {1}", moniker, runtimeVersion);
                        return(null);
                    }
                }

                if (reader.MoveToAttribute("ToolsVersion") && reader.ReadAttributeValue())
                {
                    string toolsVersion = reader.ReadContentAsString();
                    switch (toolsVersion)
                    {
                    case "2.0":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V2_0;
                        break;

                    case "3.5":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V3_5;
                        break;

                    case "4.0":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V4_0;
                        break;

                    case "4.5":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V4_5;
                        break;

                    default:
                        LoggingService.LogInfo("Framework {0} has unknown ToolsVersion {1}", moniker, toolsVersion);
                        return(null);
                    }
                }

                if (reader.MoveToAttribute("IncludeFramework") && reader.ReadAttributeValue())
                {
                    string include = reader.ReadContentAsString();
                    if (!string.IsNullOrEmpty(include))
                    {
                        fx.includesFramework = include;
                    }
                }

                //this is a Mono-specific extension
                if (reader.MoveToAttribute("TargetFrameworkDirectory") && reader.ReadAttributeValue())
                {
                    string targetDir = reader.ReadContentAsString();
                    if (!string.IsNullOrEmpty(targetDir))
                    {
                        targetDir = targetDir.Replace('\\', System.IO.Path.DirectorySeparatorChar);
                        dir       = fxList.ParentDirectory.Combine(targetDir).FullPath;
                    }
                }

                var assemblies = new List <AssemblyInfo> ();
                if (reader.ReadToFollowing("File"))
                {
                    do
                    {
                        var ainfo = new AssemblyInfo();
                        assemblies.Add(ainfo);
                        if (reader.MoveToAttribute("AssemblyName") && reader.ReadAttributeValue())
                        {
                            ainfo.Name = reader.ReadContentAsString();
                        }
                        if (string.IsNullOrEmpty(ainfo.Name))
                        {
                            throw new Exception("Missing AssemblyName attribute");
                        }
                        if (reader.MoveToAttribute("Version") && reader.ReadAttributeValue())
                        {
                            ainfo.Version = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("PublicKeyToken") && reader.ReadAttributeValue())
                        {
                            ainfo.PublicKeyToken = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("Culture") && reader.ReadAttributeValue())
                        {
                            ainfo.Culture = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("ProcessorArchitecture") && reader.ReadAttributeValue())
                        {
                            ainfo.ProcessorArchitecture = (ProcessorArchitecture)
                                                          Enum.Parse(typeof(ProcessorArchitecture), reader.ReadContentAsString(), true);
                        }
                        if (reader.MoveToAttribute("InGac") && reader.ReadAttributeValue())
                        {
                            ainfo.InGac = reader.ReadContentAsBoolean();
                        }
                    } while (reader.ReadToFollowing("File"));
                }
                else
                {
                    // HACK: we were using EnumerateFiles but it's broken in some Mono releases
                    // https://bugzilla.xamarin.com/show_bug.cgi?id=2975
                    var files = Directory.GetFiles(dir, "*.dll");
                    foreach (var f in files)
                    {
                        try {
                            var an    = SystemAssemblyService.GetAssemblyNameObj(dir.Combine(f));
                            var ainfo = new AssemblyInfo();
                            ainfo.Update(an);
                            assemblies.Add(ainfo);
                        } catch (Exception ex) {
                            LoggingService.LogError("Error reading name for assembly '{0}' in framework '{1}':\n{2}",
                                                    f, fx.Id, ex.ToString());
                        }
                    }
                }

                fx.Assemblies = assemblies.ToArray();
            }

            var supportedFrameworksDir = dir.Combine("SupportedFrameworks");

            if (Directory.Exists(supportedFrameworksDir))
            {
                foreach (var sfx in Directory.GetFiles(supportedFrameworksDir))
                {
                    fx.SupportedFrameworks.Add(SupportedFramework.Load(fx, sfx));
                }
            }

            return(fx);
        }
Exemplo n.º 7
0
        public static TargetFramework FromFrameworkDirectory(TargetFrameworkMoniker moniker, FilePath dir)
        {
            var fxList = dir.Combine("RedistList", "FrameworkList.xml");

            if (!File.Exists(fxList))
            {
                return(null);
            }

            var fx = new TargetFramework(moniker);

            using (var reader = System.Xml.XmlReader.Create(fxList)) {
                if (!reader.ReadToDescendant("FileList"))
                {
                    throw new Exception("Missing FileList element");
                }

                //not sure what this is for
                //if (reader.MoveToAttribute ("Redist") && reader.ReadAttributeValue ())
                //	redist = reader.ReadContentAsString ();

                if (reader.MoveToAttribute("Name") && reader.ReadAttributeValue())
                {
                    fx.name = reader.ReadContentAsString();
                }

                if (reader.MoveToAttribute("IncludeFramework") && reader.ReadAttributeValue())
                {
                    string include = reader.ReadContentAsString();
                    if (!string.IsNullOrEmpty(include))
                    {
                        fx.includesFramework = include;
                    }
                }

                //this is a Mono-specific extension
                if (reader.MoveToAttribute("TargetFrameworkDirectory") && reader.ReadAttributeValue())
                {
                    string targetDir = reader.ReadContentAsString();
                    if (!string.IsNullOrEmpty(targetDir))
                    {
                        targetDir = targetDir.Replace('\\', System.IO.Path.DirectorySeparatorChar);
                        dir       = fxList.ParentDirectory.Combine(targetDir).FullPath;
                    }
                }

                var assemblies = new List <AssemblyInfo> ();
                if (reader.ReadToFollowing("File"))
                {
                    do
                    {
                        var ainfo = new AssemblyInfo();
                        assemblies.Add(ainfo);
                        if (reader.MoveToAttribute("AssemblyName") && reader.ReadAttributeValue())
                        {
                            ainfo.Name = reader.ReadContentAsString();
                        }
                        if (string.IsNullOrEmpty(ainfo.Name))
                        {
                            throw new Exception("Missing AssemblyName attribute");
                        }
                        if (reader.MoveToAttribute("Version") && reader.ReadAttributeValue())
                        {
                            ainfo.Version = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("PublicKeyToken") && reader.ReadAttributeValue())
                        {
                            ainfo.PublicKeyToken = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("Culture") && reader.ReadAttributeValue())
                        {
                            ainfo.Culture = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("ProcessorArchitecture") && reader.ReadAttributeValue())
                        {
                            ainfo.ProcessorArchitecture = (ProcessorArchitecture)
                                                          Enum.Parse(typeof(ProcessorArchitecture), reader.ReadContentAsString(), true);
                        }
                        if (reader.MoveToAttribute("InGac") && reader.ReadAttributeValue())
                        {
                            ainfo.InGac = reader.ReadContentAsBoolean();
                        }
                    } while (reader.ReadToFollowing("File"));
                }
                else if (Directory.Exists(dir))
                {
                    foreach (var f in Directory.EnumerateFiles(dir, "*.dll"))
                    {
                        try {
                            var an    = SystemAssemblyService.GetAssemblyNameObj(dir.Combine(f));
                            var ainfo = new AssemblyInfo();
                            ainfo.Update(an);
                            assemblies.Add(ainfo);
                        } catch (BadImageFormatException ex) {
                            LoggingService.LogError("Invalid assembly in framework '{0}': {1}{2}{3}", fx.Id, f, Environment.NewLine, ex.ToString());
                        } catch (Exception ex) {
                            LoggingService.LogError("Error reading assembly '{0}' in framework '{1}':{2}{3}",
                                                    f, fx.Id, Environment.NewLine, ex.ToString());
                        }
                    }
                }

                fx.Assemblies = assemblies.ToArray();
            }

            var supportedFrameworksDir = dir.Combine("SupportedFrameworks");

            if (Directory.Exists(supportedFrameworksDir))
            {
                foreach (var sfx in Directory.GetFiles(supportedFrameworksDir))
                {
                    fx.SupportedFrameworks.Add(SupportedFramework.Load(fx, sfx));
                }
            }

            return(fx);
        }