PageRenderTime 66ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Server/web/App_Code/TopicItem.cs

https://bitbucket.org/fboltz/afpmobile
C# | 2586 lines | 2118 code | 432 blank | 36 comment | 323 complexity | 0dfb8f1cad7924b5c8c72320a10ddece MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0, LGPL-2.1, MIT, BSD-3-Clause, 0BSD, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Xml;
  5. using System.Xml.Xsl;
  6. using System.Net;
  7. using System.Text;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Globalization;
  11. using System.Net.Cache;
  12. /// <summary>
  13. /// Summary description for TopicItem
  14. /// </summary>
  15. public class TopicItem : List<TopicItem>, IAdvisory, IIconElement
  16. {
  17. public enum TopicType
  18. {
  19. eStandardTopic,
  20. eFavoritesTopic,
  21. eHearthTopic,
  22. eRatedTopic,
  23. eVideoramaTopic,
  24. eLocalSearchTopic,
  25. eRemoteSearchTopic,
  26. eDiaporamaTopic,
  27. eMagazinTopic,
  28. eAlertTopic,
  29. eDocumentationTopic,
  30. eCollectedVideo = 128
  31. }
  32. public struct NewsItemRef
  33. {
  34. public String headline;
  35. public String duid;
  36. public String href;
  37. public String description;
  38. }
  39. struct NewsMLTopicInfos
  40. {
  41. public String newsItemId;
  42. public String topicName;
  43. public String firstCreated;
  44. public String revisionDate;
  45. public String topicSource;
  46. public List<NewsItemRef> newsItemRefs;
  47. public List<NewsItemDocument> checkedComponents;
  48. public NewsMLTopicInfos(List<NewsItemRef> refs)
  49. {
  50. newsItemId = String.Empty;
  51. topicName = String.Empty;
  52. firstCreated = String.Empty;
  53. revisionDate = String.Empty;
  54. topicSource = String.Empty;
  55. newsItemRefs = null;
  56. checkedComponents = null;
  57. newsItemRefs = refs;
  58. }
  59. public NewsMLTopicInfos(List<NewsItemDocument> components)
  60. {
  61. newsItemId = String.Empty;
  62. topicName = String.Empty;
  63. firstCreated = String.Empty;
  64. revisionDate = String.Empty;
  65. topicSource = String.Empty;
  66. newsItemRefs = null;
  67. checkedComponents = components;
  68. newsItemRefs = null;
  69. }
  70. }
  71. class Thumbnail : IIconElement
  72. {
  73. private String mvar_IconName;
  74. private String mvar_IconDatas;
  75. private DateTime mvar_IconModified;
  76. public Thumbnail(String iconName, String iconDatas, DateTime iconLastModified)
  77. {
  78. mvar_IconName = iconName;
  79. mvar_IconDatas = iconDatas;
  80. mvar_IconModified = iconLastModified;
  81. }
  82. #region IIconElement Members
  83. public string IconName
  84. {
  85. get { return mvar_IconName; }
  86. }
  87. public DateTime LastModifiedIcons
  88. {
  89. get { return mvar_IconModified; }
  90. }
  91. public void WriteIcons(HttpRequest currentRequest, XmlWriter wr)
  92. {
  93. wr.WriteStartElement("icons");
  94. wr.WriteAttributeString("name", this.IconName);
  95. wr.WriteAttributeString("class", "thumbnail");
  96. wr.WriteStartElement("icon");
  97. wr.WriteAttributeString("smallSize", "0");
  98. wr.WriteString(mvar_IconDatas);
  99. wr.WriteEndElement();
  100. wr.WriteEndElement();
  101. }
  102. public DateTime CollectIcons(SortedList<string, IIconElement> icons)
  103. {
  104. return mvar_IconModified;
  105. }
  106. #endregion
  107. }
  108. class NewsItemDocument
  109. {
  110. private XmlDocument mvar_Content;
  111. private String mvar_HRef;
  112. private TopicItem mvar_OwnerTopic;
  113. private Utilities.XmlDocumentCache mvar_DocumentCache;
  114. private DateTime mvar_LastModified;
  115. public Utilities.XmlDocumentCache DocumentCache
  116. {
  117. get
  118. {
  119. return mvar_DocumentCache;
  120. }
  121. }
  122. public DateTime LastModified
  123. {
  124. get
  125. {
  126. return mvar_LastModified;
  127. }
  128. }
  129. public NewsItemDocument(TopicItem ownerTopic, Uri remoteDocumentUrl, String href, DateTime lastModified)
  130. {
  131. Uri remoteItemUrl = new Uri(remoteDocumentUrl, href);
  132. mvar_HRef = href;
  133. mvar_LastModified = lastModified;
  134. mvar_DocumentCache = Utilities.LoadXmlDocument(remoteItemUrl, out mvar_Content, ref mvar_LastModified, RequestCacheLevel.Revalidate);
  135. mvar_OwnerTopic = ownerTopic;
  136. }
  137. public void AppendDocumentToIndex(XmlWriter wr, String parentUno, DataCenter dc)
  138. {
  139. Uri remoteMediaUrl = this.OwnerTopic.GetRemoteMediaUrl(false);
  140. String itemHref;
  141. XmlElement bagPhoto;
  142. XmlNode geolocNode;
  143. String itemUno;
  144. float globalrate = 0;
  145. float rate = 0;
  146. int totalrate = 0;
  147. String parentItem;
  148. String CatchLine;
  149. String TitleLine;
  150. String headLine;
  151. String subHeadLine;
  152. String slugLine;
  153. String revision;
  154. String refPhoto;
  155. String dateLine;
  156. String copyright;
  157. String firstCreated;
  158. String revisionDate;
  159. String root;
  160. try
  161. {
  162. if (this.href.Contains("/"))
  163. {
  164. itemUno = Utilities.removeExtension(this.href.Substring(this.href.LastIndexOf("/") + 1));
  165. root = this.href.Substring(0, this.href.LastIndexOf("/") + 1);
  166. }
  167. else
  168. {
  169. itemUno = Utilities.removeExtension(this.href);
  170. root = String.Empty;
  171. }
  172. if (String.IsNullOrEmpty(root))
  173. {
  174. if (Settings.WriteFullURL)
  175. itemHref = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.OwnerTopic.Uno, itemUno);
  176. else
  177. itemHref = String.Format("view.ashx?uno={0}&item={1}", this.OwnerTopic.Uno, itemUno);
  178. }
  179. else
  180. {
  181. if (Settings.WriteFullURL)
  182. itemHref = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.OwnerTopic.Uno, Utilities.removeExtension(this.href));
  183. else
  184. itemHref = String.Format("view.ashx?uno={0}&item={1}", this.OwnerTopic.Uno, Utilities.removeExtension(this.href));
  185. }
  186. {
  187. headLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
  188. subHeadLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine");
  189. slugLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine");
  190. revision = Utilities.InnerText(this.content, "/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId");
  191. refPhoto = Utilities.InnerAttribute(this.content, "/NewsML/NewsItem/NewsComponent/NewsComponent[1]/ContentItem/DataContent/media[@media-type='image']/media-reference/@data-location");
  192. dateLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/DateLine");
  193. copyright = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine");
  194. geolocNode = this.content.SelectSingleNode("/NewsML/NewsItem/NewsComponent/DescriptiveMetadata/Location[@HowPresent='Origin']");
  195. if (String.IsNullOrEmpty(refPhoto))
  196. refPhoto = Utilities.InnerAttribute(this.content, "/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]/@Duid");
  197. else if (refPhoto.StartsWith("#"))
  198. refPhoto = refPhoto.Substring(1);
  199. firstCreated = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsManagement/FirstCreated");
  200. revisionDate = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
  201. firstCreated = ConvertToGMTIfNeeded(firstCreated);
  202. revisionDate = ConvertToGMTIfNeeded(revisionDate);
  203. dc.GetRating(this.OwnerTopic.Parent.Langue, this.OwnerTopic.Uno, itemUno, out parentItem, out rate, out globalrate, out totalrate);
  204. wr.WriteStartElement("Item");
  205. wr.WriteAttributeString("type", "multimedia");
  206. wr.WriteAttributeString("uno", itemUno);
  207. wr.WriteAttributeString("href", itemHref);
  208. wr.WriteAttributeString("revision", revision);
  209. if (String.IsNullOrEmpty(parentUno) == false)
  210. wr.WriteAttributeString("parentId", parentUno);
  211. if (totalrate > 0)
  212. {
  213. wr.WriteAttributeString("globalRate", globalrate.ToString("0.00", CultureInfo.InvariantCulture));
  214. wr.WriteAttributeString("yourRate", rate.ToString("0.00", CultureInfo.InvariantCulture));
  215. wr.WriteAttributeString("numberOfVote", totalrate.ToString(CultureInfo.InvariantCulture));
  216. }
  217. if (geolocNode != null)
  218. {
  219. wr.WriteAttributeString("country", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'Country']/@Value"));
  220. wr.WriteAttributeString("city", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'City']/@Value"));
  221. wr.WriteAttributeString("longitude", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'Longitude']/@Value"));
  222. wr.WriteAttributeString("latitude", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'Latitude']/@Value"));
  223. }
  224. {
  225. wr.WriteStartElement("NewsLines");
  226. wr.WriteElementString("HeadLine", headLine);
  227. wr.WriteElementString("SubHeadLine", subHeadLine);
  228. wr.WriteElementString("SlugLine", slugLine);
  229. wr.WriteElementString("DateCreated", firstCreated);
  230. wr.WriteElementString("DatePublished", revisionDate);
  231. wr.WriteElementString("DateLine", dateLine);
  232. wr.WriteElementString("CopyRightLine", copyright);
  233. wr.WriteEndElement();
  234. }
  235. {
  236. wr.WriteStartElement("Bag");
  237. // Check if media
  238. if (this.content.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]").Count == 0)
  239. {
  240. wr.WriteAttributeString("uno", itemUno);
  241. wr.WriteStartElement("Content");
  242. wr.WriteAttributeString("type", "Text");
  243. wr.WriteAttributeString("role", "News");
  244. foreach (XmlElement text in this.content.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent[preceding-sibling::MediaType[@FormalName='Text']]/p"))
  245. {
  246. wr.WriteStartElement("p");
  247. wr.WriteString(Utilities.CleanParagraphe(text.InnerText));
  248. wr.WriteEndElement();
  249. }
  250. wr.WriteEndElement();
  251. }
  252. else
  253. {
  254. String bagUno = itemUno;
  255. if (String.IsNullOrEmpty(refPhoto) == false)
  256. {
  257. bagUno = this.OwnerTopic.buildUnoBagPhoto((XmlElement)this.content.SelectSingleNode(String.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']/NewsComponent/ContentItem[@Href]", refPhoto)), itemUno);
  258. wr.WriteAttributeString("uno", bagUno);
  259. dc.GetRating(this.OwnerTopic.Parent.Langue, this.OwnerTopic.Uno, bagUno, out parentItem, out rate, out globalrate, out totalrate);
  260. if (totalrate > 0)
  261. {
  262. wr.WriteAttributeString("globalRate", globalrate.ToString("0.00", CultureInfo.InvariantCulture));
  263. wr.WriteAttributeString("yourRate", rate.ToString("0.00", CultureInfo.InvariantCulture));
  264. wr.WriteAttributeString("numberOfVote", totalrate.ToString(CultureInfo.InvariantCulture));
  265. }
  266. }
  267. else
  268. {
  269. wr.WriteAttributeString("uno", itemUno);
  270. }
  271. CatchLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
  272. TitleLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
  273. if (String.IsNullOrEmpty(TitleLine))
  274. TitleLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/HeadLine");
  275. if (String.IsNullOrEmpty(CatchLine))
  276. {
  277. CatchLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent[preceding-sibling::MediaType[@FormalName='Text']]/p[1]");
  278. }
  279. if (String.IsNullOrEmpty(TitleLine) == false)
  280. {
  281. wr.WriteStartElement("Content");
  282. wr.WriteAttributeString("type", "Text");
  283. wr.WriteAttributeString("role", "Title");
  284. wr.WriteElementString("p", Utilities.CleanParagraphe(TitleLine));
  285. wr.WriteEndElement();
  286. }
  287. wr.WriteStartElement("Content");
  288. wr.WriteAttributeString("type", "Text");
  289. wr.WriteAttributeString("role", "News");
  290. wr.WriteElementString("p", Utilities.CleanParagraphe(CatchLine));
  291. wr.WriteEndElement();
  292. }
  293. //if (this.Video)
  294. {
  295. foreach (XmlElement videoAnchor in this.content.SelectNodes("//a[@class = 'video']"))
  296. {
  297. //Uri href = new Uri(remoteMediaUrl, videoAnchor.GetAttribute("href"));
  298. Uri href = this.OwnerTopic.GetRemoteMediaUrl(String.Format("{0}{1}", root, videoAnchor.GetAttribute("href")));
  299. wr.WriteStartElement("Content");
  300. wr.WriteAttributeString("type", "Video");
  301. wr.WriteAttributeString("role", videoAnchor.GetAttribute("title"));
  302. wr.WriteAttributeString("href", href.ToString());
  303. wr.WriteEndElement();
  304. }
  305. }
  306. if (String.IsNullOrEmpty(refPhoto) == false)
  307. {
  308. bagPhoto = (XmlElement)this.content.SelectSingleNode(String.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']", refPhoto));
  309. this.OwnerTopic.WriteBagItem(wr, remoteMediaUrl, bagPhoto, root, false, dc);
  310. }
  311. wr.WriteEndElement();
  312. foreach (XmlElement photo in this.content.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]"))
  313. {
  314. if (String.IsNullOrEmpty(refPhoto) || photo.GetAttribute("Duid").Equals(refPhoto) == false)
  315. {
  316. wr.WriteStartElement("Bag");
  317. this.OwnerTopic.WriteBagItem(wr, remoteMediaUrl, photo, root, true, dc);
  318. wr.WriteEndElement();
  319. }
  320. }
  321. }
  322. wr.WriteEndElement();
  323. }
  324. }
  325. catch (Exception ex)
  326. {
  327. System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
  328. }
  329. }
  330. public TopicItem OwnerTopic
  331. {
  332. get
  333. {
  334. return mvar_OwnerTopic;
  335. }
  336. }
  337. public XmlDocument content
  338. {
  339. get
  340. {
  341. return mvar_Content;
  342. }
  343. }
  344. public String href
  345. {
  346. get
  347. {
  348. return mvar_HRef;
  349. }
  350. }
  351. }
  352. // <topic startup="0" preferred="1" diaporama="1" uno="2008-11-4-11-10-00-32" name="Tout en image" icon="images/topics/diaporama.png"/>
  353. protected int mvar_NumOrder;
  354. protected string mvar_Uno;
  355. protected bool mvar_Startup;
  356. protected bool mvar_Preferred;
  357. protected bool mvar_Diaporama;
  358. protected bool mvar_Video;
  359. protected String mvar_FullName;
  360. protected String mvar_ShortName;
  361. protected String mvar_IconName;
  362. protected String mvar_LocalHref;
  363. protected TopicItems mvar_Parent;
  364. protected SortedList<String, SubTopicItem> mvar_SubTopicItems;
  365. protected List<Advisory> mvar_Advisories;
  366. protected TopicType mvar_TypeOfTopic;
  367. protected String mvar_Href;
  368. protected String mvar_Root;
  369. protected Site.NewsFormat mvar_Format;
  370. protected String mvar_XsltFileName;
  371. private String mvar_HTMLTag;
  372. private String mvar_TidyEncoding;
  373. private List<KeyValuePair<String, String>> mvar_foreignAttributes;
  374. private DateTime mvar_LastModified;
  375. private String mvar_FirstThumbnail;
  376. private String mvar_TopicDescription;
  377. private String mvar_topicID;
  378. public String TopicDescription
  379. {
  380. get
  381. {
  382. return mvar_TopicDescription;
  383. }
  384. set
  385. {
  386. mvar_TopicDescription = value;
  387. }
  388. }
  389. public String TopicID
  390. {
  391. get
  392. {
  393. return mvar_topicID;
  394. }
  395. set
  396. {
  397. mvar_topicID = value;
  398. }
  399. }
  400. private static List<String> phDeclaredAttributes;
  401. static TopicItem()
  402. {
  403. phDeclaredAttributes = new List<string>();
  404. phDeclaredAttributes.Add("type");
  405. phDeclaredAttributes.Add("fullName");
  406. phDeclaredAttributes.Add("shortName");
  407. phDeclaredAttributes.Add("uno");
  408. phDeclaredAttributes.Add("topicID");
  409. phDeclaredAttributes.Add("icon");
  410. phDeclaredAttributes.Add("local");
  411. phDeclaredAttributes.Add("root");
  412. phDeclaredAttributes.Add("href");
  413. phDeclaredAttributes.Add("video");
  414. phDeclaredAttributes.Add("diaporama");
  415. phDeclaredAttributes.Add("format");
  416. phDeclaredAttributes.Add("htmltag");
  417. phDeclaredAttributes.Add("startup");
  418. phDeclaredAttributes.Add("preferred");
  419. phDeclaredAttributes.Add("xslt");
  420. }
  421. public CompiledXsltFile GetCompiledXsltFile()
  422. {
  423. if (String.IsNullOrEmpty(mvar_XsltFileName) == false)
  424. return CompiledXsltFile.GetXlst(HttpContext.Current.Server.MapPath(String.Format("xslt/{0}", mvar_XsltFileName)), System.Diagnostics.Debugger.IsAttached, false);
  425. else
  426. return mvar_Parent.GetCompiledXsltFile();
  427. }
  428. public List<KeyValuePair<String, String>> foreignAttributes
  429. {
  430. get
  431. {
  432. if (mvar_foreignAttributes == null)
  433. mvar_foreignAttributes = new List<KeyValuePair<string, string>>();
  434. return mvar_foreignAttributes;
  435. }
  436. set
  437. {
  438. mvar_foreignAttributes = value;
  439. }
  440. }
  441. public void addForeignAttributes(XmlElement fromNode)
  442. {
  443. foreach (XmlAttribute attrib in fromNode.Attributes)
  444. {
  445. if (phDeclaredAttributes.Contains(attrib.Name) == false)
  446. this.foreignAttributes.Add(new KeyValuePair<string, string>(attrib.Name, attrib.Value));
  447. }
  448. }
  449. protected String HTMLTag
  450. {
  451. get { return mvar_HTMLTag; }
  452. }
  453. protected String TidyEncoding
  454. {
  455. get { return mvar_TidyEncoding; }
  456. }
  457. public Site.NewsFormat NewsItemFormat
  458. {
  459. get
  460. {
  461. if (mvar_Format == Site.NewsFormat.eFormatUseParent)
  462. return this.Parent.Parent.NewsItemFormat;
  463. else
  464. return mvar_Format;
  465. }
  466. }
  467. public String FirstThumbnail
  468. {
  469. get
  470. {
  471. return mvar_FirstThumbnail;
  472. }
  473. set
  474. {
  475. mvar_FirstThumbnail = value;
  476. }
  477. }
  478. public DateTime LastModified
  479. {
  480. get
  481. {
  482. return mvar_LastModified;
  483. }
  484. set
  485. {
  486. mvar_LastModified = value;
  487. }
  488. }
  489. public bool HaveHref
  490. {
  491. get
  492. {
  493. return String.IsNullOrEmpty(mvar_Href) == false;
  494. }
  495. }
  496. public bool HaveLocalHref
  497. {
  498. get
  499. {
  500. return String.IsNullOrEmpty(mvar_LocalHref) == false;
  501. }
  502. }
  503. public virtual Uri Href
  504. {
  505. get
  506. {
  507. if (String.IsNullOrEmpty(mvar_Href))
  508. return this.Parent.Href;
  509. else
  510. return new Uri(mvar_Href);
  511. }
  512. set
  513. {
  514. if (value != null)
  515. mvar_Href = value.ToString();
  516. else
  517. mvar_Href = null;
  518. }
  519. }
  520. public bool HaveRoot
  521. {
  522. get
  523. {
  524. return String.IsNullOrEmpty(mvar_Root) == false;
  525. }
  526. }
  527. public virtual String Root
  528. {
  529. get
  530. {
  531. if (String.IsNullOrEmpty(mvar_Root))
  532. return this.Parent.Root;
  533. else
  534. return mvar_Root;
  535. }
  536. set
  537. {
  538. mvar_Root = value;
  539. }
  540. }
  541. public static TopicType StringToTopicType(String value)
  542. {
  543. if (String.IsNullOrEmpty(value))
  544. return TopicType.eStandardTopic;
  545. if (value.CompareTo("favorite") == 0)
  546. return TopicType.eFavoritesTopic;
  547. if (value.CompareTo("rated") == 0)
  548. return TopicType.eRatedTopic;
  549. if (value.CompareTo("hearth") == 0)
  550. return TopicType.eHearthTopic;
  551. if (value.CompareTo("videorama") == 0)
  552. return TopicType.eVideoramaTopic;
  553. if (value.CompareTo("localsearch") == 0)
  554. return TopicType.eLocalSearchTopic;
  555. if (value.CompareTo("search") == 0)
  556. return TopicType.eRemoteSearchTopic;
  557. if (value.CompareTo("diaporama") == 0)
  558. return TopicType.eDiaporamaTopic;
  559. if (value.CompareTo("magazin") == 0)
  560. return TopicType.eMagazinTopic;
  561. if (value.CompareTo("alert") == 0)
  562. return TopicType.eAlertTopic;
  563. if (value.CompareTo("documentation") == 0)
  564. return TopicType.eDocumentationTopic;
  565. if (value.CompareTo("collect") == 0)
  566. return TopicType.eCollectedVideo;
  567. return TopicType.eStandardTopic;
  568. }
  569. public void AddAdvisory(Advisory ads)
  570. {
  571. if (mvar_Advisories == null)
  572. mvar_Advisories = new List<Advisory>();
  573. mvar_Advisories.Add(ads);
  574. }
  575. public Advisory GetNextAdvisory()
  576. {
  577. Advisory ads = null;
  578. if (mvar_Advisories != null)
  579. {
  580. mvar_Advisories.Sort(new Advisory.ComparisonAdvisory());
  581. ads = mvar_Advisories[0];
  582. }
  583. else
  584. ads = this.Parent.GetNextAdvisory();
  585. return ads;
  586. }
  587. public TopicType TypeOfTopic
  588. {
  589. get
  590. {
  591. return mvar_TypeOfTopic;
  592. }
  593. }
  594. public string Uno
  595. {
  596. get
  597. {
  598. return mvar_Uno;
  599. }
  600. }
  601. public bool Startup
  602. {
  603. get
  604. {
  605. return mvar_Startup;
  606. }
  607. }
  608. public bool Preferred
  609. {
  610. get
  611. {
  612. return mvar_Preferred;
  613. }
  614. }
  615. public string FullName
  616. {
  617. get
  618. {
  619. return mvar_FullName;
  620. }
  621. set
  622. {
  623. mvar_FullName = value;
  624. }
  625. }
  626. public string ShortName
  627. {
  628. get
  629. {
  630. return mvar_ShortName;
  631. }
  632. set
  633. {
  634. mvar_ShortName = value;
  635. }
  636. }
  637. public string IconName
  638. {
  639. get
  640. {
  641. return mvar_IconName;
  642. }
  643. }
  644. public TopicItems Parent
  645. {
  646. get
  647. {
  648. return mvar_Parent;
  649. }
  650. }
  651. public string LocalHref
  652. {
  653. get
  654. {
  655. return mvar_LocalHref;
  656. }
  657. }
  658. public bool Diaporama
  659. {
  660. get
  661. {
  662. return mvar_Diaporama;
  663. }
  664. }
  665. public bool Video
  666. {
  667. get
  668. {
  669. return mvar_Video;
  670. }
  671. }
  672. public SortedList<string, SubTopicItem> SubTopicItems
  673. {
  674. get
  675. {
  676. return mvar_SubTopicItems;
  677. }
  678. }
  679. public int NumOrder
  680. {
  681. get
  682. {
  683. return mvar_NumOrder;
  684. }
  685. }
  686. public void AddSubTopicItem(SubTopicItem item)
  687. {
  688. SubTopicItem temp;
  689. if (mvar_SubTopicItems == null)
  690. mvar_SubTopicItems = new SortedList<String, SubTopicItem>();
  691. this.Add(item);
  692. if (mvar_SubTopicItems.TryGetValue(item.Uno, out temp) == false)
  693. mvar_SubTopicItems.Add(item.Uno, item);
  694. else if (temp != item)
  695. throw new Exception(String.Format("In topic:{0}, subtopic with duplicate uno:{1} name:{2} conflict with {3}", this.FullName, item.Uno, item.FullName, temp.FullName));
  696. }
  697. public SubTopicItem GetSubTopicItemByID(String topicID)
  698. {
  699. if (mvar_SubTopicItems != null && String.IsNullOrEmpty(topicID) == false)
  700. {
  701. topicID = topicID.ToLowerInvariant();
  702. foreach (SubTopicItem item in mvar_SubTopicItems.Values)
  703. {
  704. if (item.TopicID.ToLowerInvariant().Equals(topicID))
  705. return item;
  706. }
  707. }
  708. return null;
  709. }
  710. public SubTopicItem GetSubTopicItem(String uno)
  711. {
  712. SubTopicItem item;
  713. if (mvar_SubTopicItems != null && mvar_SubTopicItems.TryGetValue(uno, out item))
  714. return item;
  715. return null;
  716. }
  717. public Utilities.XmlDocumentCache ListMediaItem(PhotoItemsCollection photoItems, DataCenter dc, ref DateTime lastModified)
  718. {
  719. XmlDocument remoteTopic;
  720. Uri remoteDocumentUrl;
  721. Uri remoteItemUrl;
  722. XmlDocument remoteItem;
  723. PhotoItems currentPhotoItems;
  724. PhotoItem currentPhotoItem;
  725. Utilities.XmlDocumentCache cache;
  726. remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}", this.Root, this.LocalHref));
  727. // Uri remoteMediaUrl = this.GetRemoteMediaUrl(false);
  728. cache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref lastModified, RequestCacheLevel.CacheIfAvailable);
  729. if (cache != Utilities.XmlDocumentCache.DocumentNotModified)
  730. {
  731. foreach (XmlElement item in remoteTopic.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent"))
  732. {
  733. String NewsItemRef = Utilities.InnerAttribute(item, "NewsItemRef/@NewsItem");
  734. try
  735. {
  736. remoteItemUrl = new Uri(remoteDocumentUrl, NewsItemRef);
  737. Utilities.LoadXmlDocument(remoteItemUrl, out remoteItem, ref lastModified, RequestCacheLevel.Revalidate);
  738. // Video only
  739. if (remoteItem.SelectNodes("//a[@class = 'video']").Count > 0)
  740. {
  741. String topicUno = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/NewsItemId");
  742. String topicSource = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/ProviderId");
  743. String firstCreated = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsManagement/FirstCreated");
  744. String revisionDate = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
  745. String headLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
  746. String subHeadLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine");
  747. String slugLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine");
  748. // String revision = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId");
  749. String CatchLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
  750. String TitleLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
  751. String dateLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/DateLine");
  752. String copyright = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine");
  753. if (String.IsNullOrEmpty(TitleLine))
  754. {
  755. CatchLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
  756. }
  757. if (String.IsNullOrEmpty(CatchLine))
  758. {
  759. CatchLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsComponent[1]/ContentItem/DataContent/p[1]");
  760. }
  761. foreach (XmlElement newsComponent in remoteItem.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]"))
  762. {
  763. String provider = Utilities.InnerAttribute(newsComponent, "AdministrativeMetadata/Provider/Party/@FormalName");
  764. String creator = Utilities.InnerAttribute(newsComponent, "AdministrativeMetadata/Creator/Party/@FormalName");
  765. float rate;
  766. float globalrate;
  767. int totalrate;
  768. String parentItem;
  769. currentPhotoItems = new PhotoItems();
  770. dc.GetRating(this.Parent.Langue, this.Uno, Utilities.removeExtension(NewsItemRef), out parentItem, out rate, out globalrate, out totalrate);
  771. currentPhotoItems.Source = topicSource;
  772. currentPhotoItems.DateCreated = firstCreated;
  773. currentPhotoItems.DateUpdated = revisionDate;
  774. //currentPhotoItems.Uno = topicUno;
  775. currentPhotoItems.MediaUno = String.Empty;
  776. currentPhotoItems.Owner = this;
  777. currentPhotoItems.Headline = headLine;
  778. currentPhotoItems.SlugLine = slugLine;
  779. currentPhotoItems.SubHeadLine = subHeadLine;
  780. currentPhotoItems.NewsUno = NewsItemRef;
  781. currentPhotoItems.CatchLine = CatchLine;
  782. currentPhotoItems.Title = TitleLine;
  783. currentPhotoItems.DateLine = dateLine;
  784. currentPhotoItems.CopyRightLine = copyright;
  785. currentPhotoItems.GlobalRate = globalrate;
  786. currentPhotoItems.Rate = rate;
  787. currentPhotoItems.TotalVote = totalrate;
  788. globalrate = 0;
  789. rate = 0;
  790. totalrate = 0;
  791. //if (this.Video)
  792. {
  793. foreach (XmlElement videoAnchor in remoteItem.SelectNodes("//a[@class = 'video']"))
  794. {
  795. //Uri videoUri = new Uri(remoteMediaUrl, videoAnchor.GetAttribute("href"));
  796. Uri videoUri = this.GetRemoteMediaUrl(videoAnchor.GetAttribute("href"));
  797. //VideoItem videoItem = new VideoItem(videoAnchor.GetAttribute("title"), this.BuildVideoHRef(videoAnchor.GetAttribute("href")));
  798. VideoItem videoItem = new VideoItem(videoAnchor.GetAttribute("title"), videoUri);
  799. currentPhotoItems.AddVideoItem(videoItem);
  800. }
  801. }
  802. foreach (XmlElement photo in newsComponent.SelectNodes("NewsComponent"))
  803. {
  804. String mediaType = Utilities.InnerAttribute(photo, "ContentItem/MediaType/@FormalName");
  805. String role = Utilities.InnerAttribute(photo, "Role/@FormalName");
  806. if (mediaType.Equals("Photo"))
  807. {
  808. String width = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Width']/@Value");
  809. String height = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Height']/@Value");
  810. String href = Utilities.InnerAttribute(photo, "ContentItem/@Href");
  811. if (String.IsNullOrEmpty(currentPhotoItems.MediaUno) && href.IndexOf("-") >= 0)
  812. {
  813. currentPhotoItems.MediaUno = href.Substring(0, href.IndexOf("-"));
  814. dc.GetRating(this.Parent.Langue, this.Uno, currentPhotoItems.MediaUno, out parentItem, out rate, out globalrate, out totalrate);
  815. }
  816. currentPhotoItem = new PhotoItem();
  817. currentPhotoItem.GlobalRate = globalrate;
  818. currentPhotoItem.Rate = rate;
  819. currentPhotoItem.TotalVote = totalrate;
  820. currentPhotoItem.Height = Int32.Parse(height);
  821. currentPhotoItem.Width = Int32.Parse(width);
  822. currentPhotoItem.Role = role;
  823. currentPhotoItem.Href = new Uri(remoteDocumentUrl, href);
  824. currentPhotoItems.AddItem(currentPhotoItem);
  825. }
  826. else
  827. {
  828. currentPhotoItems.Creator = creator;
  829. currentPhotoItems.Provider = provider;
  830. currentPhotoItems.Caption = Utilities.InnerText(photo, "ContentItem/DataContent/p").Trim();
  831. }
  832. }
  833. if (String.IsNullOrEmpty(currentPhotoItems.MediaUno))
  834. currentPhotoItems.MediaUno = topicUno;
  835. photoItems.Add(currentPhotoItems);
  836. }
  837. }
  838. }
  839. catch (Exception ex)
  840. {
  841. System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
  842. }
  843. }
  844. }
  845. return cache;
  846. }
  847. public virtual Uri GetRemoteMediaUrl(Uri uri)
  848. {
  849. if (Settings.WriteFullURL == false)
  850. uri = this.Href.MakeRelativeUri(uri);
  851. return uri;
  852. }
  853. public virtual Uri GetRemoteMediaUrl(String mediaHRef)
  854. {
  855. Uri uri = new Uri(this.GetRemoteMediaUrl(false), mediaHRef);
  856. if (Settings.WriteFullURL == false)
  857. uri = this.Href.MakeRelativeUri(uri);
  858. return uri;
  859. }
  860. public virtual Uri GetRemoteMediaUrl(bool forDownload)
  861. {
  862. Uri remoteDocumentUrl;
  863. if (String.IsNullOrEmpty(this.Parent.Parent.DirectLink) == false)
  864. {
  865. Uri requestUrl;
  866. requestUrl = HttpContext.Current.Request.Url;
  867. remoteDocumentUrl = new Uri(String.Format("{0}://{1}:{2}/{3}/{4}/{5}/",
  868. requestUrl.Scheme,
  869. requestUrl.Host,
  870. requestUrl.Port,
  871. this.Parent.Parent.DirectLink,
  872. this.Root,
  873. Utilities.ParentPath(this.LocalHref)));
  874. }
  875. else if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
  876. {
  877. remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}/", this.Root, Utilities.ParentPath(this.LocalHref)));
  878. }
  879. else
  880. {
  881. remoteDocumentUrl = null;
  882. }
  883. // System.Console.WriteLine(remoteDocumentUrl.ToString());
  884. return remoteDocumentUrl;
  885. }
  886. public virtual Uri GetRemoteTopicItemDocumentUrl(String queryItem)
  887. {
  888. Uri remoteDocumentUrl;
  889. if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
  890. {
  891. remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}/{2}.xml", this.Root, Utilities.ParentPath(this.LocalHref), queryItem));
  892. }
  893. else
  894. {
  895. remoteDocumentUrl = null;
  896. }
  897. return remoteDocumentUrl;
  898. }
  899. private void AppendBagPhoto(XmlTextWriter wr, XmlDocument remoteDocument, Uri remoteDocumentUrl, String refPhoto, Uri previewUri, bool itsVideo, bool writeAsData)
  900. {
  901. XmlElement bagPhoto = (XmlElement)remoteDocument.SelectSingleNode(String.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']", refPhoto));
  902. XmlElement contentPhoto;
  903. Uri imgUrl;
  904. if (bagPhoto != null)
  905. {
  906. String provider = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Provider/Party/@FormalName");
  907. String creator = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Creator/Party/@FormalName");
  908. String caption = Utilities.InnerText(bagPhoto, "NewsLines/HeadLine").Trim();
  909. XmlElement preview = (XmlElement)bagPhoto.SelectSingleNode("NewsComponent[Role[@FormalName='Preview']]");
  910. int width;
  911. int height;
  912. contentPhoto = (XmlElement)bagPhoto.SelectSingleNode("NewsComponent[Role[@FormalName='Quicklook']]");
  913. if (contentPhoto == null)
  914. contentPhoto = (XmlElement)bagPhoto.SelectSingleNode("NewsComponent[Role[@FormalName='Thumbnail']]");
  915. if (contentPhoto == null)
  916. contentPhoto = preview;
  917. if (contentPhoto != null)
  918. {
  919. imgUrl = new Uri(remoteDocumentUrl, Utilities.InnerAttribute(contentPhoto, "ContentItem/@Href"));
  920. if (previewUri == null && preview != null)
  921. previewUri = new Uri(remoteDocumentUrl, Utilities.InnerAttribute(preview, "ContentItem/@Href"));
  922. width = Utilities.InnerAttributeAsInteger(contentPhoto, "ContentItem/Characteristics/Property[@FormalName='Width']/@Value");
  923. height = Utilities.InnerAttributeAsInteger(contentPhoto, "ContentItem/Characteristics/Property[@FormalName='Height']/@Value");
  924. wr.WriteStartElement("div");
  925. {
  926. wr.WriteAttributeString("align", "center");
  927. wr.WriteStartElement("div");
  928. wr.WriteAttributeString("class", "media");
  929. if (width > 0 && height > 0)
  930. {
  931. wr.WriteAttributeString("style", String.Format("width:{0}px;", width + 2));
  932. }
  933. {
  934. wr.WriteStartElement("div");
  935. {
  936. wr.WriteAttributeString("class", "image");
  937. wr.WriteStartElement("div");
  938. if (height > 0)
  939. wr.WriteAttributeString("style", String.Format("display: block; height:{0}px;", height));
  940. else
  941. wr.WriteAttributeString("style", String.Format("display: block;"));
  942. {
  943. if (previewUri != null)
  944. {
  945. wr.WriteStartElement("a");
  946. wr.WriteAttributeString("class", "preview");
  947. wr.WriteAttributeString("href", previewUri.ToString());
  948. }
  949. {
  950. wr.WriteStartElement("img");
  951. wr.WriteAttributeString("class", "imglink");
  952. wr.WriteAttributeString("alt", caption);
  953. Utilities.WriteDataUrl(wr, imgUrl);
  954. if (width > 0)
  955. wr.WriteAttributeString("width", width.ToString());
  956. if (height > 0)
  957. wr.WriteAttributeString("height", height.ToString());
  958. wr.WriteEndElement();
  959. }
  960. if (previewUri != null)
  961. wr.WriteEndElement();
  962. }
  963. if (itsVideo)
  964. {
  965. wr.WriteStartElement("div");
  966. wr.WriteAttributeString("style", String.Format("display: inline; position: relative; top:-{0}px", (height / 2) + 20));
  967. wr.WriteStartElement("a");
  968. wr.WriteAttributeString("class", "preview");
  969. wr.WriteAttributeString("href", previewUri.ToString());
  970. wr.WriteStartElement("img");
  971. wr.WriteAttributeString("alt", String.Empty);
  972. Utilities.WriteDataUrl(wr, new Uri(String.Format("{0}/images/video.png", Utilities.getRootPath())));
  973. wr.WriteEndElement();
  974. wr.WriteEndElement();
  975. wr.WriteEndElement();
  976. }
  977. wr.WriteEndElement(); //span
  978. wr.WriteEndElement(); //span
  979. if (String.IsNullOrEmpty(caption) == false)
  980. {
  981. wr.WriteStartElement("div");
  982. {
  983. wr.WriteAttributeString("class", "caption");
  984. wr.WriteString(caption);
  985. }
  986. wr.WriteEndElement();
  987. }
  988. if (String.IsNullOrEmpty(provider) == false || String.IsNullOrEmpty(creator) == false)
  989. {
  990. wr.WriteStartElement("div");
  991. wr.WriteAttributeString("class", "provider");
  992. {
  993. if (String.IsNullOrEmpty(provider) == false && String.IsNullOrEmpty(creator) == false)
  994. wr.WriteString(String.Format("{0} - {1}", provider, creator));
  995. else if (String.IsNullOrEmpty(provider) == false)
  996. wr.WriteString(provider);
  997. else
  998. wr.WriteString(creator);
  999. }
  1000. wr.WriteEndElement();
  1001. }
  1002. }
  1003. }
  1004. wr.WriteEndElement();
  1005. wr.WriteEndElement();
  1006. }
  1007. }
  1008. }
  1009. }
  1010. public void MostEmailedTopicItem(XmlTextWriter wr, String queryItem, DataCenter dc)
  1011. {
  1012. dc.AddMostEmailed(this.Parent.Langue, this.Uno, queryItem);
  1013. wr.WriteStartElement("EmailedResult");
  1014. wr.WriteStartElement("Emailed");
  1015. wr.WriteAttributeString("result", "1");
  1016. wr.WriteEndElement();
  1017. wr.WriteEndElement();
  1018. }
  1019. public void RateTopicItem(XmlTextWriter wr, String parentItem,
  1020. String queryItem, DataCenter.TypeOfRate kindOfItem, float rate, DataCenter dc)
  1021. {
  1022. Uri remoteDocumentUrl;
  1023. XmlDocument doc;
  1024. float globalrate = 0;
  1025. int totalvote = 0;
  1026. bool result;
  1027. String queryDocumentName;
  1028. DateTime lastModified = DateTime.MinValue;
  1029. try
  1030. {
  1031. // No parent meant that is a news ml doc
  1032. if (kindOfItem == DataCenter.TypeOfRate.eNewsItemRate)
  1033. {
  1034. queryDocumentName = String.Format("{0}.xml", queryItem);
  1035. if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
  1036. {
  1037. remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}/{2}", this.Root, Utilities.ParentPath(this.LocalHref), queryDocumentName));
  1038. }
  1039. else
  1040. {
  1041. remoteDocumentUrl = null;
  1042. }
  1043. Utilities.LoadXmlDocument(remoteDocumentUrl, out doc, ref lastModified, RequestCacheLevel.Revalidate);
  1044. parentItem = queryItem;
  1045. }
  1046. result = dc.AddRating(this.Parent.Langue, this.Uno, parentItem, queryItem, (DataCenter.TypeOfRate)kindOfItem, ref rate, out globalrate, out totalvote);
  1047. wr.WriteStartElement("RatingResult");
  1048. wr.WriteStartElement("Rate");
  1049. wr.WriteAttributeString("result", result ? "1" : "0");
  1050. wr.WriteAttributeString("globalRate", globalrate.ToString("0.00", CultureInfo.InvariantCulture));
  1051. wr.WriteAttributeString("yourRate", rate.ToString("0.00", CultureInfo.InvariantCulture));
  1052. wr.WriteAttributeString("numberOfVote", totalvote.ToString());
  1053. if (result == false)
  1054. {
  1055. wr.WriteStartElement("Reason");
  1056. wr.WriteAttributeString("errCode", "0");
  1057. wr.WriteString("Already voted");
  1058. wr.WriteEndElement();
  1059. }
  1060. wr.WriteEndElement();
  1061. wr.WriteEndElement();
  1062. }
  1063. catch (WebException ex)
  1064. {
  1065. int statusCode = 500;
  1066. if (ex.Response is HttpWebResponse)
  1067. {
  1068. statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
  1069. }
  1070. wr.WriteStartElement("RatingResult");
  1071. wr.WriteStartElement("Rate");
  1072. wr.WriteAttributeString("result", "0");
  1073. wr.WriteAttributeString("globalRate", "0.0");
  1074. wr.WriteAttributeString("yourRate", "0.0");
  1075. wr.WriteAttributeString("numberOfVote", "0");
  1076. wr.WriteStartElement("Reason");
  1077. wr.WriteAttributeString("errCode", statusCode.ToString());
  1078. wr.WriteString("Document not found");
  1079. wr.WriteEndElement();
  1080. wr.WriteEndElement();
  1081. wr.WriteEndElement();
  1082. }
  1083. }
  1084. private void WriteCssContent(XmlTextWriter wr, bool writeAsLink)
  1085. {
  1086. if (writeAsLink)
  1087. {
  1088. wr.WriteStartElement("link");
  1089. wr.WriteAttributeString("rel", "stylesheet");
  1090. wr.WriteAttributeString("type", "text/css");
  1091. if (File.Exists(HttpContext.Current.Server.MapPath(String.Format("css/{0}/document.css", this.Parent.Langue))))
  1092. wr.WriteAttributeString("href", String.Format("{0}/css/{1}/document.css", Utilities.getRootPath(), this.Parent.Langue));
  1093. else
  1094. wr.WriteAttributeString("href", String.Format("{0}/css/document.css", Utilities.getRootPath()));
  1095. wr.WriteEndElement(); // link
  1096. }
  1097. else
  1098. {
  1099. String cssPath;
  1100. String cssContent;
  1101. if (File.Exists(HttpContext.Current.Server.MapPath(String.Format("css/{0}/document.css", this.Parent.Langue))))
  1102. cssPath = HttpContext.Current.Server.MapPath(String.Format("css/{0}/document.css", this.Parent.Langue));
  1103. else
  1104. cssPath = HttpContext.Current.Server.MapPath("css/document.css");
  1105. cssContent = String.Format("{0}{1}{2}", "\n", File.ReadAllText(cssPath), "\n");
  1106. cssContent = cssContent.Replace("\n", "").Replace("\r", "").Replace("\t", "");
  1107. wr.WriteStartElement("style");
  1108. wr.WriteAttributeString("type", "text/css");
  1109. wr.WriteRaw(cssContent);
  1110. wr.WriteEndElement(); // link
  1111. }
  1112. }
  1113. private static String[] phQuicklookRoles = { "Quicklook", "Squared220", "Squared170", "Thumbnail" };
  1114. private static String[] phPreviewRoles = { "HighDef", "Preview", "Quicklook" };
  1115. virtual public Utilities.XmlDocumentCache DownloadTopicItem(XmlTextWriter wr, String queryItem,
  1116. DataCenter dc, ref DateTime lastModified, ref String ETag)
  1117. {
  1118. XmlDocument remoteDocument = null;
  1119. Uri remoteDocumentUrl = this.GetRemoteTopicItemDocumentUrl(queryItem);
  1120. Uri remoteMediaUrl = this.GetRemoteMediaUrl(true);
  1121. Utilities.XmlDocumentCache cache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteDocument, ref lastModified, RequestCacheLevel.Revalidate);
  1122. XmlNode disclaimer = this.Parent.Disclaimer;
  1123. CompiledXsltFile xsltFile = this.GetCompiledXsltFile();
  1124. int fixedSize = Settings.FixedSize;
  1125. int version = Settings.XsltVersion;
  1126. ETag = queryItem;
  1127. if (cache == Utilities.XmlDocumentCache.DocumentNotModified)
  1128. {
  1129. if (xsltFile.ChangedDate.CompareTo(lastModified) > 0)
  1130. {
  1131. cache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteDocument, ref lastModified, RequestCacheLevel.Reload);
  1132. lastModified = xsltFile.ChangedDate;
  1133. }
  1134. }
  1135. if (cache != Utilities.XmlDocumentCache.DocumentNotModified)
  1136. {
  1137. String dateAndTime = Utilities.InnerText(remoteDocument, "/NewsML/NewsEnvelope/DateAndTime");
  1138. String firstCreated = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsManagement/FirstCreated");
  1139. String revisionDate = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
  1140. dateAndTime = ConvertToGMTIfNeeded(dateAndTime);
  1141. firstCreated = ConvertToGMTIfNeeded(firstCreated);
  1142. revisionDate = ConvertToGMTIfNeeded(revisionDate);
  1143. String normalizedUno = queryItem;
  1144. if (normalizedUno.Contains("/"))
  1145. normalizedUno = normalizedUno.Substring(normalizedUno.LastIndexOf("/") + 1);
  1146. if (xsltFile != null)
  1147. {
  1148. XmlNodeList docAnchors = remoteDocument.SelectNodes("//a[@class = 'document']");
  1149. List<TopicItem> documentation = this.Parent.GetTopicItemByType(TopicType.eDocumentationTopic);
  1150. XmlElement NewsExtension = remoteDocument.CreateElement("NewsExtension");
  1151. String docUno = String.Empty;
  1152. if (documentation.Count > 0)
  1153. docUno = documentation[0].Uno;
  1154. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("version")).Value = version.ToString();
  1155. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("id")).Value = normalizedUno;
  1156. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("uno")).Value = this.Uno;
  1157. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("server")).Value = Utilities.getRootPath();
  1158. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("documentation")).Value = docUno;
  1159. // Traitement des dates
  1160. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("dateAndTime")).Value = dateAndTime;
  1161. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("firstCreated")).Value = firstCreated;
  1162. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("thisRevisionCreated")).Value = revisionDate;
  1163. if (Settings.WriteNormalImgUrl)
  1164. NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("DontUseDataUrl")).Value = "1";
  1165. if (docAnchors.Count > 0 && String.IsNullOrEmpty(docUno) == false)
  1166. {
  1167. XmlElement NewsComponent = (XmlElement)NewsExtension.AppendChild(remoteDocument.CreateElement("NewsComponent"));
  1168. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = "document";
  1169. foreach (XmlElement anchor in docAnchors)
  1170. {
  1171. XmlElement docComponent = (XmlElement)remoteDocument.CreateElement("NewsComponent");
  1172. String docHref = anchor.GetAttribute("href");
  1173. docHref = docHref.Substring(docHref.LastIndexOf("/") + 1);
  1174. String itemUno = docHref.Substring(0, docHref.LastIndexOf("."));
  1175. String itemHref = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), docUno, itemUno);
  1176. docComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = "document";
  1177. docComponent.Attributes.Append(remoteDocument.CreateAttribute("duid")).Value = itemUno;
  1178. docComponent.Attributes.Append(remoteDocument.CreateAttribute("href")).Value = itemHref;
  1179. NewsComponent.AppendChild(docComponent);
  1180. }
  1181. }
  1182. foreach (XmlElement dataContent in remoteDocument.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]"))
  1183. {
  1184. String Duid = dataContent.GetAttribute("Duid");
  1185. XmlElement NewsComponent = remoteDocument.CreateElement("NewsComponent");
  1186. XmlElement previewComponent = null;
  1187. XmlElement videoComponent = null;
  1188. int width = 0;
  1189. int height = 0;
  1190. int video = 0;
  1191. Uri imgUrl = null;
  1192. Uri previewUrl = null;
  1193. String href;
  1194. videoComponent = (XmlElement)remoteDocument.SelectSingleNode(String.Format("//a[@class = 'videoSet']/a[@class = 'video' and @title = '{0}' and preceding-sibling::a[@class = 'photo' and @href = '#{1}']]", Settings.VideoClass, Duid));
  1195. if (videoComponent != null)
  1196. {
  1197. previewUrl = new Uri(remoteDocumentUrl, videoComponent.GetAttribute("href"));
  1198. video = 1;
  1199. }
  1200. else
  1201. {
  1202. foreach (String role in Settings.GetNamedCollection("PreviewRoles", phPreviewRoles))
  1203. {
  1204. previewComponent = (XmlElement)dataContent.SelectSingleNode(String.Format("NewsComponent[Role[@FormalName='{0}']]", role));
  1205. if (previewComponent != null)
  1206. {
  1207. previewUrl = new Uri(remoteDocumentUrl, Utilities.InnerAttribute(previewComponent, "ContentItem/@Href"));
  1208. break;
  1209. }
  1210. }
  1211. }
  1212. if (version > 1)
  1213. {
  1214. NewsExtension.AppendChild(NewsComponent);
  1215. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("duid")).Value = dataContent.GetAttribute("Duid");
  1216. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("hduid")).Value = string.Format("#{0}", dataContent.GetAttribute("Duid"));
  1217. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("preview")).Value = previewUrl.AbsoluteUri;
  1218. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("video")).Value = video.ToString();
  1219. foreach (XmlElement component in dataContent.SelectNodes("NewsComponent[ContentItem/MediaType[@FormalName = 'Photo']]"))
  1220. {
  1221. href = Utilities.InnerAttribute(component, "ContentItem/@Href");
  1222. if (String.IsNullOrEmpty(href) == false)
  1223. {
  1224. XmlElement subNewsComponent = (XmlElement)NewsComponent.AppendChild(remoteDocument.CreateElement("NewsComponent"));
  1225. width = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Width']/@Value");
  1226. height = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Height']/@Value");
  1227. imgUrl = new Uri(remoteDocumentUrl, href);
  1228. subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = Utilities.InnerAttribute(component, "Role/@FormalName");
  1229. subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("width")).Value = width.ToString();
  1230. subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("height")).Value = height.ToString();
  1231. subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("href")).Value = imgUrl.AbsoluteUri;
  1232. if (Settings.WriteNormalImgUrl)
  1233. {
  1234. subNewsComponent.InnerText = imgUrl.AbsoluteUri;
  1235. }
  1236. else
  1237. {
  1238. String contentType;
  1239. String imgDatas = Utilities.WebRequestContentEncodedBase64(imgUrl, out contentType);
  1240. if (String.IsNullOrEmpty(imgDatas) == false)
  1241. subNewsComponent.InnerText = imgDatas;
  1242. else
  1243. subNewsComponent.InnerText = imgUrl.AbsoluteUri;
  1244. }
  1245. NewsComponent.AppendChild(subNewsComponent);
  1246. }
  1247. }
  1248. }
  1249. else
  1250. {
  1251. XmlElement component = null;
  1252. // Search Quicklook
  1253. foreach (String role in Settings.GetNamedCollection("QuicklookRoles", phQuicklookRoles))
  1254. {
  1255. component = (XmlElement)dataContent.SelectSingleNode(String.Format("NewsComponent[Role[@FormalName='{0}']]", role));
  1256. if (component != null)
  1257. break;
  1258. }
  1259. if (component != null)
  1260. {
  1261. href = Utilities.InnerAttribute(component, "ContentItem/@Href");
  1262. if (String.IsNullOrEmpty(href) == false)
  1263. {
  1264. width = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Width']/@Value");
  1265. height = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Height']/@Value");
  1266. imgUrl = new Uri(remoteDocumentUrl, href);
  1267. NewsExtension.AppendChild(NewsComponent);
  1268. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("duid")).Value = dataContent.GetAttribute("Duid");
  1269. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("hduid")).Value = string.Format("#{0}", dataContent.GetAttribute("Duid"));
  1270. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = "Quicklook";
  1271. if (fixedSize == 0)
  1272. {
  1273. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("width")).Value = width.ToString();
  1274. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("height")).Value = height.ToString();
  1275. }
  1276. else
  1277. {
  1278. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("width")).Value = fixedSize.ToString();
  1279. }
  1280. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("href")).Value = imgUrl.AbsoluteUri;
  1281. NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("preview")).Value = previewUrl.AbsoluteUri;
  1282. if (Settings.WriteNormalImgUrl)
  1283. {
  1284. NewsComponent.InnerText = imgUrl.AbsoluteUri;
  1285. }
  1286. else
  1287. {
  1288. String contentType;
  1289. String imgDatas = Utilities.WebRequestContentEncodedBase64(imgUrl, out contentType);
  1290. if (String.IsNullOrEmpty(imgDatas) == false)
  1291. NewsComponent.InnerText = imgD

Large files files are truncated, but you can click here to view the full file