private static string GetConnectionString(int index) { return(Settings.Load().ConnectionStrings[index]); }
public FormSettings(int index) { InitializeComponent(); var s = Settings.Load(); if (s.Providers.ContainsKey(index)) { try { editConnectionString.Text = s.ConnectionStrings[index]; editProvider.Text = s.Providers[index].ToString(); editSiteAddress.Text = s.SiteAddress[index]; editEmail.Text = s.Emails[index]; editPassword.Text = s.Passwords[index]; try { Database.Database db = Provider.GetDb(index); var dt = db.GetDataTable("select Id, Title from Content where ClassName='Category' order by Title"); loadCategories(editCategoryId0, dt); loadCategories(editCategoryId1, dt); loadCategories(editCategoryId2, dt); loadCategories(editCategoryId3, dt); loadCategories(editCategoryId4, dt); loadCategories(editCategoryId5, dt); loadCategories(editCategoryId6, dt); loadCategories(editCategoryId7, dt); loadCategories(editCategoryId8, dt); loadCategories(editCategoryId9, dt); } catch { } if (s.Feed == null || string.IsNullOrWhiteSpace(s.Feed[index])) { s.Feed[index] = "|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n"; } var feeds = s.Feed[index].Replace("\r", "").Split('\n'); try { editRSS0.Text = feeds[0].Split('|')[0]; editCategoryId0.SelectedIndex = editCategoryId0.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[0].Split('|')[1])); } catch { } try { editRSS1.Text = feeds[1].Split('|')[0]; editCategoryId1.SelectedIndex = editCategoryId1.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[1].Split('|')[1])); } catch { } try { editRSS2.Text = feeds[2].Split('|')[0]; editCategoryId2.SelectedIndex = editCategoryId2.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[2].Split('|')[1])); } catch { } try { editRSS3.Text = feeds[3].Split('|')[0]; editCategoryId3.SelectedIndex = editCategoryId3.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[3].Split('|')[1])); } catch { } try { editRSS4.Text = feeds[4].Split('|')[0]; editCategoryId4.SelectedIndex = editCategoryId4.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[4].Split('|')[1])); } catch { } try { editRSS5.Text = feeds[5].Split('|')[0]; editCategoryId5.SelectedIndex = editCategoryId5.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[5].Split('|')[1])); } catch { } try { editRSS6.Text = feeds[6].Split('|')[0]; editCategoryId6.SelectedIndex = editCategoryId6.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[6].Split('|')[1])); } catch { } try { editRSS7.Text = feeds[7].Split('|')[0]; editCategoryId7.SelectedIndex = editCategoryId7.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[7].Split('|')[1])); } catch { } try { editRSS8.Text = feeds[8].Split('|')[0]; editCategoryId8.SelectedIndex = editCategoryId8.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[8].Split('|')[1])); } catch { } try { editRSS9.Text = feeds[9].Split('|')[0]; editCategoryId9.SelectedIndex = editCategoryId9.Items.Cast <Item>().IndexOf(i => i.Id == Convert.ToInt32(feeds[9].Split('|')[1])); } catch { } } catch { } } }
private static DatabaseProvider GetDbProvider(int index) { return(Settings.Load().Providers[index]); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var s = Settings.Load(); foreach (var item in s.Feed) { if (string.IsNullOrWhiteSpace(item.Value)) { continue; } var siteIndex = item.Key; var site = s.SiteAddress[siteIndex]; var db = Provider.GetDb(siteIndex).CreateNewInstance(); foreach (string rssItem in item.Value.Replace("\r", "").SplitWithTrim('\n')) { try { if (!rssItem.Contains("|")) { continue; } var rssUrl = rssItem.SplitWithTrim("|")[0]; var categoryId = int.Parse(rssItem.SplitWithTrim("|")[1]); XElement rss = XElement.Parse(rssUrl.DownloadPage()); XNamespace mediaNS = "http://search.yahoo.com/mrss/"; var haberler = rss.Element("channel").Elements("item").ToList(); if (haberler.Count == 0) { continue; } backgroundWorker.ReportProgress(0, rss.Element("channel").Element("title").Value + "|" + haberler.Count + "|" + site.Trim('/')); for (int i = 0; i < haberler.Count; i++) { var media = haberler[i].Element(mediaNS + "content"); var picture = media == null ? "" : media.Attribute("url").Value; var title = haberler[i].Element("title").Value; var sourceLink = haberler[i].Element("link").Value; if (db.GetInt("select Id from Content where SourceLink={0}", sourceLink) > 0) { backgroundWorker.ReportProgress(((i + 1) * 100) / haberler.Count); continue; } var metin = haberler[i].Element("description").Value; if (metin.Contains(")- ")) { metin = metin.Substring(metin.IndexOf(")- ") + 3); } var pubDate = DateTime.Parse(haberler[i].Element("pubDate").Value); NameValueCollection postData = new NameValueCollection(); postData.Add("Id", "0"); postData.Add("ClassName", "Content"); postData.Add("Title", title); if (title.Replace("İ", "I").ToLowerInvariant().StartsWith("cihan") || title.Replace("Ü", "U").ToLowerInvariant().StartsWith("duzeltme")) { backgroundWorker.ReportProgress(((i + 1) * 100) / haberler.Count); continue; } postData.Add("SourceLink", sourceLink); postData.Add("CategoryId", categoryId.ToString()); try { postData.Add("Description", metin.SplitWithTrim(".").First()); } catch { } postData.Add("Picture", picture); postData.Add("PublishDate", pubDate.ToString("dd.MM.yyyy hh:mm")); postData.Add("Metin", metin); string res = HttpUploadHelper.Upload(site.Trim('/') + "/UploadContent.ashx", new UploadFile[0], postData); backgroundWorker.ReportProgress(((i + 1) * 100) / haberler.Count); } } catch (Exception ex) { } } } }