Beispiel #1
0
        /// <summary>
        /// Gets the list of Silverlight assemblies found in the manifest within the specified
        /// Silverlight framework directory.
        /// </summary>
        /// <param name="silverlightFrameworkDirectory">The directory containing the Silverlight framework manifest.</param>
        /// <returns>The list of assemblies that are part of the Silverlight runtime.</returns>
        private static FrameworkManifest GetSilverlightFrameworkManifest(string silverlightFrameworkDirectory)
        {
            FrameworkManifest             manifest   = new FrameworkManifest();
            List <FrameworkManifestEntry> assemblies = new List <FrameworkManifestEntry>();

            XPathDocument     manifestDocument = new XPathDocument(silverlightFrameworkDirectory + SilverlightManifestFilename);
            XPathNavigator    navigator        = manifestDocument.CreateNavigator();
            XPathNodeIterator iterator         = navigator.Select("/manifest/*[name and publickeytoken and version]");

            while (iterator.MoveNext())
            {
                // guaranteed to have name, publickeytoken and version by the XPath query
                iterator.Current.MoveToChild("name", string.Empty);
                string name = iterator.Current.Value;
                iterator.Current.MoveToParent();

                iterator.Current.MoveToChild("publickeytoken", string.Empty);
                string publickeytoken = iterator.Current.Value;
                iterator.Current.MoveToParent();

                iterator.Current.MoveToChild("version", string.Empty);
                string version = iterator.Current.Value;
                iterator.Current.MoveToParent();

                // The public key token that was read as a hex string; convert it to a byte array
                // Every 2 characters represent a single byte in hex.
                byte[] publicKeyTokenBytes =
                    Enumerable.Range(0, publickeytoken.Length)
                    .Where(x => 0 == x % 2)
                    .Select(x => Convert.ToByte(publickeytoken.Substring(x, 2), 16))
                    .ToArray();

                FrameworkManifestEntry assembly = new FrameworkManifestEntry();
                assembly.Name                = name;
                assembly.Version             = new Version(version);
                assembly.PublicKeyTokenBytes = publicKeyTokenBytes;

                assemblies.Add(assembly);
            }

            manifest.Assemblies = assemblies.ToArray();
            return(manifest);
        }
        /// <summary>
        /// Gets the list of Silverlight assemblies found in the manifest within the specified
        /// Silverlight framework directory.
        /// </summary>
        /// <param name="silverlightFrameworkDirectory">The directory containing the Silverlight framework manifest.</param>
        /// <returns>The list of assemblies that are part of the Silverlight runtime.</returns>
        private static FrameworkManifest GetSilverlightFrameworkManifest(string silverlightFrameworkDirectory)
        {
            FrameworkManifest manifest = new FrameworkManifest();
            List<FrameworkManifestEntry> assemblies = new List<FrameworkManifestEntry>();

            XPathDocument manifestDocument = new XPathDocument(silverlightFrameworkDirectory + SilverlightManifestFilename);
            XPathNavigator navigator = manifestDocument.CreateNavigator();
            XPathNodeIterator iterator = navigator.Select("/manifest/*[name and publickeytoken and version]");

            while (iterator.MoveNext())
            {
                // guaranteed to have name, publickeytoken and version by the XPath query
                iterator.Current.MoveToChild("name", string.Empty);
                string name = iterator.Current.Value;
                iterator.Current.MoveToParent();

                iterator.Current.MoveToChild("publickeytoken", string.Empty);
                string publickeytoken = iterator.Current.Value;
                iterator.Current.MoveToParent();

                iterator.Current.MoveToChild("version", string.Empty);
                string version = iterator.Current.Value;
                iterator.Current.MoveToParent();

                // The public key token that was read as a hex string; convert it to a byte array
                // Every 2 characters represent a single byte in hex.
                byte[] publicKeyTokenBytes =
                    Enumerable.Range(0, publickeytoken.Length)
                    .Where(x => 0 == x % 2)
                    .Select(x => Convert.ToByte(publickeytoken.Substring(x, 2), 16))
                    .ToArray();

                FrameworkManifestEntry assembly = new FrameworkManifestEntry();
                assembly.Name = name;
                assembly.Version = new Version(version);
                assembly.PublicKeyTokenBytes = publicKeyTokenBytes;

                assemblies.Add(assembly);
            }

            manifest.Assemblies = assemblies.ToArray();
            return manifest;
        }