Esempio n. 1
0
    public static IFileStorage GetStorage(FileStorageTypes types)
    {
        switch (types)
        {
        case FileStorageTypes.Database: return(new DatabaseStorage());

        case FileStorageTypes.FileSystem: return(new FileStorage());
        }
    }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        //public bool Resize

        public bool FileExistInStorage(FileStorageTypes storageType, string fileName, int id)
        {
            var path = _workingFolder + "\\" + storageType.ToString() + "\\" + id + "\\" + fileName;
            return File.Exists(path);
        }
Esempio n. 4
0
        public void Delete(FileStorageTypes storageType, int id)
        {
            var path = _workingFolder + "\\" + storageType.ToString() + "\\" + id + "\\";
            if (Directory.Exists(path))
            {
                Directory.Delete(path,true);
            }

        }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 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 "";
     }
 }
Esempio n. 8
0
        /// <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 "";
            }

        }