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; } }
public MemoryMappedFileInfo(FileInfo fileInfo) { _fileInfo = fileInfo; _memoryMappedFile = MemoryMappedFile.CreateNew( PhysicalPath.Replace(Path.PathSeparator, '_').Replace(Path.DirectorySeparatorChar, '_') .Replace(Path.AltDirectorySeparatorChar, '_').Replace(Path.VolumeSeparatorChar, '_'), Length); using var file = fileInfo.OpenRead(); using var view = _memoryMappedFile.CreateViewStream(0, Length, MemoryMappedFileAccess.Write); file.CopyTo(view); view.Flush(); }
/// <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> /// Determines the application folder for the application described by this settings class /// </summary> /// <returns></returns> public string GetApplicationFolder() { if (PhysicalPath.IsEmpty()) { return(ParentFolder.IsEmpty() ? AppDomain.CurrentDomain.BaseDirectory : ParentFolder); } if (Path.IsPathRooted(PhysicalPath)) { return(PhysicalPath); } return(ParentFolder.ToFullPath().AppendPath(PhysicalPath).ToFullPath()); }
/// <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); }
protected FileBasedFunctionProvider(string name, string folder) { _name = name; VirtualPath = folder; PhysicalPath = PathUtil.Resolve(VirtualPath); _rootFolder = PhysicalPath.Split(Path.DirectorySeparatorChar).Last(); var watcher = new C1FileSystemWatcher(PhysicalPath, "*") { IncludeSubdirectories = true }; watcher.Created += watcher_Changed; watcher.Deleted += watcher_Changed; watcher.Changed += watcher_Changed; watcher.Renamed += watcher_Changed; watcher.EnableRaisingEvents = true; }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { // A given project can't be added twice to the same solution, so we use the // Physical path as the key. return(PhysicalPath.GetHashCode()); }