Пример #1
0
        public string CreateCsvReport <TEvent>(IEnumerable <TEvent> events, string reportName) where TEvent : BaseEvent
        {
            try
            {
                using (var stream = new MemoryStream())
                    using (var writer = new StreamWriter(stream, Encoding.UTF8))
                        using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                        {
                            csv.Configuration.RegisterClassMap(new BaseEventMap <TEvent>());

                            csv.WriteHeader <TEvent>();
                            csv.NextRecord();
                            csv.WriteRecords(events);
                            writer.Flush();

                            var file    = FileUploader.Exec(GlobalFolderHelper.FolderMy, reportName, stream.Length, stream, true);
                            var fileUrl = CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.GetFileWebEditorUrl(file.ID));

                            fileUrl += string.Format("&options={{\"delimiter\":{0},\"codePage\":{1}}}",
                                                     (int)FileUtility.CsvDelimiter.Comma,
                                                     Encoding.UTF8.CodePage);
                            return(fileUrl);
                        }
            }
            catch (Exception ex)
            {
                Log.Error("Error while generating login report: " + ex);
                throw;
            }
        }
Пример #2
0
 public GoogleDriveApp(
     PathProvider pathProvider,
     TenantUtil tenantUtil,
     AuthContext authContext,
     SecurityContext securityContext,
     UserManager userManager,
     UserManagerWrapper userManagerWrapper,
     CookiesManager cookiesManager,
     MessageService messageService,
     Global global,
     GlobalStore globalStore,
     EmailValidationKeyProvider emailValidationKeyProvider,
     FilesLinkUtility filesLinkUtility,
     SettingsManager settingsManager,
     PersonalSettingsHelper personalSettingsHelper,
     BaseCommonLinkUtility baseCommonLinkUtility,
     IOptionsMonitor <ILog> option,
     FileUtility fileUtility,
     FilesSettingsHelper filesSettingsHelper,
     IOptionsSnapshot <AccountLinker> snapshot,
     SetupInfo setupInfo,
     GoogleLoginProvider googleLoginProvider,
     TokenHelper tokenHelper,
     DocumentServiceConnector documentServiceConnector,
     ThirdPartyAppHandler thirdPartyAppHandler,
     IServiceProvider serviceProvider,
     TenantManager tenantManager,
     CoreBaseSettings coreBaseSettings,
     CoreSettings coreSettings,
     IConfiguration configuration,
     ICacheNotify <ConsumerCacheItem> cache,
     string name, int order, Dictionary <string, string> additional)
     : base(tenantManager, coreBaseSettings, coreSettings, configuration, cache, name, order, additional)
 {
     Logger                     = option.CurrentValue;
     PathProvider               = pathProvider;
     TenantUtil                 = tenantUtil;
     AuthContext                = authContext;
     SecurityContext            = securityContext;
     UserManager                = userManager;
     UserManagerWrapper         = userManagerWrapper;
     CookiesManager             = cookiesManager;
     MessageService             = messageService;
     Global                     = global;
     GlobalStore                = globalStore;
     EmailValidationKeyProvider = emailValidationKeyProvider;
     FilesLinkUtility           = filesLinkUtility;
     SettingsManager            = settingsManager;
     PersonalSettingsHelper     = personalSettingsHelper;
     BaseCommonLinkUtility      = baseCommonLinkUtility;
     FileUtility                = fileUtility;
     FilesSettingsHelper        = filesSettingsHelper;
     Snapshot                   = snapshot;
     SetupInfo                  = setupInfo;
     GoogleLoginProvider        = googleLoginProvider;
     TokenHelper                = tokenHelper;
     DocumentServiceConnector   = documentServiceConnector;
     ThirdPartyAppHandler       = thirdPartyAppHandler;
     ServiceProvider            = serviceProvider;
 }
Пример #3
0
 public DocuSignHelper(
     DocuSignToken docuSignToken,
     FileSecurity fileSecurity,
     IDaoFactory daoFactory,
     IOptionsMonitor <ILog> options,
     BaseCommonLinkUtility baseCommonLinkUtility,
     UserManager userManager,
     AuthContext authContext,
     DisplayUserSettingsHelper displayUserSettingsHelper,
     FileMarker fileMarker,
     GlobalFolderHelper globalFolderHelper,
     FilesMessageService filesMessageService,
     FilesLinkUtility filesLinkUtility,
     IServiceProvider serviceProvider,
     ConsumerFactory consumerFactory)
 {
     DocuSignToken             = docuSignToken;
     FileSecurity              = fileSecurity;
     DaoFactory                = daoFactory;
     BaseCommonLinkUtility     = baseCommonLinkUtility;
     UserManager               = userManager;
     AuthContext               = authContext;
     DisplayUserSettingsHelper = displayUserSettingsHelper;
     FileMarker                = fileMarker;
     GlobalFolderHelper        = globalFolderHelper;
     FilesMessageService       = filesMessageService;
     FilesLinkUtility          = filesLinkUtility;
     ServiceProvider           = serviceProvider;
     ConsumerFactory           = consumerFactory;
     Log = options.CurrentValue;
 }
Пример #4
0
        public string CreateLoginHistoryReport()
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            string fileUrl;

            var to   = DateTime.UtcNow;
            var from = to.AddMonths(-6);

            var events     = LoginEventsRepository.Get(CurrentTenant, from, to);
            var reportPath = AuditReportCreator.CreateXlsxReport(events);

            try
            {
                var reportName = string.Format(AuditReportResource.LoginHistoryReportName + ".xlsx", from.ToString("MM.dd.yyyy"), to.ToString("MM.dd.yyyy"));
                using (var stream = new FileStream(reportPath, FileMode.Open))
                {
                    var file = FileUploader.Exec(Global.FolderMy.ToString(), reportName, stream.Length, stream, true);
                    fileUrl = FilesLinkUtility.GetFileWebEditorUrl((int)file.ID);
                }
            }
            finally
            {
                AuditReportCreator.DeleteReport(reportPath);
            }

            MessageService.Send(context, MessageAction.LoginHistoryReportDownloaded);

            return(fileUrl);
        }
Пример #5
0
 public FileConverter(
     FileUtility fileUtility,
     FilesLinkUtility filesLinkUtility,
     IDaoFactory daoFactory,
     SetupInfo setupInfo,
     PathProvider pathProvider,
     FileSecurity fileSecurity,
     FileMarker fileMarker,
     TenantManager tenantManager,
     AuthContext authContext,
     EntryManager entryManager,
     IOptionsMonitor <ILog> options,
     FilesSettingsHelper filesSettingsHelper,
     GlobalFolderHelper globalFolderHelper,
     FilesMessageService filesMessageService,
     FileShareLink fileShareLink,
     DocumentServiceHelper documentServiceHelper,
     DocumentServiceConnector documentServiceConnector,
     IServiceProvider serviceProvider,
     IHttpContextAccessor httpContextAccesor)
     : this(fileUtility, filesLinkUtility, daoFactory, setupInfo, pathProvider, fileSecurity,
            fileMarker, tenantManager, authContext, entryManager, options, filesSettingsHelper,
            globalFolderHelper, filesMessageService, fileShareLink, documentServiceHelper, documentServiceConnector,
            serviceProvider)
 {
     HttpContextAccesor = httpContextAccesor;
 }
Пример #6
0
            public EditorConfiguration(
                UserManager userManager,
                AuthContext authContext,
                DisplayUserSettingsHelper displayUserSettingsHelper,
                FilesLinkUtility filesLinkUtility,
                BaseCommonLinkUtility baseCommonLinkUtility,
                PluginsConfig pluginsConfig,
                EmbeddedConfig embeddedConfig,
                CustomizationConfig customizationConfig)
            {
                UserManager           = userManager;
                AuthContext           = authContext;
                FilesLinkUtility      = filesLinkUtility;
                BaseCommonLinkUtility = baseCommonLinkUtility;
                Customization         = customizationConfig;
                Plugins   = pluginsConfig;
                Embedded  = embeddedConfig;
                _userInfo = userManager.GetUsers(authContext.CurrentAccount.ID);

                User = _userInfo.ID.Equals(ASC.Core.Configuration.Constants.Guest.ID)
                           ? new UserConfig
                {
                    Id   = Guid.NewGuid().ToString(),
                    Name = FilesCommonResource.Guest,
                }
                           : new UserConfig
                {
                    Id   = _userInfo.ID.ToString(),
                    Name = _userInfo.DisplayUserName(false, displayUserSettingsHelper),
                };
            }
Пример #7
0
        public ChunkedUploadSession InitiateUpload(string folderId, string fileId, string fileName, long contentLength, bool encrypted)
        {
            if (string.IsNullOrEmpty(folderId))
            {
                folderId = null;
            }

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

            var file = ServiceProvider.GetService <File>();

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

            var dao           = DaoFactory.FileDao;
            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);
        }
Пример #8
0
        private FileWrapper <T> GetFileWrapper <T>(File <T> file)
        {
            var result = Get <FileWrapper <T>, T>(file);

            result.FileExst          = FileUtility.GetFileExtension(file.Title);
            result.FileType          = FileUtility.GetFileTypeByExtention(result.FileExst);
            result.Version           = file.Version;
            result.VersionGroup      = file.VersionGroup;
            result.ContentLength     = file.ContentLengthString;
            result.FileStatus        = file.FileStatus;
            result.PureContentLength = file.ContentLength.NullIfDefault();
            result.Comment           = file.Comment;
            result.Encrypted         = file.Encrypted.NullIfDefault();
            result.Locked            = file.Locked.NullIfDefault();
            result.LockedBy          = file.LockedBy;

            try
            {
                result.ViewUrl = CommonLinkUtility.GetFullAbsolutePath(file.DownloadUrl);

                result.WebUrl = CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.GetFileWebPreviewUrl(FileUtility, file.Title, file.ID));
            }
            catch (Exception)
            {
                //Don't catch anything here because of httpcontext
            }

            return(result);
        }
Пример #9
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);
            }
        }
Пример #10
0
        public static string CreateCsvReport(IEnumerable <AuditEvent> events, string reportName)
        {
            try
            {
                using (var stream = new MemoryStream())
                    using (var writer = new StreamWriter(stream))
                        using (var csv = new CsvWriter(writer))
                        {
                            csv.Configuration.RegisterClassMap <AuditEventMap>();

                            csv.WriteHeader <AuditEvent>();
                            foreach (var evt in events)
                            {
                                csv.WriteRecord(evt);
                            }

                            writer.Flush();

                            var file    = FileUploader.Exec(Global.FolderMy.ToString(), reportName, stream.Length, stream, true);
                            var fileUrl = CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.GetFileWebEditorUrl((int)file.ID));

                            fileUrl += string.Format("&options={{\"delimiter\":{0},\"codePage\":{1}}}",
                                                     (int)FileUtility.CsvDelimiter.Comma,
                                                     Encoding.UTF8.CodePage);
                            return(fileUrl);
                        }
            }
            catch (Exception ex)
            {
                Log.Error("Error while generating audit report: " + ex);
                throw;
            }
        }
Пример #11
0
 public AuditReportCreator(GlobalFolderHelper globalFolderHelper, IOptionsMonitor <ILog> options, FileUploader fileUploader, FilesLinkUtility filesLinkUtility, CommonLinkUtility commonLinkUtility)
 {
     GlobalFolderHelper = globalFolderHelper;
     Log               = options.CurrentValue;
     FileUploader      = fileUploader;
     FilesLinkUtility  = filesLinkUtility;
     CommonLinkUtility = commonLinkUtility;
 }
Пример #12
0
 public FileDownloadOperationScope(GlobalStore globalStore, FilesLinkUtility filesLinkUtility, SetupInfo setupInfo, FileConverter fileConverter, FilesMessageService filesMessageService)
 {
     GlobalStore         = globalStore;
     FilesLinkUtility    = filesLinkUtility;
     SetupInfo           = setupInfo;
     FileConverter       = fileConverter;
     FilesMessageService = filesMessageService;
 }
Пример #13
0
 public void Deconstruct(out GlobalStore globalStore, out FilesLinkUtility filesLinkUtility, out SetupInfo setupInfo, out FileConverter fileConverter, out FilesMessageService filesMessageService)
 {
     globalStore         = GlobalStore;
     filesLinkUtility    = FilesLinkUtility;
     setupInfo           = SetupInfo;
     fileConverter       = FileConverter;
     filesMessageService = FilesMessageService;
 }
Пример #14
0
 public FileHelper(FileTrackerHelper fileTracker, FilesLinkUtility filesLinkUtility, FileUtility fileUtility, FileConverter fileConverter, Global global)
 {
     FileTracker      = fileTracker;
     FilesLinkUtility = filesLinkUtility;
     FileUtility      = fileUtility;
     FileConverter    = fileConverter;
     Global           = global;
 }
Пример #15
0
        private void RequestCode(HttpContext context)
        {
            var token = GetToken(context.Request.Query["code"]);

            if (token == null)
            {
                Logger.Error("BoxApp: token is null");
                throw new SecurityException("Access token is null");
            }

            var boxUserId = context.Request.Query["userId"];

            if (AuthContext.IsAuthenticated)
            {
                if (!CurrentUser(boxUserId))
                {
                    Logger.Debug("BoxApp: logout for " + boxUserId);
                    CookiesManager.ClearCookies(CookiesType.AuthKey);
                    AuthContext.Logout();
                }
            }

            if (!AuthContext.IsAuthenticated)
            {
                var userInfo = GetUserInfo(token, out var isNew);

                if (userInfo == null)
                {
                    Logger.Error("BoxApp: UserInfo is null");
                    throw new Exception("Profile is null");
                }

                var cookiesKey = SecurityContext.AuthenticateMe(userInfo.ID);
                CookiesManager.SetCookies(CookiesType.AuthKey, cookiesKey);
                MessageService.Send(MessageAction.LoginSuccessViaSocialApp);

                if (isNew)
                {
                    var userHelpTourSettings = SettingsManager.LoadForCurrentUser <UserHelpTourSettings>();
                    userHelpTourSettings.IsNewUser = true;
                    SettingsManager.SaveForCurrentUser(userHelpTourSettings);

                    PersonalSettingsHelper.IsNewUser      = true;
                    PersonalSettingsHelper.IsNotActivated = true;
                }

                if (!string.IsNullOrEmpty(boxUserId) && !CurrentUser(boxUserId))
                {
                    AddLinker(boxUserId);
                }
            }

            TokenHelper.SaveToken(token);

            var fileId = context.Request.Query["id"];

            context.Response.Redirect(FilesLinkUtility.GetFileWebEditorUrl(ThirdPartySelector.BuildAppFileId(AppAttr, fileId)), true);
        }
Пример #16
0
        private void EditDocument(int attachment_id, HttpContext context)
        {
            var mail_box_manager = new MailBoxManager(0);
            var file             = mail_box_manager.GetMessageAttachment(attachment_id, TenantId, Username);
            var temp_file_url    = MailStoragePathCombiner.GetPreSignedUrl(file);
            var editor_url       = FilesLinkUtility.GetFileWebEditorExternalUrl(temp_file_url, file.fileName);

            editor_url = new UriBuilder(CommonLinkUtility.GetFullAbsolutePath(editor_url)).ToString();
            context.Response.Redirect(editor_url, false);
        }
Пример #17
0
        private void RequestCode(HttpContext context)
        {
            var token = GetToken(context.Request["code"]);

            if (token == null)
            {
                Global.Logger.Error("BoxApp: token is null");
                throw new SecurityException("Access token is null");
            }

            var boxUserId = context.Request["userId"];

            if (SecurityContext.IsAuthenticated)
            {
                if (!CurrentUser(boxUserId))
                {
                    Global.Logger.Debug("BoxApp: logout for " + boxUserId);
                    CookiesManager.ClearCookies(CookiesType.AuthKey);
                    SecurityContext.Logout();
                }
            }

            if (!SecurityContext.IsAuthenticated)
            {
                bool isNew;
                var  userInfo = GetUserInfo(token, out isNew);

                if (userInfo == null)
                {
                    Global.Logger.Error("BoxApp: UserInfo is null");
                    throw new Exception("Profile is null");
                }

                CookiesManager.AuthenticateMeAndSetCookies(userInfo.Tenant, userInfo.ID, MessageAction.LoginSuccessViaSocialApp);

                if (isNew)
                {
                    UserHelpTourHelper.IsNewUser    = true;
                    PersonalSettings.IsNewUser      = true;
                    PersonalSettings.IsNotActivated = true;
                }

                if (!string.IsNullOrEmpty(boxUserId) && !CurrentUser(boxUserId))
                {
                    AddLinker(boxUserId);
                }
            }

            Token.SaveToken(token);

            var fileId = context.Request["id"];

            context.Response.Redirect(FilesLinkUtility.GetFileWebEditorUrl(ThirdPartySelector.BuildAppFileId(AppAttr, fileId)), true);
        }
Пример #18
0
        private void ViewDocument(int attachmentId, HttpContext context)
        {
            var mailBoxManager = new MailBoxManager();
            var file           = mailBoxManager.GetMessageAttachment(attachmentId, TenantId, Username);
            var tempFileUrl    = MailStoragePathCombiner.GetPreSignedUrl(file);

            var viewerUrl = FilesLinkUtility.GetFileWebViewerExternalUrl(tempFileUrl, file.fileName);

            viewerUrl = new UriBuilder(CommonLinkUtility.GetFullAbsolutePath(viewerUrl)).ToString();
            context.Response.Redirect(viewerUrl, false);
        }
Пример #19
0
        private static void CreateFile(HttpContext context)
        {
            var folderId = context.Request[FilesLinkUtility.FolderId];

            if (string.IsNullOrEmpty(folderId))
            {
                folderId = Global.FolderMy.ToString();
            }
            Folder folder;

            using (var folderDao = Global.DaoFactory.GetFolderDao())
            {
                folder = folderDao.GetFolder(folderId);
            }
            if (folder == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, FilesCommonResource.ErrorMassage_FolderNotFound);
            }
            if (!Global.GetFilesSecurity().CanCreate(folder))
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            File file      = null;
            var  fileUri   = context.Request[FilesLinkUtility.FileUri];
            var  fileTitle = context.Request[FilesLinkUtility.FileTitle];

            try
            {
                if (!string.IsNullOrEmpty(fileUri))
                {
                    file = CreateFileFromUri(folder, fileUri, fileTitle);
                }
                else
                {
                    var template = context.Request["template"];
                    var docType  = context.Request["doctype"];
                    file = CreateFileFromTemplate(folder, template, fileTitle, docType);
                }
            }
            catch (Exception ex)
            {
                Global.Logger.Error(ex);
                context.Response.Redirect(PathProvider.StartURL + "#error/" + ex.Message);
            }

            FileMarker.MarkAsNew(file);

            context.Response.Redirect(
                (context.Request["openfolder"] ?? "").Equals("true")
                    ? PathProvider.GetFolderUrl(file.FolderID)
                    : FilesLinkUtility.GetFileWebEditorUrl(file.ID));
        }
Пример #20
0
        private static void EditDocument(int attachmentId, HttpContext context)
        {
            var engine = new EngineFactory(TenantId, Username);
            var file   = engine.AttachmentEngine.GetAttachment(
                new ConcreteUserAttachmentExp(attachmentId, TenantId, Username));

            var tempFileUrl = MailStoragePathCombiner.GetPreSignedUrl(file);
            var editorUrl   = FilesLinkUtility.GetFileWebEditorExternalUrl(tempFileUrl, file.fileName);

            editorUrl = new UriBuilder(CommonLinkUtility.GetFullAbsolutePath(editorUrl)).ToString();
            context.Response.Redirect(editorUrl, false);
        }
Пример #21
0
 /// <summary>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="fileStorageService"></param>
 public FilesControllerHelper(
     ApiContext context,
     FileStorageService <T> fileStorageService,
     FileWrapperHelper fileWrapperHelper,
     FilesSettingsHelper filesSettingsHelper,
     FilesLinkUtility filesLinkUtility,
     FileUploader fileUploader,
     DocumentServiceHelper documentServiceHelper,
     TenantManager tenantManager,
     SecurityContext securityContext,
     FolderWrapperHelper folderWrapperHelper,
     FileOperationWraperHelper fileOperationWraperHelper,
     FileShareWrapperHelper fileShareWrapperHelper,
     FileShareParamsHelper fileShareParamsHelper,
     EntryManager entryManager,
     FolderContentWrapperHelper folderContentWrapperHelper,
     ChunkedUploadSessionHelper chunkedUploadSessionHelper,
     DocumentServiceTrackerHelper documentServiceTracker,
     IOptionsMonitor <ILog> optionMonitor,
     SettingsManager settingsManager,
     EncryptionKeyPairHelper encryptionKeyPairHelper,
     IHttpContextAccessor httpContextAccessor,
     FileConverter fileConverter,
     ApiDateTimeHelper apiDateTimeHelper,
     UserManager userManager,
     DisplayUserSettingsHelper displayUserSettingsHelper)
 {
     ApiContext                 = context;
     FileStorageService         = fileStorageService;
     FileWrapperHelper          = fileWrapperHelper;
     FilesSettingsHelper        = filesSettingsHelper;
     FilesLinkUtility           = filesLinkUtility;
     FileUploader               = fileUploader;
     DocumentServiceHelper      = documentServiceHelper;
     TenantManager              = tenantManager;
     SecurityContext            = securityContext;
     FolderWrapperHelper        = folderWrapperHelper;
     FileOperationWraperHelper  = fileOperationWraperHelper;
     FileShareWrapperHelper     = fileShareWrapperHelper;
     FileShareParamsHelper      = fileShareParamsHelper;
     EntryManager               = entryManager;
     FolderContentWrapperHelper = folderContentWrapperHelper;
     ChunkedUploadSessionHelper = chunkedUploadSessionHelper;
     DocumentServiceTracker     = documentServiceTracker;
     SettingsManager            = settingsManager;
     EncryptionKeyPairHelper    = encryptionKeyPairHelper;
     ApiDateTimeHelper          = apiDateTimeHelper;
     UserManager                = userManager;
     DisplayUserSettingsHelper  = displayUserSettingsHelper;
     HttpContextAccessor        = httpContextAccessor;
     FileConverter              = fileConverter;
     Logger = optionMonitor.Get("ASC.Files");
 }
Пример #22
0
 public FileShareLink(
     FileUtility fileUtility,
     FilesLinkUtility filesLinkUtility,
     BaseCommonLinkUtility baseCommonLinkUtility,
     Global global,
     FileSecurity fileSecurity)
 {
     FileUtility           = fileUtility;
     FilesLinkUtility      = filesLinkUtility;
     BaseCommonLinkUtility = baseCommonLinkUtility;
     Global       = global;
     FileSecurity = fileSecurity;
 }
Пример #23
0
 public File(Global global,
             FilesLinkUtility filesLinkUtility,
             FileUtility fileUtility,
             FileConverter fileConverter)
     : base(global)
 {
     Version          = 1;
     VersionGroup     = 1;
     FileEntryType    = FileEntryType.File;
     FilesLinkUtility = filesLinkUtility;
     FileUtility      = fileUtility;
     FileConverter    = fileConverter;
 }
Пример #24
0
        private Feed ToFeed(Tuple <File, SmallShareRecord> tuple)
        {
            var file        = tuple.Item1;
            var shareRecord = tuple.Item2;

            var rootFolder = new FolderDao(Tenant, DbId).GetFolder(file.FolderID);

            if (shareRecord != null)
            {
                var feed = new Feed(shareRecord.ShareBy, shareRecord.ShareOn, true)
                {
                    Item             = sharedFileItem,
                    ItemId           = string.Format("{0}_{1}", file.ID, shareRecord.ShareTo),
                    ItemUrl          = FilesLinkUtility.GetFileRedirectPreviewUrl(file.ID, true),
                    Product          = Product,
                    Module           = Name,
                    Title            = file.Title,
                    ExtraLocation    = rootFolder.FolderType == FolderType.DEFAULT ? rootFolder.Title : string.Empty,
                    ExtraLocationUrl = rootFolder.FolderType == FolderType.DEFAULT ? FilesLinkUtility.GetFileRedirectPreviewUrl(file.FolderID, false) : string.Empty,
                    AdditionalInfo   = file.ContentLengthString,
                    Keywords         = string.Format("{0}", file.Title),
                    HasPreview       = false,
                    CanComment       = false,
                    Target           = shareRecord.ShareTo,
                    GroupId          = GetGroupId(sharedFileItem, shareRecord.ShareBy, file.FolderID.ToString())
                };

                return(feed);
            }

            var updated = file.Version != 1;

            return(new Feed(file.ModifiedBy, file.ModifiedOn, true)
            {
                Item = fileItem,
                ItemId = string.Format("{0}_{1}", file.ID, file.Version > 1 ? 1 : 0),
                ItemUrl = FilesLinkUtility.GetFileRedirectPreviewUrl(file.ID, true),
                Product = Product,
                Module = Name,
                Action = updated ? FeedAction.Updated : FeedAction.Created,
                Title = file.Title,
                ExtraLocation = rootFolder.FolderType == FolderType.DEFAULT ? rootFolder.Title : string.Empty,
                ExtraLocationUrl = rootFolder.FolderType == FolderType.DEFAULT ? FilesLinkUtility.GetFileRedirectPreviewUrl(file.FolderID, false) : string.Empty,
                AdditionalInfo = file.ContentLengthString,
                Keywords = string.Format("{0}", file.Title),
                HasPreview = false,
                CanComment = false,
                Target = null,
                GroupId = GetGroupId(fileItem, file.ModifiedBy, file.FolderID.ToString(), updated ? 1 : 0)
            });
        }
Пример #25
0
        public static void SendShareNotice(FileEntry fileEntry, Dictionary <Guid, FileShare> recipients, string message)
        {
            if (fileEntry == null || recipients.Count == 0)
            {
                return;
            }

            using (var folderDao = Global.DaoFactory.GetFolderDao())
            {
                if (fileEntry is File &&
                    folderDao.GetFolder(((File)fileEntry).FolderID) == null)
                {
                    return;
                }

                String url;
                if (fileEntry is File)
                {
                    url = FilesLinkUtility.GetFileWebPreviewUrl(fileEntry.Title, fileEntry.ID);
                }
                else
                {
                    url = PathProvider.GetFolderUrl(((Folder)fileEntry));
                }

                var recipientsProvider = NotifySource.Instance.GetRecipientsProvider();

                foreach (var recipientPair in recipients)
                {
                    var u       = CoreContext.UserManager.GetUsers(recipientPair.Key);
                    var culture = string.IsNullOrEmpty(u.CultureName)
                                      ? CoreContext.TenantManager.GetCurrentTenant().GetCulture()
                                      : CultureInfo.GetCultureInfo(u.CultureName);

                    var aceString = GetAccessString(recipientPair.Value, culture);
                    var recipient = recipientsProvider.GetRecipient(u.ID.ToString());

                    Instance.SendNoticeAsync(
                        fileEntry is File ? NotifyConstants.Event_ShareDocument : NotifyConstants.Event_ShareFolder,
                        fileEntry.UniqID,
                        recipient,
                        true,
                        new TagValue(NotifyConstants.Tag_DocumentTitle, fileEntry.Title),
                        new TagValue(NotifyConstants.Tag_FolderID, fileEntry.ID),
                        new TagValue(NotifyConstants.Tag_DocumentUrl, CommonLinkUtility.GetFullAbsolutePath(url)),
                        new TagValue(NotifyConstants.Tag_AccessRights, aceString),
                        new TagValue(NotifyConstants.Tag_Message, message.HtmlEncode())
                        );
                }
            }
        }
        private void OutputData(Report report, string result, string reportName, ReportViewType outputFormat)
        {
            switch (outputFormat)
            {
                case ReportViewType.Html:
                    reportResult.Text = result;

                    var sb = new StringBuilder();
                    sb.Append("<div class='report-name'>");
                    sb.Append(reportName);
                    sb.Append("<span class='generation-date'> (");
                    sb.Append(TenantUtil.DateTimeNow().ToString(DateTimeExtension.ShortDatePattern));
                    sb.Append(")</span>");
                    sb.Append("</div>");
                    reportFilter.Text = sb.ToString();
                    break;

                case ReportViewType.Xml:
                case ReportViewType.EMail:
                    if (result != null)
                    {
                        var ext = outputFormat.ToString().ToLower();
                        Response.Clear();
                        Response.ContentType = "text/" + ext + "; charset=utf-8";
                        Response.ContentEncoding = Encoding.UTF8;
                        Response.Charset = Encoding.UTF8.WebName;
                        Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.{1}", report.FileName, ext));
                        Response.Write(result);
                        Response.End();
                    }
                    break;

                case ReportViewType.Csv:
                    string fileURL;

                    using (var memStream = new MemoryStream(Encoding.UTF8.GetBytes(result)))
                    {
                        var file = FileUploader.Exec(Files.Classes.Global.FolderMy.ToString(), report.FileName + ".csv", result.Length, memStream, true);

                        fileURL = FilesLinkUtility.GetFileWebEditorUrl((int)file.ID);
                        fileURL += string.Format("&options={{\"delimiter\":{0},\"codePage\":{1}}}",
                                                 (int)Global.ReportCsvDelimiter.Key,
                                                 Encoding.UTF8.CodePage);
                    }

                    Response.Redirect(fileURL);

                    break;
            }
        }
Пример #27
0
 public FoldersModule(
     TenantManager tenantManager,
     UserManager userManager,
     WebItemSecurity webItemSecurity,
     FilesLinkUtility filesLinkUtility,
     FileSecurity fileSecurity,
     IDaoFactory daoFactory)
     : base(tenantManager, webItemSecurity)
 {
     UserManager      = userManager;
     FilesLinkUtility = filesLinkUtility;
     FileSecurity     = fileSecurity;
     FolderDao        = daoFactory.GetFolderDao <int>();
 }
Пример #28
0
        public static string GetLink(File file)
        {
            var url = file.ViewUrl;

            if (!FileUtility.CanImageView(file.Title))
            {
                url = FilesLinkUtility.GetFileWebPreviewUrl(file.Title, file.ID);
            }

            var linkParams = CreateKey(file.ID.ToString());

            url += "&" + FilesLinkUtility.DocShareKey + "=" + HttpUtility.UrlEncode(linkParams);

            return(CommonLinkUtility.GetFullAbsolutePath(url));
        }
Пример #29
0
        public override SearchResultItem[] Search(string text)
        {
            using (var folderDao = Global.DaoFactory.GetFolderDao())
            {
                var result = SearchFiles(text)
                             .Select(r =>
                {
                    var folders = EntryManager.GetBreadCrumbs(r.FolderID, folderDao);
                    return(new SearchResultItem
                    {
                        Name = r.Title ?? string.Empty,
                        Description = string.Empty,
                        URL = FilesLinkUtility.GetFileWebPreviewUrl(r.Title, r.ID),
                        Date = r.ModifiedOn,
                        Additional = new Dictionary <string, object>
                        {
                            { "Author", r.CreateByString.HtmlEncode() },
                            { "Path", FolderPathBuilder(folders) },
                            { "FullPath", FolderFullPathBuilder(folders) },
                            { "FolderUrl", PathProvider.GetFolderUrl(r.FolderID) },
                            { "Size", FileSizeComment.FilesSizeToString(r.ContentLength) }
                        }
                    });
                });

                var resultFolder = SearchFolders(text)
                                   .Select(f =>
                {
                    var folders = EntryManager.GetBreadCrumbs(f.ID, folderDao);
                    return(new SearchResultItem
                    {
                        Name = f.Title ?? string.Empty,
                        Description = String.Empty,
                        URL = PathProvider.GetFolderUrl(f),
                        Date = f.ModifiedOn,
                        Additional = new Dictionary <string, object>
                        {
                            { "Author", f.CreateByString.HtmlEncode() },
                            { "Path", FolderPathBuilder(folders) },
                            { "FullPath", FolderFullPathBuilder(folders) },
                            { "IsFolder", true }
                        }
                    });
                });

                return(result.Concat(resultFolder).ToArray());
            }
        }
Пример #30
0
        private static String SaveCSVFileInMyDocument(String title, String data)
        {
            string fileURL;

            using (var memStream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var file = FileUploader.Exec(Files.Classes.Global.FolderMy.ToString(), title, data.Length, memStream, true);

                fileURL = FilesLinkUtility.GetFileWebEditorUrl((int)file.ID);
            }
            fileURL += string.Format("&options={{\"delimiter\":{0},\"codePage\":{1}}}",
                                     (int)FileUtility.CsvDelimiter.Comma,
                                     Encoding.UTF8.CodePage);

            return(fileURL);
        }