Пример #1
0
        public static async Task <string> ExportRelatedFieldListAsync(IPathManager pathManager, IDatabaseManager databaseManager, int siteId)
        {
            var directoryPath = pathManager.GetTemporaryFilesPath("relatedField");
            var filePath      = pathManager.GetTemporaryFilesPath("relatedField.zip");

            FileUtils.DeleteFileIfExists(filePath);
            DirectoryUtils.DeleteDirectoryIfExists(directoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(directoryPath);

            var site = await databaseManager.SiteRepository.GetAsync(siteId);

            var relatedFieldInfoList = await databaseManager.RelatedFieldRepository.GetRelatedFieldsAsync(siteId);

            var relatedFieldIe = new RelatedFieldIe(databaseManager, site, directoryPath);

            foreach (var relatedFieldInfo in relatedFieldInfoList)
            {
                await relatedFieldIe.ExportRelatedFieldAsync(relatedFieldInfo);
            }

            pathManager.CreateZip(filePath, directoryPath);

            DirectoryUtils.DeleteDirectoryIfExists(directoryPath);

            return(PathUtils.GetFileName(filePath));
        }
Пример #2
0
        public async Task ExportFilesAsync(string filePath)
        {
            var filesDirectoryPath = PathUtils.Combine(DirectoryUtils.GetDirectoryPath(filePath), PathUtils.GetFileNameWithoutExtension(filePath));

            DirectoryUtils.DeleteDirectoryIfExists(filesDirectoryPath);
            FileUtils.DeleteFileIfExists(filePath);

            var sitePath = await _pathManager.GetSitePathAsync(_site);

            DirectoryUtils.Copy(sitePath, filesDirectoryPath);

            _pathManager.CreateZip(filePath, filesDirectoryPath);

            DirectoryUtils.DeleteDirectoryIfExists(filesDirectoryPath);
        }
Пример #3
0
        public static async Task <(string title, string imageUrl, string body)> GetWordAsync(IPathManager pathManager, Site siteInfo, bool isFirstLineTitle, bool isClearFormat, bool isFirstLineIndent, bool isClearFontSize, bool isClearFontFamily, bool isClearImages, string docsFilePath, string docsFileTitle)
        {
            string imageDirectoryPath;
            string imageDirectoryUrl;

            if (siteInfo != null)
            {
                imageDirectoryPath = await pathManager.GetUploadDirectoryPathAsync(siteInfo, UploadType.Image);

                imageDirectoryUrl = await pathManager.GetSiteUrlByPhysicalPathAsync(siteInfo, imageDirectoryPath, true);
            }
            else
            {
                var fileName = PathUtils.GetFileName(docsFilePath);
                imageDirectoryPath = PathUtils.Combine(pathManager.WebRootPath, PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Image));
                imageDirectoryUrl  = PathUtils.GetMaterialVirtualFilePath(UploadType.Image, fileName);
            }

            var settings = new ConverterSettings
            {
                IsFirstLineTitle   = isFirstLineTitle,
                IsClearFormat      = isClearFormat,
                IsFirstLineIndent  = isFirstLineIndent,
                IsClearFontSize    = isClearFontSize,
                IsClearFontFamily  = isClearFontFamily,
                IsClearImages      = isClearImages,
                ImageDirectoryPath = imageDirectoryPath,
                ImageDirectoryUrl  = imageDirectoryUrl,
                IsSaveHtml         = false
            };

            var(title, imageUrl, body) = ConvertToHtml(docsFilePath, settings);

            FileUtils.DeleteFileIfExists(docsFilePath);

            if (siteInfo != null)
            {
                body = await pathManager.DecodeTextEditorAsync(siteInfo, body, true);
            }

            if (string.IsNullOrEmpty(title))
            {
                title = docsFileTitle;
            }

            return(title, imageUrl, body);
        }
Пример #4
0
        public async Task <bool> ExportContentsAsync(string filePath, List <Content> contentInfoList)
        {
            var siteContentDirectoryPath = PathUtils.Combine(DirectoryUtils.GetDirectoryPath(filePath), PathUtils.GetFileNameWithoutExtension(filePath));

            FileUtils.DeleteFileIfExists(filePath);
            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(siteContentDirectoryPath);

            var contentIe = new ContentIe(_pathManager, _databaseManager, _caching, _site, siteContentDirectoryPath);
            var isExport  = await contentIe.ExportContentsAsync(_site, contentInfoList);

            if (isExport)
            {
                _pathManager.CreateZip(filePath, siteContentDirectoryPath);
                DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            }
            return(isExport);
        }
Пример #5
0
        public async Task <bool> ExportContentsAsync(string filePath, int channelId, List <int> contentIdArrayList, bool isPeriods, string dateFrom, string dateTo, bool?checkedState)
        {
            var siteContentDirectoryPath = PathUtils.Combine(DirectoryUtils.GetDirectoryPath(filePath), PathUtils.GetFileNameWithoutExtension(filePath));

            FileUtils.DeleteFileIfExists(filePath);
            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(siteContentDirectoryPath);

            var contentIe = new ContentIe(_pathManager, _databaseManager, _caching, _site, siteContentDirectoryPath);
            var isExport  = await contentIe.ExportContentsAsync(_site, channelId, contentIdArrayList, isPeriods, dateFrom, dateTo, checkedState);

            if (isExport)
            {
                _pathManager.CreateZip(filePath, siteContentDirectoryPath);
                DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            }
            return(isExport);
        }
Пример #6
0
        public async Task ExportFilesToSiteAsync(string siteTemplatePath, bool isAllFiles, IList <string> directories, IList <string> files, bool isCreateMetadataDirectory)
        {
            DirectoryUtils.CreateDirectoryIfNotExists(siteTemplatePath);

            var siteDirList = await _databaseManager.SiteRepository.GetSiteDirsAsync(0);

            var sitePath = await _pathManager.GetSitePathAsync(_site);

            var directoryNames = DirectoryUtils.GetDirectoryNames(sitePath);
            var fileNames      = DirectoryUtils.GetFileNames(sitePath);

            foreach (var directoryName in directoryNames)
            {
                var srcPath  = PathUtils.Combine(sitePath, directoryName);
                var destPath = PathUtils.Combine(siteTemplatePath, directoryName);

                if (!isAllFiles && !ListUtils.ContainsIgnoreCase(directories, directoryName))
                {
                    continue;
                }

                var isSiteDirectory = false;

                if (_site.Root)
                {
                    foreach (var siteDir in siteDirList)
                    {
                        if (StringUtils.EqualsIgnoreCase(siteDir, directoryName))
                        {
                            isSiteDirectory = true;
                        }
                    }
                }
                if (!isSiteDirectory && !_pathManager.IsSystemDirectory(directoryName))
                {
                    DirectoryUtils.CreateDirectoryIfNotExists(destPath);
                    DirectoryUtils.MoveDirectory(srcPath, destPath, false);
                }
            }

            foreach (var fileName in fileNames)
            {
                var srcPath  = PathUtils.Combine(sitePath, fileName);
                var destPath = PathUtils.Combine(siteTemplatePath, fileName);

                if (!isAllFiles && !ListUtils.ContainsIgnoreCase(files, fileName))
                {
                    continue;
                }

                FileUtils.CopyFile(srcPath, destPath);
            }

            //var fileSystems = FileUtility.GetFileSystemInfoExtendCollection(await _pathManager.GetSitePathAsync(_site));
            //foreach (FileSystemInfoExtend fileSystem in fileSystems)
            //{
            //    var srcPath = PathUtils.Combine(sitePath, fileSystem.Name);
            //    var destPath = PathUtils.Combine(siteTemplatePath, fileSystem.Name);

            //    if (fileSystem.IsDirectory)
            //    {
            //        if (!isAllFiles && !StringUtils.ContainsIgnoreCase(directories, fileSystem.Name)) continue;

            //        var isSiteDirectory = false;

            //        if (_site.Root)
            //        {
            //            foreach (var siteDir in siteDirList)
            //            {
            //                if (StringUtils.EqualsIgnoreCase(siteDir, fileSystem.Name))
            //                {
            //                    isSiteDirectory = true;
            //                }
            //            }
            //        }
            //        if (!isSiteDirectory && !_pathManager.IsSystemDirectory(fileSystem.Name))
            //        {
            //            DirectoryUtils.CreateDirectoryIfNotExists(destPath);
            //            DirectoryUtils.MoveDirectory(srcPath, destPath, false);
            //        }
            //    }
            //    else
            //    {
            //        if (!isAllFiles && !StringUtils.ContainsIgnoreCase(files, fileSystem.Name)) continue;

            //        FileUtils.CopyFile(srcPath, destPath);
            //    }
            //}

            if (isCreateMetadataDirectory)
            {
                var siteTemplateMetadataPath = _pathManager.GetSiteTemplateMetadataPath(siteTemplatePath, string.Empty);
                DirectoryUtils.CreateDirectoryIfNotExists(siteTemplateMetadataPath);
            }
        }