Пример #1
0
        /// <summary>
        /// Reads the specified manifest XML and returns an object representation.
        /// </summary>
        /// <param name="manifestType">Specifies the expected type of the manifest. Valid values are "AssemblyManifest", "ApplicationManifest", or "DepoyManifest".</param>
        /// <param name="input">Specifies an input stream.</param>
        /// <param name="preserveStream">Specifies whether to preserve the input stream in the InputStream property of the resulting manifest object. Used by ManifestWriter to reconstitute input which is not represented in the object representation.</param>
        /// <returns>A base object representation of the manifest. Can be cast to AssemblyManifest, ApplicationManifest, or DeployManifest to access more specific functionality.</returns>
        public static Manifest ReadManifest(string manifestType, Stream input, bool preserveStream)
        {
            int      t1       = Environment.TickCount;
            string   resource = "read2.xsl";
            Manifest m        = null;
            Stream   s;

            if (manifestType != null)
            {
                DictionaryEntry arg = new DictionaryEntry("manifest-type", manifestType);
                s = XmlUtil.XslTransform(resource, input, arg);
            }
            else
            {
                s = XmlUtil.XslTransform(resource, input);
            }

            try
            {
                s.Position = 0;
                m          = Deserialize(s);
                if (m.GetType() == typeof(ApplicationManifest))
                {
                    ApplicationManifest am = (ApplicationManifest)m;
                    am.TrustInfo = new TrustInfo();
                    am.TrustInfo.ReadManifest(input);
                }
                if (preserveStream)
                {
                    input.Position = 0;
                    m.InputStream  = new MemoryStream();
                    Util.CopyStream(input, m.InputStream);
                }
                s.Position = 0;
                string n = m.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);
                if (String.IsNullOrEmpty(n))
                {
                    n = m.GetType().Name;
                }
                Util.WriteLogFile(n + ".read.xml", s);
            }
            finally
            {
                s.Close();
            }
            Util.WriteLog(String.Format(CultureInfo.InvariantCulture, "ManifestReader.ReadManifest t={0}", Environment.TickCount - t1));
            m.OnAfterLoad();
            return(m);
        }
Пример #2
0
        public static Manifest ReadManifest(string manifestType, Stream input, bool preserveStream)
        {
            Stream   stream;
            int      tickCount = Environment.TickCount;
            string   resource  = "read2.xsl";
            Manifest manifest  = null;

            if (manifestType != null)
            {
                DictionaryEntry   entry   = new DictionaryEntry("manifest-type", manifestType);
                DictionaryEntry[] entries = new DictionaryEntry[] { entry };
                stream = XmlUtil.XslTransform(resource, input, entries);
            }
            else
            {
                stream = XmlUtil.XslTransform(resource, input, new DictionaryEntry[0]);
            }
            try
            {
                stream.Position = 0L;
                manifest        = Deserialize(stream);
                if (manifest.GetType() == typeof(ApplicationManifest))
                {
                    ApplicationManifest manifest2 = (ApplicationManifest)manifest;
                    manifest2.TrustInfo = new TrustInfo();
                    manifest2.TrustInfo.ReadManifest(input);
                }
                if (preserveStream)
                {
                    input.Position       = 0L;
                    manifest.InputStream = new MemoryStream();
                    Util.CopyStream(input, manifest.InputStream);
                }
                stream.Position = 0L;
                string fullName = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);
                if (string.IsNullOrEmpty(fullName))
                {
                    fullName = manifest.GetType().Name;
                }
                Util.WriteLogFile(fullName + ".read.xml", stream);
            }
            finally
            {
                stream.Close();
            }
            Util.WriteLog(string.Format(CultureInfo.InvariantCulture, "ManifestReader.ReadManifest t={0}", new object[] { Environment.TickCount - tickCount }));
            manifest.OnAfterLoad();
            return(manifest);
        }