/// <summary> /// Writes the application trust to an XML file. /// </summary> /// <param name="output"></param> public void Write(Stream output) { XmlDocument outputDocument = new XmlDocument(); XmlElement inputPermissionSetElement = GetInputPermissionSetElement(); //NOTE: XmlDocument.ImportNode munges "xmlns:asmv2" to "xmlns:d1p1" for some reason, use XmlUtil.CloneElementToDocument instead XmlElement outputPermissionSetElement = XmlUtil.CloneElementToDocument(inputPermissionSetElement, outputDocument, XmlNamespaces.asmv2); outputDocument.AppendChild(outputPermissionSetElement); string tempPrivilegeDocument = null; XmlDocument privilegeDocument = new XmlDocument(); XmlElement inputRequestedPrivilegeElement = GetInputRequestedPrivilegeElement(); XmlElement requestedPrivilegeElement = null; requestedPrivilegeElement = GetRequestedPrivilegeElement(inputRequestedPrivilegeElement, privilegeDocument); if (requestedPrivilegeElement != null) { privilegeDocument.AppendChild(requestedPrivilegeElement); MemoryStream p = new MemoryStream(); privilegeDocument.Save(p); p.Position = 0; tempPrivilegeDocument = Util.WriteTempFile(p); } try { string trustInfoResource2 = "trustinfo2.xsl"; // If permission set was not altered, just write out what was read in... MemoryStream m = new MemoryStream(); if (_outputPermissionSet == null && !_sameSiteChanged) { XmlElement permissionSetElement = outputDocument.DocumentElement; FixupPermissionSetElement(permissionSetElement); outputDocument.Save(m); m.Position = 0; } else { XmlDocument permissionSetDocument = GetOutputPermissionSetDocument(); XmlElement permissionSetElement = permissionSetDocument.DocumentElement; FixupPermissionSetElement(permissionSetElement); if (outputDocument.DocumentElement == null) { permissionSetDocument.Save(m); m.Position = 0; } else { XmlElement oldPermissionSetElement = outputDocument.DocumentElement; XmlElement newPermissionSetElement = (XmlElement)outputDocument.ImportNode(permissionSetElement, true); oldPermissionSetElement.ParentNode.ReplaceChild(newPermissionSetElement, oldPermissionSetElement); outputDocument.Save(m); m.Position = 0; } } // Wrap <PermissionSet> in a <TrustInfo> section Stream s = null; if (tempPrivilegeDocument != null) { s = XmlUtil.XslTransform(trustInfoResource2, m, new DictionaryEntry("defaultRequestedPrivileges", tempPrivilegeDocument)); } else { s = XmlUtil.XslTransform(trustInfoResource2, m); } Util.CopyStream(s, output); } finally { if (tempPrivilegeDocument != null) { File.Delete(tempPrivilegeDocument); } } }
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 })); }
public void Write(Stream output) { XmlDocument document = new XmlDocument(); XmlElement newChild = XmlUtil.CloneElementToDocument(this.GetInputPermissionSetElement(), document, "urn:schemas-microsoft-com:asm.v2"); document.AppendChild(newChild); string str = null; XmlDocument document2 = new XmlDocument(); XmlElement inputRequestedPrivilegeElement = this.GetInputRequestedPrivilegeElement(); XmlElement requestedPrivilegeElement = null; requestedPrivilegeElement = this.GetRequestedPrivilegeElement(inputRequestedPrivilegeElement, document2); if (requestedPrivilegeElement != null) { document2.AppendChild(requestedPrivilegeElement); MemoryStream outStream = new MemoryStream(); document2.Save(outStream); outStream.Position = 0L; str = Util.WriteTempFile(outStream); } try { string resource = "trustinfo2.xsl"; MemoryStream stream2 = new MemoryStream(); if ((this._outputPermissionSet == null) && !this.sameSiteChanged) { XmlElement documentElement = document.DocumentElement; this.FixupPermissionSetElement(documentElement); document.Save(stream2); stream2.Position = 0L; } else { XmlDocument outputPermissionSetDocument = this.GetOutputPermissionSetDocument(); XmlElement permissionSetElement = outputPermissionSetDocument.DocumentElement; this.FixupPermissionSetElement(permissionSetElement); if (document.DocumentElement == null) { outputPermissionSetDocument.Save(stream2); stream2.Position = 0L; } else { XmlElement oldChild = document.DocumentElement; XmlElement element8 = (XmlElement)document.ImportNode(permissionSetElement, true); oldChild.ParentNode.ReplaceChild(element8, oldChild); document.Save(stream2); stream2.Position = 0L; } } Stream input = null; if (str != null) { DictionaryEntry[] entries = new DictionaryEntry[] { new DictionaryEntry("defaultRequestedPrivileges", str) }; input = XmlUtil.XslTransform(resource, stream2, entries); } else { input = XmlUtil.XslTransform(resource, stream2, new DictionaryEntry[0]); } Util.CopyStream(input, output); } finally { if (str != null) { File.Delete(str); } } }