Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
 private static Stream Serialize(Manifest manifest)
 {
     manifest.OnBeforeSave();
     MemoryStream stream = new MemoryStream();
     XmlSerializer serializer = new XmlSerializer(manifest.GetType());
     StreamWriter writer = new StreamWriter(stream);
     int tickCount = Environment.TickCount;
     serializer.Serialize((TextWriter) writer, manifest);
     Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.Serialize t={0}", new object[] { Environment.TickCount - tickCount }));
     writer.Flush();
     stream.Position = 0L;
     return stream;
 }
        private static Stream Serialize(Manifest manifest)
        {
            manifest.OnBeforeSave();
            MemoryStream  stream     = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(manifest.GetType());
            StreamWriter  writer     = new StreamWriter(stream);
            int           tickCount  = Environment.TickCount;

            serializer.Serialize((TextWriter)writer, manifest);
            Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.Serialize t={0}", new object[] { Environment.TickCount - tickCount }));
            writer.Flush();
            stream.Position = 0L;
            return(stream);
        }
Exemplo n.º 5
0
        private static Stream Serialize(Manifest manifest)
        {
            manifest.OnBeforeSave();
            MemoryStream m = new MemoryStream();
            XmlSerializer s = new XmlSerializer(manifest.GetType());
            StreamWriter w = new StreamWriter(m);

            int t1 = Environment.TickCount;
            s.Serialize(w, manifest);
            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.Serialize t={0}", Environment.TickCount - t1));

            w.Flush();
            m.Position = 0;
            return m;
        }
Exemplo n.º 6
0
        private static Stream Serialize(Manifest manifest)
        {
            manifest.OnBeforeSave();
            var m = new MemoryStream();
            var s = new XmlSerializer(manifest.GetType());
            var w = new StreamWriter(m);

            int t1 = Environment.TickCount;

            s.Serialize(w, manifest);
            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.Serialize t={0}", Environment.TickCount - t1));

            w.Flush();
            m.Position = 0;
            return(m);
        }
        public static void WriteManifest(Manifest manifest, Stream output)
        {
            int    tickCount = Environment.TickCount;
            Stream s         = Serialize(manifest);
            string fullName  = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);

            if (string.IsNullOrEmpty(fullName))
            {
                fullName = manifest.GetType().Name;
            }
            Util.WriteLogFile(fullName + ".write.0-serialized.xml", s);
            string resource = "write2.xsl";
            Stream stream2  = null;

            if (manifest.GetType() == typeof(ApplicationManifest))
            {
                ApplicationManifest manifest2 = (ApplicationManifest)manifest;
                if (manifest2.TrustInfo == null)
                {
                    stream2 = XmlUtil.XslTransform(resource, s, new DictionaryEntry[0]);
                }
                else
                {
                    string temporaryFile = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();
                    manifest2.TrustInfo.Write(temporaryFile);
                    if (Util.logging)
                    {
                        try
                        {
                            File.Copy(temporaryFile, Path.Combine(Util.logPath, fullName + ".trust-file.xml"), true);
                        }
                        catch (IOException)
                        {
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (UnauthorizedAccessException)
                        {
                        }
                        catch (NotSupportedException)
                        {
                        }
                    }
                    DictionaryEntry entry = new DictionaryEntry("trust-file", temporaryFile);
                    try
                    {
                        DictionaryEntry[] entries = new DictionaryEntry[] { entry };
                        stream2 = XmlUtil.XslTransform(resource, s, entries);
                    }
                    finally
                    {
                        File.Delete(temporaryFile);
                    }
                }
            }
            else
            {
                stream2 = XmlUtil.XslTransform(resource, s, new DictionaryEntry[0]);
            }
            Util.WriteLogFile(fullName + ".write.1-transformed.xml", stream2);
            Stream stream3 = null;

            if (manifest.InputStream == null)
            {
                stream3 = stream2;
            }
            else
            {
                string          str4   = Util.WriteTempFile(manifest.InputStream);
                DictionaryEntry entry2 = new DictionaryEntry("base-file", str4);
                try
                {
                    DictionaryEntry[] entryArray2 = new DictionaryEntry[] { entry2 };
                    stream3 = XmlUtil.XslTransform("merge.xsl", stream2, entryArray2);
                }
                finally
                {
                    File.Delete(str4);
                }
                Util.WriteLogFile(fullName + ".write.2-merged.xml", stream3);
            }
            Stream stream4 = ManifestFormatter.Format(stream3);

            Util.WriteLogFile(fullName + ".write.3-formatted.xml", stream4);
            Util.CopyStream(stream4, output);
            Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteManifest t={0}", new object[] { Environment.TickCount - tickCount }));
        }
Exemplo n.º 8
0
        private static void WriteManifest(Manifest manifest, Stream output, string targetframeWorkVersion)
        {
            int    t1 = Environment.TickCount;
            Stream s1 = Serialize(manifest);
            string n  = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);

            if (String.IsNullOrEmpty(n))
            {
                n = manifest.GetType().Name;
            }
            Util.WriteLogFile(n + ".write.0-serialized.xml", s1);

            string resource;

            if (string.IsNullOrEmpty(targetframeWorkVersion) || Util.CompareFrameworkVersions(targetframeWorkVersion, Constants.TargetFrameworkVersion40) <= 0)
            {
                resource = "write2.xsl";
            }
            else
            {
                resource = "write3.xsl";
            }

            Stream s2;

            if (manifest.GetType() == typeof(ApplicationManifest))
            {
                var am = (ApplicationManifest)manifest;
                if (am.TrustInfo == null)
                {
                    s2 = XmlUtil.XslTransform(resource, s1);
                }
                else
                {
                    // May throw IO-related exceptions
                    string temp = FileUtilities.GetTemporaryFile();

                    am.TrustInfo.Write(temp);
                    if (Util.logging)
                    {
                        try
                        {
                            File.Copy(temp, Path.Combine(Util.logPath, n + ".trust-file.xml"), true);
                        }
                        catch (IOException)
                        {
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (UnauthorizedAccessException)
                        {
                        }
                        catch (NotSupportedException)
                        {
                        }
                    }

                    var arg = new DictionaryEntry("trust-file", temp);
                    try
                    {
                        s2 = XmlUtil.XslTransform(resource, s1, arg);
                    }
                    finally
                    {
                        File.Delete(temp);
                    }
                }
            }
            else
            {
                s2 = XmlUtil.XslTransform(resource, s1);
            }
            Util.WriteLogFile(n + ".write.1-transformed.xml", s2);

            Stream s3;

            if (manifest.InputStream == null)
            {
                s3 = s2;
            }
            else
            {
                string temp = Util.WriteTempFile(manifest.InputStream);
                var    arg  = new DictionaryEntry("base-file", temp);
                try
                {
                    s3 = XmlUtil.XslTransform("merge.xsl", s2, arg);
                }
                finally
                {
                    File.Delete(temp);
                }
                Util.WriteLogFile(n + ".write.2-merged.xml", s3);
            }

            Stream s4 = ManifestFormatter.Format(s3);

            Util.WriteLogFile(n + ".write.3-formatted.xml", s4);

            Util.CopyStream(s4, output);
            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteManifest t={0}", Environment.TickCount - t1));
        }
 public static void WriteManifest(Manifest manifest, Stream output)
 {
     int tickCount = Environment.TickCount;
     Stream s = Serialize(manifest);
     string fullName = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);
     if (string.IsNullOrEmpty(fullName))
     {
         fullName = manifest.GetType().Name;
     }
     Util.WriteLogFile(fullName + ".write.0-serialized.xml", s);
     string resource = "write2.xsl";
     Stream stream2 = null;
     if (manifest.GetType() == typeof(ApplicationManifest))
     {
         ApplicationManifest manifest2 = (ApplicationManifest) manifest;
         if (manifest2.TrustInfo == null)
         {
             stream2 = XmlUtil.XslTransform(resource, s, new DictionaryEntry[0]);
         }
         else
         {
             string temporaryFile = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();
             manifest2.TrustInfo.Write(temporaryFile);
             if (Util.logging)
             {
                 try
                 {
                     File.Copy(temporaryFile, Path.Combine(Util.logPath, fullName + ".trust-file.xml"), true);
                 }
                 catch (IOException)
                 {
                 }
                 catch (ArgumentException)
                 {
                 }
                 catch (UnauthorizedAccessException)
                 {
                 }
                 catch (NotSupportedException)
                 {
                 }
             }
             DictionaryEntry entry = new DictionaryEntry("trust-file", temporaryFile);
             try
             {
                 DictionaryEntry[] entries = new DictionaryEntry[] { entry };
                 stream2 = XmlUtil.XslTransform(resource, s, entries);
             }
             finally
             {
                 File.Delete(temporaryFile);
             }
         }
     }
     else
     {
         stream2 = XmlUtil.XslTransform(resource, s, new DictionaryEntry[0]);
     }
     Util.WriteLogFile(fullName + ".write.1-transformed.xml", stream2);
     Stream stream3 = null;
     if (manifest.InputStream == null)
     {
         stream3 = stream2;
     }
     else
     {
         string str4 = Util.WriteTempFile(manifest.InputStream);
         DictionaryEntry entry2 = new DictionaryEntry("base-file", str4);
         try
         {
             DictionaryEntry[] entryArray2 = new DictionaryEntry[] { entry2 };
             stream3 = XmlUtil.XslTransform("merge.xsl", stream2, entryArray2);
         }
         finally
         {
             File.Delete(str4);
         }
         Util.WriteLogFile(fullName + ".write.2-merged.xml", stream3);
     }
     Stream stream4 = ManifestFormatter.Format(stream3);
     Util.WriteLogFile(fullName + ".write.3-formatted.xml", stream4);
     Util.CopyStream(stream4, output);
     Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteManifest t={0}", new object[] { Environment.TickCount - tickCount }));
 }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="manifest"></param>
        /// <param name="output"></param>
        /// <param name="targetframeWorkVersion">it will always use sha256 as signature algorithm if TFV is null</param>
        private static void WriteManifest(Manifest manifest, Stream output, string targetframeWorkVersion)
        {
            int t1 = Environment.TickCount;
            Stream s1 = Serialize(manifest);
            string n = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);
            if (String.IsNullOrEmpty(n))
                n = manifest.GetType().Name;
            Util.WriteLogFile(n + ".write.0-serialized.xml", s1);

            string resource = null;

            if (targetframeWorkVersion == null || targetframeWorkVersion.Length == 0 || Util.CompareFrameworkVersions(targetframeWorkVersion, Constants.TargetFrameworkVersion40) <= 0)
            {
                resource = "write2.xsl";
            }
            else
            {
                resource = "write3.xsl";
            }

            Stream s2 = null;

            if (manifest.GetType() == typeof(ApplicationManifest))
            {
                ApplicationManifest am = (ApplicationManifest)manifest;
                if (am.TrustInfo == null)
                {
                    s2 = XmlUtil.XslTransform(resource, s1);
                }
                else
                {
                    // May throw IO-related exceptions
                    string temp = FileUtilities.GetTemporaryFile();

                    am.TrustInfo.Write(temp);
                    if (Util.logging)
                    {
                        try
                        {
                            File.Copy(temp, Path.Combine(Util.logPath, n + ".trust-file.xml"), true);
                        }
                        catch (IOException)
                        {
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (UnauthorizedAccessException)
                        {
                        }
                        catch (NotSupportedException)
                        {
                        }
                    }

                    DictionaryEntry arg = new DictionaryEntry("trust-file", temp);
                    try
                    {
                        s2 = XmlUtil.XslTransform(resource, s1, arg);
                    }
                    finally
                    {
                        File.Delete(temp);
                    }
                }
            }
            else
                s2 = XmlUtil.XslTransform(resource, s1);
            Util.WriteLogFile(n + ".write.1-transformed.xml", s2);

            Stream s3 = null;
            if (manifest.InputStream == null)
            {
                s3 = s2;
            }
            else
            {
                string temp = Util.WriteTempFile(manifest.InputStream);
                DictionaryEntry arg = new DictionaryEntry("base-file", temp);
                try
                {
                    s3 = XmlUtil.XslTransform("merge.xsl", s2, arg);
                }
                finally
                {
                    File.Delete(temp);
                }
                Util.WriteLogFile(n + ".write.2-merged.xml", s3);
            }

            Stream s4 = ManifestFormatter.Format(s3);
            Util.WriteLogFile(n + ".write.3-formatted.xml", s4);

            Util.CopyStream(s4, output);
            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteManifest t={0}", Environment.TickCount - t1));
        }