Пример #1
0
        public override bool Uploading(HttpContext context, string fileName, string serverFilePath, long fileSize, long uploadedSize, ref object customResult)
        {
            if (m_ValidatedFreeSpace == false)
            {
                AuthUser user = User.Current;

                TempUploadFileCollection tempFiles = FileManager.GetUserTempUploadFiles(user.UserID, "album", null);

                long maxPhotoFileSize = AllSettings.Current.AlbumSettings.MaxPhotoFileSize[user];

                if (fileSize > maxPhotoFileSize)
                {
                    WebEngine.Context.ThrowError <OverMaxPhotoFileSizeError>(new OverMaxPhotoFileSizeError(maxPhotoFileSize));
                }

                long maxAlbumCapacity = AllSettings.Current.AlbumSettings.MaxAlbumCapacity[user];

                if (user.UsedAlbumSize + tempFiles.GetTotalFileSize() + fileSize > maxAlbumCapacity)
                {
                    WebEngine.Context.ThrowError <OverMaxAlbumCapacityError>(new OverMaxAlbumCapacityError(maxAlbumCapacity));

                    return(false);
                }

                m_ValidatedFreeSpace = true;
            }

            return(true);
        }
Пример #2
0
        public static void ClearExperisTempUploadFiles()
        {
            TempUploadFileCollection tempUploadFiles = FileDao.Instance.ClearExperisTempUploadFiles();

            foreach (TempUploadFile tempUploadFile in tempUploadFiles)
            {
                try
                {
                    File.Delete(tempUploadFile.PhysicalFilePath);
                }
                catch { }
            }
        }
Пример #3
0
        public static PhysicalFileFromTempCollection Save(int operatorID, TempUploadFileCollection tempUploadFiles)
        {
            if (operatorID <= 0)
            {
                Context.ThrowError(new NotLoginError());
                return(new PhysicalFileFromTempCollection());
            }

            if (tempUploadFiles == null || tempUploadFiles.Count == 0)
            {
                return(new PhysicalFileFromTempCollection());
            }

            //循环这些临时文件,分离出那些是需要保存的哪些是需要删除的
            //判断标准是:FileID相同的TempUploadFile,只保留第一份,并移动到最终实际位置,剩余的直接从临时文件夹删除

            List <int> allTempUploadFileIds    = new List <int>();
            List <int> saveTempUploadFileIds   = new List <int>();
            List <int> deleteTempUploadFileIds = new List <int>();

            List <string> deleteTempUploadFileNames = new List <string>();
            List <string> distinctFileIds           = new List <string>();

            foreach (TempUploadFile tempUploadFile in tempUploadFiles)
            {
                allTempUploadFileIds.Add(tempUploadFile.TempUploadFileID);

                if (distinctFileIds.Contains(tempUploadFile.FileID))
                {
                    deleteTempUploadFileIds.Add(tempUploadFile.TempUploadFileID);
                    deleteTempUploadFileNames.Add(tempUploadFile.ServerFileName);
                }
                else
                {
                    saveTempUploadFileIds.Add(tempUploadFile.TempUploadFileID);
                }

                distinctFileIds.Add(tempUploadFile.FileID);
            }


            PhysicalFileFromTempCollection files = FileDao.Instance.SaveFiles(operatorID, allTempUploadFileIds, saveTempUploadFileIds, deleteTempUploadFileIds);


            //对于保存成功的临时文件,将文件从临时文件夹移动到最终文件夹
            foreach (PhysicalFileFromTemp file in files)
            {
                string tempUploadFilePath = Globals.GetPath(SystemDirecotry.Temp_Upload, file.TempUploadServerFileName);
                string targetFilePath     = Globals.GetPath(SystemDirecotry.Upload_File, file.ServerFilePath);

                string targetDirectory = Path.GetDirectoryName(targetFilePath);

                try
                {
                    if (File.Exists(targetFilePath))
                    {
                        File.Delete(tempUploadFilePath);
                    }

                    else
                    {
                        if (Directory.Exists(targetDirectory) == false)
                        {
                            Directory.CreateDirectory(targetDirectory);
                        }

                        File.Move(tempUploadFilePath, targetFilePath);
                    }
                }
                catch { }
            }

            //对于筛选出来重复的临时文件,直接将他们从临时文件夹删除
            foreach (string filename in deleteTempUploadFileNames)
            {
                string path = Globals.GetPath(SystemDirecotry.Temp_Upload, filename);

                try
                {
                    File.Delete(path);
                }
                catch { }
            }

            return(files);
        }