コード例 #1
0
        public void DeleteFile(IModelFilePath modelFile)
        {
            string path = $"{AssetsPath}{modelFile.GetFullPath()}";

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
コード例 #2
0
        public void SaveTextFile(IModelFilePath modelFile, string text)
        {
            if (modelFile.GetFilePath().FileType != FileType.Text)
            {
                throw new Exception("FileType is not text");
            }

            InitializeFolders(modelFile);
            string path = $"{AssetsPath}{modelFile.GetFullPath()}";

            File.WriteAllText(path, text);
        }
コード例 #3
0
        public void SaveUploadedFile(HttpPostedFileBase upload, IModelFilePath modelFile)
        {
            if (!FileIsValid(upload))
            {
                throw new Exception("Invalid HttpPostedFileBase");
            }

            InitializeFolders(modelFile);
            string path = $"{AssetsPath}{modelFile.GetFullPath()}";

            upload.SaveAs(path);
        }
コード例 #4
0
        public string ReadTextFile(IModelFilePath modelFile)
        {
            if (modelFile.GetFilePath().FileType != FileType.Text)
            {
                throw new Exception("FileType is not text");
            }

            string path = $"{AssetsPath}{modelFile.GetFullPath()}";

            if (!File.Exists(path))
            {
                return("");
            }

            return(File.ReadAllText(path));
        }
コード例 #5
0
        private void InitializeFolders(IModelFilePath modelFile)
        {
            string path = $"{AssetsPath}{modelFile.ModelType}/";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path += $"{modelFile.GetModelId()}/";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path += $"{modelFile.GetFileType()}/";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
コード例 #6
0
 public FileUploadBinder(IModelFilePath filePath, HttpPostedFileBase postedFile)
 {
     FilePath   = filePath;
     PostedFile = postedFile;
 }