Ejemplo n.º 1
0
        public static FileShare Check(string key, IFileDao fileDao, out File file)
        {
            file = null;
            if (string.IsNullOrEmpty(key))
            {
                return(FileShare.Restrict);
            }
            var fileId = Parse(key);

            file = fileDao.GetFile(fileId);
            if (file == null)
            {
                return(FileShare.Restrict);
            }

            var filesSecurity = Global.GetFilesSecurity();

            if (filesSecurity.CanEdit(file, FileConstant.ShareLinkId))
            {
                return(FileShare.ReadWrite);
            }
            if (filesSecurity.CanRead(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Read);
            }
            return(FileShare.Restrict);
        }
Ejemplo n.º 2
0
        public static List <DocServiceParams.RecentDocument> GetRecentEditedDocument(bool forEdit, int count, string crumbsSeporator, IFileDao fileDao)
        {
            var recent = new List <DocServiceParams.RecentDocument>();

            var activity = UserActivityManager.GetUserActivities(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID,
                                                                 ProductEntryPoint.ID, null, UserActivityConstants.AllActionType,
                                                                 new[] { "OpenEditorFile" }, 0, 100);

            foreach (var entryId in activity.Select(userActivity => userActivity.ContentID.Substring("file_".Length)))
            {
                if (recent.Exists(r => r.ID.Equals(entryId)))
                {
                    continue;
                }

                var fileAct = fileDao.GetFile(entryId);

                if (fileAct.RootFolderType == FolderType.TRASH)
                {
                    continue;
                }

                if (!FileUtility.UsingHtml5(fileAct.Title))
                {
                    continue;
                }

                if (!Global.GetFilesSecurity().CanRead(fileAct))
                {
                    continue;
                }

                string uri;
                if (forEdit && Global.GetFilesSecurity().CanEdit(fileAct))
                {
                    uri = CommonLinkUtility.GetFileWebEditorUrl(fileAct.ID);
                }
                else
                {
                    uri = CommonLinkUtility.GetFileWebViewerUrl(fileAct.ID);
                }

                var fileBreadCrumbs = Global.GetBreadCrumbs(fileAct.FolderID);
                recent.Add(new DocServiceParams.RecentDocument
                {
                    ID         = entryId,
                    Title      = fileAct.Title,
                    Uri        = CommonLinkUtility.GetFullAbsolutePath(uri),
                    FolderPath = string.Join(crumbsSeporator, fileBreadCrumbs.Select(folder => folder.Title).ToArray())
                });

                if (recent.Count == count)
                {
                    break;
                }
            }
            return(recent);
        }
Ejemplo n.º 3
0
        public static FileShare Check(string key, IFileDao fileDao, out File file)
        {
            file = null;
            if (string.IsNullOrEmpty(key)) return FileShare.Restrict;
            var fileId = Parse(key);
            file = fileDao.GetFile(fileId);
            if (file == null) return FileShare.Restrict;

            var filesSecurity = Global.GetFilesSecurity();
            if (filesSecurity.CanEdit(file, FileConstant.ShareLinkId)) return FileShare.ReadWrite;
            if (filesSecurity.CanRead(file, FileConstant.ShareLinkId)) return FileShare.Read;
            return FileShare.Restrict;
        }
Ejemplo n.º 4
0
        private void GenerateThumbnail(IFileDao <T> fileDao, FileData <T> fileData)
        {
            File <T> file = null;

            try
            {
                file = fileDao.GetFile(fileData.FileId);

                if (file == null)
                {
                    logger.ErrorFormat("GenerateThumbnail: FileId: {0}. File not found.", fileData.FileId);
                    return;
                }

                if (file.ThumbnailStatus != Thumbnail.Waiting)
                {
                    logger.InfoFormat("GenerateThumbnail: FileId: {0}. Thumbnail already processed.", fileData.FileId);
                    return;
                }

                var ext = FileUtility.GetFileExtension(file.Title);

                if (!config.FormatsArray.Contains(ext) || file.Encrypted || file.RootFolderType == FolderType.TRASH || file.ContentLength > config.AvailableFileSize)
                {
                    file.ThumbnailStatus = Thumbnail.NotRequired;
                    fileDao.SaveThumbnail(file, null);
                    return;
                }

                if (IsImage(file))
                {
                    CropImage(fileDao, file);
                }
                else
                {
                    MakeThumbnail(fileDao, file);
                }
            }
            catch (Exception exception)
            {
                logger.Error(string.Format("GenerateThumbnail: FileId: {0}.", fileData.FileId), exception);
                if (file != null)
                {
                    file.ThumbnailStatus = Thumbnail.Error;
                    fileDao.SaveThumbnail(file, null);
                }
            }
        }
Ejemplo n.º 5
0
        public static FileShare Check(string doc, IFileDao fileDao, out File file)
        {
            file = null;
            if (!FilesSettings.ExternalShare)
            {
                return(FileShare.Restrict);
            }
            if (string.IsNullOrEmpty(doc))
            {
                return(FileShare.Restrict);
            }
            var fileId = Parse(doc);

            file = fileDao.GetFile(fileId);
            if (file == null)
            {
                return(FileShare.Restrict);
            }

            var filesSecurity = Global.GetFilesSecurity();

            if (filesSecurity.CanEdit(file, FileConstant.ShareLinkId))
            {
                return(FileShare.ReadWrite);
            }
            if (filesSecurity.CanCustomFilterEdit(file, FileConstant.ShareLinkId))
            {
                return(FileShare.CustomFilter);
            }
            if (filesSecurity.CanReview(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Review);
            }
            if (filesSecurity.CanFillForms(file, FileConstant.ShareLinkId))
            {
                return(FileShare.FillForms);
            }
            if (filesSecurity.CanComment(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Comment);
            }
            if (filesSecurity.CanRead(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Read);
            }
            return(FileShare.Restrict);
        }
Ejemplo n.º 6
0
        public static List<DocServiceParams.RecentDocument> GetRecentEditedDocument(bool forEdit, int count, string crumbsSeporator, IFileDao fileDao)
        {
            var recent = new List<DocServiceParams.RecentDocument>();

            var activity = UserActivityManager.GetUserActivities(TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID,
                                                                 ProductEntryPoint.ID, null, UserActivityConstants.AllActionType,
                                                                 new[] {"OpenEditorFile"}, 0, 100);

            foreach (var entryId in activity.Select(userActivity => userActivity.ContentID.Substring("file_".Length)))
            {
                if (recent.Exists(r => r.ID.Equals(entryId)))
                    continue;

                var fileAct = fileDao.GetFile(entryId);

                if (fileAct.RootFolderType == FolderType.TRASH)
                    continue;

                if (!FileUtility.UsingHtml5(fileAct.Title))
                    continue;

                if (!Global.GetFilesSecurity().CanRead(fileAct))
                    continue;

                string uri;
                if (forEdit && Global.GetFilesSecurity().CanEdit(fileAct))
                    uri = CommonLinkUtility.GetFileWebEditorUrl(fileAct.ID);
                else
                    uri = CommonLinkUtility.GetFileWebViewerUrl(fileAct.ID);

                var fileBreadCrumbs = Global.GetBreadCrumbs(fileAct.FolderID);
                recent.Add(new DocServiceParams.RecentDocument
                               {
                                   ID = entryId,
                                   Title = fileAct.Title,
                                   Uri = CommonLinkUtility.GetFullAbsolutePath(uri),
                                   FolderPath = string.Join(crumbsSeporator, fileBreadCrumbs.Select(folder => folder.Title).ToArray())
                               });

                if (recent.Count == count)
                    break;
            }
            return recent;
        }
Ejemplo n.º 7
0
        public FileShare Check <T>(string doc, IFileDao <T> fileDao, out File <T> file)
        {
            file = null;
            if (string.IsNullOrEmpty(doc))
            {
                return(FileShare.Restrict);
            }
            var fileId = Parse <T>(doc);

            file = fileDao.GetFile(fileId);
            if (file == null)
            {
                return(FileShare.Restrict);
            }

            var filesSecurity = FileSecurity;

            if (filesSecurity.CanEdit(file, FileConstant.ShareLinkId))
            {
                return(FileShare.ReadWrite);
            }
            if (filesSecurity.CanCustomFilterEdit(file, FileConstant.ShareLinkId))
            {
                return(FileShare.CustomFilter);
            }
            if (filesSecurity.CanReview(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Review);
            }
            if (filesSecurity.CanFillForms(file, FileConstant.ShareLinkId))
            {
                return(FileShare.FillForms);
            }
            if (filesSecurity.CanComment(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Comment);
            }
            if (filesSecurity.CanRead(file, FileConstant.ShareLinkId))
            {
                return(FileShare.Read);
            }
            return(FileShare.Restrict);
        }
Ejemplo n.º 8
0
        public File <TTo> PerformCrossDaoFileCopy <TFrom, TTo>(
            TFrom fromFileId, IFileDao <TFrom> fromFileDao, Func <TFrom, TFrom> fromConverter,
            TTo toFolderId, IFileDao <TTo> toFileDao, Func <TTo, TTo> toConverter,
            bool deleteSourceFile)
        {
            //Get File from first dao
            var fromFile = fromFileDao.GetFile(fromConverter(fromFileId));

            if (fromFile.ContentLength > SetupInfo.AvailableFileSize)
            {
                throw new Exception(string.Format(deleteSourceFile ? FilesCommonResource.ErrorMassage_FileSizeMove : FilesCommonResource.ErrorMassage_FileSizeCopy,
                                                  FileSizeComment.FilesSizeToString(SetupInfo.AvailableFileSize)));
            }

            var securityDao = ServiceProvider.GetService <SecurityDao <TFrom> >();
            var tagDao      = ServiceProvider.GetService <TagDao <TFrom> >();

            var fromFileShareRecords = securityDao.GetPureShareRecords(fromFile).Where(x => x.EntryType == FileEntryType.File);
            var fromFileNewTags      = tagDao.GetNewTags(Guid.Empty, fromFile).ToList();
            var fromFileLockTag      = tagDao.GetTags(fromFile.ID, FileEntryType.File, TagType.Locked).FirstOrDefault();
            var fromFileFavoriteTag  = tagDao.GetTags(fromFile.ID, FileEntryType.File, TagType.Favorite);
            var fromFileTemplateTag  = tagDao.GetTags(fromFile.ID, FileEntryType.File, TagType.Template);

            var toFile = ServiceProvider.GetService <File <TTo> >();

            toFile.Title     = fromFile.Title;
            toFile.Encrypted = fromFile.Encrypted;
            toFile.FolderID  = toConverter(toFolderId);

            fromFile.ID = fromConverter(fromFile.ID);

            var mustConvert = !string.IsNullOrEmpty(fromFile.ConvertedType);

            using (var fromFileStream = mustConvert
                                            ? FileConverter.Exec(fromFile)
                                            : fromFileDao.GetFileStream(fromFile))
            {
                toFile.ContentLength = fromFileStream.CanSeek ? fromFileStream.Length : fromFile.ContentLength;
                toFile = toFileDao.SaveFile(toFile, fromFileStream);
            }

            if (deleteSourceFile)
            {
                if (fromFileShareRecords.Any())
                {
                    fromFileShareRecords.ToList().ForEach(x =>
                    {
                        x.EntryId = toFile.ID;
                        securityDao.SetShare(x);
                    });
                }

                var fromFileTags = fromFileNewTags;
                if (fromFileLockTag != null)
                {
                    fromFileTags.Add(fromFileLockTag);
                }
                if (fromFileFavoriteTag != null)
                {
                    fromFileTags.AddRange(fromFileFavoriteTag);
                }
                if (fromFileTemplateTag != null)
                {
                    fromFileTags.AddRange(fromFileTemplateTag);
                }

                if (fromFileTags.Any())
                {
                    fromFileTags.ForEach(x => x.EntryId = toFile.ID);

                    tagDao.SaveTags(fromFileTags);
                }

                //Delete source file if needed
                fromFileDao.DeleteFile(fromConverter(fromFileId));
            }
            return(toFile);
        }
Ejemplo n.º 9
0
        private static FileShare CheckShareLink(string key, IFileDao fileDao, out File file)
        {
            file = null;

            var fileId = ParseShareLink(key);
            file = fileDao.GetFile(fileId);
            if (file == null)
            {
                return FileShare.Restrict;
            }

            var filesSecurity = Global.GetFilesSecurity();
            if (filesSecurity.CanEdit(file, FileConstant.ShareLinkId))
            {
                return FileShare.ReadWrite;
            }
            if (filesSecurity.CanRead(file, FileConstant.ShareLinkId))
            {
                return FileShare.Read;
            }
            return FileShare.Restrict;
        }