Пример #1
0
        public async Task <ActionResult <StringResult> > Submit([FromBody] SubmitRequest request)
        {
            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(this.Error("无法确定内容对应的站点"));
            }

            var builder = new StringBuilder();

            foreach (var file in request.Files)
            {
                if (string.IsNullOrEmpty(file.FileName) || string.IsNullOrEmpty(file.Title))
                {
                    continue;
                }

                var filePath = _pathManager.GetTemporaryFilesPath(file.FileName);
                var(_, _, wordContent) = await WordManager.GetWordAsync(_pathManager, site, false, request.IsClearFormat, request.IsFirstLineIndent, request.IsClearFontSize, request.IsClearFontFamily, request.IsClearImages, filePath, file.Title);

                wordContent = await _pathManager.DecodeTextEditorAsync(site, wordContent, true);

                builder.Append(wordContent);
                FileUtils.DeleteFileIfExists(filePath);
            }

            return(new StringResult
            {
                Value = builder.ToString()
            });
        }
Пример #2
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);
        }
Пример #3
0
        public async Task <string> GetContentByTableStyleAsync(string content, string separator, Site site, TableStyle style, string formatString, NameValueCollection attributes, string innerHtml, bool isStlEntity)
        {
            var parsedContent = content;

            var inputType = style.InputType;

            if (inputType == InputType.Date)
            {
                var dateTime = TranslateUtils.ToDateTime(content);
                if (dateTime != Constants.SqlMinValue)
                {
                    if (string.IsNullOrEmpty(formatString))
                    {
                        formatString = DateUtils.FormatStringDateOnly;
                    }
                    parsedContent = DateUtils.Format(dateTime, formatString);
                }
                else
                {
                    parsedContent = string.Empty;
                }
            }
            else if (inputType == InputType.DateTime)
            {
                var dateTime = TranslateUtils.ToDateTime(content);
                if (dateTime != Constants.SqlMinValue)
                {
                    if (string.IsNullOrEmpty(formatString))
                    {
                        formatString = DateUtils.FormatStringDateTime;
                    }
                    parsedContent = DateUtils.Format(dateTime, formatString);
                }
                else
                {
                    parsedContent = string.Empty;
                }
            }
            else if (inputType == InputType.CheckBox || inputType == InputType.Radio || inputType == InputType.SelectMultiple || inputType == InputType.SelectOne)//选择类型
            {
                var selectedTexts  = new List <string>();
                var selectedValues = ListUtils.GetStringList(content);
                var styleItems     = style.Items;
                if (styleItems != null)
                {
                    foreach (var itemInfo in styleItems)
                    {
                        if (selectedValues.Contains(itemInfo.Value))
                        {
                            selectedTexts.Add(isStlEntity ? itemInfo.Value : itemInfo.Label);
                        }
                    }
                }

                parsedContent = separator == null?ListUtils.ToString(selectedTexts) : ListUtils.ToString(selectedTexts, separator);
            }
            //else if (style.InputType == InputType.TextArea)
            //{
            //    parsedContent = StringUtils.ReplaceNewlineToBR(parsedContent);
            //}
            else if (inputType == InputType.TextEditor)
            {
                parsedContent = await _pathManager.DecodeTextEditorAsync(site, parsedContent, true);
            }
            else if (inputType == InputType.Image)
            {
                parsedContent = await GetImageOrFlashHtmlAsync(site, parsedContent, attributes, isStlEntity);
            }
            else if (inputType == InputType.Video)
            {
                parsedContent = await GetVideoHtmlAsync(site, parsedContent, attributes, isStlEntity);
            }
            else if (inputType == InputType.File)
            {
                parsedContent = GetFileHtmlWithoutCount(site, parsedContent, attributes, innerHtml, isStlEntity, false, false);
            }

            return(parsedContent);
        }