Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string         exportType = Request["type"];
        WikiReader     reader     = PXGraph.CreateInstance <WikiReader>();
        PXWikiSettings settings   = new PXWikiSettings(this, reader);

        this.SetReaderFilter(reader);
        WikiPage article = reader.Pages.SelectWindowed(0, 1);

        reader.Pages.Current = article;
        PXRenderer renderer = this.CreateRenderer(exportType, settings.Absolute);

        if (article != null && !string.IsNullOrEmpty(article.Content) && renderer != null)
        {
            var ctx = new PXDBContext(settings.Absolute);

            ctx.Renderer = renderer;
            ctx.WikiID   = article.WikiID;
            string result = PXWikiParser.Parse(article.Content, ctx);
            string mime   = MimeTypes.GetMimeType("." + exportType);
            Response.AddHeader("cache-control", "no-store, private");
            Response.Clear();
            Response.Cache.SetCacheability(HttpCacheability.Private);
            Response.Cache.SetExpires(DateTime.Now.AddSeconds(2));
            Response.Cache.SetValidUntilExpires(true);
            Response.AddHeader("Content-Type", mime);
            Response.AddHeader("Content-Encoding", "ansi");
            this.AdditionalResponseParams(renderer, article);
            Response.Write(result);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        WikiReader     reader   = PXGraph.CreateInstance <WikiReader>();
        PXWikiSettings settings = new PXWikiSettings(this, reader);

        reader.Filter.Current.PageID = PX.Common.GUID.CreateGuid(this.Request["PageID"]);
        WikiPage article = reader.Pages.SelectWindowed(0, 1);

        reader.Pages.Current = article;
        if (article != null && !string.IsNullOrEmpty(article.Content))
        {
            MemoryStream  stream   = new MemoryStream();
            PXPdfRenderer renderer = new PXPdfRenderer(stream, settings.Relative);
            settings.Relative.Renderer = renderer;
            PXWikiParser.Parse(article.Content, settings.Relative);
            string mime  = MimeTypes.GetMimeType(".pdf");
            byte[] bytes = new byte[renderer.ResultPDFStream.Length];

            renderer.ResultPDFStream.Position = 0;
            renderer.ResultPDFStream.Read(bytes, 0, bytes.Length);
            Response.AddHeader("cache-control", "no-store, private");
            Response.Clear();
            Response.Cache.SetCacheability(HttpCacheability.Private);
            Response.Cache.SetExpires(DateTime.Now.AddSeconds(2));
            Response.Cache.SetValidUntilExpires(true);
            Response.AddHeader("Content-Type", mime);
            Response.AddHeader("Content-Length", renderer.ResultPDFStream.Length.ToString());
            Response.BinaryWrite(bytes);
        }
    }
Esempio n. 3
0
        public virtual IEnumerable IndexCustomArticles(PXAdapter adapter)
        {
            PXLongOperation.StartOperation(this, delegate()
            {
                foreach (var result in WikiArticles.Select())
                {
                    string plaintext = null;

                    var _wp = (WikiPage)result[typeof(WikiPage)];
                    var _wr = (WikiRevision)result[typeof(WikiRevision)];
                    var _wl = (WikiPageLanguage)result[typeof(WikiPageLanguage)];

                    if (_wp.IsHtml != true)
                    {
                        WikiReader reader       = PXGraph.CreateInstance <WikiReader>();
                        PXWikiSettings settings = new PXWikiSettings(new PXPage(), reader);
                        PXTxtRenderer renderer  = new PXTxtRenderer(settings.Absolute);
                        var ctx      = new PXDBContext(settings.Absolute);
                        ctx.Renderer = renderer;
                        plaintext    = (_wl.Title ?? "") + Environment.NewLine + PXWikiParser.Parse(_wr.Content, ctx);
                    }
                    else
                    {
                        plaintext = (_wl.Title ?? "") + Environment.NewLine + SearchService.Html2PlainText(_wr.Content);
                    }


                    //Try updating the article in current Company
                    if (!PXDatabase.Update <WikiRevision>(
                            new PXDataFieldAssign("PlainText", PXDbType.NVarChar, plaintext),
                            new PXDataFieldRestrict("PageID", PXDbType.UniqueIdentifier, _wr.PageID),
                            new PXDataFieldRestrict("PageRevisionID", PXDbType.Int, _wr.PageRevisionID),
                            new PXDataFieldRestrict("Language", PXDbType.VarChar, _wr.Language)
                            ))
                    {
                        //Article may be shared. Try updating the article through graph (thus handling the shared record update stratagy)
                        //if article is not updatable an exception may be thrown - ignore.
                        try
                        {
                            ArticleUpdater updater = PXGraph.CreateInstance <ArticleUpdater>();
                            WikiRevision rev       = updater.Revision.Select(_wr.PageID, _wr.PageRevisionID, _wr.Language);
                            rev.PlainText          = plaintext;
                            updater.Revision.Update(rev);
                            updater.Persist();
                        }
                        catch (Exception ex)
                        {
                            PXTrace.WriteInformation("Plain text field could not be updated for article = {0}. Error Message: {1}", _wr.PageID, ex.Message);
                        }
                    }
                }
            });



            return(adapter.Get());
        }