Пример #1
0
        /// <summary>
        /// Gets the name of the exported file.
        /// </summary>
        /// <param name="appealLetter">The appeal letter container.</param>
        /// <param name="reportVirtualPath">The report virtual path.</param>
        /// <param name="fileBaseName">Name of the file base.</param>
        /// <returns></returns>
        public static string[] GetExportedFileName(AppealLetter appealLetter, string reportVirtualPath, string fileBaseName)
        {
            string fileName;

            if (appealLetter.ReportThreshold == Constants.ReportThreshold) // Exceeded threshold limit
            {
                fileName = Convert.ToString(Constants.ReportThreshold);
            }
            else if (appealLetter.AppealLetterClaims.Count == 0) //No Records Found
            {
                fileName = Constants.EmptyReportResult;
            }
            else
            {
                _appealLetter = appealLetter;
                string dateTimeStamp = DateTime.Now.ToString(Constants.DateTimeExtendedFormat);
                fileName  = string.Format("{0}{1}.{2}", fileBaseName, dateTimeStamp, Constants.AppealLetterFileExtension);
                _filePath = Path.Combine(reportVirtualPath, fileName);
                //Build rtf document object
                RtfDocument rtfDocument = GetRtfDocument();

                //Get rtf content String
                RtfWriter rtfWriter          = new RtfWriter();
                string    templateRtfContent = rtfWriter.GetRtfContent(rtfDocument);
                //loop through each claim data and replace claim text and merge rtf content
                string finalRtfContent = _appealLetter.AppealLetterClaims.Select(
                    appealLetterClaim => ReplaceClaimData(templateRtfContent, appealLetterClaim))
                                         .Aggregate(string.Empty,
                                                    (current, rtfClaimText) =>
                                                    !string.IsNullOrEmpty(current)
                                ? MergeRtfContent(current, rtfClaimText)
                                : rtfClaimText);

                //Write rtf content into file
                using (TextWriter writer = new StreamWriter(_filePath))
                {
                    rtfWriter.Write(writer, finalRtfContent);
                }
                if (appealLetter.IsPreview)
                {
                    return(new[] { appealLetter.LetterTemplaterText, fileName });
                }
            }
            return(new[] { fileName });
        }
Пример #2
0
        public static string JsonArticleToRtfTranslate(JObject article, string targetLanguage, SetValue setValueCallback)
        {
            int counter             = 0;
            var rtf                 = new RtfDocument();
            var listOfDocumentParts = new List <RtfDocumentContentBase>();

            var titleParagraph = new RtfFormattedParagraph(new RtfParagraphFormatting(16, RtfTextAlign.Center));

            if (article["metadata"] != null && article["metadata"]["title"] != null)
            {
                setValueCallback(counter++);
                var translatedTitle = GoogleTranslate.Translate(article["metadata"]["title"].ToString(), targetLanguage);
                titleParagraph.AppendText(
                    new RtfFormattedText(translatedTitle, RtfCharacterFormatting.Bold));
            }
            titleParagraph.AppendParagraph();
            listOfDocumentParts.Add(titleParagraph);

            if (article["metadata"] != null && article["metadata"]["authors"]?.Children() != null)
            {
                foreach (var author in article["metadata"]["authors"].Children())
                {
                    var authorParagraph = new RtfFormattedParagraph(new RtfParagraphFormatting(14, RtfTextAlign.Left));
                    var authorLine      = GetAuthor(author);

                    if (authorLine.ToString().Length >= 10)
                    {
                        // We should not add some dummy values.
                        var authorLineAsString = authorLine.Substring(0, authorLine.Length - 2);
                        authorParagraph.AppendText(authorLineAsString);
                        listOfDocumentParts.Add(authorParagraph);
                    }
                }
            }

            // Add abstract.
            var abstractParagraph = new RtfFormattedParagraph(new RtfParagraphFormatting(12, RtfTextAlign.Left));

            abstractParagraph.AppendParagraph();
            if (article["abstract"] != null && article["abstract"].Children().Count() > 0)
            {
                foreach (var articleAbstract in article["abstract"].Children())
                {
                    var translatedAbstract = GoogleTranslate.Translate(articleAbstract["text"].ToString(), targetLanguage);
                    setValueCallback(counter++);
                    abstractParagraph.AppendText(
                        new RtfFormattedText(translatedAbstract, RtfCharacterFormatting.Italic));
                    abstractParagraph.AppendParagraph();
                }
            }
            listOfDocumentParts.Add(abstractParagraph);

            // Add content.
            if (article["body_text"] != null && article["body_text"].Children().Count() > 0)
            {
                foreach (var bodyText in article["body_text"].Children())
                {
                    var contentParagraph = new RtfFormattedParagraph(new RtfParagraphFormatting(12, RtfTextAlign.Left));
                    setValueCallback(counter++);
                    var translatedBody = GoogleTranslate.Translate(bodyText["text"].ToString(), targetLanguage);
                    contentParagraph.AppendText(translatedBody);
                    contentParagraph.AppendParagraph();
                    listOfDocumentParts.Add(contentParagraph);
                }
            }

            // Add Bibliography
            foreach (var bibEntry in article["bib_entries"].Children())
            {
                var bibliographyParagraph = new RtfFormattedParagraph(new RtfParagraphFormatting(10, RtfTextAlign.Left));
                var bibEntryAsString      = GetBibEntry(bibEntry);

                // Control spacing
                bibliographyParagraph.AppendText(bibEntryAsString);
                listOfDocumentParts.Add(bibliographyParagraph);
            }

            var arrayOfDocumentParts = listOfDocumentParts.ToArray();

            rtf.Contents.AddRange(arrayOfDocumentParts);

            var rtfWriter = new RtfWriter();
            var result    = rtfWriter.GetRtfContent(rtf);

            return(result);
        }