public static IFileStorage GetStorage(FileStorageTypes types) { switch (types) { case FileStorageTypes.Database: return(new DatabaseStorage()); case FileStorageTypes.FileSystem: return(new FileStorage()); } }
public string GetPhoto(FileStorageTypes type, string filename, int id) { string filePath = ""; switch (type) { case FileStorageTypes.PhysioBodyParts: filePath = _workingFolder + "\\" + FileStorageTypes.PhysioBodyParts.ToString(); break; default: break; } filePath += "\\" + id + "\\" + filename; return filePath; }
//public bool Resize public bool FileExistInStorage(FileStorageTypes storageType, string fileName, int id) { var path = _workingFolder + "\\" + storageType.ToString() + "\\" + id + "\\" + fileName; return File.Exists(path); }
public void Delete(FileStorageTypes storageType, int id) { var path = _workingFolder + "\\" + storageType.ToString() + "\\" + id + "\\"; if (Directory.Exists(path)) { Directory.Delete(path,true); } }
public byte[] GetFileBytes(string fileName, FileStorageTypes storageTypes, int id) { var fullFilePath = _workingFolder + "\\" + storageTypes.ToString() + "\\" + id + "\\" + fileName; if (File.Exists(fullFilePath)) { return File.ReadAllBytes(fullFilePath); } return null; }
public FileStream GetFileStream(string fileName, FileStorageTypes storageTypes) { var fullFilePath = _workingFolder + "\\" + storageTypes.ToString() + "\\" + fileName; if (File.Exists(fullFilePath)) { return new FileStream(fullFilePath, FileMode.Open, FileAccess.Read); } return null; }
public string SetDefaultPrifilePic(FileStorageTypes storageType, int id, string newFileName) { var tempFilePath = _workingFolder + "\\" + "DefaultPics" + "\\" + "ProfilePicture.jpg"; if (File.Exists(tempFilePath)) { var newPath = _workingFolder + "\\" + storageType.ToString() + "\\" + id + "\\"; var newFileFullPath = newPath + newFileName; try { Directory.CreateDirectory(newPath); foreach (string file in Directory.GetFiles(newPath, "*" + newFileName + "*")) { File.Delete(file); } File.Copy(tempFilePath, newFileFullPath); return newFileName; } catch (Exception) { return ""; } } else { return ""; } }
/// <summary> /// Move file from temp storage /// </summary> /// <param name="tempFileName">Temp file name</param> /// <param name="storageType"> </param> /// <param name="id">ID table row</param> /// <param name="newFileName">new file name without extention</param> /// <returns></returns> public string MoveFromTemp(string tempFileName, FileStorageTypes storageType, int id, string newFileName) { var tempFilePath = _workingFolder + "\\" + "temp" + "\\" + tempFileName; if (File.Exists(tempFilePath)) { var newPath = _workingFolder + "\\" + storageType.ToString() + "\\" + id + "\\"; var newFileFullPath = newPath + newFileName + Path.GetExtension(tempFileName); try { Directory.CreateDirectory(newPath); foreach (string file in Directory.GetFiles(newPath, "*" + newFileName + "*")) { File.Delete(file); } File.Move(tempFilePath, newFileFullPath); return newFileName + Path.GetExtension(tempFileName); } catch (Exception) { return ""; } } else { return ""; } }