Ejemplo n.º 1
0
        public static ChunkedUploadSession UploadChunk(string uploadId, Stream stream, long chunkLength)
        {
            var uploadSession = ChunkedUploadSessionHolder.GetSession(uploadId);

            uploadSession.Expired = DateTime.UtcNow + ChunkedUploadSessionHolder.SlidingExpiration;

            if (chunkLength <= 0)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile);
            }

            if (chunkLength > SetupInfo.MaxUploadSize)
            {
                throw FileSizeComment.GetFileSizeException(SetupInfo.MaxUploadSize);
            }

            if (uploadSession.BytesUploaded + chunkLength > GetMaxFileSize(uploadSession))
            {
                AbortUpload(uploadSession);
                throw FileSizeComment.GetFileSizeException(GetMaxFileSize(uploadSession));
            }

            using (var dao = Global.DaoFactory.GetFileDao())
            {
                dao.UploadChunk(uploadSession, stream, chunkLength);
            }

            if (uploadSession.BytesUploaded == uploadSession.BytesTotal)
            {
                FileMarker.MarkAsNew(uploadSession.File);
                ChunkedUploadSessionHolder.RemoveSession(uploadSession);
            }

            return(uploadSession);
        }
Ejemplo n.º 2
0
        public static ChunkedUploadSession InitiateUpload(string folderId, string fileId, string fileName, long contentLength)
        {
            if (string.IsNullOrEmpty(folderId))
            {
                folderId = null;
            }

            if (string.IsNullOrEmpty(fileId))
            {
                fileId = null;
            }

            var file = new File {
                ID = fileId, FolderID = folderId, Title = fileName, ContentLength = contentLength
            };

            using (var dao = Global.DaoFactory.GetFileDao())
            {
                var uploadSession = dao.CreateUploadSession(file, contentLength);

                uploadSession.Expired  = uploadSession.Created + ChunkedUploadSessionHolder.SlidingExpiration;
                uploadSession.Location = FilesLinkUtility.GetUploadChunkLocationUrl(uploadSession.Id, contentLength > 0);
                uploadSession.TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId;
                uploadSession.UserId   = SecurityContext.CurrentAccount.ID;
                uploadSession.FolderId = folderId;

                ChunkedUploadSessionHolder.StoreSession(uploadSession);

                return(uploadSession);
            }
        }
Ejemplo n.º 3
0
        private static void AbortUpload(ChunkedUploadSession uploadSession)
        {
            using (var dao = Global.DaoFactory.GetFileDao())
            {
                dao.AbortUploadSession(uploadSession);
            }

            ChunkedUploadSessionHolder.RemoveSession(uploadSession);
        }
Ejemplo n.º 4
0
        public ChunkedUploadSession <T> UploadChunk <T>(string uploadId, Stream stream, long chunkLength)
        {
            var uploadSession = ChunkedUploadSessionHolder.GetSession <T>(uploadId);

            uploadSession.Expired = DateTime.UtcNow + ChunkedUploadSessionHolder.SlidingExpiration;

            if (chunkLength <= 0)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile);
            }

            if (chunkLength > SetupInfo.ChunkUploadSize)
            {
                throw FileSizeComment.GetFileSizeException(SetupInfo.MaxUploadSize(TenantExtra, TenantStatisticsProvider));
            }

            var maxUploadSize = GetMaxFileSize(uploadSession.FolderId, uploadSession.BytesTotal > 0);

            if (uploadSession.BytesUploaded + chunkLength > maxUploadSize)
            {
                AbortUpload(uploadSession);
                throw FileSizeComment.GetFileSizeException(maxUploadSize);
            }

            var dao = DaoFactory.GetFileDao <T>();

            dao.UploadChunk(uploadSession, stream, chunkLength);

            if (uploadSession.BytesUploaded == uploadSession.BytesTotal)
            {
                var linkDao = DaoFactory.GetLinkDao();
                linkDao.DeleteAllLink(uploadSession.File.ID.ToString());

                FileMarker.MarkAsNew(uploadSession.File);
                ChunkedUploadSessionHolder.RemoveSession(uploadSession);
            }
            else
            {
                ChunkedUploadSessionHolder.StoreSession(uploadSession);
            }

            return(uploadSession);
        }
Ejemplo n.º 5
0
 public FileUploader(
     FilesSettingsHelper filesSettingsHelper,
     FileUtility fileUtility,
     UserManager userManager,
     TenantManager tenantManager,
     AuthContext authContext,
     SetupInfo setupInfo,
     TenantExtra tenantExtra,
     TenantStatisticsProvider tenantStatisticsProvider,
     FileMarker fileMarker,
     FileConverter fileConverter,
     IDaoFactory daoFactory,
     Global global,
     FilesLinkUtility filesLinkUtility,
     FilesMessageService filesMessageService,
     FileSecurity fileSecurity,
     EntryManager entryManager,
     IServiceProvider serviceProvider,
     ChunkedUploadSessionHolder chunkedUploadSessionHolder,
     FileTrackerHelper fileTracker)
 {
     FilesSettingsHelper      = filesSettingsHelper;
     FileUtility              = fileUtility;
     UserManager              = userManager;
     TenantManager            = tenantManager;
     AuthContext              = authContext;
     SetupInfo                = setupInfo;
     TenantExtra              = tenantExtra;
     TenantStatisticsProvider = tenantStatisticsProvider;
     FileMarker               = fileMarker;
     FileConverter            = fileConverter;
     DaoFactory               = daoFactory;
     Global                     = global;
     FilesLinkUtility           = filesLinkUtility;
     FilesMessageService        = filesMessageService;
     FileSecurity               = fileSecurity;
     EntryManager               = entryManager;
     ServiceProvider            = serviceProvider;
     ChunkedUploadSessionHolder = chunkedUploadSessionHolder;
     FileTracker                = fileTracker;
 }
Ejemplo n.º 6
0
        public ChunkedUploadSession <T> InitiateUpload <T>(T folderId, T fileId, string fileName, long contentLength, bool encrypted)
        {
            var file = ServiceProvider.GetService <File <T> >();

            file.ID            = fileId;
            file.FolderID      = folderId;
            file.Title         = fileName;
            file.ContentLength = contentLength;

            var dao           = DaoFactory.GetFileDao <T>();
            var uploadSession = dao.CreateUploadSession(file, contentLength);

            uploadSession.Expired     = uploadSession.Created + ChunkedUploadSessionHolder.SlidingExpiration;
            uploadSession.Location    = FilesLinkUtility.GetUploadChunkLocationUrl(uploadSession.Id);
            uploadSession.TenantId    = TenantManager.GetCurrentTenant().TenantId;
            uploadSession.UserId      = AuthContext.CurrentAccount.ID;
            uploadSession.FolderId    = folderId;
            uploadSession.CultureName = Thread.CurrentThread.CurrentUICulture.Name;
            uploadSession.Encrypted   = encrypted;

            ChunkedUploadSessionHolder.StoreSession(uploadSession);

            return(uploadSession);
        }
Ejemplo n.º 7
0
 public static void AbortUpload(string uploadId)
 {
     AbortUpload(ChunkedUploadSessionHolder.GetSession(uploadId));
 }
Ejemplo n.º 8
0
        private void AbortUpload <T>(ChunkedUploadSession <T> uploadSession)
        {
            DaoFactory.GetFileDao <T>().AbortUploadSession(uploadSession);

            ChunkedUploadSessionHolder.RemoveSession(uploadSession);
        }
Ejemplo n.º 9
0
 public void AbortUpload <T>(string uploadId)
 {
     AbortUpload(ChunkedUploadSessionHolder.GetSession <T>(uploadId));
 }