//****************************************************************************************************** // EmbeddedResourceVirtualFile.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 05/04/2010 - Pinal C. Patel // Generated original version of source code. // 12/20/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using System.IO; using System.Reflection; using System.Web.Hosting; namespace GSF.Web.Hosting { /// /// Represents a file object in embedded resource space. /// /// /// /// This type is used by the /// to serve embedded resources as virtual files. The properties on the /// file can be used to retrieve an embedded resource stream from the /// /// at the appropriate /// /// using reflection. As part of the /// interface, you can do this easily via . /// /// /// For more information on embedded resource virtual filesystem /// usage, see /// /// /// public class EmbeddedResourceVirtualFile : VirtualFile { #region EmbeddedResourceVirtualFile Variables #region Instance /// /// Internal storage for the /// /// property. /// /// private readonly Assembly _containingAssembly; /// /// Internal storage for the /// /// property. /// /// private readonly string _resourcePath; #endregion #endregion #region EmbeddedResourceVirtualFile Properties /// /// Gets a reference to the assembly containing the virtual file. /// /// /// A that contains the embedded /// resource with the file contents. /// /// public Assembly ContainingAssembly { get { return _containingAssembly; } } /// /// Gets the path to the embedded resource in the containing assembly. /// /// /// A that indicates an embedded resource /// in the /// that represents the file for this instance. /// /// public string ResourcePath { get { return _resourcePath; } } #endregion #region EmbeddedResourceVirtualFile Implementation #region Constructors /// /// Initializes a new instance of the class. /// /// The virtual path to the resource represented by this instance. /// The containing the resource represented by this instance. /// The path to the embedded resource in the . /// /// Thrown if or is . /// /// /// Thrown if is . /// /// public EmbeddedResourceVirtualFile(string virtualPath, Assembly containingAssembly, string resourcePath) : base(virtualPath) { if (containingAssembly == null) { throw new ArgumentNullException("containingAssembly"); } if (resourcePath == null) { throw new ArgumentNullException("resourcePath"); } if (resourcePath.Length == 0) { throw new ArgumentOutOfRangeException("resourcePath"); } this._containingAssembly = containingAssembly; this._resourcePath = resourcePath; } #endregion #region Overrides /// /// Returns a read-only stream to the virtual resource. /// /// A read-only stream to the virtual file. /// /// public override Stream Open() { return this.ContainingAssembly.GetManifestResourceStream(this.ResourcePath); } #endregion #endregion } }