Example #1
0
        public PasteCode selectPasteCodeById(int id)
        {
            init();
            con.Open();
            string sql = "select * from paste_code where "
                         + "id = " + id;

            System.Diagnostics.Debug.WriteLine(sql);
            MySQLCommand    cmd       = new MySQLCommand(sql, con);
            MySQLDataReader reader    = cmd.ExecuteReaderEx();
            PasteCode       pasteCode = new PasteCode();

            while (reader.Read())
            {
                pasteCode.id     = (int)reader[0];
                pasteCode.poster = reader[1].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.poster);
                pasteCode.language = reader[2].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.language);
                pasteCode.languagemode = reader[3].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.languagemode);
                pasteCode.theme = reader[4].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.theme);
                byte[] buf = (byte[])reader[5];
                pasteCode.code = System.Text.Encoding.UTF8.GetString(buf);
                System.Diagnostics.Debug.WriteLine(pasteCode.code);
                pasteCode.time = reader[6].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.time);
            }
            con.Close();
            return(pasteCode);
        }
Example #2
0
        public int insertNewPasteCode(PasteCode pasteCode)
        {
            init();
            con.Open();
            string sql = "insert into paste_code value(null,"
                         + "\"" + pasteCode.poster + "\","
                         + "\"" + pasteCode.language + "\","
                         + "\"" + pasteCode.languagemode + "\","
                         + "\"" + pasteCode.theme + "\","
                         + "\"" + pasteCode.code + "\","
                         + "\"" + pasteCode.time + "\")";

            System.Diagnostics.Debug.WriteLine(sql);
            MySQLCommand cmd = new MySQLCommand(sql, con);

            cmd.ExecuteNonQuery();
            sql = "select id from paste_code where "
                  + "poster = " + "\"" + pasteCode.poster + "\" && "
                  + "time = " + "\"" + pasteCode.time + "\"";
            System.Diagnostics.Debug.WriteLine(sql);
            cmd = new MySQLCommand(sql, con);
            MySQLDataReader reader = cmd.ExecuteReaderEx();
            int             id     = 0;

            while (reader.Read())
            {
                id = (int)reader[0];
            }
            con.Close();
            return(id);
        }
Example #3
0
        public ActionResult show(int id)
        {
            PasteCode pasteCode = pastebinDao.selectPasteCodeById(id);

            pasteCode.code             = encode.numToString(pasteCode.code);
            base.ViewData["PasteCode"] = pasteCode;
            return(View(pasteCode));
        }
Example #4
0
        public ActionResult postCode(PasteCode pasteCode)
        {
            pasteCode.code = encode.stringToNum(pasteCode.code);
            int    id     = pastebinDao.insertNewPasteCode(pasteCode);
            Object result = new
            {
                id = id
            };
            string jsonStr = JsonConvert.SerializeObject(result);

            return(Content(jsonStr));
        }
        /// <summary>
        /// Takes action on the selected string in the editor using
        /// predefined commands.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="input"></param>
        /// <param name="style"></param>
        /// <returns></returns>
        public string MarkupMarkdown(string action, string input, string style = null)
        {
            if (string.IsNullOrEmpty(action))
            {
                return(input);
            }

            action = action.ToLower();

            if (string.IsNullOrEmpty(input) && !StringUtils.Inlist(action, new string[] { "image", "href", "code" }))
            {
                return(null);
            }

            string html = input;

            if (action == "bold")
            {
                html = "**" + input + "**";
            }
            else if (action == "italic")
            {
                html = "*" + input + "*";
            }
            else if (action == "small")
            {
                html = "<small>" + input + "</small>";
            }
            else if (action == "underline")
            {
                html = "<u>" + input + "</u>";
            }
            else if (action == "strikethrough")
            {
                html = "~~" + input + "~~";
            }
            else if (action == "inlinecode")
            {
                html = "`" + input + "`";
            }
            else if (action == "h1")
            {
                html = "# " + input;
            }
            else if (action == "h2")
            {
                html = "## " + input;
            }
            else if (action == "h3")
            {
                html = "### " + input;
            }
            else if (action == "h4")
            {
                html = "#### " + input;
            }
            else if (action == "h5")
            {
                html = "##### " + input;
            }

            else if (action == "quote")
            {
                StringBuilder sb    = new StringBuilder();
                var           lines = StringUtils.GetLines(input);
                foreach (var line in lines)
                {
                    sb.AppendLine("> " + line);
                }
                html = sb.ToString();
            }
            else if (action == "list")
            {
                StringBuilder sb    = new StringBuilder();
                var           lines = StringUtils.GetLines(input);
                foreach (var line in lines)
                {
                    sb.AppendLine("* " + line);
                }
                html = sb.ToString();
            }
            else if (action == "numberlist")
            {
                StringBuilder sb    = new StringBuilder();
                var           lines = StringUtils.GetLines(input);
                int           ct    = 0;
                foreach (var line in lines)
                {
                    ct++;
                    sb.AppendLine($"{ct}. " + line);
                }
                html = sb.ToString();
            }
            else if (action == "href")
            {
                var form = new PasteHref()
                {
                    Owner        = Window,
                    LinkText     = input,
                    MarkdownFile = MarkdownDocument.Filename
                };

                // check for links in input or on clipboard
                string link = input;
                if (string.IsNullOrEmpty(link))
                {
                    link = Clipboard.GetText();
                }

                if (!(input.StartsWith("http:") || input.StartsWith("https:") || input.StartsWith("mailto:") || input.StartsWith("ftp:")))
                {
                    link = string.Empty;
                }
                form.Link = link;

                bool?res = form.ShowDialog();
                if (res != null && res.Value)
                {
                    if (form.IsExternal)
                    {
                        html = $"<a href=\"{form.Link}\" target=\"top\">{form.LinkText}</a>";
                    }
                    else
                    {
                        html = $"[{form.LinkText}]({form.Link})";
                    }
                }
            }
            else if (action == "image")
            {
                var form = new PasteImage
                {
                    Owner        = Window,
                    ImageText    = input,
                    MarkdownFile = MarkdownDocument.Filename
                };


                // check for links in input or on clipboard
                string link = input;
                if (string.IsNullOrEmpty(link))
                {
                    link = Clipboard.GetText();
                }

                if (!(input.StartsWith("http:") || input.StartsWith("https:") || input.StartsWith("mailto:") || input.StartsWith("ftp:")))
                {
                    link = string.Empty;
                }

                if (input.Contains(".png") || input.Contains(".jpg") || input.Contains(".gif"))
                {
                    link = input;
                }

                form.Image = link;

                bool?res = form.ShowDialog();
                if (res != null && res.Value)
                {
                    var image = form.Image;
                    html = $"![{form.ImageText}]({form.Image})";
                }
            }
            else if (action == "code")
            {
                var form = new PasteCode();
                form.Owner        = Window;
                form.Code         = input;
                form.CodeLanguage = "csharp";

                bool?res = form.ShowDialog();
                if (res != null && res.Value)
                {
                    html = "```" + form.CodeLanguage + "\r\n" +
                           form.Code.Trim() + "\r\n" +
                           "```\r\n";
                }
            }
            else
            {
                // allow addins to handle custom actions
                string addinAction = AddinManager.Current.RaiseOnEditorCommand(action, input);
                if (!string.IsNullOrEmpty(addinAction))
                {
                    html = addinAction;
                }
            }

            return(html);
        }
Example #6
0
        /// <summary>
        /// Takes action on the selected string in the editor using
        /// predefined commands.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="input"></param>
        /// <param name="style"></param>
        /// <returns></returns>
        public string MarkupMarkdown(string action, string input, string style = null)
        {
            if (string.IsNullOrEmpty(action))
            {
                return(input);
            }

            action = action.ToLower();

            // check for insert actions that don't require a pre selection
            if (string.IsNullOrEmpty(input) && !StringUtils.Inlist(action, new string[] { "image", "href", "code", "emoji" }))
            {
                return(null);
            }

            string html = input;

            if (action == "bold")
            {
                html = "**" + input + "**";
            }
            else if (action == "italic")
            {
                html = "*" + input + "*";
            }
            else if (action == "small")
            {
                html = "<small>" + input + "</small>";
            }
            else if (action == "underline")
            {
                html = "<u>" + input + "</u>";
            }
            else if (action == "strikethrough")
            {
                html = "~~" + input + "~~";
            }
            else if (action == "inlinecode")
            {
                html = "`" + input + "`";
            }
            else if (action == "h1")
            {
                html = "# " + input;
            }
            else if (action == "h2")
            {
                html = "## " + input;
            }
            else if (action == "h3")
            {
                html = "### " + input;
            }
            else if (action == "h4")
            {
                html = "#### " + input;
            }
            else if (action == "h5")
            {
                html = "##### " + input;
            }

            else if (action == "quote")
            {
                StringBuilder sb    = new StringBuilder();
                var           lines = StringUtils.GetLines(input);
                foreach (var line in lines)
                {
                    sb.AppendLine("> " + line);
                }
                html = sb.ToString();
            }
            else if (action == "list")
            {
                StringBuilder sb    = new StringBuilder();
                var           lines = StringUtils.GetLines(input);
                foreach (var line in lines)
                {
                    sb.AppendLine("* " + line);
                }
                html = sb.ToString();
            }
            else if (action == "numberlist")
            {
                StringBuilder sb    = new StringBuilder();
                var           lines = StringUtils.GetLines(input);
                int           ct    = 0;
                foreach (var line in lines)
                {
                    ct++;
                    sb.AppendLine($"{ct}. " + line);
                }
                html = sb.ToString();
            }
            else if (action == "emoji")
            {
                var form = new EmojiWindow();
                form.Owner = Window;
                form.ShowDialog();

                if (form.Cancelled)
                {
                    return(input);
                }

                html = form.EmojiString;
            }
            else if (action == "href")
            {
                var form = new PasteHref()
                {
                    Owner        = Window,
                    LinkText     = input,
                    MarkdownFile = MarkdownDocument.Filename
                };

                // check for links in input or on clipboard
                string link = input;
                if (string.IsNullOrEmpty(link))
                {
                    link = Clipboard.GetText();
                }

                if (!(input.StartsWith("http:") || input.StartsWith("https:") || input.StartsWith("mailto:") || input.StartsWith("ftp:")))
                {
                    link = string.Empty;
                }
                form.Link = link;

                bool?res = form.ShowDialog();
                if (res != null && res.Value)
                {
                    if (form.IsExternal)
                    {
                        html = $"<a href=\"{form.Link}\" target=\"_blank\">{form.LinkText}</a>";
                    }
                    else
                    {
                        html = $"[{form.LinkText}]({form.Link})";
                    }
                }
            }
            else if (action == "image")
            {
                var form = new PasteImageWindow(Window)
                {
                    ImageText    = input,
                    MarkdownFile = MarkdownDocument.Filename
                };


                // check for links in input or on clipboard
                string link = input;
                if (string.IsNullOrEmpty(link))
                {
                    link = Clipboard.GetText();
                }

                if (!(input.StartsWith("http:") || input.StartsWith("https:") || input.StartsWith("mailto:") || input.StartsWith("ftp:")))
                {
                    link = string.Empty;
                }

                if (input.Contains(".png") || input.Contains(".jpg") || input.Contains(".gif"))
                {
                    link = input;
                }

                form.Image = link;

                bool?res = form.ShowDialog();
                if (res != null && res.Value)
                {
                    var image = form.Image;
                    if (!image.StartsWith("data:image/"))
                    {
                        html = $"![{form.ImageText}]({form.Image})";
                    }
                    else
                    {
                        var id = "image_ref_" + DataUtils.GenerateUniqueId();

                        dynamic pos    = AceEditor.getCursorPosition(false);
                        dynamic scroll = AceEditor.getscrolltop(false);

                        // the ID tag
                        html = $"\r\n\r\n[{id}]: {image}\r\n";

                        // set selction position to bottom of document
                        AceEditor.gotoBottom(false);
                        SetSelection(html);

                        // reset the selection point
                        AceEditor.setcursorposition(pos); //pos.column,pos.row);

                        if (scroll != null)
                        {
                            AceEditor.setscrolltop(scroll);
                        }

                        WindowUtilities.DoEvents();
                        html = $"![{form.ImageText}][{id}]";
                    }
                }
            }
            else if (action == "code")
            {
                var form = new PasteCode();
                form.Owner        = Window;
                form.Code         = input;
                form.CodeLanguage = "csharp";
                bool?res = form.ShowDialog();

                if (res != null && res.Value)
                {
                    html = "```" + form.CodeLanguage + "\r\n" +
                           form.Code.Trim() + "\r\n" +
                           "```\r\n";
                }
            }
            else
            {
                // allow addins to handle custom actions
                string addinAction = AddinManager.Current.RaiseOnEditorCommand(action, input);
                if (!string.IsNullOrEmpty(addinAction))
                {
                    html = addinAction;
                }
            }

            return(html);
        }