Пример #1
0
        private void OnBibliographyReady(CSLProcessorOutputConsumer ip)
        {
            StringBuilder result_rtf = new StringBuilder();


            result_rtf.Append(CSLProcessorOutputConsumer.RTF_START);

            if (!ip.success)
            {
                result_rtf.Append("---------------------------------------------");
                result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
                result_rtf.Append("There was a problem processing the CSL.");
                result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
                result_rtf.Append("---------------------------------------------");
                result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
                result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            }


            result_rtf.Append("---------------------------------------------");
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append("Citations:");
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append("---------------------------------------------");
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            foreach (string cluster_id in ip.GetCitationClusterKeys())
            {
                string text_for_cluster = ip.GetTextForCluster(cluster_id);
                result_rtf.Append(text_for_cluster);
                result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            }

            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append("---------------------------------------------");
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append("Bibliography:");
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append("---------------------------------------------");
            result_rtf.Append(CSLProcessorOutputConsumer.RTF_NEWLINE);
            result_rtf.Append(ip.GetFormattedBibliographySection());

            result_rtf.Append(CSLProcessorOutputConsumer.RTF_END);

            // Set the box
            //string formatted_bibliography_section = ip.GetFormattedBibliographySection();
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result_rtf.ToString())))
            {
                ObjRichTextEditor.SelectAll();
                ObjRichTextEditor.Selection.Load(ms, DataFormats.Rtf);
            }

            // Display any errors
            LogMessage(ip.error_message);

            LogMessage("Done!");
        }
Пример #2
0
        private void GenerateRtfCitationSnippet_OnBibliographyReady(CSLProcessorOutputConsumer ip)
        {
            if (ip.success)
            {
                using (System.Windows.Forms.RichTextBox rich_text_box = new System.Windows.Forms.RichTextBox())
                {
                    rich_text_box.Rtf = ip.GetRtf();
                    string text = rich_text_box.Text;

                    text = text.Trim();
                    text = text.Replace(";", ",");
                    if (text.StartsWith("1.\t"))
                    {
                        text = text.Substring(3);
                    }
                    if (text.StartsWith("1 \t"))
                    {
                        text = text.Substring(3);
                    }
                    if (text.StartsWith("1\t"))
                    {
                        text = text.Substring(2);
                    }

                    if (text.Length > 32)
                    {
                        string POSTAMBLE_QIQQA_TWITTER = " @Qiqqa";
                        string POSTAMBLE_QIQQA_URL     = " http://www.qiqqa.com";
                        int    POSTAMBLE_QIQQA_URL_SHORTENED_LENGTH = 22;
                        string PREAMBLE_CHECK_OUT = "Check out ";

                        if (text.Length < 140 - POSTAMBLE_QIQQA_TWITTER.Length)
                        {
                            text = text + POSTAMBLE_QIQQA_TWITTER;
                        }
                        if (text.Length < 140 - POSTAMBLE_QIQQA_URL_SHORTENED_LENGTH)
                        {
                            text = text + POSTAMBLE_QIQQA_URL;
                        }
                        if (text.Length < 140 - PREAMBLE_CHECK_OUT.Length)
                        {
                            text = PREAMBLE_CHECK_OUT + text;
                        }

                        TxtTweet.Text = text;
                    }
                }
            }
            else
            {
                Logging.Warn("There was a problem generating a citation snippet to tweet, so ignoring...");
            }
        }