Пример #1
0
 /// <summary>
 /// Writes the specified object representation of a manifest to XML.
 /// </summary>
 /// <param name="manifest">The object representation of the manifest.</param>
 /// <param name="path">The name of the output file.</param>
 public static void WriteManifest(Manifest manifest, string path)
 {
     using (Stream s = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Write))
     {
         WriteManifest(manifest, s);
     }
 }
Пример #2
0
 /// <summary>
 /// Writes the specified object representation of a manifest to XML.
 /// The name of the output file is inferred from the SourcePath property of the manifest.
 /// </summary>
 /// <param name="manifest">The object representation of the manifest.</param>
 public static void WriteManifest(Manifest manifest)
 {
     string path = manifest.SourcePath;
     if (path == null)
         path = "manifest.xml";
     WriteManifest(manifest, path);
 }
Пример #3
0
 /// <summary>
 /// Writes the specified object representation of a manifest to XML.
 /// </summary>
 /// <param name="manifest">The object representation of the manifest.</param>
 /// <param name="path">The name of the output file.</param>
 /// <param name="targetframeWorkVersion">The target framework version.</param>
 public static void WriteManifest(Manifest manifest, string path, string targetframeWorkVersion)
 {
     using (Stream s = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Write))
     {
         WriteManifest(manifest, s, targetframeWorkVersion);
     }
 }
 public static void WriteManifest(Manifest manifest)
 {
     string sourcePath = manifest.SourcePath;
     if (sourcePath == null)
     {
         sourcePath = "manifest.xml";
     }
     WriteManifest(manifest, sourcePath);
 }
 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;
 }
Пример #6
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;
        }
Пример #7
0
 protected abstract bool OnManifestLoaded(Manifest manifest);
 protected override bool OnManifestResolved(Manifest manifest)
 {
     return this.BuildResolvedSettings(manifest as DeployManifest);
 }
 protected override bool OnManifestLoaded(Manifest manifest)
 {
     return this.BuildDeployManifest(manifest as DeployManifest);
 }
 protected override bool OnManifestResolved(Manifest manifest)
 {
     if (UseApplicationTrust)
         return BuildResolvedSettings(manifest as ApplicationManifest);
     return true;
 }
 protected override bool OnManifestLoaded(Manifest manifest)
 {
     return BuildApplicationManifest(manifest as ApplicationManifest);
 }
		protected override bool OnManifestResolved (Manifest manifest)
		{
			throw new NotImplementedException ();
		}
 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 }));
 }
Пример #14
0
		public static void WriteManifest (Manifest manifest,
						  Stream output)
		{
			throw new NotImplementedException ();
		}
Пример #15
0
 protected abstract bool OnManifestResolved(Manifest manifest);
Пример #16
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));
        }
Пример #17
0
 /// <summary>
 /// Writes the specified object representation of a manifest to XML.
 /// </summary>
 /// <param name="manifest">The object representation of the manifest.</param>
 /// <param name="output">Specifies an output stream.</param>
 public static void WriteManifest(Manifest manifest, Stream output)
 {
     WriteManifest(manifest, output, null);
 }
Пример #18
0
		public static void WriteManifest (Manifest manifest,
						  string path)
		{
			throw new NotImplementedException ();
		}
Пример #19
0
        private bool InitializeManifest(Type manifestType)
        {
            _startTime = Environment.TickCount;

            if (!ValidateInputs())
                return false;

            if (manifestType == null)
                throw new ArgumentNullException("manifestType");
            if (InputManifest == null || String.IsNullOrEmpty(InputManifest.ItemSpec))
            {
                if (manifestType == typeof(ApplicationManifest))
                    _manifest = new ApplicationManifest(this.TargetFrameworkVersion);
                else if (manifestType == typeof(DeployManifest))
                    _manifest = new DeployManifest(this.TargetFrameworkMoniker);
                else
                    throw new ArgumentException(String.Empty /* no message */, "manifestType");
            }
            else
            {
                try
                {
                    _manifest = ManifestReader.ReadManifest(manifestType.Name, InputManifest.ItemSpec, true);
                }
                catch (Exception ex)
                {
                    Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", InputManifest.ItemSpec, ex.Message);
                    return false;
                }
            }

            if (manifestType != _manifest.GetType())
            {
                Log.LogErrorWithCodeFromResources("GenerateManifest.InvalidInputManifest");
                return false;
            }

            if (_manifest is DeployManifest)
            {
                DeployManifest deployManifest = _manifest as DeployManifest;
                if (string.IsNullOrEmpty(deployManifest.TargetFrameworkMoniker))
                    deployManifest.TargetFrameworkMoniker = this.TargetFrameworkMoniker;
            }
            else if (_manifest is ApplicationManifest)
            {
                ApplicationManifest applicationManifest = _manifest as ApplicationManifest;
                if (string.IsNullOrEmpty(applicationManifest.TargetFrameworkVersion))
                    applicationManifest.TargetFrameworkVersion = this.TargetFrameworkVersion;
            }

            if (EntryPoint != null && !String.IsNullOrEmpty(EntryPoint.ItemSpec))
            {
                AssemblyReferenceType referenceType = AssemblyReferenceType.Unspecified;
                if (_manifest is DeployManifest)
                    referenceType = AssemblyReferenceType.ClickOnceManifest;
                if (_manifest is ApplicationManifest)
                    referenceType = AssemblyReferenceType.ManagedAssembly;
                _manifest.EntryPoint = AddEntryPointFromItem(EntryPoint, referenceType);
            }

            if (Description != null)
                _manifest.Description = Description;

            return true;
        }
 private bool InitializeManifest(Type manifestType)
 {
     this.startTime = Environment.TickCount;
     if (!this.ValidateInputs())
     {
         return false;
     }
     if (manifestType == null)
     {
         throw new ArgumentNullException("manifestType");
     }
     if ((this.InputManifest == null) || string.IsNullOrEmpty(this.InputManifest.ItemSpec))
     {
         if (manifestType != typeof(ApplicationManifest))
         {
             if (manifestType != typeof(DeployManifest))
             {
                 throw new ArgumentException(string.Empty, "manifestType");
             }
             this.manifest = new DeployManifest(this.TargetFrameworkMoniker);
         }
         else
         {
             this.manifest = new ApplicationManifest(this.TargetFrameworkVersion);
         }
     }
     else
     {
         try
         {
             this.manifest = ManifestReader.ReadManifest(manifestType.Name, this.InputManifest.ItemSpec, true);
         }
         catch (Exception exception)
         {
             base.Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", new object[] { this.InputManifest.ItemSpec, exception.Message });
             return false;
         }
     }
     if (manifestType != this.manifest.GetType())
     {
         base.Log.LogErrorWithCodeFromResources("GenerateManifest.InvalidInputManifest", new object[0]);
         return false;
     }
     if (this.manifest is DeployManifest)
     {
         DeployManifest manifest = this.manifest as DeployManifest;
         if (string.IsNullOrEmpty(manifest.TargetFrameworkMoniker))
         {
             manifest.TargetFrameworkMoniker = this.TargetFrameworkMoniker;
         }
     }
     else if (this.manifest is ApplicationManifest)
     {
         ApplicationManifest manifest2 = this.manifest as ApplicationManifest;
         if (string.IsNullOrEmpty(manifest2.TargetFrameworkVersion))
         {
             manifest2.TargetFrameworkVersion = this.TargetFrameworkVersion;
         }
     }
     if ((this.EntryPoint != null) && !string.IsNullOrEmpty(this.EntryPoint.ItemSpec))
     {
         AssemblyReferenceType unspecified = AssemblyReferenceType.Unspecified;
         if (this.manifest is DeployManifest)
         {
             unspecified = AssemblyReferenceType.ClickOnceManifest;
         }
         if (this.manifest is ApplicationManifest)
         {
             unspecified = AssemblyReferenceType.ManagedAssembly;
         }
         this.manifest.EntryPoint = this.AddEntryPointFromItem(this.EntryPoint, unspecified);
     }
     if (this.Description != null)
     {
         this.manifest.Description = this.Description;
     }
     return true;
 }