public Stream CreateReadStream() { using (var file = File.OpenRead(Path.Combine(AppDirectory, ZipFilename))) using (var archive = new ZipArchive(file, ZipArchiveMode.Read)) { var zipFile = archive.GetEntry(PhysicalPath); if (zipFile != null) { using (var zipEntryStream = zipFile.Open()) { if (PhysicalPath.EndsWith(".html", StringComparison.OrdinalIgnoreCase)) { using (var reader = new StreamReader(zipEntryStream)) { var content = reader.ReadToEnd(); return(Patcher.PatchHtml(content)); } } else { var ms = new MemoryStream(); zipEntryStream.CopyTo(ms); ms.Position = 0; // rewind return(ms); } } } } throw new Exception("Failed"); }
public PatchablePhysicalFileInfo(FileInfo info) { m_info = info; if (PhysicalPath.EndsWith(".html", StringComparison.OrdinalIgnoreCase)) { m_extraLength = Global.Patch.Length; } }
/// <summary> /// Host an IIS web site in memory /// </summary> /// <param name="physicalPath">Path to the site (including any Global.asax & web.config files)</param> /// <param name="enableDirectoryListing">If true, expose directory browsing pages. Defaults to false.</param> public DirectServer(string physicalPath, bool enableDirectoryListing = false) { DisableDirectoryListing = !enableDirectoryListing; _lockObject = new object(); Port = 0; VirtualPath = "/"; PhysicalPath = Path.GetFullPath(physicalPath); PhysicalPath = PhysicalPath.EndsWith("\\", StringComparison.Ordinal) ? PhysicalPath : PhysicalPath + "\\"; string uniqueAppString = string.Concat("/", physicalPath, ":", Port.ToString()).ToLowerInvariant(); AppId = (uniqueAppString.GetHashCode()).ToString("x", CultureInfo.InvariantCulture); }
/// <summary> /// </summary> /// <param name="port"></param> /// <param name="virtualPath"></param> /// <param name="physicalPath"></param> /// <param name="disableDirectoryListing"></param> public SocketServer(int port, string virtualPath, string physicalPath, bool disableDirectoryListing) { IPAddress = IPAddress.Loopback; DisableDirectoryListing = disableDirectoryListing; _lockObject = new object(); Port = port; VirtualPath = virtualPath; PhysicalPath = Path.GetFullPath(physicalPath); PhysicalPath = PhysicalPath.EndsWith("\\", StringComparison.Ordinal) ? PhysicalPath : PhysicalPath + "\\"; string uniqueAppString = string.Concat(virtualPath, physicalPath, ":", Port.ToString()).ToLowerInvariant(); AppId = (uniqueAppString.GetHashCode()).ToString("x", CultureInfo.InvariantCulture); }