protected override bool Process(IInteraction parameters) { bool success = true; IInteraction uncastParameters; IHttpInteraction httpParameters = null; string requestedPath = RootPath; string coreUrl = ""; if (parameters.TryGetClosest(typeof(IHttpInteraction), out uncastParameters) && UseHttp) { httpParameters = (IHttpInteraction)uncastParameters; string[] urlArray = httpParameters.URL.ToArray(); coreUrl = string.Join("/", urlArray); string decodedPathFromURL = HttpUtility.UrlDecode(Path.Combine(urlArray)); requestedPath = Path.Combine(requestedPath, decodedPathFromURL); } DirectoryInfo requestedInfo = new DirectoryInfo(requestedPath); if (requestedInfo.Exists) { FilesystemItemInteraction itemInteraction = new FilesystemItemInteraction(parameters, RootPath, coreUrl); foreach (DirectoryInfo info in requestedInfo.GetDirectories()) { itemInteraction.Assume(info); success &= directoryItem.TryProcess(itemInteraction); } foreach (FileInfo info in requestedInfo.GetFiles()) { itemInteraction.Assume(info); success &= fileItem.TryProcess(itemInteraction); } } else { httpParameters.SetStatusCode(404); success &= dirNotFound.TryProcess(httpParameters); } return(success); }
/// <summary> /// Initializes a new instance of the /// <see cref="BorrehSoft.Extensions.BasicWeblings.Site.Filesystem.FilesystemChangeInteraction"/> class. /// </summary> /// <param name="info">File info</param> /// <param name="keywords">Keywords this file associates with</param> /// <param name="rootPath">Root that was being watched</param> public FilesystemChangeInteraction( FileSystemInfo info, string[] keywords, string rootPath = "", IInteraction parent = null) : base(parent) { this ["name"] = info.Name; this ["fullname"] = info.FullName; this ["lastdate"] = info.LastWriteTime.ToString("s", System.Globalization.CultureInfo.InvariantCulture); if (info.FullName.StartsWith(rootPath)) { string url = info.FullName.Remove(0, rootPath.Length); this ["url"] = url; this ["parent"] = url.Remove(url.Length - info.Name.Length); this ["parenturl"] = this ["parent"]; } this["keywords"] = keywords; this["isdirectory"] = (info.Attributes & FileAttributes.Directory) == FileAttributes.Directory; FileInfo fileInfo = info as FileInfo; if (fileInfo != null) { this ["filesize"] = FilesystemItemInteraction.Filesize(fileInfo.Length); this ["bytecount"] = fileInfo.Length; if (fileInfo.Extension.Length > 0) { this ["shortname"] = info.Name.Remove(info.Name.Length - info.Extension.Length); this ["extension"] = info.Extension.TrimStart('.').ToLower(); } } else { this["filesize"] = "-"; } }