public CreateEmbeddedResource ( System.Web.Compilation.BuildProvider buildProvider, string name ) : Stream | ||
buildProvider | System.Web.Compilation.BuildProvider | |
name | string | |
리턴 | Stream |
private void GenerateResourceFile(AssemblyBuilder assemblyBuilder, IResourceReader reader) { string str; if (this._ns == null) { str = UrlPath.GetFileNameWithoutExtension(base.VirtualPath) + ".resources"; } else if (this._cultureName == null) { str = this._ns + "." + this._typeName + ".resources"; } else { str = this._ns + "." + this._typeName + "." + this._cultureName + ".resources"; } str = str.ToLower(CultureInfo.InvariantCulture); Stream stream = null; try { try { try { } finally { stream = assemblyBuilder.CreateEmbeddedResource(this, str); } } catch (ArgumentException) { throw new HttpException(System.Web.SR.GetString("Duplicate_Resource_File", new object[] { base.VirtualPath })); } using (stream) { using (ResourceWriter writer = new ResourceWriter(stream)) { writer.TypeNameConverter = new Func <Type, string>(TargetFrameworkUtil.TypeNameConverter); foreach (DictionaryEntry entry in reader) { writer.AddResource((string)entry.Key, entry.Value); } } } } finally { if (stream != null) { stream.Close(); } } }
public override void GenerateCode (AssemblyBuilder assemblyBuilder) { base.GenerateCode (assemblyBuilder); SchematronParser schParser = (SchematronParser)this.Parser; IXsltProcessor proc = Processors.Xslt [schParser.ProcessorName]; IXPathNavigable schemaDoc; using (TextReader textReader = OpenReader()) schemaDoc = proc.ItemFactory.CreateNodeReadOnly (textReader, new XmlParsingOptions { BaseUri = this.PhysicalPath }); Stream resourceStream; try { resourceStream = assemblyBuilder.CreateEmbeddedResource (this, this.ValidatorUri.AbsolutePath); } catch (ArgumentException) { throw CreateCompileException (String.Format (CultureInfo.InvariantCulture, "There is already another type generated with the name '{0}'.", this.GeneratedTypeFullName)); } using (resourceStream) { using (MemoryStream copyStream = new MemoryStream()) { try { using (XmlWriter writer = XmlWriter.Create(copyStream)) proc.BuildSchematronValidatorStylesheet (schemaDoc, writer); } catch (ProcessorException ex) { throw CreateCompileException (ex); } copyStream.Position = 0; copyStream.WriteTo (resourceStream); // test compilation copyStream.Position = 0; try { proc.Compile (copyStream, new XsltCompileOptions { BaseUri = this.PhysicalPath }); } catch (ProcessorException ex) { throw CreateCompileException (ex); } } } }
internal static void AddArtifactReference(AssemblyBuilder assemblyBuilder, BuildProvider prov, string virtualPath) { // add the artifact as a resource to the DLL using (Stream input = VirtualPathProvider.OpenFile(virtualPath)) { // derive the resource name string name = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPath); using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, name)) { int byteRead = input.ReadByte(); while (byteRead != -1) { resStream.WriteByte((byte)byteRead); byteRead = input.ReadByte(); } } } }
private static void SetupEmbeddedResource(AssemblyBuilder assemblyBuilder, BuildProvider prov, XmlElement xmlElement, string resourceName) { using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, resourceName)) { EntityDesignerUtils.OutputXmlElementToStream(xmlElement, resStream); } }
private void GenerateResourceFile(AssemblyBuilder assemblyBuilder, IResourceReader reader) { // Get the name of the generated .resource file string resourceFileName; if (_ns == null) { // In the case where we don't generate code, just name the resource file // after the virtual file resourceFileName = UrlPath.GetFileNameWithoutExtension(VirtualPath) + ".resources"; } else if (_cultureName == null) { // Name the resource file after the generated class, since that's what the // generated class expects resourceFileName = _ns + "." + _typeName + ".resources"; } else { // If it's a non-default resource, include the culture in the name resourceFileName = _ns + "." + _typeName + "." + _cultureName + ".resources"; } // Make it lower case, since GetManifestResourceStream (which we use later on) is // case sensitive resourceFileName = resourceFileName.ToLower(CultureInfo.InvariantCulture); Stream outputStream = null; try { try { try { } finally { // Put the assignment in a finally block to avoid a ThreadAbortException from // causing the created stream to not get assigned and become leaked (Dev10 outputStream = assemblyBuilder.CreateEmbeddedResource(this, resourceFileName); } } catch (ArgumentException) { // This throws an ArgumentException if the resource file name was already added. // Catch the situation, and give a better error message (VSWhidbey 87110) throw new HttpException(SR.GetString(SR.Duplicate_Resource_File, VirtualPath)); } // Create an output stream from the .resource file using (outputStream) { using (ResourceWriter writer = new ResourceWriter(outputStream)) { // Enable resource writer to be target-aware writer.TypeNameConverter = System.Web.UI.TargetFrameworkUtil.TypeNameConverter; // Copy the resources foreach (DictionaryEntry de in reader) { writer.AddResource((string)de.Key, de.Value); } } } } finally { // Always close the stream to avoid a ThreadAbortException from causing the stream // to be leaked (Dev10 if (outputStream != null) { outputStream.Close(); } } }
private void GenerateResourceFile(AssemblyBuilder assemblyBuilder, IResourceReader reader) { // Get the name of the generated .resource file string resourceFileName; if (_ns == null) { // In the case where we don't generate code, just name the resource file // after the virtual file resourceFileName = UrlPath.GetFileNameWithoutExtension(VirtualPath) + ".resources"; } else if (_cultureName == null) { // Name the resource file after the generated class, since that's what the // generated class expects resourceFileName = _ns + "." + _typeName + ".resources"; } else { // If it's a non-default resource, include the culture in the name resourceFileName = _ns + "." + _typeName + "." + _cultureName + ".resources"; } // Make it lower case, since GetManifestResourceStream (which we use later on) is // case sensitive resourceFileName = resourceFileName.ToLower(CultureInfo.InvariantCulture); Stream outputStream = null; try { try { try { } finally { // Put the assignment in a finally block to avoid a ThreadAbortException from // causing the created stream to not get assigned and become leaked (Dev10 bug 844463) outputStream = assemblyBuilder.CreateEmbeddedResource(this, resourceFileName); } } catch (ArgumentException) { // This throws an ArgumentException if the resource file name was already added. // Catch the situation, and give a better error message (VSWhidbey 87110) throw new HttpException(SR.GetString(SR.Duplicate_Resource_File, VirtualPath)); } // Create an output stream from the .resource file using (outputStream) { using (ResourceWriter writer = new ResourceWriter(outputStream)) { // Enable resource writer to be target-aware writer.TypeNameConverter = System.Web.UI.TargetFrameworkUtil.TypeNameConverter; // Copy the resources foreach (DictionaryEntry de in reader) { writer.AddResource((string)de.Key, de.Value); } } } } finally { // Always close the stream to avoid a ThreadAbortException from causing the stream // to be leaked (Dev10 bug 844463) if (outputStream != null) { outputStream.Close(); } } }
private void GenerateResourceFile(AssemblyBuilder assemblyBuilder, IResourceReader reader) { string str; if (this._ns == null) { str = UrlPath.GetFileNameWithoutExtension(base.VirtualPath) + ".resources"; } else if (this._cultureName == null) { str = this._ns + "." + this._typeName + ".resources"; } else { str = this._ns + "." + this._typeName + "." + this._cultureName + ".resources"; } str = str.ToLower(CultureInfo.InvariantCulture); Stream stream = null; try { try { try { } finally { stream = assemblyBuilder.CreateEmbeddedResource(this, str); } } catch (ArgumentException) { throw new HttpException(System.Web.SR.GetString("Duplicate_Resource_File", new object[] { base.VirtualPath })); } using (stream) { using (ResourceWriter writer = new ResourceWriter(stream)) { writer.TypeNameConverter = new Func<Type, string>(TargetFrameworkUtil.TypeNameConverter); foreach (DictionaryEntry entry in reader) { writer.AddResource((string) entry.Key, entry.Value); } } } } finally { if (stream != null) { stream.Close(); } } }