public IEnumerable<CustomFile> AllEnumerable(CustomDirectory dir) { List<CustomFile> list = new List<CustomFile>(); var baseDir = dir.PhysicalPath; if (Directory.Exists(baseDir)) { //output directory foreach (var folder in IO.IOUtility.EnumerateDirectoriesExludeHidden(baseDir)) { var customFile = new CustomFile(); customFile.Site = dir.Site; customFile.FileType = "Folder"; customFile.Name = folder.Name; customFile.Directory = new CustomDirectory(dir, customFile.Name); list.Add(customFile); } //output files foreach (var file in IO.IOUtility.EnumerateFilesExludeHidden(baseDir)) { var customFile = new CustomFile(file.FullName); customFile.Site = dir.Site; customFile.Directory = new CustomDirectory(dir, customFile.Name); list.Add(customFile); } } return list; }
public void TestVirtualPath() { var site = new Site("Site1"); string imageName = "image1.jpg"; var image = new CustomFile(site, imageName); string expected1 = Kooboo.Web.Url.UrlUtility.Combine(site.VirtualPath, "files", imageName); Assert.AreEqual(expected1, image.VirtualPath, true); }
public void TestPhysicalPath() { var site = new Site("Site1"); string imageName = "image1.jpg"; var image = new CustomFile(site, imageName); string expected1 = Path.Combine(site.PhysicalPath, "files", imageName); Assert.AreEqual(expected1, image.PhysicalPath, true); }
public void TestParseFromPhysicalPath() { string siteName = "site1"; string imageName = "image1"; string extension = ".jpg"; string physicalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sites", siteName, "files", imageName + extension); var imageFile = new CustomFile(physicalPath); Assert.AreEqual(imageName, imageFile.Name); Assert.AreEqual(extension, imageFile.FileExtension); Assert.AreEqual(siteName, imageFile.Site.Name); }
public virtual ActionResult Create(CustomFile model, string fullName) { Msg msg = new Msg(); try { var userFile = Request.Files["image"]; if (userFile.InputStream.Length == 0) { throw new FriendlyException("Please select a file!"); } Manager.SaveFile(this.Site, fullName, userFile.FileName, userFile.InputStream); return RedirectToAction("Index", new { fullName = fullName }); } catch (FriendlyException e) { ModelState.AddModelError("", e.Message); return View(); } }
public virtual ActionResult File(string name) { var dir = Path.GetDirectoryName(name); CustomFile file; if (string.IsNullOrEmpty(dir)) { file = new CustomFile(Site, name); } else { CustomDirectory customDir = new CustomDirectory(Site, dir).LastVersion(); file = new CustomFile(customDir, Path.GetFileName(name)); } file = file.LastVersion(); if (file.Exists()) { SetCache(Response, 2592000, "*"); return File(file.PhysicalPath, IOUtility.MimeType(file.PhysicalPath)); } return null; }
/// <summary> /// The file URL. /// </summary> /// <param name="relativeFilePath">The relative file path.</param> /// <param name="withCDNResolving">if set to <c>true</c> [with CDN resolving].</param> /// <returns></returns> public virtual IHtmlString FileUrl(string relativeFilePath, bool withCDNResolving) { Site site = this.Site; var dir = Path.GetDirectoryName(relativeFilePath); CustomFile file; if (string.IsNullOrEmpty(dir)) { file = new CustomFile(site, relativeFilePath); } else { CustomDirectory customDir = new CustomDirectory(site, dir).LastVersion(); file = new CustomFile(customDir, Path.GetFileName(relativeFilePath)); } file = file.LastVersion(); if (withCDNResolving) { return ResourceCDNUrl(file.VirtualPath); } else { return new HtmlString(Url.Content(file.VirtualPath)); } }
public void Remove(CustomFile item) { throw new NotImplementedException(); }
public CustomFile Get(CustomFile dummy) { throw new NotImplementedException(); }
public void Update(CustomFile @new, CustomFile old) { throw new NotImplementedException(); }
/// <summary> /// The file URL. /// </summary> /// <param name="relativeFilePath">The relative file path.</param> /// <returns></returns> public virtual IHtmlString FileUrl(string relativeFilePath) { Site site = this.PageRequestContext.Site; var dir = Path.GetDirectoryName(relativeFilePath); CustomFile file; if (string.IsNullOrEmpty(dir)) { file = new CustomFile(site, relativeFilePath); } else { CustomDirectory customDir = new CustomDirectory(site, dir).LastVersion(); file = new CustomFile(customDir, Path.GetFileName(relativeFilePath)); } file = file.LastVersion(); return ResourceCDNUrl(file.VirtualPath); }