public void Refresh() { ViewCells?.Clear(); ViewCells = new List <ViewCell>(); foreach (var directory in CurrentPath.EnumerateDirectories()) { var cell = new DirectoryCell(directory, Settings); ViewCells.Add(cell); } foreach (var file in CurrentPath.EnumerateFiles()) { if (DisplayFilter != null && !DisplayFilter.Contains(file.Extension.ToLower().Trim('.'))) { continue; } var cell = new FileCell(file, Settings); if (IsExchangePath || CurrentPath.FullName == AddonPath.FullName) { cell.CanDelete = true; } else { cell.CanDelete = false; } ViewCells.Add(cell); } }
public ActionResult ChangeFileStatus(string fileName) { try { NavigateToLastFolder(); FileCell file = _explorer.SearchChildFile(fileName); if (file.IsEnabled) { _explorer.DisableFile(file.Name); } else { _explorer.EnableFile(file.Name); } return(Json(new JsonModelBase(200, "success", "success", null))); } catch (InvalidOperationException e) { return(Json(new JsonModelBase(403, "failed", e.Message, null))); } catch (Exception e) { return(Json(new JsonModelBase(500, "failed", e.Message, null))); } }
public ActionResult GetFile(string fileName = null, bool getContent = true) { try { NavigateToLastFolder(); FileCell file = _explorer.SearchChildFile(fileName); string content; //if (getContent) Explorer.TryGetContent(file.FullPath, out content); //else // content = "文件过大,不给予显示。"; var iconPath = Path.Combine(_env.WebRootPath, "images", "icons", file.Extension + ".png"); if (!System.IO.File.Exists(iconPath)) { file.FileIcon.Save(iconPath); } return(Json(new JsonModelBase(200, "success", "success", new { detail = file, content }))); } catch (FileNotFoundException e) { return(Json(new JsonModelBase(404, "failed", e.Message, null))); } catch (Exception e) { return(Json(new JsonModelBase(500, "failed", e.Message, null))); } }
public void ReadsWithoutContent() { using (var dir = new TempDirectory()) using (var item = new FileCell(Path.Combine(dir.Value().FullName, "itemFile.tmp"))) { Assert.Empty(item.Content()); } }
public void FailsOnEmptyPath() { Assert.Throws <ArgumentException>(() => { using (var file = new FileCell("")) { file.Content(); } }); }
public void FailsOnMissingRootPath() { Assert.Throws <ArgumentException>(() => { using (var cell = new FileCell("test.txt")) { cell.Content(); } }); }
public void AllowsWhiteSpacesFoldername() { using (var dir = new TempDirectory()) using (var item = new FileCell(Path.Combine(dir.Value().FullName, $"white space folder{Path.AltDirectorySeparatorChar}filename.txt"))) { item.Update(new InputOf("after holiday is before holiday")); Assert.True( File.Exists(Path.Combine(dir.Value().FullName, "white space folder", "filename.txt")) ); } }
public void FailsOnMissingFilename() { Assert.Throws <ArgumentException>(() => { using (var file = new FileCell("d:/")) { file.Content(); } } ); }
public void RemovesEmptyFile() { using (var dir = new TempDirectory()) using (var item = new FileCell(Path.Combine(dir.Value().FullName, "niceFileName"))) { item.Update(new InputOf("after holiday is before holiday")); item.Update(new InputOf(String.Empty)); Assert.False( File.Exists(dir.Value().FullName) ); } }
public void CanUpdate() { using (var dir = new TempDirectory()) using (var item = new FileCell(Path.Combine(dir.Value().FullName, "niceFileName"))) { item.Update(new InputOf("after holiday is before holiday")); Assert.Equal( "after holiday is before holiday", new TextOf(item.Content()).AsString() ); } }
public void ResetsStreamAfterUpdate() { using (var tmp = new TempDirectory()) { using (var cell = new FileCell(Path.Combine(tmp.Value().FullName, "test.txt"))) { var content = new InputOf("its so hot outside"); cell.Update(content); Assert.Equal(0, content.Stream().Position); } } }
public void DeleteFile(string childName) { FileCell file = SearchChildFile(childName); if (file.CanDelete) { File.Delete(file.FullPath); } else { throw new UnauthorizedAccessException("You cannot delete this file."); } }
public void DisableFile(string childName) { FileCell file = SearchChildFile(childName); if (file.IsEnabled) { file.IsEnabled = false; } else { Console.WriteLine(childName + " is already disabled!"); } Refresh(); }
public void SaveContent(string childName, string content) { FileCell file = SearchChildFile(childName); if (!TryGetContent(file.FullPath, out _)) { throw new InvalidOperationException("Can't overwrite binary file."); } if (content.Any(ch => char.IsControl(ch) && ch != '\r' && ch != '\n' && ch != '\t')) { throw new InvalidOperationException("Invalid char."); } File.WriteAllText(file.FullPath, content); Refresh(); }
public void WorksWithEncoding(string name) { var encoding = Encoding.GetEncoding(name); var inBytes = encoding.GetBytes("Can or can't I dö prüpär äncöding?"); using (var dir = new TempDirectory()) using (var item = new FileCell(Path.Combine(dir.Value().FullName, "itemFile.tmp"))) { item.Update(new InputOf(inBytes)); Assert.Equal( "Can or can't I dö prüpär äncöding?", new TextOf( new InputOf(inBytes), encoding ).AsString() ); } }