private void FillMetaFromDocRecord(SmeDoc res, SpDocumentModel docInfo)
 {
     res.Meta.LangId    = docInfo.LangId;
     res.Meta.ShortLang = docInfo.ShortLang;
     res.Meta.DocLangId = docInfo.DocLanguageId;
     res.Meta.DocNumber = docInfo.DocNumber;
 }
        private SmeDoc CreateSmeDoc(SpDocumentModel docInfo, string searchText)
        {
            if (docInfo.DocLanguageId != -1)
            {
                var docText = this.dbHelper.GetDocumentTextByDocLangId(docInfo.DocLanguageId);
                if (this.IsBlob(docText, out string fileName))
                {
                    var smeDoc = new SmeDoc();
                    smeDoc.Meta            = DocConverter.GetSmeDocMeta(docText);
                    smeDoc.Meta.ShortTitle = smeDoc.Meta.ShortTitle; //must change when ShortTitle column is available in database
                    this.FillMetaFromDocRecord(smeDoc, docInfo);
                    smeDoc.Meta.IsBlob = true;

                    var filePath = $@"{this.pathsProvider.PdfPath}\{smeDoc.Meta.Idenitifier}\{fileName}";
                    if (System.IO.File.Exists(filePath))
                    {
                        smeDoc.Items = new List <SmeDocItem>();
                        var fileExt = System.IO.Path.GetExtension(filePath).ToLower();
                        if (fileExt == ".html")
                        {
                            var docContent = System.IO.File.ReadAllText(filePath);
                            smeDoc.Meta.IsBlob = false;
                            smeDoc.Items.Add(new SmeDocItem
                            {
                                Text = docContent,
                                Type = SmeDocItemType.Text
                            });
                        }
                        else
                        {
                            smeDoc.Items.Add(new SmeDocItem
                            {
                                Text = fileName,
                                Type = SmeDocItemType.Text
                            });
                        }
                    }
                    return(smeDoc);
                }
                else
                {
                    var html = AkomaNtosoPreProcessor.ConvertToHtml(docText, new AkomaNtosoPreProcessorConfig());
                    html = this.ReplaceImgUrls(html);

                    if (!string.IsNullOrEmpty(searchText))
                    {
                        html = this.ColorizeSearch(searchText, html, docInfo.LangId);
                    }

                    html = DocumentLinkRewrite.ReplaceNationalLegislation(html);

                    var res = this.CreateSmeDoc(html, docText, docInfo);
                    return(res);
                }
            }
            else
            {
                return(null);
            }
        }
        private SmeDoc CreateSmeDoc(string html, string pt, SpDocumentModel docInfo)
        {
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(html);

            var res = DocConverter.DoDocConvert(htmlDoc, pt);

            if (res.Meta.IsConsolidatedEuLegislation && res.HasRecitals() == false)
            {
                var preambleWithRecitals = this.dbHelper.GetRecitalsPreambleForConsVersion(docInfo.DocLanguageId);
                if (String.IsNullOrEmpty(preambleWithRecitals) == false)
                {
                    var preambleWithRecitalsHtml = AkomaNtosoPreProcessor.ConvertToHtml(preambleWithRecitals, new AkomaNtosoPreProcessorConfig());
                    InsertRecitalsAtPreambleEnd(htmlDoc, preambleWithRecitalsHtml);
                    res = DocConverter.DoDocConvert(htmlDoc, pt);
                }
            }


            this.FillMetaFromDocRecord(res, docInfo);
            var filePath = @".\data\smedata.css";

            if (!string.IsNullOrEmpty(this.pathsProvider.BasePath))
            {
                filePath = System.IO.Path.Combine(this.pathsProvider.BasePath, filePath);
            }
            res.Head += System.IO.File.ReadAllText(filePath);
            return(res);
        }