private void config_Add() { ConfigItem first = txt_TextFirst.Value; ConfigItem last = txt_TextLast.Value; if (first == null || last == null || string.IsNullOrEmpty(first.Text) || string.IsNullOrEmpty(last.Text)) { MessageBox.Show("Please input text first and last config."); return; } IndexDynamic id = db.FindItemFirstByContainFieldValue(new CNSPLIT() { SITE = Domain, TEXT_FIRST = first.Text, TEXT_LAST = last.Text }, "SITE,TEXT_FIRST,TEXT_LAST"); if (id.Index == -1 || id.Item == null) { object o = new CNSPLIT() { SITE = Domain, TEXT_FIRST = first.Text, TEXT_LAST = last.Text, SKIP_LINE_BOTTOM = (byte)last.SkipLine, SKIP_LINE_TOP = (byte)first.SkipLine, }; object add = db.AddItem(o); if (add != null && add.GetType().Name != typeof(EditStatus).Name) { CNSPLIT val = add.Convert <CNSPLIT>(); list_TextFirst.Items.Insert(0, new ComboboxItem() { Value = val.ID, Text = first.SkipLine.ToString() + " | " + first.Text }); list_TextLast.Items.Insert(0, new ComboboxItem() { Value = val.ID, Text = last.SkipLine.ToString() + " | " + last.Text }); txt_TextFirst.Reset(); txt_TextLast.Reset(); } else { MessageBox.Show("Add object fail"); } } else { MessageBox.Show("Config exist"); } }
public static CmsExtract get_CmsExtract(this string content, string url, CNSPLIT config, string htm) { CmsExtract cms = new CmsExtract(); cms.PLAIN_TEXT = content; string[] a = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Where(x => x != "").ToArray(); if (config.SKIP_LINE_TOP == 1) { cms.Title = a[0]; cms.Description = a[1]; a = a.Where((x, k) => k > 1).ToArray(); } else { cms.Description = a[0]; a = a.Where((x, k) => k > 0).ToArray(); } if (config.SKIP_LINE_BOTTOM == 1) { a = a.Where((x, k) => k != a.Length - 1).ToArray(); } string[] ah = a.Select(x => string.Format("<div class={0}>{1}</div>", (x.Contains("{img") ? "_DIMG" : "_DTEXT"), x)).ToArray(); string _htmContent = string.Join(Environment.NewLine + Environment.NewLine, ah); List <string> listImg = new List <string>(); var ps2 = Regex.Matches(_htmContent, "{img(.+?)img}", RegexOptions.IgnoreCase); foreach (Match mi in ps2) { string img = mi.ToString(), src = img.Substring(4, img.Length - 8); string tag = string.Format(Environment.NewLine + "<p class=_PIMG><img class=\"_IMG\" src=\"{0}\"></p>" + Environment.NewLine, src); _htmContent = _htmContent.Replace(img, tag); listImg.Add(src); } cms.IMG_SRC = listImg.ToArray(); if (listImg.Count > 0) { cms.ImgDefault = listImg[0]; } cms.ContentHtml = _htmContent; return(cms); }
void url_Extract(string url) { string dom = url.getDomainFromURL(); SearchResult rs = db.FindItemByContainFieldValue(new CNSPLIT() { SITE = dom }, "SITE", 1000, 1); if (rs == null || rs.Total == 0) { url_buildConfig(url); } else { string Content = url.getContentTextFromURL(); var ls = ((IList)rs.Message).Convert <CNSPLIT>().ToArray(); CNSPLIT config = (CNSPLIT)ls[0]; IndexLine[] a = Content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Select(x => x.Trim()).Where(x => x.Length > 1).Select((x, k) => new IndexLine(k, x)).ToArray(); int pLast = a.getIndex(new ConfigItem() { Text = config.TEXT_LAST, SkipLine = config.SKIP_LINE_BOTTOM }, -1), pFirst = a.getIndex(new ConfigItem() { Text = config.TEXT_FIRST, SkipLine = config.SKIP_LINE_TOP }, pLast); if (pFirst == -1 || pLast == -1) { //MessageBox.Show("Config wrong, can not find position first or last of data content"); url_buildConfig(url, Content); return; } string[] con = a.Where(x => x.Index > pFirst && x.Index < pLast).Select(x => x.Line).ToArray(); string data = string.Join(Environment.NewLine, con); //CmsExtract cms = data.get_CmsExtract(url, config, ""); new Thread(new ParameterizedThreadStart((x) => { new FormELDocAdd(url, x.ToString(), new string[] { }).ShowDialog(); })).Start(data); } }
public void addButton_WebCopy() { var b = new ToolStripButton(); b.Image = ___HtmlEditorResource.GetImageIcon("web.gif"); b.ToolTipText = "Copy from URL Website"; b.Click += (se, ev) => { string urc = Clipboard.GetText(TextDataFormat.Text); if (!string.IsNullOrEmpty(urc) && !urc.ToLower().StartsWith("http")) { urc = ""; } var url = Interaction.InputBox("Please enter an site url", "URL", urc, 99, 99); if (!string.IsNullOrEmpty(url)) { // Set cursor as hourglass Cursor.Current = Cursors.WaitCursor; string dom = url.getDomainFromURL(); SearchResult rs = db.FindItemByContainFieldValue(new CNSPLIT() { SITE = dom }, "SITE", 1000, 1); if (rs == null || rs.Total == 0) { var fc = new FormDataSplitConfig(db, url); fc.OnSubmit += (config, htm, content) => { CmsExtract cms = content.get_CmsExtract(url, config, htm); this.Html = cms.ContentHtml; this.cmsExtract = cms; fillFormCMS(cms); fc.Close(); }; fc.ShowDialog(); } else { string Content = url.getContentTextFromURL(); var ls = ((IList)rs.Message).Convert <CNSPLIT>().ToArray(); CNSPLIT config = (CNSPLIT)ls[0]; IndexLine[] a = Content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Select(x => x.Trim()).Where(x => x != "").Select((x, k) => new IndexLine(k, x)).ToArray(); //int pLast = a.getIndex(config.TEXT_LAST, -1), pFirst = a.getIndex(config.TEXT_FIRST, pLast); int pLast = a.getIndex(new ConfigItem() { Text = config.TEXT_LAST, SkipLine = config.SKIP_LINE_BOTTOM }, -1), pFirst = a.getIndex(new ConfigItem() { Text = config.TEXT_FIRST, SkipLine = config.SKIP_LINE_TOP }, pLast); if (pFirst == -1 || pLast == -1) { MessageBox.Show("Config wrong, can not find position first or last of data content"); return; } string[] con = a.Where(x => x.Index > pFirst && x.Index < pLast).Select(x => x.Line).ToArray(); string data = string.Join(Environment.NewLine, con); CmsExtract cms = data.get_CmsExtract(url, config, ""); this.Html = cms.ContentHtml; this.cmsExtract = cms; fillFormCMS(cms); } // Set cursor as default arrow Cursor.Current = Cursors.Default; } }; this.AddToolbarItem(b); }