PageRenderTime 65ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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 = imgDatas;
  1292. else
  1293. NewsComponent.InnerText = imgUrl.AbsoluteUri;
  1294. }
  1295. }
  1296. }
  1297. }
  1298. }
  1299. XsltArgumentList arguments = new XsltArgumentList();
  1300. arguments.AddParam("NewsExtension", String.Empty, NewsExtension);
  1301. arguments.AddParam("Version", String.Empty, version);
  1302. arguments.AddParam("CSS", String.Empty, Settings.Css);
  1303. arguments.AddParam("ImageActive", String.Empty, Settings.ImageActive);
  1304. //wr.WriteDocType("html", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd", String.Empty);
  1305. xsltFile.Transform(remoteDocument, arguments, wr);
  1306. }
  1307. else
  1308. {
  1309. #region HTML Document
  1310. //wr.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", String.Empty);
  1311. wr.WriteStartElement("html");
  1312. wr.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml");
  1313. if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
  1314. {
  1315. String headLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
  1316. // String subHeadLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine");
  1317. // String slugLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine");
  1318. // String revision = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId");
  1319. String dateLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/DateLine");
  1320. String copyright = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine");
  1321. // String CatchLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
  1322. String TitleLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
  1323. bool paraOpened = false;
  1324. if (String.IsNullOrEmpty(TitleLine))
  1325. TitleLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
  1326. #region HTML Head
  1327. wr.WriteStartElement("head");
  1328. wr.WriteElementString("title", TitleLine);
  1329. // WriteCssContent(wr, false);
  1330. wr.WriteEndElement();
  1331. #endregion
  1332. #region HTML Body
  1333. wr.WriteStartElement("body");
  1334. wr.WriteAttributeString("style", "font-family:Arial");
  1335. if (Settings.WriteFullURL)
  1336. wr.WriteAttributeString("viewedUrl", String.Format("{0}/viewed.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.Uno, normalizedUno));
  1337. else
  1338. wr.WriteAttributeString("viewedUrl", String.Format("viewed.ashx?uno={0}&item={1}", this.Uno, normalizedUno));
  1339. if (String.IsNullOrEmpty(this.Parent.Direction) == false)
  1340. wr.WriteAttributeString("dir", this.Parent.Direction);
  1341. WriteCssContent(wr, false);
  1342. #region Head
  1343. if (remoteDocument.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]").Count == 0)
  1344. {
  1345. wr.WriteStartElement("div");
  1346. wr.WriteAttributeString("class", "head");
  1347. #region Headline SportDirect
  1348. wr.WriteElementString("h3", headLine);
  1349. wr.WriteStartElement("h4");
  1350. wr.WriteString(String.Format("{0} - ", copyright));
  1351. wr.WriteElementString("date", revisionDate);
  1352. wr.WriteEndElement();
  1353. #endregion
  1354. wr.WriteEndElement();
  1355. }
  1356. else
  1357. {
  1358. wr.WriteStartElement("div");
  1359. wr.WriteAttributeString("class", "head");
  1360. #region Title
  1361. if (String.IsNullOrEmpty(TitleLine) == false)
  1362. {
  1363. wr.WriteStartElement("div");
  1364. wr.WriteAttributeString("class", "title");
  1365. wr.WriteString(TitleLine);
  1366. wr.WriteEndElement();
  1367. }
  1368. #endregion
  1369. #region DateLine
  1370. {
  1371. if (String.IsNullOrEmpty(dateLine))
  1372. {
  1373. wr.WriteStartElement("div");
  1374. wr.WriteAttributeString("class", "dateLine");
  1375. wr.WriteElementString("date", revisionDate);
  1376. wr.WriteEndElement();
  1377. }
  1378. else
  1379. {
  1380. wr.WriteStartElement("div");
  1381. wr.WriteAttributeString("class", "dateLine");
  1382. wr.WriteString(String.Format("{0} - ", dateLine));
  1383. wr.WriteElementString("date", revisionDate);
  1384. wr.WriteEndElement();
  1385. }
  1386. }
  1387. #endregion
  1388. #region Paragraphe
  1389. wr.WriteStartElement("div");
  1390. wr.WriteAttributeString("class", "paragraphe");
  1391. wr.WriteElementString("p", "");
  1392. wr.WriteEndElement(); // DIV
  1393. #endregion
  1394. wr.WriteEndElement(); // DIV
  1395. }
  1396. #endregion
  1397. #region Content
  1398. foreach (XmlElement dataContent in remoteDocument.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent[preceding-sibling::MediaType[@FormalName='Text']]"))
  1399. {
  1400. foreach (XmlElement element in dataContent.ChildNodes)
  1401. {
  1402. if (element.Name == "media")
  1403. {
  1404. if (element.GetAttribute("media-type") == "image")
  1405. {
  1406. String refPhoto = Utilities.InnerAttribute(element, "media-reference/@data-location");
  1407. if (refPhoto.StartsWith("#"))
  1408. refPhoto = refPhoto.Substring(1);
  1409. if (paraOpened)
  1410. {
  1411. wr.WriteEndElement();
  1412. paraOpened = false;
  1413. }
  1414. AppendBagPhoto(wr, remoteDocument, remoteMediaUrl, refPhoto, null, false, true);
  1415. }
  1416. }
  1417. else if (element.Name == "p")
  1418. {
  1419. foreach (XmlElement anchors in element.SelectNodes("a"))
  1420. {
  1421. if (anchors.GetAttribute("class") == "videoSet")
  1422. {
  1423. String refPhoto = null;
  1424. String refVideo = null;
  1425. if (paraOpened)
  1426. {
  1427. wr.WriteEndElement();
  1428. paraOpened = false;
  1429. }
  1430. foreach (XmlElement anchor in anchors.SelectNodes("a"))
  1431. {
  1432. if (anchor.GetAttribute("class") == "photo")
  1433. {
  1434. refPhoto = anchor.GetAttribute("href");
  1435. }
  1436. else if (anchor.GetAttribute("class") == "video" && anchor.GetAttribute("title").Equals(Settings.VideoClass))
  1437. {
  1438. refVideo = anchor.GetAttribute("href");
  1439. }
  1440. }
  1441. if (String.IsNullOrEmpty(refPhoto) == false && String.IsNullOrEmpty(refVideo) == false)
  1442. {
  1443. if (refPhoto.StartsWith("#"))
  1444. refPhoto = refPhoto.Substring(1);
  1445. AppendBagPhoto(wr, remoteDocument, remoteMediaUrl, refPhoto, new Uri(remoteDocumentUrl, refVideo), true, true);
  1446. }
  1447. }
  1448. }
  1449. if (paraOpened == false)
  1450. {
  1451. paraOpened = true;
  1452. wr.WriteStartElement("div");
  1453. wr.WriteAttributeString("class", "paragraphe");
  1454. }
  1455. #region Paragraphe
  1456. wr.WriteStartElement("p");
  1457. wr.WriteAttributeString("class", "paragraphe");
  1458. wr.WriteString(Utilities.CleanParagraphe(element.InnerText));
  1459. wr.WriteEndElement();
  1460. #endregion
  1461. }
  1462. }
  1463. }
  1464. #endregion
  1465. if (paraOpened)
  1466. {
  1467. wr.WriteEndElement();
  1468. paraOpened = false;
  1469. }
  1470. #region Disclaimer
  1471. if (disclaimer != null)
  1472. {
  1473. wr.WriteStartElement("disclaimer");
  1474. wr.WriteNode(new XmlNodeReader(disclaimer), false);
  1475. wr.WriteEndElement();
  1476. }
  1477. #endregion
  1478. wr.WriteEndElement(); // body
  1479. #endregion
  1480. }
  1481. wr.WriteEndElement(); //html
  1482. #endregion
  1483. }
  1484. }
  1485. return cache;
  1486. }
  1487. public virtual Uri RemoteTopicIndexUrl
  1488. {
  1489. get
  1490. {
  1491. return new Uri(this.Href, String.Format("{0}/{1}", this.Root, this.LocalHref));
  1492. }
  1493. }
  1494. public static String ConvertToGMTIfNeeded(String date)
  1495. {
  1496. if (date.ToUpper().EndsWith("Z") == false)
  1497. {
  1498. DateTime dd;
  1499. if (DateTime.TryParseExact(date, "yyyyMMddTHHmmsszzzz", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dd) == false)
  1500. dd = DateTime.Now;
  1501. date = dd.ToUniversalTime().ToString("yyyyMMddTHHmmssZ");
  1502. }
  1503. return date;
  1504. }
  1505. public Uri BuildVideoHRef(String videoAnchor)
  1506. {
  1507. Uri newUri;
  1508. if (String.IsNullOrEmpty(this.Parent.Parent.DirectLink) == false)
  1509. {
  1510. Uri requestUrl;
  1511. requestUrl = new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority));
  1512. if (requestUrl.PathAndQuery.Equals("/"))
  1513. newUri = new Uri(String.Format("{0}://{1}:{2}/{3}/{4}/{5}", requestUrl.Scheme, requestUrl.Host, requestUrl.Port, this.Parent.Parent.DirectLink, Utilities.ParentPath(this.LocalHref), videoAnchor));
  1514. else
  1515. newUri = new Uri(String.Format("{0}://{1}:{2}{3}/{4}/{5}/{6}", requestUrl.Scheme, requestUrl.Host, requestUrl.Port, requestUrl.PathAndQuery, this.Parent.Parent.DirectLink, Utilities.ParentPath(this.LocalHref), videoAnchor));
  1516. }
  1517. else
  1518. newUri = new Uri(new Uri(String.Format("{0}/{1}/{2}", this.Href, this.Root, this.Parent.Photos)), videoAnchor);
  1519. return newUri;
  1520. }
  1521. private String buildUnoBagPhoto(XmlElement contentItem, String defaultUno)
  1522. {
  1523. String result = String.Empty;
  1524. if (contentItem != null)
  1525. {
  1526. String href = contentItem.GetAttribute("Href");
  1527. int offset = href.IndexOf("-");
  1528. if (offset < 0)
  1529. offset = href.IndexOf(".");
  1530. href = href.Substring(0, offset);
  1531. result = href;
  1532. }
  1533. else if (String.IsNullOrEmpty(defaultUno) == false)
  1534. result = defaultUno;
  1535. return result;
  1536. }
  1537. protected void WriteBagItem(XmlWriter wr, Uri remoteMediaUrl, XmlElement bagPhoto, String root, bool extractUno, DataCenter dc)
  1538. {
  1539. String provider = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Provider/Party/@FormalName");
  1540. String creator = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Creator/Party/@FormalName");
  1541. String headLine = Utilities.CleanParagraphe(Utilities.InnerText(bagPhoto, "NewsLines/HeadLine"));
  1542. String bagUno = String.Empty;
  1543. if (extractUno)
  1544. {
  1545. bagUno = buildUnoBagPhoto((XmlElement)bagPhoto.SelectSingleNode("NewsComponent/ContentItem[@Href]"), null);
  1546. if (String.IsNullOrEmpty(bagUno) == false)
  1547. {
  1548. float globalrate = 0;
  1549. float rate = 0;
  1550. int totalrate = 0;
  1551. String parentItem;
  1552. wr.WriteAttributeString("uno", bagUno);
  1553. dc.GetRating(this.Parent.Langue, this.Uno, bagUno, out parentItem, out rate, out globalrate, out totalrate);
  1554. if (totalrate > 0)
  1555. {
  1556. wr.WriteAttributeString("globalRate", globalrate.ToString(CultureInfo.InvariantCulture));
  1557. wr.WriteAttributeString("yourRate", rate.ToString(CultureInfo.InvariantCulture));
  1558. wr.WriteAttributeString("numberOfVote", totalrate.ToString(CultureInfo.InvariantCulture));
  1559. }
  1560. }
  1561. }
  1562. if (Settings.WritePhotoHeadline && String.IsNullOrEmpty(headLine) == false)
  1563. {
  1564. wr.WriteStartElement("Content");
  1565. wr.WriteAttributeString("type", "Text");
  1566. wr.WriteAttributeString("role", "HeadLine");
  1567. wr.WriteAttributeString("provider", provider);
  1568. wr.WriteAttributeString("creator", creator);
  1569. wr.WriteElementString("p", headLine);
  1570. wr.WriteEndElement();
  1571. }
  1572. foreach (XmlElement photo in bagPhoto.SelectNodes("NewsComponent"))
  1573. {
  1574. String mediaType = Utilities.InnerAttribute(photo, "ContentItem/MediaType/@FormalName");
  1575. String role = Utilities.InnerAttribute(photo, "Role/@FormalName");
  1576. wr.WriteStartElement("Content");
  1577. wr.WriteAttributeString("type", mediaType);
  1578. wr.WriteAttributeString("role", role);
  1579. if (mediaType.Equals("Photo"))
  1580. {
  1581. String width = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Width']/@Value");
  1582. String height = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Height']/@Value");
  1583. Uri href = new Uri(remoteMediaUrl, String.Format("{0}{1}", root, Utilities.InnerAttribute(photo, "ContentItem/@Href")));
  1584. // System.Console.WriteLine(Utilities.InnerAttribute(photo, "ContentItem/@Href"));
  1585. wr.WriteAttributeString("height", height);
  1586. wr.WriteAttributeString("width", width);
  1587. wr.WriteAttributeString("href", this.GetRemoteMediaUrl(href).ToString());
  1588. }
  1589. else
  1590. {
  1591. String dataContent = Utilities.InnerText(photo, "ContentItem/DataContent/p").Trim();
  1592. if (role.Equals("Caption") && String.IsNullOrEmpty(dataContent))
  1593. {
  1594. if (Settings.WritePhotoHeadline == false)
  1595. {
  1596. dataContent = headLine;
  1597. }
  1598. }
  1599. wr.WriteAttributeString("provider", provider);
  1600. wr.WriteAttributeString("creator", creator);
  1601. wr.WriteElementString("p", dataContent);
  1602. //wr.WriteElementString("p", Utilities.CleanParagraphe(Utilities.InnerText(bagPhoto, "NewsLines/HeadLine")));
  1603. }
  1604. wr.WriteEndElement();
  1605. }
  1606. }
  1607. private NewsMLTopicInfos DownloadNewsMLIndex(XmlDocument remoteTopic, ref NewsMLTopicInfos infos, bool append, bool headOnly)
  1608. {
  1609. Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
  1610. XmlNodeList newsComponents = remoteTopic.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent");
  1611. int maxArticles = this.Parent.Parent.MaxNumberOfItems;
  1612. if (append == false)
  1613. {
  1614. infos.newsItemId = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/NewsItemId");
  1615. infos.topicName = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NameLabel");
  1616. infos.firstCreated = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/NewsManagement/FirstCreated");
  1617. infos.revisionDate = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
  1618. infos.topicSource = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/ProviderId");
  1619. infos.checkedComponents = new List<NewsItemDocument>();
  1620. infos.firstCreated = ConvertToGMTIfNeeded(infos.firstCreated);
  1621. infos.revisionDate = ConvertToGMTIfNeeded(infos.revisionDate);
  1622. if (infos.newsItemRefs != null)
  1623. {
  1624. foreach (XmlNode node in remoteTopic.SelectNodes("//NewsItem/NewsComponent/NewsComponent"))
  1625. {
  1626. NewsItemRef itemRef = new NewsItemRef();
  1627. itemRef.headline = Utilities.InnerText(node, "NewsLines/HeadLine");
  1628. itemRef.duid = Utilities.InnerAttribute(node, "NewsItemRef/@Duid");
  1629. itemRef.href = Utilities.InnerAttribute(node, "NewsItemRef/@NewsItem");
  1630. itemRef.description = Utilities.InnerText(node, "NewsItemRef/Comment[@FormalName='Description']");
  1631. infos.newsItemRefs.Add(itemRef);
  1632. }
  1633. }
  1634. }
  1635. if (headOnly == false)
  1636. {
  1637. foreach (XmlElement item in newsComponents)
  1638. {
  1639. String NewsItemRef = Utilities.InnerAttribute(item, "NewsItemRef/@NewsItem");
  1640. NewsItemDocument remoteItem = null;
  1641. try
  1642. {
  1643. remoteItem = new NewsItemDocument(this, remoteDocumentUrl, NewsItemRef, DateTime.MinValue);
  1644. infos.checkedComponents.Add(remoteItem);
  1645. if (infos.checkedComponents.Count >= maxArticles)
  1646. break;
  1647. }
  1648. catch (Exception ex)
  1649. {
  1650. System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
  1651. }
  1652. }
  1653. }
  1654. return infos;
  1655. }
  1656. private void WriteNewsMLContent(XmlWriter wr, DataCenter dc, NewsMLTopicInfos infos)
  1657. {
  1658. #region Index Xml document
  1659. wr.WriteStartElement("Xafp");
  1660. {
  1661. wr.WriteAttributeString("type", "collection");
  1662. wr.WriteAttributeString("id", this.Uno);
  1663. wr.WriteAttributeString("newsItemId", infos.newsItemId);
  1664. wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
  1665. {
  1666. wr.WriteStartElement("Head");
  1667. wr.WriteElementString("Name", infos.topicName);
  1668. wr.WriteElementString("DateCreated", infos.firstCreated);
  1669. wr.WriteElementString("DateUpdated", infos.revisionDate);
  1670. wr.WriteElementString("Source", infos.topicSource);
  1671. wr.WriteElementString("NumberOfItems", infos.checkedComponents.Count.ToString());
  1672. wr.WriteEndElement();
  1673. {
  1674. wr.WriteStartElement("Bag");
  1675. foreach (NewsItemDocument remoteItem in infos.checkedComponents)
  1676. {
  1677. remoteItem.AppendDocumentToIndex(wr, remoteItem.OwnerTopic.Uno, dc);
  1678. }
  1679. wr.WriteEndElement();
  1680. }
  1681. }
  1682. }
  1683. wr.WriteEndElement();
  1684. #endregion
  1685. }
  1686. public bool isTopicModifiedSince(DateTime lastModified)
  1687. {
  1688. Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
  1689. Utilities.XmlDocumentCache docCache = Utilities.IfModifiedSince(remoteDocumentUrl, ref mvar_LastModified, RequestCacheLevel.Revalidate);
  1690. return (docCache != Utilities.XmlDocumentCache.DocumentNotModified) | (lastModified.CompareTo(mvar_LastModified) < 0);
  1691. }
  1692. public String getTopicOrderTable(String localName, List<NewsItemRef> diaporamOrder)
  1693. {
  1694. if (this.HaveLocalHref)
  1695. {
  1696. String nameLabel = localName;
  1697. XmlDocument remoteTopic = new XmlDocument();
  1698. Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
  1699. Utilities.XmlDocumentCache docCache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref mvar_LastModified, RequestCacheLevel.Revalidate);
  1700. // if (docCache != Utilities.XmlDocumentCache.DocumentNotModified)
  1701. // {
  1702. NewsMLTopicInfos infos;
  1703. infos.checkedComponents = new List<NewsItemDocument>();
  1704. infos.newsItemId = String.Empty;
  1705. infos.topicName = String.Empty;
  1706. infos.firstCreated = String.Empty;
  1707. infos.revisionDate = String.Empty;
  1708. infos.topicSource = String.Empty;
  1709. infos.newsItemRefs = diaporamOrder;
  1710. infos.firstCreated = String.Empty;
  1711. infos.revisionDate = String.Empty;
  1712. DownloadNewsMLIndex(remoteTopic, ref infos, false, false);
  1713. nameLabel = infos.topicName;
  1714. // }
  1715. // else if (docCache == Utilities.XmlDocumentCache.DocumentNotModified)
  1716. // {
  1717. // }
  1718. return nameLabel;
  1719. }
  1720. return localName;
  1721. }
  1722. public String getTopicNameLabel(String localName)
  1723. {
  1724. String nameLabel = localName;
  1725. XmlDocument remoteTopic = new XmlDocument();
  1726. Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
  1727. try
  1728. {
  1729. Utilities.XmlDocumentCache docCache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref mvar_LastModified, RequestCacheLevel.Revalidate);
  1730. // if (docCache != Utilities.XmlDocumentCache.DocumentNotModified)
  1731. {
  1732. if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
  1733. {
  1734. NewsMLTopicInfos infos;
  1735. infos.checkedComponents = null;
  1736. infos.newsItemId = String.Empty;
  1737. infos.topicName = String.Empty;
  1738. infos.firstCreated = String.Empty;
  1739. infos.revisionDate = String.Empty;
  1740. infos.topicSource = String.Empty;
  1741. infos.newsItemRefs = new List<TopicItem.NewsItemRef>();
  1742. infos.firstCreated = String.Empty;
  1743. infos.revisionDate = String.Empty;
  1744. DownloadNewsMLIndex(remoteTopic, ref infos, false, true);
  1745. nameLabel = infos.topicName;
  1746. if (infos.newsItemRefs.Count > 0)
  1747. {
  1748. if (String.IsNullOrEmpty(infos.newsItemRefs[0].duid) == false)
  1749. {
  1750. Uri uri = new Uri(remoteDocumentUrl, infos.newsItemRefs[0].duid);
  1751. this.FirstThumbnail = Utilities.LoadBinaryDocumentToBase64(uri);
  1752. }
  1753. if (String.IsNullOrEmpty(infos.newsItemRefs[0].description) == false)
  1754. this.TopicDescription = infos.newsItemRefs[0].description;
  1755. }
  1756. }
  1757. }
  1758. }
  1759. catch (Exception)
  1760. {
  1761. nameLabel = localName;
  1762. }
  1763. return nameLabel;
  1764. }
  1765. virtual public Utilities.XmlDocumentCache TopicIndex(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
  1766. {
  1767. XmlDocument remoteTopic = new XmlDocument();
  1768. Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
  1769. Utilities.XmlDocumentCache docCache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref lastModified, RequestCacheLevel.Revalidate);
  1770. if (docCache != Utilities.XmlDocumentCache.DocumentNotModified)
  1771. {
  1772. if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
  1773. {
  1774. NewsMLTopicInfos infos;
  1775. infos.checkedComponents = new List<NewsItemDocument>();
  1776. infos.newsItemRefs = null;
  1777. infos.newsItemId = String.Empty;
  1778. infos.topicName = String.Empty;
  1779. infos.firstCreated = String.Empty;
  1780. infos.revisionDate = String.Empty;
  1781. infos.topicSource = String.Empty;
  1782. infos.firstCreated = String.Empty;
  1783. infos.revisionDate = String.Empty;
  1784. DownloadNewsMLIndex(remoteTopic, ref infos, false, false);
  1785. WriteNewsMLContent(wr, dc, infos);
  1786. }
  1787. else
  1788. {
  1789. remoteTopic.WriteContentTo(wr);
  1790. }
  1791. }
  1792. return docCache;
  1793. }
  1794. private List<NewsItemDocument> ListHearthedItems(DataCenter dc)
  1795. {
  1796. IList<DataCenter.DataCenterResponse> responses = dc.ListMostHearthed(this, this.Parent.Parent.MaxNumberOfItems);
  1797. List<NewsItemDocument> checkedComponents = new List<NewsItemDocument>();
  1798. foreach (DataCenter.DataCenterResponse response in responses)
  1799. {
  1800. String NewsItemRef = String.Format("{0}.xml", response.parent);
  1801. NewsItemDocument remoteItem = null;
  1802. try
  1803. {
  1804. TopicItem ownerTopic = this.Parent.GetTopicItem(response.topic);
  1805. if (ownerTopic != null)
  1806. {
  1807. Uri remoteDocumentUrl = ownerTopic.RemoteTopicIndexUrl;
  1808. remoteItem = new NewsItemDocument(ownerTopic, remoteDocumentUrl, NewsItemRef, DateTime.MinValue);
  1809. checkedComponents.Add(remoteItem);
  1810. }
  1811. }
  1812. catch (Exception ex)
  1813. {
  1814. System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
  1815. }
  1816. }
  1817. return checkedComponents;
  1818. }
  1819. private List<NewsItemDocument> ListRatedItems(DataCenter dc)
  1820. {
  1821. IList<DataCenter.DataCenterResponse> responses = dc.ListMostRated(this, this.Parent.Parent.MaxNumberOfItems);
  1822. List<NewsItemDocument> checkedComponents = new List<NewsItemDocument>();
  1823. foreach (DataCenter.DataCenterResponse response in responses)
  1824. {
  1825. String NewsItemRef = response.uno;
  1826. NewsItemDocument remoteItem = null;
  1827. try
  1828. {
  1829. TopicItem ownerTopic = this.Parent.GetTopicItem(response.topic);
  1830. if (ownerTopic != null)
  1831. {
  1832. Uri remoteDocumentUrl = ownerTopic.RemoteTopicIndexUrl;
  1833. remoteItem = new NewsItemDocument(ownerTopic, remoteDocumentUrl, String.Format("{0}.xml", NewsItemRef), DateTime.MinValue);
  1834. checkedComponents.Add(remoteItem);
  1835. }
  1836. }
  1837. catch (Exception ex)
  1838. {
  1839. System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
  1840. }
  1841. }
  1842. return checkedComponents;
  1843. }
  1844. public Utilities.XmlDocumentCache HearthTopic(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
  1845. {
  1846. List<NewsItemDocument> checkedComponents = ListHearthedItems(dc);
  1847. lastModified = DateTime.Now;
  1848. #region Index Xml document
  1849. wr.WriteStartElement("Xafp");
  1850. {
  1851. wr.WriteAttributeString("type", "collection");
  1852. wr.WriteAttributeString("uno", this.Uno);
  1853. wr.WriteAttributeString("newsItemId", String.Format("mmd--{0}", this.FullName));
  1854. wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
  1855. {
  1856. wr.WriteStartElement("Head");
  1857. wr.WriteElementString("Name", this.FullName);
  1858. wr.WriteElementString("DateCreated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
  1859. wr.WriteElementString("DateUpdated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
  1860. wr.WriteElementString("Source", "AFP");
  1861. wr.WriteElementString("NumberOfItems", checkedComponents.Count.ToString());
  1862. wr.WriteEndElement();
  1863. {
  1864. wr.WriteStartElement("Bag");
  1865. foreach (NewsItemDocument remoteItem in checkedComponents)
  1866. {
  1867. remoteItem.AppendDocumentToIndex(wr, remoteItem.OwnerTopic.Uno, dc);
  1868. }
  1869. wr.WriteEndElement();
  1870. }
  1871. }
  1872. }
  1873. wr.WriteEndElement();
  1874. #endregion
  1875. return Utilities.XmlDocumentCache.DocumentModified;
  1876. }
  1877. public Utilities.XmlDocumentCache RatedTopic(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
  1878. {
  1879. List<NewsItemDocument> checkedComponents = ListRatedItems(dc);
  1880. lastModified = DateTime.Now;
  1881. #region Index Xml document
  1882. wr.WriteStartElement("Xafp");
  1883. {
  1884. wr.WriteAttributeString("type", "collection");
  1885. wr.WriteAttributeString("uno", this.Uno);
  1886. wr.WriteAttributeString("newsItemId", String.Format("mmd--{0}", this.FullName));
  1887. wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
  1888. {
  1889. wr.WriteStartElement("Head");
  1890. wr.WriteElementString("Name", this.FullName);
  1891. wr.WriteElementString("DateCreated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
  1892. wr.WriteElementString("DateUpdated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
  1893. wr.WriteElementString("Source", "AFP");
  1894. wr.WriteElementString("NumberOfItems", checkedComponents.Count.ToString());
  1895. wr.WriteEndElement();
  1896. {
  1897. wr.WriteStartElement("Bag");
  1898. foreach (NewsItemDocument remoteItem in checkedComponents)
  1899. {
  1900. remoteItem.AppendDocumentToIndex(wr, remoteItem.OwnerTopic.Uno, dc);
  1901. }
  1902. wr.WriteEndElement();
  1903. }
  1904. }
  1905. }
  1906. wr.WriteEndElement();
  1907. #endregion
  1908. return Utilities.XmlDocumentCache.DocumentModified;
  1909. }
  1910. public Utilities.XmlDocumentCache FavoritesTopic(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
  1911. {
  1912. lastModified = DateTime.Now;
  1913. #region Index Xml document
  1914. wr.WriteStartElement("Xafp");
  1915. {
  1916. wr.WriteAttributeString("type", "collection");
  1917. wr.WriteAttributeString("uno", this.Uno);
  1918. wr.WriteAttributeString("newsItemId", String.Format("mmd--{0}", this.FullName));
  1919. wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
  1920. {
  1921. wr.WriteStartElement("Head");
  1922. wr.WriteElementString("Name", this.FullName);
  1923. wr.WriteElementString("DateCreated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
  1924. wr.WriteElementString("DateUpdated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
  1925. wr.WriteElementString("Source", "AFP");
  1926. wr.WriteElementString("NumberOfItems", "0");
  1927. wr.WriteEndElement();
  1928. {
  1929. wr.WriteStartElement("Bag");
  1930. wr.WriteEndElement();
  1931. }
  1932. }
  1933. }
  1934. wr.WriteEndElement();
  1935. #endregion
  1936. return Utilities.XmlDocumentCache.DocumentModified;
  1937. }
  1938. public TopicItem(TopicItems parent,
  1939. TopicType topicType,
  1940. int numOrder,
  1941. String topicID,
  1942. String uno,
  1943. String fullName,
  1944. String shortName,
  1945. String local,
  1946. String icon,
  1947. bool startup,
  1948. bool preferred,
  1949. bool diaporama,
  1950. bool video,
  1951. String href,
  1952. String root,
  1953. Site.NewsFormat newsFormat,
  1954. String htmltag,
  1955. String tidyEncoding,
  1956. String xsltFileName,
  1957. String description
  1958. )
  1959. {
  1960. mvar_NumOrder = numOrder;
  1961. mvar_topicID = topicID;
  1962. mvar_Uno = uno;
  1963. mvar_Startup = startup;
  1964. mvar_Preferred = preferred;
  1965. mvar_FullName = fullName;
  1966. mvar_ShortName = shortName;
  1967. mvar_IconName = icon;
  1968. mvar_Diaporama = diaporama;
  1969. mvar_LocalHref = local;
  1970. mvar_Video = video;
  1971. mvar_Parent = parent;
  1972. mvar_TypeOfTopic = topicType;
  1973. mvar_Href = href;
  1974. mvar_Root = root;
  1975. mvar_Format = newsFormat;
  1976. mvar_HTMLTag = htmltag;
  1977. mvar_TidyEncoding = tidyEncoding;
  1978. mvar_XsltFileName = xsltFileName;
  1979. mvar_TopicDescription = description;
  1980. }
  1981. public DateTime CollectIcons(SortedList<String, IIconElement> icons)
  1982. {
  1983. DateTime lastModified = DateTime.MinValue;
  1984. if (String.IsNullOrEmpty(this.IconName) == false)
  1985. {
  1986. String key = String.Format("topic/{0}", this.IconName);
  1987. if (icons.ContainsKey(key) == false)
  1988. icons.Add(key, this);
  1989. if (String.IsNullOrEmpty(this.FirstThumbnail) == false)
  1990. {
  1991. key = String.Format("{0}@{1}", this.Parent.Langue, this.IconName);
  1992. if (icons.ContainsKey(key) == false)
  1993. icons.Add(key, new Thumbnail(key, this.FirstThumbnail, lastModified));
  1994. }
  1995. }
  1996. foreach (SubTopicItem item in this)
  1997. lastModified = Utilities.MaxDate(lastModified, item.CollectIcons(icons));
  1998. return lastModified;
  1999. }
  2000. public DateTime LastModifiedIcons
  2001. {
  2002. get
  2003. {
  2004. DateTime dt = DateTime.MinValue;
  2005. if (String.IsNullOrEmpty(this.IconName) == false)
  2006. {
  2007. String fName = HttpContext.Current.Server.MapPath(String.Format("images/topics/big/{0}.png", this.IconName));
  2008. if (System.IO.File.Exists(fName))
  2009. dt = Utilities.GetLastWriteTime(fName);
  2010. }
  2011. return dt;
  2012. }
  2013. }
  2014. public void WriteIcons(HttpRequest currentRequest, XmlWriter wr)
  2015. {
  2016. if (String.IsNullOrEmpty(this.IconName) == false)
  2017. {
  2018. wr.WriteStartElement("icons");
  2019. wr.WriteAttributeString("name", this.IconName);
  2020. wr.WriteAttributeString("class", "topic");
  2021. Site.WriteIconDatas(wr, currentRequest.MapPath(String.Format("images/topics/big/{0}.png", this.IconName)), false);
  2022. Site.WriteIconDatas(wr, currentRequest.MapPath(String.Format("images/topics/small/{0}.png", this.IconName)), true);
  2023. wr.WriteEndElement();
  2024. }
  2025. }
  2026. public void WriteTo(HttpRequest currentRequest, XmlWriter wr, String nodeName, String referrer)
  2027. {
  2028. //<topic startup="0" preferred="1" diaporama="1" uno="2008-11-4-11-10-00-32" name="Tout en image" icon="images/topics/diaporama.png" href=""/>
  2029. wr.WriteStartElement(nodeName);
  2030. wr.WriteAttributeString("uno", this.Uno);
  2031. wr.WriteAttributeString("fullName", this.FullName);
  2032. wr.WriteAttributeString("shortName", String.IsNullOrEmpty(this.ShortName) ? this.FullName : this.ShortName);
  2033. if (this.TypeOfTopic != TopicType.eStandardTopic)
  2034. {
  2035. if (this.TypeOfTopic == TopicType.eCollectedVideo)
  2036. wr.WriteAttributeString("type", Convert.ToInt16(TopicType.eVideoramaTopic).ToString());
  2037. else
  2038. wr.WriteAttributeString("type", Convert.ToInt16(this.TypeOfTopic).ToString());
  2039. }
  2040. if (this.Startup)
  2041. wr.WriteAttributeString("startup", Utilities.BoolToString(this.Startup));
  2042. if (this.Preferred)
  2043. wr.WriteAttributeString("preferred", Utilities.BoolToString(this.Preferred));
  2044. if (this.Diaporama)
  2045. {
  2046. wr.WriteAttributeString("diaporama", Utilities.BoolToString(this.Diaporama));
  2047. }
  2048. else if (this.TypeOfTopic == TopicType.eCollectedVideo)
  2049. {
  2050. wr.WriteAttributeString("diaporama", "1");
  2051. wr.WriteAttributeString("video", "1");
  2052. }
  2053. else if (this.Video)
  2054. {
  2055. wr.WriteAttributeString("video", Utilities.BoolToString(this.Video));
  2056. }
  2057. if (String.IsNullOrEmpty(this.HTMLTag) == false)
  2058. wr.WriteAttributeString("htmltag", this.HTMLTag);
  2059. if (String.IsNullOrEmpty(this.TidyEncoding) == false)
  2060. wr.WriteAttributeString("tidyEncoding", this.TidyEncoding);
  2061. if (this.Count == 0)
  2062. {
  2063. String href;
  2064. if (this.NewsItemFormat == Site.NewsFormat.eFormatRss)
  2065. {
  2066. Uri uri = new Uri(new Uri(this.Parent.Parent.Href, this.Parent.Root), this.LocalHref);
  2067. wr.WriteAttributeString("format", "rss");
  2068. href = uri.ToString();
  2069. }
  2070. else
  2071. {
  2072. if (Settings.WriteFullURL)
  2073. {
  2074. if (this.TypeOfTopic == TopicType.eCollectedVideo)
  2075. href = String.Format("{0}/Diaporama.ashx?uno={1}&site={2}", referrer, this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
  2076. else
  2077. href = String.Format("{0}/Topic.ashx?uno={1}&site={2}", referrer, this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
  2078. }
  2079. else
  2080. {
  2081. if (this.TypeOfTopic == TopicType.eCollectedVideo)
  2082. href = String.Format("Diaporama.ashx?uno={0}&site={1}", this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
  2083. else
  2084. href = String.Format("Topic.ashx?uno={0}&site={1}", this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
  2085. }
  2086. }
  2087. //href = "maintenance.htm";
  2088. wr.WriteAttributeString("href", href);
  2089. }
  2090. if (Settings.SeparateIcons == false)
  2091. WriteIcons(currentRequest, wr);
  2092. else if (String.IsNullOrEmpty(this.IconName) == false)
  2093. wr.WriteAttributeString("icon", this.IconName);
  2094. foreach (KeyValuePair<String, String> attribute in this.foreignAttributes)
  2095. {
  2096. wr.WriteAttributeString(attribute.Key, attribute.Value);
  2097. }
  2098. if (mvar_Advisories != null && mvar_Advisories.Count > 0)
  2099. {
  2100. wr.WriteStartElement("advisories");
  2101. foreach (Advisory ads in mvar_Advisories)
  2102. ads.WriteTo(wr);
  2103. wr.WriteEndElement();
  2104. }
  2105. if (this.Count > 0)
  2106. {
  2107. if (mvar_Advisories != null && mvar_Advisories.Count > 0)
  2108. {
  2109. wr.WriteStartElement("advisories");
  2110. foreach (Advisory ads in mvar_Advisories)
  2111. ads.WriteTo(wr);
  2112. wr.WriteEndElement();
  2113. }
  2114. foreach (SubTopicItem item in this)
  2115. item.WriteTo(currentRequest, wr, referrer);
  2116. }
  2117. if (String.IsNullOrEmpty(this.TopicDescription) == false)
  2118. wr.WriteString(this.TopicDescription);
  2119. wr.WriteEndElement();
  2120. }
  2121. public virtual void WriteTo(HttpRequest currentRequest, XmlWriter wr, String referrer)
  2122. {
  2123. this.WriteTo(currentRequest, wr, "topic", referrer);
  2124. }
  2125. public virtual void SaveForAirship(AirshipCenter ac)
  2126. {
  2127. Uri remoteIndexUrl = this.RemoteTopicIndexUrl;
  2128. String queryPart = remoteIndexUrl.PathAndQuery;
  2129. String viewUrl = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.Uno, "{0}");
  2130. queryPart = queryPart.Substring(0, queryPart.LastIndexOf("/"));
  2131. ac.AddTopics(this.Parent.Parent.ApplicationID, this.Parent.Parent.ApplicationKey, this.Parent.Parent.ApplicationMaster, this.Parent.Parent.ProductKey, this.Parent.Langue, this.Uno, queryPart, viewUrl);
  2132. foreach (SubTopicItem item in this)
  2133. {
  2134. switch (item.TypeOfTopic)
  2135. {
  2136. case TopicItem.TopicType.eAlertTopic:
  2137. case TopicItem.TopicType.eCollectedVideo:
  2138. case TopicItem.TopicType.eDiaporamaTopic:
  2139. case TopicItem.TopicType.eDocumentationTopic:
  2140. case TopicItem.TopicType.eMagazinTopic:
  2141. case TopicItem.TopicType.eStandardTopic:
  2142. case TopicItem.TopicType.eVideoramaTopic:
  2143. item.SaveForAirship(ac);
  2144. break;
  2145. }
  2146. }
  2147. }
  2148. virtual public SubTopicItem createSubTopicItem(TopicType topicType, int numOrder, String topicID, String uno, String fullName, String shortName, String local,
  2149. String icon, bool startup, bool preferred, bool diaporama, bool video, String href, String root, Site.NewsFormat newsFormat, String htmltag, String tidyEncoding, String xsltFileName, String description)
  2150. {
  2151. return new SubTopicItem(this, topicType, numOrder, topicID, uno, fullName, shortName,
  2152. local, icon, startup, preferred, diaporama, video, href, root, newsFormat, htmltag, tidyEncoding, xsltFileName, description);
  2153. }
  2154. }