Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 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)));
     }
 }
Exemplo n.º 3
0
 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)));
     }
 }
Exemplo n.º 4
0
 public void ReadsWithoutContent()
 {
     using (var dir = new TempDirectory())
         using (var item = new FileCell(Path.Combine(dir.Value().FullName, "itemFile.tmp")))
         {
             Assert.Empty(item.Content());
         }
 }
Exemplo n.º 5
0
 public void FailsOnEmptyPath()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (var file = new FileCell(""))
         {
             file.Content();
         }
     });
 }
Exemplo n.º 6
0
 public void FailsOnMissingRootPath()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (var cell = new FileCell("test.txt"))
         {
             cell.Content();
         }
     });
 }
Exemplo n.º 7
0
 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"))
                 );
         }
 }
Exemplo n.º 8
0
 public void FailsOnMissingFilename()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (var file = new FileCell("d:/"))
         {
             file.Content();
         }
     }
                                       );
 }
Exemplo n.º 9
0
 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)
                 );
         }
 }
Exemplo n.º 10
0
 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()
                 );
         }
 }
Exemplo n.º 11
0
 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);
         }
     }
 }
Exemplo n.º 12
0
        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.");
            }
        }
Exemplo n.º 13
0
        public void DisableFile(string childName)
        {
            FileCell file = SearchChildFile(childName);

            if (file.IsEnabled)
            {
                file.IsEnabled = false;
            }
            else
            {
                Console.WriteLine(childName + " is already disabled!");
            }
            Refresh();
        }
Exemplo n.º 14
0
        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();
        }
Exemplo n.º 15
0
        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()
                        );
                }
        }