Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.73 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.IO;
  5. using System.Xml;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12.  
  13. /// <summary>
  14. /// Summary description for rss
  15. /// </summary>
  16. public class rss
  17. {
  18. public rss()
  19. {
  20. //
  21. // TODO: Add constructor logic here
  22. //
  23. }
  24.  
  25. public static void Generate(string strRssPath)
  26. {
  27. try
  28. {
  29. //Fysisk sökväg på servern
  30. string strXMLPath = strRssPath;
  31.  
  32. FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
  33. XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
  34. xtw.Formatting = Formatting.Indented;
  35. xtw.WriteStartDocument();
  36.  
  37. //skriv ut <rss version="2.0">
  38. xtw.WriteStartElement("rss");
  39. xtw.WriteAttributeString("version", "2.0");
  40.  
  41. //skriv ut <channel>
  42. xtw.WriteStartElement("channel");
  43.  
  44. //skriv ut element som tillhör <channel>
  45. xtw.WriteElementString("title", "Teknikfreak");
  46. xtw.WriteElementString("link", "http://www.teknikfreak.se/");
  47. xtw.WriteElementString("description", "Data, mobil, ljudteknik, filmteknik m.m");
  48. xtw.WriteElementString("language", "sv-SE");
  49. xtw.WriteElementString("copyright", "Copyright (c) 2006-2009 Teknikfreak");
  50.  
  51. NewsCollection newsGetLatestNewsToRSS = bll_tekniknyheter.GetLatestNewsToRSS();
  52.  
  53. int i;
  54. for (i = 0; i < newsGetLatestNewsToRSS.Count; i++)
  55. {
  56. string strTitle = newsGetLatestNewsToRSS[i].Headline;
  57. string strNewsId = newsGetLatestNewsToRSS[i].Id.ToString();
  58. bool boolRssFeed = newsGetLatestNewsToRSS[i].RssFeed;
  59. string strDescription;
  60. if (boolRssFeed)
  61. {
  62. strDescription = (newsGetLatestNewsToRSS[i].Text).Replace(System.Environment.NewLine, "<br />");
  63. }
  64. else
  65. {
  66. strDescription = System.Web.HttpUtility.HtmlEncode(newsGetLatestNewsToRSS[i].Text).Replace(System.Environment.NewLine, "<br />");
  67. }
  68. strDescription = RegExp.UrlBB(strDescription);
  69. strDescription = RegExp.Bold(strDescription);
  70. strDescription = RegExp.Italic(strDescription);
  71. strDescription = RegExp.Ul_list(strDescription);
  72. strDescription = RegExp.Li_list(strDescription);
  73. strDescription = RegExp.Underlined(strDescription);
  74. string strpubDate = newsGetLatestNewsToRSS[i].Date.ToUniversalTime().ToString("r");
  75.  
  76. //skriv ut <item> och dess innehåll
  77. xtw.WriteStartElement("item");
  78. xtw.WriteElementString("title", strTitle);
  79. xtw.WriteElementString("link", "http://www.teknikfreak.se/TeknikNyheter/" + strNewsId +"/" + TextFormat.NoSpecial(strTitle) +".aspx");
  80. xtw.WriteElementString("description", strDescription);
  81. xtw.WriteElementString("pubDate", strpubDate);
  82. xtw.WriteEndElement();
  83.  
  84. }
  85.  
  86. //skriv ut </channel>
  87. xtw.WriteEndElement();
  88.  
  89. //skriv ut </rss>
  90. xtw.WriteEndElement();
  91.  
  92. //Stäng xml skrivaren
  93. xtw.Close();
  94. }
  95. catch (Exception ex)
  96. {
  97. Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
  98. }
  99. }
  100.  
  101. public static void Tests()
  102. {
  103. try
  104. {
  105. //Fysisk sökväg på servern
  106. string strXMLPath = HttpContext.Current.Server.MapPath("~/Recensioner/rss.xml");
  107.  
  108. FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
  109. XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
  110. xtw.Formatting = Formatting.Indented;
  111. xtw.WriteStartDocument();
  112.  
  113. //skriv ut <rss version="2.0">
  114. xtw.WriteStartElement("rss");
  115. xtw.WriteAttributeString("version", "2.0");
  116.  
  117. //skriv ut <channel>
  118. xtw.WriteStartElement("channel");
  119.  
  120. //skriv ut element som tillhör <channel>
  121. xtw.WriteElementString("title", "Teknikfreak- Recensioner");
  122. xtw.WriteElementString("link", "http://www.teknikfreak.se/");
  123. xtw.WriteElementString("description", "Här bevakar du samtliga av våra recensioner");
  124. xtw.WriteElementString("language", "sv-SE");
  125. xtw.WriteElementString("copyright", "Copyright (c) 2006-2009 Teknikfreak");
  126.  
  127. TestsCollection tGetLatestTestsToRSS = bll_recensioner.GetLatestTestsToRSS();
  128.  
  129. int i;
  130. for (i = 0; i < tGetLatestTestsToRSS.Count; i++)
  131. {
  132. string strTitle = tGetLatestTestsToRSS[i].Headline;
  133. string strTestsId = tGetLatestTestsToRSS[i].Id.ToString();
  134. string strDescription = HttpContext.Current.Server.HtmlEncode(tGetLatestTestsToRSS[i].Text.Substring(0, 400) + "...").Replace(System.Environment.NewLine, "<br />");
  135. strDescription = RegExp.Url(strDescription);
  136. strDescription = RegExp.Bold(strDescription);
  137. strDescription = RegExp.Italic(strDescription);
  138. strDescription = RegExp.Ul_list(strDescription);
  139. strDescription = RegExp.Li_list(strDescription);
  140. string strpubDate = tGetLatestTestsToRSS[i].Date.ToUniversalTime().ToString("r");
  141.  
  142. //skriv ut <item> och dess innehåll
  143. xtw.WriteStartElement("item");
  144. xtw.WriteElementString("title", strTitle);
  145. xtw.WriteElementString("link", "http://www.teknikfreak.se/Recensioner/" + strTestsId + "/" + tGetLatestTestsToRSS[i].Category + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
  146. xtw.WriteElementString("description", strDescription);
  147. xtw.WriteElementString("pubDate", strpubDate);
  148. xtw.WriteEndElement();
  149.  
  150. }
  151.  
  152. //skriv ut </channel>
  153. xtw.WriteEndElement();
  154.  
  155. //skriv ut </rss>
  156. xtw.WriteEndElement();
  157.  
  158. //Stäng xml skrivaren
  159. xtw.Close();
  160. }
  161. catch (Exception ex)
  162. {
  163. Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
  164. }
  165. }
  166.  
  167. public static void TipsTrix()
  168. {
  169. try
  170. {
  171. //Fysisk sökväg på servern
  172. string strXMLPath = HttpContext.Current.Server.MapPath("~/TipsTrix/rss.xml");
  173.  
  174. FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
  175. XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
  176. xtw.Formatting = Formatting.Indented;
  177. xtw.WriteStartDocument();
  178.  
  179. //skriv ut <rss version="2.0">
  180. xtw.WriteStartElement("rss");
  181. xtw.WriteAttributeString("version", "2.0");
  182.  
  183. //skriv ut <channel>
  184. xtw.WriteStartElement("channel");
  185.  
  186. //skriv ut element som tillhör <channel>
  187. xtw.WriteElementString("title", "Teknikfreak- Recensioner");
  188. xtw.WriteElementString("link", "http://www.teknikfreak.se/");
  189. xtw.WriteElementString("description", "Här bevakar du samtliga av våra Tips & Trix");
  190. xtw.WriteElementString("language", "sv-SE");
  191. xtw.WriteElementString("copyright", "Copyright (c) 2006-2009 Teknikfreak");
  192.  
  193. TipsTrixCollection ttGetLatestTTToRSS = bll_tipstrix.GetLatestTipsTrixToRSS();
  194.  
  195. int i;
  196. for (i = 0; i < ttGetLatestTTToRSS.Count; i++)
  197. {
  198. string strTitle = ttGetLatestTTToRSS[i].Headline;
  199. string strTipsTrixId = ttGetLatestTTToRSS[i].Id.ToString();
  200. string strDescription = HttpContext.Current.Server.HtmlEncode(ttGetLatestTTToRSS[i].Text.Substring(0, 200) + "...").Replace(System.Environment.NewLine, "<br />");
  201. strDescription = RegExp.Url(strDescription);
  202. strDescription = RegExp.Bold(strDescription);
  203. strDescription = RegExp.Italic(strDescription);
  204. strDescription = RegExp.Ul_list(strDescription);
  205. strDescription = RegExp.Li_list(strDescription);
  206. string strpubDate = ttGetLatestTTToRSS[i].Date.ToUniversalTime().ToString("r");
  207.  
  208. //skriv ut <item> och dess innehåll
  209. xtw.WriteStartElement("item");
  210. xtw.WriteElementString("title", strTitle);
  211. xtw.WriteElementString("link", "http://www.teknikfreak.se/TipsTrix/" + strTipsTrixId + "/" + ttGetLatestTTToRSS[i].Category + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
  212. xtw.WriteElementString("description", strDescription);
  213. xtw.WriteElementString("pubDate", strpubDate);
  214. xtw.WriteEndElement();
  215.  
  216. }
  217.  
  218. //skriv ut </channel>
  219. xtw.WriteEndElement();
  220.  
  221. //skriv ut </rss>
  222. xtw.WriteEndElement();
  223.  
  224. //Stäng xml skrivaren
  225. xtw.Close();
  226. }
  227. catch (Exception ex)
  228. {
  229. Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
  230. }
  231. }
  232.  
  233. public static void NewsWordpress()
  234. {
  235. try
  236. {
  237. //Fysisk sökväg på servern
  238. string strXMLPath = HttpContext.Current.Server.MapPath("~/Tekniknyheter/wordpress.xml");
  239.  
  240. FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
  241. XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
  242. xtw.Formatting = Formatting.Indented;
  243. xtw.WriteStartDocument();
  244.  
  245. //skriv ut <rss version="2.0">
  246. xtw.WriteStartElement("rss");
  247. xtw.WriteAttributeString("version", "2.0");
  248.  
  249. //skriv ut <channel>
  250. xtw.WriteStartElement("channel");
  251.  
  252. //skriv ut element som tillhör <channel>
  253. xtw.WriteElementString("title", "Teknikfreak- Tekniknyheter");
  254. xtw.WriteElementString("link", "http://www.teknikfreak.se/");
  255. xtw.WriteElementString("description", "Här bevakar du samtliga av våra Nyheter");
  256. xtw.WriteElementString("language", "sv-SE");
  257. xtw.WriteElementString("copyright", "Copyright (c) 2017 Teknikfreak");
  258.  
  259. NewsCollection newsGetNewsToRSS = bll_tekniknyheter.GetNewsToRSS();
  260.  
  261. int i;
  262. for (i = 0; i < newsGetNewsToRSS.Count; i++)
  263. {
  264. string strTitle = newsGetNewsToRSS[i].Headline;
  265. string strNewsId = newsGetNewsToRSS[i].Id.ToString();
  266. string strDescription = HttpContext.Current.Server.HtmlEncode(newsGetNewsToRSS[i].Text).Replace(System.Environment.NewLine, "<br />");
  267. string strpubDate = newsGetNewsToRSS[i].Date.ToUniversalTime().ToString("r");
  268. string strImage = newsGetNewsToRSS[i].Image;
  269. strDescription = RegExp.UrlBB(strDescription);
  270. strDescription = RegExp.Bold(strDescription);
  271. strDescription = RegExp.Italic(strDescription);
  272. strDescription = RegExp.Ul_list(strDescription);
  273. strDescription = RegExp.Li_list(strDescription);
  274. strDescription = RegExp.H2(strDescription);
  275.  
  276. //skriv ut <item> och dess innehåll
  277. xtw.WriteStartElement("item");
  278. xtw.WriteElementString("title", strTitle);
  279. xtw.WriteElementString("link", "http://www.teknikfreak.se/TeknikNyheter/" + strNewsId + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
  280. xtw.WriteElementString("description", strDescription);
  281. xtw.WriteElementString("pubDate", strpubDate);
  282. xtw.WriteStartElement("image");
  283. xtw.WriteElementString("url", "http://www.teknikfreak.se/Bilder/Nyhetsbilder/" + strImage);
  284. xtw.WriteElementString("title", strTitle);
  285. xtw.WriteElementString("link", "http://www.teknikfreak.se/TeknikNyheter/" + strNewsId + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
  286. xtw.WriteEndElement();
  287.  
  288. TagsCollection tcGetTagsForNews = bll_tekniknyheter.GetTagsForNews(Convert.ToInt32(strNewsId));
  289. if (tcGetTagsForNews.Count > 0)
  290. {
  291. for (i = 0; i < tcGetTagsForNews.Count; i++)
  292. {
  293. xtw.WriteStartElement("category");
  294. xtw.WriteString(tcGetTagsForNews[i].Tag);
  295. xtw.WriteEndElement();
  296. }
  297. }
  298. //skriv ut </item>
  299. xtw.WriteEndElement();
  300.  
  301. }
  302.  
  303. //skriv ut </channel>
  304. xtw.WriteEndElement();
  305.  
  306. //skriv ut </rss>
  307. xtw.WriteEndElement();
  308.  
  309. //Stäng xml skrivaren
  310. xtw.Close();
  311. }
  312. catch (Exception ex)
  313. {
  314. Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
  315. }
  316. }
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement