/Server/web/App_Code/TopicItem.cs
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
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Xml;
- using System.Xml.Xsl;
- using System.Net;
- using System.Text;
- using System.IO;
- using System.Reflection;
- using System.Globalization;
- using System.Net.Cache;
-
- /// <summary>
- /// Summary description for TopicItem
- /// </summary>
- public class TopicItem : List<TopicItem>, IAdvisory, IIconElement
- {
- public enum TopicType
- {
- eStandardTopic,
- eFavoritesTopic,
- eHearthTopic,
- eRatedTopic,
- eVideoramaTopic,
- eLocalSearchTopic,
- eRemoteSearchTopic,
- eDiaporamaTopic,
- eMagazinTopic,
- eAlertTopic,
- eDocumentationTopic,
- eCollectedVideo = 128
- }
-
- public struct NewsItemRef
- {
- public String headline;
- public String duid;
- public String href;
- public String description;
- }
-
- struct NewsMLTopicInfos
- {
- public String newsItemId;
- public String topicName;
- public String firstCreated;
- public String revisionDate;
- public String topicSource;
- public List<NewsItemRef> newsItemRefs;
- public List<NewsItemDocument> checkedComponents;
-
- public NewsMLTopicInfos(List<NewsItemRef> refs)
- {
- newsItemId = String.Empty;
- topicName = String.Empty;
- firstCreated = String.Empty;
- revisionDate = String.Empty;
- topicSource = String.Empty;
- newsItemRefs = null;
- checkedComponents = null;
- newsItemRefs = refs;
- }
-
- public NewsMLTopicInfos(List<NewsItemDocument> components)
- {
- newsItemId = String.Empty;
- topicName = String.Empty;
- firstCreated = String.Empty;
- revisionDate = String.Empty;
- topicSource = String.Empty;
- newsItemRefs = null;
- checkedComponents = components;
- newsItemRefs = null;
- }
- }
-
- class Thumbnail : IIconElement
- {
- private String mvar_IconName;
- private String mvar_IconDatas;
- private DateTime mvar_IconModified;
-
- public Thumbnail(String iconName, String iconDatas, DateTime iconLastModified)
- {
- mvar_IconName = iconName;
- mvar_IconDatas = iconDatas;
- mvar_IconModified = iconLastModified;
- }
-
- #region IIconElement Members
-
- public string IconName
- {
- get { return mvar_IconName; }
- }
-
- public DateTime LastModifiedIcons
- {
- get { return mvar_IconModified; }
- }
-
- public void WriteIcons(HttpRequest currentRequest, XmlWriter wr)
- {
- wr.WriteStartElement("icons");
- wr.WriteAttributeString("name", this.IconName);
- wr.WriteAttributeString("class", "thumbnail");
- wr.WriteStartElement("icon");
- wr.WriteAttributeString("smallSize", "0");
- wr.WriteString(mvar_IconDatas);
- wr.WriteEndElement();
- wr.WriteEndElement();
- }
-
- public DateTime CollectIcons(SortedList<string, IIconElement> icons)
- {
- return mvar_IconModified;
- }
-
- #endregion
- }
-
- class NewsItemDocument
- {
- private XmlDocument mvar_Content;
- private String mvar_HRef;
- private TopicItem mvar_OwnerTopic;
- private Utilities.XmlDocumentCache mvar_DocumentCache;
- private DateTime mvar_LastModified;
-
- public Utilities.XmlDocumentCache DocumentCache
- {
- get
- {
- return mvar_DocumentCache;
- }
- }
-
- public DateTime LastModified
- {
- get
- {
- return mvar_LastModified;
- }
- }
-
- public NewsItemDocument(TopicItem ownerTopic, Uri remoteDocumentUrl, String href, DateTime lastModified)
- {
- Uri remoteItemUrl = new Uri(remoteDocumentUrl, href);
-
- mvar_HRef = href;
- mvar_LastModified = lastModified;
- mvar_DocumentCache = Utilities.LoadXmlDocument(remoteItemUrl, out mvar_Content, ref mvar_LastModified, RequestCacheLevel.Revalidate);
- mvar_OwnerTopic = ownerTopic;
- }
-
- public void AppendDocumentToIndex(XmlWriter wr, String parentUno, DataCenter dc)
- {
- Uri remoteMediaUrl = this.OwnerTopic.GetRemoteMediaUrl(false);
- String itemHref;
- XmlElement bagPhoto;
- XmlNode geolocNode;
- String itemUno;
- float globalrate = 0;
- float rate = 0;
- int totalrate = 0;
- String parentItem;
- String CatchLine;
- String TitleLine;
- String headLine;
- String subHeadLine;
- String slugLine;
- String revision;
- String refPhoto;
- String dateLine;
- String copyright;
- String firstCreated;
- String revisionDate;
- String root;
-
- try
- {
- if (this.href.Contains("/"))
- {
- itemUno = Utilities.removeExtension(this.href.Substring(this.href.LastIndexOf("/") + 1));
- root = this.href.Substring(0, this.href.LastIndexOf("/") + 1);
- }
- else
- {
- itemUno = Utilities.removeExtension(this.href);
- root = String.Empty;
- }
-
- if (String.IsNullOrEmpty(root))
- {
- if (Settings.WriteFullURL)
- itemHref = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.OwnerTopic.Uno, itemUno);
- else
- itemHref = String.Format("view.ashx?uno={0}&item={1}", this.OwnerTopic.Uno, itemUno);
- }
- else
- {
- if (Settings.WriteFullURL)
- itemHref = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.OwnerTopic.Uno, Utilities.removeExtension(this.href));
- else
- itemHref = String.Format("view.ashx?uno={0}&item={1}", this.OwnerTopic.Uno, Utilities.removeExtension(this.href));
- }
-
- {
- headLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
- subHeadLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine");
- slugLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine");
- revision = Utilities.InnerText(this.content, "/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId");
- refPhoto = Utilities.InnerAttribute(this.content, "/NewsML/NewsItem/NewsComponent/NewsComponent[1]/ContentItem/DataContent/media[@media-type='image']/media-reference/@data-location");
- dateLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/DateLine");
- copyright = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine");
-
- geolocNode = this.content.SelectSingleNode("/NewsML/NewsItem/NewsComponent/DescriptiveMetadata/Location[@HowPresent='Origin']");
-
- if (String.IsNullOrEmpty(refPhoto))
- refPhoto = Utilities.InnerAttribute(this.content, "/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]/@Duid");
- else if (refPhoto.StartsWith("#"))
- refPhoto = refPhoto.Substring(1);
-
- firstCreated = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsManagement/FirstCreated");
- revisionDate = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
-
- firstCreated = ConvertToGMTIfNeeded(firstCreated);
- revisionDate = ConvertToGMTIfNeeded(revisionDate);
-
- dc.GetRating(this.OwnerTopic.Parent.Langue, this.OwnerTopic.Uno, itemUno, out parentItem, out rate, out globalrate, out totalrate);
-
- wr.WriteStartElement("Item");
- wr.WriteAttributeString("type", "multimedia");
- wr.WriteAttributeString("uno", itemUno);
- wr.WriteAttributeString("href", itemHref);
- wr.WriteAttributeString("revision", revision);
-
- if (String.IsNullOrEmpty(parentUno) == false)
- wr.WriteAttributeString("parentId", parentUno);
-
- if (totalrate > 0)
- {
- wr.WriteAttributeString("globalRate", globalrate.ToString("0.00", CultureInfo.InvariantCulture));
- wr.WriteAttributeString("yourRate", rate.ToString("0.00", CultureInfo.InvariantCulture));
- wr.WriteAttributeString("numberOfVote", totalrate.ToString(CultureInfo.InvariantCulture));
- }
-
- if (geolocNode != null)
- {
- wr.WriteAttributeString("country", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'Country']/@Value"));
- wr.WriteAttributeString("city", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'City']/@Value"));
- wr.WriteAttributeString("longitude", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'Longitude']/@Value"));
- wr.WriteAttributeString("latitude", Utilities.InnerAttribute(geolocNode, "Property[@FormalName = 'Latitude']/@Value"));
- }
-
- {
- wr.WriteStartElement("NewsLines");
- wr.WriteElementString("HeadLine", headLine);
- wr.WriteElementString("SubHeadLine", subHeadLine);
- wr.WriteElementString("SlugLine", slugLine);
- wr.WriteElementString("DateCreated", firstCreated);
- wr.WriteElementString("DatePublished", revisionDate);
- wr.WriteElementString("DateLine", dateLine);
- wr.WriteElementString("CopyRightLine", copyright);
- wr.WriteEndElement();
- }
-
- {
- wr.WriteStartElement("Bag");
-
- // Check if media
- if (this.content.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]").Count == 0)
- {
- wr.WriteAttributeString("uno", itemUno);
- wr.WriteStartElement("Content");
- wr.WriteAttributeString("type", "Text");
- wr.WriteAttributeString("role", "News");
-
- foreach (XmlElement text in this.content.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent[preceding-sibling::MediaType[@FormalName='Text']]/p"))
- {
- wr.WriteStartElement("p");
- wr.WriteString(Utilities.CleanParagraphe(text.InnerText));
- wr.WriteEndElement();
- }
- wr.WriteEndElement();
- }
- else
- {
- String bagUno = itemUno;
-
- if (String.IsNullOrEmpty(refPhoto) == false)
- {
- bagUno = this.OwnerTopic.buildUnoBagPhoto((XmlElement)this.content.SelectSingleNode(String.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']/NewsComponent/ContentItem[@Href]", refPhoto)), itemUno);
- wr.WriteAttributeString("uno", bagUno);
-
- dc.GetRating(this.OwnerTopic.Parent.Langue, this.OwnerTopic.Uno, bagUno, out parentItem, out rate, out globalrate, out totalrate);
-
- if (totalrate > 0)
- {
- wr.WriteAttributeString("globalRate", globalrate.ToString("0.00", CultureInfo.InvariantCulture));
- wr.WriteAttributeString("yourRate", rate.ToString("0.00", CultureInfo.InvariantCulture));
- wr.WriteAttributeString("numberOfVote", totalrate.ToString(CultureInfo.InvariantCulture));
- }
- }
- else
- {
- wr.WriteAttributeString("uno", itemUno);
- }
-
- CatchLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
- TitleLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
-
- if (String.IsNullOrEmpty(TitleLine))
- TitleLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/HeadLine");
-
- if (String.IsNullOrEmpty(CatchLine))
- {
- CatchLine = Utilities.InnerText(this.content, "/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent[preceding-sibling::MediaType[@FormalName='Text']]/p[1]");
- }
-
- if (String.IsNullOrEmpty(TitleLine) == false)
- {
- wr.WriteStartElement("Content");
- wr.WriteAttributeString("type", "Text");
- wr.WriteAttributeString("role", "Title");
- wr.WriteElementString("p", Utilities.CleanParagraphe(TitleLine));
- wr.WriteEndElement();
- }
-
- wr.WriteStartElement("Content");
- wr.WriteAttributeString("type", "Text");
- wr.WriteAttributeString("role", "News");
- wr.WriteElementString("p", Utilities.CleanParagraphe(CatchLine));
- wr.WriteEndElement();
- }
-
- //if (this.Video)
- {
- foreach (XmlElement videoAnchor in this.content.SelectNodes("//a[@class = 'video']"))
- {
- //Uri href = new Uri(remoteMediaUrl, videoAnchor.GetAttribute("href"));
- Uri href = this.OwnerTopic.GetRemoteMediaUrl(String.Format("{0}{1}", root, videoAnchor.GetAttribute("href")));
-
- wr.WriteStartElement("Content");
- wr.WriteAttributeString("type", "Video");
- wr.WriteAttributeString("role", videoAnchor.GetAttribute("title"));
- wr.WriteAttributeString("href", href.ToString());
- wr.WriteEndElement();
- }
- }
-
- if (String.IsNullOrEmpty(refPhoto) == false)
- {
- bagPhoto = (XmlElement)this.content.SelectSingleNode(String.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']", refPhoto));
- this.OwnerTopic.WriteBagItem(wr, remoteMediaUrl, bagPhoto, root, false, dc);
- }
-
- wr.WriteEndElement();
-
- foreach (XmlElement photo in this.content.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]"))
- {
- if (String.IsNullOrEmpty(refPhoto) || photo.GetAttribute("Duid").Equals(refPhoto) == false)
- {
- wr.WriteStartElement("Bag");
- this.OwnerTopic.WriteBagItem(wr, remoteMediaUrl, photo, root, true, dc);
- wr.WriteEndElement();
- }
- }
- }
-
- wr.WriteEndElement();
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
- }
- }
-
- public TopicItem OwnerTopic
- {
- get
- {
- return mvar_OwnerTopic;
- }
- }
-
- public XmlDocument content
- {
- get
- {
- return mvar_Content;
- }
- }
-
- public String href
- {
- get
- {
- return mvar_HRef;
- }
- }
- }
-
- // <topic startup="0" preferred="1" diaporama="1" uno="2008-11-4-11-10-00-32" name="Tout en image" icon="images/topics/diaporama.png"/>
- protected int mvar_NumOrder;
- protected string mvar_Uno;
- protected bool mvar_Startup;
- protected bool mvar_Preferred;
- protected bool mvar_Diaporama;
- protected bool mvar_Video;
- protected String mvar_FullName;
- protected String mvar_ShortName;
- protected String mvar_IconName;
- protected String mvar_LocalHref;
- protected TopicItems mvar_Parent;
- protected SortedList<String, SubTopicItem> mvar_SubTopicItems;
- protected List<Advisory> mvar_Advisories;
- protected TopicType mvar_TypeOfTopic;
- protected String mvar_Href;
- protected String mvar_Root;
- protected Site.NewsFormat mvar_Format;
- protected String mvar_XsltFileName;
- private String mvar_HTMLTag;
- private String mvar_TidyEncoding;
- private List<KeyValuePair<String, String>> mvar_foreignAttributes;
- private DateTime mvar_LastModified;
- private String mvar_FirstThumbnail;
- private String mvar_TopicDescription;
- private String mvar_topicID;
-
- public String TopicDescription
- {
- get
- {
- return mvar_TopicDescription;
- }
- set
- {
- mvar_TopicDescription = value;
- }
- }
-
- public String TopicID
- {
- get
- {
- return mvar_topicID;
- }
- set
- {
- mvar_topicID = value;
- }
- }
-
- private static List<String> phDeclaredAttributes;
-
- static TopicItem()
- {
- phDeclaredAttributes = new List<string>();
-
- phDeclaredAttributes.Add("type");
- phDeclaredAttributes.Add("fullName");
- phDeclaredAttributes.Add("shortName");
- phDeclaredAttributes.Add("uno");
- phDeclaredAttributes.Add("topicID");
- phDeclaredAttributes.Add("icon");
- phDeclaredAttributes.Add("local");
- phDeclaredAttributes.Add("root");
- phDeclaredAttributes.Add("href");
- phDeclaredAttributes.Add("video");
- phDeclaredAttributes.Add("diaporama");
- phDeclaredAttributes.Add("format");
- phDeclaredAttributes.Add("htmltag");
- phDeclaredAttributes.Add("startup");
- phDeclaredAttributes.Add("preferred");
- phDeclaredAttributes.Add("xslt");
- }
-
- public CompiledXsltFile GetCompiledXsltFile()
- {
- if (String.IsNullOrEmpty(mvar_XsltFileName) == false)
- return CompiledXsltFile.GetXlst(HttpContext.Current.Server.MapPath(String.Format("xslt/{0}", mvar_XsltFileName)), System.Diagnostics.Debugger.IsAttached, false);
- else
- return mvar_Parent.GetCompiledXsltFile();
- }
-
- public List<KeyValuePair<String, String>> foreignAttributes
- {
- get
- {
- if (mvar_foreignAttributes == null)
- mvar_foreignAttributes = new List<KeyValuePair<string, string>>();
-
- return mvar_foreignAttributes;
- }
-
- set
- {
- mvar_foreignAttributes = value;
- }
- }
-
- public void addForeignAttributes(XmlElement fromNode)
- {
- foreach (XmlAttribute attrib in fromNode.Attributes)
- {
- if (phDeclaredAttributes.Contains(attrib.Name) == false)
- this.foreignAttributes.Add(new KeyValuePair<string, string>(attrib.Name, attrib.Value));
- }
- }
-
- protected String HTMLTag
- {
- get { return mvar_HTMLTag; }
- }
-
- protected String TidyEncoding
- {
- get { return mvar_TidyEncoding; }
- }
-
- public Site.NewsFormat NewsItemFormat
- {
- get
- {
- if (mvar_Format == Site.NewsFormat.eFormatUseParent)
- return this.Parent.Parent.NewsItemFormat;
- else
- return mvar_Format;
- }
- }
-
- public String FirstThumbnail
- {
- get
- {
- return mvar_FirstThumbnail;
- }
- set
- {
- mvar_FirstThumbnail = value;
- }
- }
-
- public DateTime LastModified
- {
- get
- {
- return mvar_LastModified;
- }
- set
- {
- mvar_LastModified = value;
- }
- }
-
- public bool HaveHref
- {
- get
- {
- return String.IsNullOrEmpty(mvar_Href) == false;
- }
- }
-
- public bool HaveLocalHref
- {
- get
- {
- return String.IsNullOrEmpty(mvar_LocalHref) == false;
- }
- }
-
- public virtual Uri Href
- {
- get
- {
- if (String.IsNullOrEmpty(mvar_Href))
- return this.Parent.Href;
- else
- return new Uri(mvar_Href);
- }
-
- set
- {
- if (value != null)
- mvar_Href = value.ToString();
- else
- mvar_Href = null;
- }
- }
-
- public bool HaveRoot
- {
- get
- {
- return String.IsNullOrEmpty(mvar_Root) == false;
- }
- }
-
- public virtual String Root
- {
- get
- {
- if (String.IsNullOrEmpty(mvar_Root))
- return this.Parent.Root;
- else
- return mvar_Root;
- }
- set
- {
- mvar_Root = value;
- }
- }
-
- public static TopicType StringToTopicType(String value)
- {
- if (String.IsNullOrEmpty(value))
- return TopicType.eStandardTopic;
-
- if (value.CompareTo("favorite") == 0)
- return TopicType.eFavoritesTopic;
-
- if (value.CompareTo("rated") == 0)
- return TopicType.eRatedTopic;
-
- if (value.CompareTo("hearth") == 0)
- return TopicType.eHearthTopic;
-
- if (value.CompareTo("videorama") == 0)
- return TopicType.eVideoramaTopic;
-
- if (value.CompareTo("localsearch") == 0)
- return TopicType.eLocalSearchTopic;
-
- if (value.CompareTo("search") == 0)
- return TopicType.eRemoteSearchTopic;
-
- if (value.CompareTo("diaporama") == 0)
- return TopicType.eDiaporamaTopic;
-
- if (value.CompareTo("magazin") == 0)
- return TopicType.eMagazinTopic;
-
- if (value.CompareTo("alert") == 0)
- return TopicType.eAlertTopic;
-
- if (value.CompareTo("documentation") == 0)
- return TopicType.eDocumentationTopic;
-
- if (value.CompareTo("collect") == 0)
- return TopicType.eCollectedVideo;
-
- return TopicType.eStandardTopic;
- }
-
- public void AddAdvisory(Advisory ads)
- {
- if (mvar_Advisories == null)
- mvar_Advisories = new List<Advisory>();
-
- mvar_Advisories.Add(ads);
- }
-
- public Advisory GetNextAdvisory()
- {
- Advisory ads = null;
-
- if (mvar_Advisories != null)
- {
- mvar_Advisories.Sort(new Advisory.ComparisonAdvisory());
-
- ads = mvar_Advisories[0];
- }
- else
- ads = this.Parent.GetNextAdvisory();
-
- return ads;
- }
-
- public TopicType TypeOfTopic
- {
- get
- {
- return mvar_TypeOfTopic;
- }
- }
-
- public string Uno
- {
- get
- {
- return mvar_Uno;
- }
- }
-
- public bool Startup
- {
- get
- {
- return mvar_Startup;
- }
- }
-
- public bool Preferred
- {
- get
- {
- return mvar_Preferred;
- }
- }
-
- public string FullName
- {
- get
- {
- return mvar_FullName;
- }
- set
- {
- mvar_FullName = value;
- }
- }
-
- public string ShortName
- {
- get
- {
- return mvar_ShortName;
- }
- set
- {
- mvar_ShortName = value;
- }
-
- }
-
- public string IconName
- {
- get
- {
- return mvar_IconName;
- }
- }
-
- public TopicItems Parent
- {
- get
- {
- return mvar_Parent;
- }
- }
-
- public string LocalHref
- {
- get
- {
- return mvar_LocalHref;
- }
- }
-
- public bool Diaporama
- {
- get
- {
- return mvar_Diaporama;
- }
- }
-
- public bool Video
- {
- get
- {
- return mvar_Video;
- }
- }
-
- public SortedList<string, SubTopicItem> SubTopicItems
- {
- get
- {
- return mvar_SubTopicItems;
- }
- }
-
- public int NumOrder
- {
- get
- {
- return mvar_NumOrder;
- }
- }
-
- public void AddSubTopicItem(SubTopicItem item)
- {
- SubTopicItem temp;
-
- if (mvar_SubTopicItems == null)
- mvar_SubTopicItems = new SortedList<String, SubTopicItem>();
-
- this.Add(item);
-
- if (mvar_SubTopicItems.TryGetValue(item.Uno, out temp) == false)
- mvar_SubTopicItems.Add(item.Uno, item);
- else if (temp != item)
- 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));
- }
-
- public SubTopicItem GetSubTopicItemByID(String topicID)
- {
- if (mvar_SubTopicItems != null && String.IsNullOrEmpty(topicID) == false)
- {
- topicID = topicID.ToLowerInvariant();
-
- foreach (SubTopicItem item in mvar_SubTopicItems.Values)
- {
- if (item.TopicID.ToLowerInvariant().Equals(topicID))
- return item;
- }
- }
-
- return null;
- }
-
- public SubTopicItem GetSubTopicItem(String uno)
- {
- SubTopicItem item;
-
- if (mvar_SubTopicItems != null && mvar_SubTopicItems.TryGetValue(uno, out item))
- return item;
-
- return null;
- }
-
- public Utilities.XmlDocumentCache ListMediaItem(PhotoItemsCollection photoItems, DataCenter dc, ref DateTime lastModified)
- {
- XmlDocument remoteTopic;
- Uri remoteDocumentUrl;
- Uri remoteItemUrl;
- XmlDocument remoteItem;
- PhotoItems currentPhotoItems;
- PhotoItem currentPhotoItem;
- Utilities.XmlDocumentCache cache;
-
- remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}", this.Root, this.LocalHref));
-
- // Uri remoteMediaUrl = this.GetRemoteMediaUrl(false);
-
- cache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref lastModified, RequestCacheLevel.CacheIfAvailable);
-
- if (cache != Utilities.XmlDocumentCache.DocumentNotModified)
- {
- foreach (XmlElement item in remoteTopic.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent"))
- {
- String NewsItemRef = Utilities.InnerAttribute(item, "NewsItemRef/@NewsItem");
-
- try
- {
- remoteItemUrl = new Uri(remoteDocumentUrl, NewsItemRef);
-
- Utilities.LoadXmlDocument(remoteItemUrl, out remoteItem, ref lastModified, RequestCacheLevel.Revalidate);
-
- // Video only
- if (remoteItem.SelectNodes("//a[@class = 'video']").Count > 0)
- {
- String topicUno = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/NewsItemId");
- String topicSource = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/ProviderId");
- String firstCreated = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsManagement/FirstCreated");
- String revisionDate = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
- String headLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
- String subHeadLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine");
- String slugLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine");
- // String revision = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId");
- String CatchLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
- String TitleLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
- String dateLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/DateLine");
- String copyright = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine");
-
- if (String.IsNullOrEmpty(TitleLine))
- {
- CatchLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
- }
-
-
- if (String.IsNullOrEmpty(CatchLine))
- {
- CatchLine = Utilities.InnerText(remoteItem, "/NewsML/NewsItem/NewsComponent/NewsComponent[1]/ContentItem/DataContent/p[1]");
- }
-
- foreach (XmlElement newsComponent in remoteItem.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]"))
- {
- String provider = Utilities.InnerAttribute(newsComponent, "AdministrativeMetadata/Provider/Party/@FormalName");
- String creator = Utilities.InnerAttribute(newsComponent, "AdministrativeMetadata/Creator/Party/@FormalName");
- float rate;
- float globalrate;
- int totalrate;
- String parentItem;
-
- currentPhotoItems = new PhotoItems();
-
- dc.GetRating(this.Parent.Langue, this.Uno, Utilities.removeExtension(NewsItemRef), out parentItem, out rate, out globalrate, out totalrate);
-
- currentPhotoItems.Source = topicSource;
- currentPhotoItems.DateCreated = firstCreated;
- currentPhotoItems.DateUpdated = revisionDate;
- //currentPhotoItems.Uno = topicUno;
- currentPhotoItems.MediaUno = String.Empty;
- currentPhotoItems.Owner = this;
- currentPhotoItems.Headline = headLine;
- currentPhotoItems.SlugLine = slugLine;
- currentPhotoItems.SubHeadLine = subHeadLine;
- currentPhotoItems.NewsUno = NewsItemRef;
- currentPhotoItems.CatchLine = CatchLine;
- currentPhotoItems.Title = TitleLine;
- currentPhotoItems.DateLine = dateLine;
- currentPhotoItems.CopyRightLine = copyright;
- currentPhotoItems.GlobalRate = globalrate;
- currentPhotoItems.Rate = rate;
- currentPhotoItems.TotalVote = totalrate;
-
- globalrate = 0;
- rate = 0;
- totalrate = 0;
-
- //if (this.Video)
- {
- foreach (XmlElement videoAnchor in remoteItem.SelectNodes("//a[@class = 'video']"))
- {
- //Uri videoUri = new Uri(remoteMediaUrl, videoAnchor.GetAttribute("href"));
- Uri videoUri = this.GetRemoteMediaUrl(videoAnchor.GetAttribute("href"));
-
- //VideoItem videoItem = new VideoItem(videoAnchor.GetAttribute("title"), this.BuildVideoHRef(videoAnchor.GetAttribute("href")));
- VideoItem videoItem = new VideoItem(videoAnchor.GetAttribute("title"), videoUri);
-
- currentPhotoItems.AddVideoItem(videoItem);
- }
- }
-
- foreach (XmlElement photo in newsComponent.SelectNodes("NewsComponent"))
- {
- String mediaType = Utilities.InnerAttribute(photo, "ContentItem/MediaType/@FormalName");
- String role = Utilities.InnerAttribute(photo, "Role/@FormalName");
-
- if (mediaType.Equals("Photo"))
- {
- String width = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Width']/@Value");
- String height = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Height']/@Value");
- String href = Utilities.InnerAttribute(photo, "ContentItem/@Href");
-
- if (String.IsNullOrEmpty(currentPhotoItems.MediaUno) && href.IndexOf("-") >= 0)
- {
- currentPhotoItems.MediaUno = href.Substring(0, href.IndexOf("-"));
- dc.GetRating(this.Parent.Langue, this.Uno, currentPhotoItems.MediaUno, out parentItem, out rate, out globalrate, out totalrate);
- }
-
- currentPhotoItem = new PhotoItem();
-
- currentPhotoItem.GlobalRate = globalrate;
- currentPhotoItem.Rate = rate;
- currentPhotoItem.TotalVote = totalrate;
- currentPhotoItem.Height = Int32.Parse(height);
- currentPhotoItem.Width = Int32.Parse(width);
- currentPhotoItem.Role = role;
- currentPhotoItem.Href = new Uri(remoteDocumentUrl, href);
- currentPhotoItems.AddItem(currentPhotoItem);
- }
- else
- {
- currentPhotoItems.Creator = creator;
- currentPhotoItems.Provider = provider;
- currentPhotoItems.Caption = Utilities.InnerText(photo, "ContentItem/DataContent/p").Trim();
- }
- }
-
- if (String.IsNullOrEmpty(currentPhotoItems.MediaUno))
- currentPhotoItems.MediaUno = topicUno;
-
- photoItems.Add(currentPhotoItems);
- }
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
- }
- }
- }
-
- return cache;
- }
-
- public virtual Uri GetRemoteMediaUrl(Uri uri)
- {
- if (Settings.WriteFullURL == false)
- uri = this.Href.MakeRelativeUri(uri);
-
- return uri;
- }
-
- public virtual Uri GetRemoteMediaUrl(String mediaHRef)
- {
- Uri uri = new Uri(this.GetRemoteMediaUrl(false), mediaHRef);
-
- if (Settings.WriteFullURL == false)
- uri = this.Href.MakeRelativeUri(uri);
-
- return uri;
- }
-
- public virtual Uri GetRemoteMediaUrl(bool forDownload)
- {
- Uri remoteDocumentUrl;
-
- if (String.IsNullOrEmpty(this.Parent.Parent.DirectLink) == false)
- {
- Uri requestUrl;
-
- requestUrl = HttpContext.Current.Request.Url;
-
- remoteDocumentUrl = new Uri(String.Format("{0}://{1}:{2}/{3}/{4}/{5}/",
- requestUrl.Scheme,
- requestUrl.Host,
- requestUrl.Port,
- this.Parent.Parent.DirectLink,
- this.Root,
- Utilities.ParentPath(this.LocalHref)));
- }
- else if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
- {
- remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}/", this.Root, Utilities.ParentPath(this.LocalHref)));
- }
- else
- {
- remoteDocumentUrl = null;
- }
-
- // System.Console.WriteLine(remoteDocumentUrl.ToString());
-
- return remoteDocumentUrl;
- }
-
- public virtual Uri GetRemoteTopicItemDocumentUrl(String queryItem)
- {
- Uri remoteDocumentUrl;
-
- if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
- {
- remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}/{2}.xml", this.Root, Utilities.ParentPath(this.LocalHref), queryItem));
- }
- else
- {
- remoteDocumentUrl = null;
- }
-
- return remoteDocumentUrl;
- }
-
- private void AppendBagPhoto(XmlTextWriter wr, XmlDocument remoteDocument, Uri remoteDocumentUrl, String refPhoto, Uri previewUri, bool itsVideo, bool writeAsData)
- {
- XmlElement bagPhoto = (XmlElement)remoteDocument.SelectSingleNode(String.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']", refPhoto));
- XmlElement contentPhoto;
- Uri imgUrl;
-
- if (bagPhoto != null)
- {
- String provider = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Provider/Party/@FormalName");
- String creator = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Creator/Party/@FormalName");
- String caption = Utilities.InnerText(bagPhoto, "NewsLines/HeadLine").Trim();
- XmlElement preview = (XmlElement)bagPhoto.SelectSingleNode("NewsComponent[Role[@FormalName='Preview']]");
- int width;
- int height;
-
- contentPhoto = (XmlElement)bagPhoto.SelectSingleNode("NewsComponent[Role[@FormalName='Quicklook']]");
-
- if (contentPhoto == null)
- contentPhoto = (XmlElement)bagPhoto.SelectSingleNode("NewsComponent[Role[@FormalName='Thumbnail']]");
-
- if (contentPhoto == null)
- contentPhoto = preview;
-
- if (contentPhoto != null)
- {
- imgUrl = new Uri(remoteDocumentUrl, Utilities.InnerAttribute(contentPhoto, "ContentItem/@Href"));
- if (previewUri == null && preview != null)
- previewUri = new Uri(remoteDocumentUrl, Utilities.InnerAttribute(preview, "ContentItem/@Href"));
-
- width = Utilities.InnerAttributeAsInteger(contentPhoto, "ContentItem/Characteristics/Property[@FormalName='Width']/@Value");
- height = Utilities.InnerAttributeAsInteger(contentPhoto, "ContentItem/Characteristics/Property[@FormalName='Height']/@Value");
-
- wr.WriteStartElement("div");
- {
- wr.WriteAttributeString("align", "center");
-
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "media");
-
- if (width > 0 && height > 0)
- {
- wr.WriteAttributeString("style", String.Format("width:{0}px;", width + 2));
- }
-
-
- {
- wr.WriteStartElement("div");
- {
- wr.WriteAttributeString("class", "image");
-
- wr.WriteStartElement("div");
-
- if (height > 0)
- wr.WriteAttributeString("style", String.Format("display: block; height:{0}px;", height));
- else
- wr.WriteAttributeString("style", String.Format("display: block;"));
-
- {
- if (previewUri != null)
- {
- wr.WriteStartElement("a");
- wr.WriteAttributeString("class", "preview");
- wr.WriteAttributeString("href", previewUri.ToString());
- }
-
- {
- wr.WriteStartElement("img");
- wr.WriteAttributeString("class", "imglink");
- wr.WriteAttributeString("alt", caption);
-
- Utilities.WriteDataUrl(wr, imgUrl);
-
- if (width > 0)
- wr.WriteAttributeString("width", width.ToString());
-
- if (height > 0)
- wr.WriteAttributeString("height", height.ToString());
-
- wr.WriteEndElement();
- }
-
- if (previewUri != null)
- wr.WriteEndElement();
- }
-
- if (itsVideo)
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("style", String.Format("display: inline; position: relative; top:-{0}px", (height / 2) + 20));
- wr.WriteStartElement("a");
- wr.WriteAttributeString("class", "preview");
- wr.WriteAttributeString("href", previewUri.ToString());
- wr.WriteStartElement("img");
- wr.WriteAttributeString("alt", String.Empty);
-
- Utilities.WriteDataUrl(wr, new Uri(String.Format("{0}/images/video.png", Utilities.getRootPath())));
-
- wr.WriteEndElement();
- wr.WriteEndElement();
- wr.WriteEndElement();
- }
-
- wr.WriteEndElement(); //span
-
- wr.WriteEndElement(); //span
- if (String.IsNullOrEmpty(caption) == false)
- {
- wr.WriteStartElement("div");
- {
- wr.WriteAttributeString("class", "caption");
- wr.WriteString(caption);
- }
- wr.WriteEndElement();
- }
-
- if (String.IsNullOrEmpty(provider) == false || String.IsNullOrEmpty(creator) == false)
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "provider");
- {
- if (String.IsNullOrEmpty(provider) == false && String.IsNullOrEmpty(creator) == false)
- wr.WriteString(String.Format("{0} - {1}", provider, creator));
- else if (String.IsNullOrEmpty(provider) == false)
- wr.WriteString(provider);
- else
- wr.WriteString(creator);
- }
- wr.WriteEndElement();
- }
- }
- }
- wr.WriteEndElement();
- wr.WriteEndElement();
- }
- }
- }
- }
-
- public void MostEmailedTopicItem(XmlTextWriter wr, String queryItem, DataCenter dc)
- {
- dc.AddMostEmailed(this.Parent.Langue, this.Uno, queryItem);
-
- wr.WriteStartElement("EmailedResult");
- wr.WriteStartElement("Emailed");
- wr.WriteAttributeString("result", "1");
- wr.WriteEndElement();
- wr.WriteEndElement();
- }
-
- public void RateTopicItem(XmlTextWriter wr, String parentItem,
- String queryItem, DataCenter.TypeOfRate kindOfItem, float rate, DataCenter dc)
- {
- Uri remoteDocumentUrl;
- XmlDocument doc;
- float globalrate = 0;
- int totalvote = 0;
- bool result;
- String queryDocumentName;
- DateTime lastModified = DateTime.MinValue;
-
- try
- {
- // No parent meant that is a news ml doc
- if (kindOfItem == DataCenter.TypeOfRate.eNewsItemRate)
- {
- queryDocumentName = String.Format("{0}.xml", queryItem);
-
- if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
- {
- remoteDocumentUrl = new Uri(this.Href, String.Format("{0}/{1}/{2}", this.Root, Utilities.ParentPath(this.LocalHref), queryDocumentName));
- }
- else
- {
- remoteDocumentUrl = null;
- }
-
- Utilities.LoadXmlDocument(remoteDocumentUrl, out doc, ref lastModified, RequestCacheLevel.Revalidate);
- parentItem = queryItem;
- }
-
- result = dc.AddRating(this.Parent.Langue, this.Uno, parentItem, queryItem, (DataCenter.TypeOfRate)kindOfItem, ref rate, out globalrate, out totalvote);
-
- wr.WriteStartElement("RatingResult");
- wr.WriteStartElement("Rate");
- wr.WriteAttributeString("result", result ? "1" : "0");
- wr.WriteAttributeString("globalRate", globalrate.ToString("0.00", CultureInfo.InvariantCulture));
- wr.WriteAttributeString("yourRate", rate.ToString("0.00", CultureInfo.InvariantCulture));
- wr.WriteAttributeString("numberOfVote", totalvote.ToString());
-
- if (result == false)
- {
- wr.WriteStartElement("Reason");
- wr.WriteAttributeString("errCode", "0");
- wr.WriteString("Already voted");
- wr.WriteEndElement();
- }
-
- wr.WriteEndElement();
-
- wr.WriteEndElement();
-
- }
- catch (WebException ex)
- {
- int statusCode = 500;
-
- if (ex.Response is HttpWebResponse)
- {
- statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
- }
-
- wr.WriteStartElement("RatingResult");
- wr.WriteStartElement("Rate");
- wr.WriteAttributeString("result", "0");
- wr.WriteAttributeString("globalRate", "0.0");
- wr.WriteAttributeString("yourRate", "0.0");
- wr.WriteAttributeString("numberOfVote", "0");
-
- wr.WriteStartElement("Reason");
- wr.WriteAttributeString("errCode", statusCode.ToString());
- wr.WriteString("Document not found");
- wr.WriteEndElement();
-
- wr.WriteEndElement();
-
- wr.WriteEndElement();
- }
- }
-
- private void WriteCssContent(XmlTextWriter wr, bool writeAsLink)
- {
- if (writeAsLink)
- {
- wr.WriteStartElement("link");
- wr.WriteAttributeString("rel", "stylesheet");
- wr.WriteAttributeString("type", "text/css");
- if (File.Exists(HttpContext.Current.Server.MapPath(String.Format("css/{0}/document.css", this.Parent.Langue))))
- wr.WriteAttributeString("href", String.Format("{0}/css/{1}/document.css", Utilities.getRootPath(), this.Parent.Langue));
- else
- wr.WriteAttributeString("href", String.Format("{0}/css/document.css", Utilities.getRootPath()));
-
- wr.WriteEndElement(); // link
- }
- else
- {
- String cssPath;
- String cssContent;
-
- if (File.Exists(HttpContext.Current.Server.MapPath(String.Format("css/{0}/document.css", this.Parent.Langue))))
- cssPath = HttpContext.Current.Server.MapPath(String.Format("css/{0}/document.css", this.Parent.Langue));
- else
- cssPath = HttpContext.Current.Server.MapPath("css/document.css");
-
- cssContent = String.Format("{0}{1}{2}", "\n", File.ReadAllText(cssPath), "\n");
-
- cssContent = cssContent.Replace("\n", "").Replace("\r", "").Replace("\t", "");
-
- wr.WriteStartElement("style");
- wr.WriteAttributeString("type", "text/css");
- wr.WriteRaw(cssContent);
- wr.WriteEndElement(); // link
- }
- }
-
- private static String[] phQuicklookRoles = { "Quicklook", "Squared220", "Squared170", "Thumbnail" };
- private static String[] phPreviewRoles = { "HighDef", "Preview", "Quicklook" };
-
- virtual public Utilities.XmlDocumentCache DownloadTopicItem(XmlTextWriter wr, String queryItem,
- DataCenter dc, ref DateTime lastModified, ref String ETag)
- {
- XmlDocument remoteDocument = null;
- Uri remoteDocumentUrl = this.GetRemoteTopicItemDocumentUrl(queryItem);
- Uri remoteMediaUrl = this.GetRemoteMediaUrl(true);
- Utilities.XmlDocumentCache cache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteDocument, ref lastModified, RequestCacheLevel.Revalidate);
- XmlNode disclaimer = this.Parent.Disclaimer;
- CompiledXsltFile xsltFile = this.GetCompiledXsltFile();
- int fixedSize = Settings.FixedSize;
- int version = Settings.XsltVersion;
-
- ETag = queryItem;
-
- if (cache == Utilities.XmlDocumentCache.DocumentNotModified)
- {
- if (xsltFile.ChangedDate.CompareTo(lastModified) > 0)
- {
- cache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteDocument, ref lastModified, RequestCacheLevel.Reload);
- lastModified = xsltFile.ChangedDate;
- }
- }
-
- if (cache != Utilities.XmlDocumentCache.DocumentNotModified)
- {
- String dateAndTime = Utilities.InnerText(remoteDocument, "/NewsML/NewsEnvelope/DateAndTime");
- String firstCreated = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsManagement/FirstCreated");
- String revisionDate = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
-
- dateAndTime = ConvertToGMTIfNeeded(dateAndTime);
- firstCreated = ConvertToGMTIfNeeded(firstCreated);
- revisionDate = ConvertToGMTIfNeeded(revisionDate);
-
- String normalizedUno = queryItem;
-
- if (normalizedUno.Contains("/"))
- normalizedUno = normalizedUno.Substring(normalizedUno.LastIndexOf("/") + 1);
-
- if (xsltFile != null)
- {
- XmlNodeList docAnchors = remoteDocument.SelectNodes("//a[@class = 'document']");
- List<TopicItem> documentation = this.Parent.GetTopicItemByType(TopicType.eDocumentationTopic);
- XmlElement NewsExtension = remoteDocument.CreateElement("NewsExtension");
- String docUno = String.Empty;
-
- if (documentation.Count > 0)
- docUno = documentation[0].Uno;
-
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("version")).Value = version.ToString();
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("id")).Value = normalizedUno;
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("uno")).Value = this.Uno;
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("server")).Value = Utilities.getRootPath();
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("documentation")).Value = docUno;
-
- // Traitement des dates
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("dateAndTime")).Value = dateAndTime;
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("firstCreated")).Value = firstCreated;
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("thisRevisionCreated")).Value = revisionDate;
-
- if (Settings.WriteNormalImgUrl)
- NewsExtension.Attributes.Append(remoteDocument.CreateAttribute("DontUseDataUrl")).Value = "1";
-
- if (docAnchors.Count > 0 && String.IsNullOrEmpty(docUno) == false)
- {
- XmlElement NewsComponent = (XmlElement)NewsExtension.AppendChild(remoteDocument.CreateElement("NewsComponent"));
-
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = "document";
-
- foreach (XmlElement anchor in docAnchors)
- {
- XmlElement docComponent = (XmlElement)remoteDocument.CreateElement("NewsComponent");
- String docHref = anchor.GetAttribute("href");
-
- docHref = docHref.Substring(docHref.LastIndexOf("/") + 1);
-
- String itemUno = docHref.Substring(0, docHref.LastIndexOf("."));
- String itemHref = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), docUno, itemUno);
-
- docComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = "document";
- docComponent.Attributes.Append(remoteDocument.CreateAttribute("duid")).Value = itemUno;
- docComponent.Attributes.Append(remoteDocument.CreateAttribute("href")).Value = itemHref;
-
- NewsComponent.AppendChild(docComponent);
- }
- }
-
- foreach (XmlElement dataContent in remoteDocument.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]"))
- {
- String Duid = dataContent.GetAttribute("Duid");
- XmlElement NewsComponent = remoteDocument.CreateElement("NewsComponent");
- XmlElement previewComponent = null;
- XmlElement videoComponent = null;
- int width = 0;
- int height = 0;
- int video = 0;
- Uri imgUrl = null;
- Uri previewUrl = null;
- String href;
-
- 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));
- if (videoComponent != null)
- {
- previewUrl = new Uri(remoteDocumentUrl, videoComponent.GetAttribute("href"));
- video = 1;
- }
- else
- {
- foreach (String role in Settings.GetNamedCollection("PreviewRoles", phPreviewRoles))
- {
- previewComponent = (XmlElement)dataContent.SelectSingleNode(String.Format("NewsComponent[Role[@FormalName='{0}']]", role));
-
- if (previewComponent != null)
- {
- previewUrl = new Uri(remoteDocumentUrl, Utilities.InnerAttribute(previewComponent, "ContentItem/@Href"));
- break;
- }
- }
- }
-
- if (version > 1)
- {
- NewsExtension.AppendChild(NewsComponent);
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("duid")).Value = dataContent.GetAttribute("Duid");
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("hduid")).Value = string.Format("#{0}", dataContent.GetAttribute("Duid"));
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("preview")).Value = previewUrl.AbsoluteUri;
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("video")).Value = video.ToString();
-
- foreach (XmlElement component in dataContent.SelectNodes("NewsComponent[ContentItem/MediaType[@FormalName = 'Photo']]"))
- {
- href = Utilities.InnerAttribute(component, "ContentItem/@Href");
-
- if (String.IsNullOrEmpty(href) == false)
- {
- XmlElement subNewsComponent = (XmlElement)NewsComponent.AppendChild(remoteDocument.CreateElement("NewsComponent"));
-
- width = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Width']/@Value");
- height = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Height']/@Value");
- imgUrl = new Uri(remoteDocumentUrl, href);
-
- subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = Utilities.InnerAttribute(component, "Role/@FormalName");
- subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("width")).Value = width.ToString();
- subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("height")).Value = height.ToString();
- subNewsComponent.Attributes.Append(remoteDocument.CreateAttribute("href")).Value = imgUrl.AbsoluteUri;
-
- if (Settings.WriteNormalImgUrl)
- {
- subNewsComponent.InnerText = imgUrl.AbsoluteUri;
- }
- else
- {
- String contentType;
- String imgDatas = Utilities.WebRequestContentEncodedBase64(imgUrl, out contentType);
-
- if (String.IsNullOrEmpty(imgDatas) == false)
- subNewsComponent.InnerText = imgDatas;
- else
- subNewsComponent.InnerText = imgUrl.AbsoluteUri;
- }
-
- NewsComponent.AppendChild(subNewsComponent);
- }
- }
- }
- else
- {
- XmlElement component = null;
-
- // Search Quicklook
- foreach (String role in Settings.GetNamedCollection("QuicklookRoles", phQuicklookRoles))
- {
- component = (XmlElement)dataContent.SelectSingleNode(String.Format("NewsComponent[Role[@FormalName='{0}']]", role));
-
- if (component != null)
- break;
- }
-
- if (component != null)
- {
- href = Utilities.InnerAttribute(component, "ContentItem/@Href");
-
- if (String.IsNullOrEmpty(href) == false)
- {
- width = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Width']/@Value");
- height = Utilities.InnerAttributeAsInteger(component, "ContentItem/Characteristics/Property[@FormalName='Height']/@Value");
- imgUrl = new Uri(remoteDocumentUrl, href);
-
- NewsExtension.AppendChild(NewsComponent);
-
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("duid")).Value = dataContent.GetAttribute("Duid");
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("hduid")).Value = string.Format("#{0}", dataContent.GetAttribute("Duid"));
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("role")).Value = "Quicklook";
-
- if (fixedSize == 0)
- {
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("width")).Value = width.ToString();
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("height")).Value = height.ToString();
- }
- else
- {
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("width")).Value = fixedSize.ToString();
- }
-
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("href")).Value = imgUrl.AbsoluteUri;
- NewsComponent.Attributes.Append(remoteDocument.CreateAttribute("preview")).Value = previewUrl.AbsoluteUri;
-
- if (Settings.WriteNormalImgUrl)
- {
- NewsComponent.InnerText = imgUrl.AbsoluteUri;
- }
- else
- {
- String contentType;
- String imgDatas = Utilities.WebRequestContentEncodedBase64(imgUrl, out contentType);
-
- if (String.IsNullOrEmpty(imgDatas) == false)
- NewsComponent.InnerText = imgDatas;
- else
- NewsComponent.InnerText = imgUrl.AbsoluteUri;
- }
- }
- }
- }
- }
-
- XsltArgumentList arguments = new XsltArgumentList();
-
- arguments.AddParam("NewsExtension", String.Empty, NewsExtension);
- arguments.AddParam("Version", String.Empty, version);
- arguments.AddParam("CSS", String.Empty, Settings.Css);
- arguments.AddParam("ImageActive", String.Empty, Settings.ImageActive);
-
- //wr.WriteDocType("html", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd", String.Empty);
- xsltFile.Transform(remoteDocument, arguments, wr);
- }
- else
- {
- #region HTML Document
- //wr.WriteDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", String.Empty);
- wr.WriteStartElement("html");
- wr.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml");
-
- if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
- {
- String headLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
- // String subHeadLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine");
- // String slugLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine");
- // String revision = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId");
- String dateLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/DateLine");
- String copyright = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine");
- // String CatchLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
- String TitleLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
- bool paraOpened = false;
-
- if (String.IsNullOrEmpty(TitleLine))
- TitleLine = Utilities.InnerText(remoteDocument, "/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
-
- #region HTML Head
- wr.WriteStartElement("head");
- wr.WriteElementString("title", TitleLine);
- // WriteCssContent(wr, false);
- wr.WriteEndElement();
- #endregion
-
- #region HTML Body
- wr.WriteStartElement("body");
- wr.WriteAttributeString("style", "font-family:Arial");
-
- if (Settings.WriteFullURL)
- wr.WriteAttributeString("viewedUrl", String.Format("{0}/viewed.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.Uno, normalizedUno));
- else
- wr.WriteAttributeString("viewedUrl", String.Format("viewed.ashx?uno={0}&item={1}", this.Uno, normalizedUno));
-
- if (String.IsNullOrEmpty(this.Parent.Direction) == false)
- wr.WriteAttributeString("dir", this.Parent.Direction);
-
- WriteCssContent(wr, false);
-
- #region Head
- if (remoteDocument.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]").Count == 0)
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "head");
-
- #region Headline SportDirect
- wr.WriteElementString("h3", headLine);
-
- wr.WriteStartElement("h4");
- wr.WriteString(String.Format("{0} - ", copyright));
- wr.WriteElementString("date", revisionDate);
- wr.WriteEndElement();
- #endregion
- wr.WriteEndElement();
- }
- else
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "head");
-
- #region Title
- if (String.IsNullOrEmpty(TitleLine) == false)
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "title");
- wr.WriteString(TitleLine);
- wr.WriteEndElement();
- }
- #endregion
-
- #region DateLine
- {
- if (String.IsNullOrEmpty(dateLine))
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "dateLine");
- wr.WriteElementString("date", revisionDate);
- wr.WriteEndElement();
- }
- else
- {
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "dateLine");
- wr.WriteString(String.Format("{0} - ", dateLine));
- wr.WriteElementString("date", revisionDate);
- wr.WriteEndElement();
- }
- }
- #endregion
-
- #region Paragraphe
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "paragraphe");
- wr.WriteElementString("p", "");
- wr.WriteEndElement(); // DIV
- #endregion
-
- wr.WriteEndElement(); // DIV
- }
-
- #endregion
-
- #region Content
- foreach (XmlElement dataContent in remoteDocument.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent[preceding-sibling::MediaType[@FormalName='Text']]"))
- {
- foreach (XmlElement element in dataContent.ChildNodes)
- {
- if (element.Name == "media")
- {
- if (element.GetAttribute("media-type") == "image")
- {
- String refPhoto = Utilities.InnerAttribute(element, "media-reference/@data-location");
-
- if (refPhoto.StartsWith("#"))
- refPhoto = refPhoto.Substring(1);
-
- if (paraOpened)
- {
- wr.WriteEndElement();
- paraOpened = false;
- }
-
- AppendBagPhoto(wr, remoteDocument, remoteMediaUrl, refPhoto, null, false, true);
- }
- }
- else if (element.Name == "p")
- {
- foreach (XmlElement anchors in element.SelectNodes("a"))
- {
- if (anchors.GetAttribute("class") == "videoSet")
- {
- String refPhoto = null;
- String refVideo = null;
-
- if (paraOpened)
- {
- wr.WriteEndElement();
- paraOpened = false;
- }
-
- foreach (XmlElement anchor in anchors.SelectNodes("a"))
- {
- if (anchor.GetAttribute("class") == "photo")
- {
- refPhoto = anchor.GetAttribute("href");
- }
- else if (anchor.GetAttribute("class") == "video" && anchor.GetAttribute("title").Equals(Settings.VideoClass))
- {
- refVideo = anchor.GetAttribute("href");
- }
- }
-
- if (String.IsNullOrEmpty(refPhoto) == false && String.IsNullOrEmpty(refVideo) == false)
- {
- if (refPhoto.StartsWith("#"))
- refPhoto = refPhoto.Substring(1);
-
- AppendBagPhoto(wr, remoteDocument, remoteMediaUrl, refPhoto, new Uri(remoteDocumentUrl, refVideo), true, true);
- }
- }
- }
-
- if (paraOpened == false)
- {
- paraOpened = true;
- wr.WriteStartElement("div");
- wr.WriteAttributeString("class", "paragraphe");
- }
-
- #region Paragraphe
- wr.WriteStartElement("p");
- wr.WriteAttributeString("class", "paragraphe");
- wr.WriteString(Utilities.CleanParagraphe(element.InnerText));
- wr.WriteEndElement();
- #endregion
- }
- }
- }
- #endregion
-
- if (paraOpened)
- {
- wr.WriteEndElement();
- paraOpened = false;
- }
-
- #region Disclaimer
- if (disclaimer != null)
- {
- wr.WriteStartElement("disclaimer");
- wr.WriteNode(new XmlNodeReader(disclaimer), false);
- wr.WriteEndElement();
- }
- #endregion
-
- wr.WriteEndElement(); // body
- #endregion
- }
-
- wr.WriteEndElement(); //html
- #endregion
- }
- }
-
- return cache;
- }
-
- public virtual Uri RemoteTopicIndexUrl
- {
- get
- {
- return new Uri(this.Href, String.Format("{0}/{1}", this.Root, this.LocalHref));
- }
- }
-
- public static String ConvertToGMTIfNeeded(String date)
- {
- if (date.ToUpper().EndsWith("Z") == false)
- {
- DateTime dd;
-
- if (DateTime.TryParseExact(date, "yyyyMMddTHHmmsszzzz", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dd) == false)
- dd = DateTime.Now;
-
- date = dd.ToUniversalTime().ToString("yyyyMMddTHHmmssZ");
- }
-
- return date;
- }
-
- public Uri BuildVideoHRef(String videoAnchor)
- {
- Uri newUri;
-
- if (String.IsNullOrEmpty(this.Parent.Parent.DirectLink) == false)
- {
- Uri requestUrl;
-
- requestUrl = new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority));
-
- if (requestUrl.PathAndQuery.Equals("/"))
- 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));
- else
- 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));
- }
- else
- newUri = new Uri(new Uri(String.Format("{0}/{1}/{2}", this.Href, this.Root, this.Parent.Photos)), videoAnchor);
-
- return newUri;
- }
-
- private String buildUnoBagPhoto(XmlElement contentItem, String defaultUno)
- {
- String result = String.Empty;
-
- if (contentItem != null)
- {
- String href = contentItem.GetAttribute("Href");
- int offset = href.IndexOf("-");
-
- if (offset < 0)
- offset = href.IndexOf(".");
-
- href = href.Substring(0, offset);
-
- result = href;
- }
- else if (String.IsNullOrEmpty(defaultUno) == false)
- result = defaultUno;
-
- return result;
- }
-
- protected void WriteBagItem(XmlWriter wr, Uri remoteMediaUrl, XmlElement bagPhoto, String root, bool extractUno, DataCenter dc)
- {
- String provider = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Provider/Party/@FormalName");
- String creator = Utilities.InnerAttribute(bagPhoto, "AdministrativeMetadata/Creator/Party/@FormalName");
- String headLine = Utilities.CleanParagraphe(Utilities.InnerText(bagPhoto, "NewsLines/HeadLine"));
- String bagUno = String.Empty;
-
- if (extractUno)
- {
- bagUno = buildUnoBagPhoto((XmlElement)bagPhoto.SelectSingleNode("NewsComponent/ContentItem[@Href]"), null);
-
- if (String.IsNullOrEmpty(bagUno) == false)
- {
- float globalrate = 0;
- float rate = 0;
- int totalrate = 0;
- String parentItem;
-
- wr.WriteAttributeString("uno", bagUno);
-
- dc.GetRating(this.Parent.Langue, this.Uno, bagUno, out parentItem, out rate, out globalrate, out totalrate);
-
- if (totalrate > 0)
- {
- wr.WriteAttributeString("globalRate", globalrate.ToString(CultureInfo.InvariantCulture));
- wr.WriteAttributeString("yourRate", rate.ToString(CultureInfo.InvariantCulture));
- wr.WriteAttributeString("numberOfVote", totalrate.ToString(CultureInfo.InvariantCulture));
- }
- }
- }
-
- if (Settings.WritePhotoHeadline && String.IsNullOrEmpty(headLine) == false)
- {
- wr.WriteStartElement("Content");
- wr.WriteAttributeString("type", "Text");
- wr.WriteAttributeString("role", "HeadLine");
- wr.WriteAttributeString("provider", provider);
- wr.WriteAttributeString("creator", creator);
- wr.WriteElementString("p", headLine);
- wr.WriteEndElement();
- }
-
- foreach (XmlElement photo in bagPhoto.SelectNodes("NewsComponent"))
- {
- String mediaType = Utilities.InnerAttribute(photo, "ContentItem/MediaType/@FormalName");
- String role = Utilities.InnerAttribute(photo, "Role/@FormalName");
-
- wr.WriteStartElement("Content");
- wr.WriteAttributeString("type", mediaType);
- wr.WriteAttributeString("role", role);
-
- if (mediaType.Equals("Photo"))
- {
- String width = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Width']/@Value");
- String height = Utilities.InnerAttribute(photo, "ContentItem/Characteristics/Property[@FormalName = 'Height']/@Value");
- Uri href = new Uri(remoteMediaUrl, String.Format("{0}{1}", root, Utilities.InnerAttribute(photo, "ContentItem/@Href")));
-
- // System.Console.WriteLine(Utilities.InnerAttribute(photo, "ContentItem/@Href"));
-
- wr.WriteAttributeString("height", height);
- wr.WriteAttributeString("width", width);
- wr.WriteAttributeString("href", this.GetRemoteMediaUrl(href).ToString());
- }
- else
- {
- String dataContent = Utilities.InnerText(photo, "ContentItem/DataContent/p").Trim();
-
- if (role.Equals("Caption") && String.IsNullOrEmpty(dataContent))
- {
- if (Settings.WritePhotoHeadline == false)
- {
- dataContent = headLine;
- }
- }
-
- wr.WriteAttributeString("provider", provider);
- wr.WriteAttributeString("creator", creator);
-
- wr.WriteElementString("p", dataContent);
- //wr.WriteElementString("p", Utilities.CleanParagraphe(Utilities.InnerText(bagPhoto, "NewsLines/HeadLine")));
- }
-
- wr.WriteEndElement();
-
- }
- }
-
- private NewsMLTopicInfos DownloadNewsMLIndex(XmlDocument remoteTopic, ref NewsMLTopicInfos infos, bool append, bool headOnly)
- {
- Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
- XmlNodeList newsComponents = remoteTopic.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent");
- int maxArticles = this.Parent.Parent.MaxNumberOfItems;
-
- if (append == false)
- {
- infos.newsItemId = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/NewsItemId");
- infos.topicName = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NameLabel");
- infos.firstCreated = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/NewsManagement/FirstCreated");
- infos.revisionDate = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
- infos.topicSource = Utilities.InnerText(remoteTopic, "/NewsML/NewsItem/Identification/NewsIdentifier/ProviderId");
- infos.checkedComponents = new List<NewsItemDocument>();
-
- infos.firstCreated = ConvertToGMTIfNeeded(infos.firstCreated);
- infos.revisionDate = ConvertToGMTIfNeeded(infos.revisionDate);
-
- if (infos.newsItemRefs != null)
- {
- foreach (XmlNode node in remoteTopic.SelectNodes("//NewsItem/NewsComponent/NewsComponent"))
- {
- NewsItemRef itemRef = new NewsItemRef();
-
- itemRef.headline = Utilities.InnerText(node, "NewsLines/HeadLine");
- itemRef.duid = Utilities.InnerAttribute(node, "NewsItemRef/@Duid");
- itemRef.href = Utilities.InnerAttribute(node, "NewsItemRef/@NewsItem");
- itemRef.description = Utilities.InnerText(node, "NewsItemRef/Comment[@FormalName='Description']");
-
- infos.newsItemRefs.Add(itemRef);
- }
- }
- }
-
- if (headOnly == false)
- {
- foreach (XmlElement item in newsComponents)
- {
- String NewsItemRef = Utilities.InnerAttribute(item, "NewsItemRef/@NewsItem");
- NewsItemDocument remoteItem = null;
-
- try
- {
- remoteItem = new NewsItemDocument(this, remoteDocumentUrl, NewsItemRef, DateTime.MinValue);
-
- infos.checkedComponents.Add(remoteItem);
-
- if (infos.checkedComponents.Count >= maxArticles)
- break;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
- }
- }
- }
-
- return infos;
- }
-
- private void WriteNewsMLContent(XmlWriter wr, DataCenter dc, NewsMLTopicInfos infos)
- {
- #region Index Xml document
- wr.WriteStartElement("Xafp");
- {
- wr.WriteAttributeString("type", "collection");
- wr.WriteAttributeString("id", this.Uno);
- wr.WriteAttributeString("newsItemId", infos.newsItemId);
- wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
-
- {
- wr.WriteStartElement("Head");
- wr.WriteElementString("Name", infos.topicName);
- wr.WriteElementString("DateCreated", infos.firstCreated);
- wr.WriteElementString("DateUpdated", infos.revisionDate);
- wr.WriteElementString("Source", infos.topicSource);
- wr.WriteElementString("NumberOfItems", infos.checkedComponents.Count.ToString());
- wr.WriteEndElement();
-
- {
- wr.WriteStartElement("Bag");
-
- foreach (NewsItemDocument remoteItem in infos.checkedComponents)
- {
- remoteItem.AppendDocumentToIndex(wr, remoteItem.OwnerTopic.Uno, dc);
- }
-
- wr.WriteEndElement();
- }
- }
- }
- wr.WriteEndElement();
- #endregion
- }
-
- public bool isTopicModifiedSince(DateTime lastModified)
- {
- Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
- Utilities.XmlDocumentCache docCache = Utilities.IfModifiedSince(remoteDocumentUrl, ref mvar_LastModified, RequestCacheLevel.Revalidate);
-
- return (docCache != Utilities.XmlDocumentCache.DocumentNotModified) | (lastModified.CompareTo(mvar_LastModified) < 0);
- }
-
- public String getTopicOrderTable(String localName, List<NewsItemRef> diaporamOrder)
- {
- if (this.HaveLocalHref)
- {
- String nameLabel = localName;
- XmlDocument remoteTopic = new XmlDocument();
- Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
- Utilities.XmlDocumentCache docCache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref mvar_LastModified, RequestCacheLevel.Revalidate);
-
- // if (docCache != Utilities.XmlDocumentCache.DocumentNotModified)
- // {
- NewsMLTopicInfos infos;
-
- infos.checkedComponents = new List<NewsItemDocument>();
- infos.newsItemId = String.Empty;
- infos.topicName = String.Empty;
- infos.firstCreated = String.Empty;
- infos.revisionDate = String.Empty;
- infos.topicSource = String.Empty;
- infos.newsItemRefs = diaporamOrder;
-
- infos.firstCreated = String.Empty;
- infos.revisionDate = String.Empty;
-
- DownloadNewsMLIndex(remoteTopic, ref infos, false, false);
-
- nameLabel = infos.topicName;
- // }
- // else if (docCache == Utilities.XmlDocumentCache.DocumentNotModified)
- // {
- // }
-
- return nameLabel;
- }
-
- return localName;
- }
-
- public String getTopicNameLabel(String localName)
- {
- String nameLabel = localName;
- XmlDocument remoteTopic = new XmlDocument();
- Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
-
- try
- {
- Utilities.XmlDocumentCache docCache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref mvar_LastModified, RequestCacheLevel.Revalidate);
-
- // if (docCache != Utilities.XmlDocumentCache.DocumentNotModified)
- {
- if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
- {
- NewsMLTopicInfos infos;
-
- infos.checkedComponents = null;
- infos.newsItemId = String.Empty;
- infos.topicName = String.Empty;
- infos.firstCreated = String.Empty;
- infos.revisionDate = String.Empty;
- infos.topicSource = String.Empty;
- infos.newsItemRefs = new List<TopicItem.NewsItemRef>();
-
- infos.firstCreated = String.Empty;
- infos.revisionDate = String.Empty;
-
- DownloadNewsMLIndex(remoteTopic, ref infos, false, true);
-
- nameLabel = infos.topicName;
-
- if (infos.newsItemRefs.Count > 0)
- {
- if (String.IsNullOrEmpty(infos.newsItemRefs[0].duid) == false)
- {
- Uri uri = new Uri(remoteDocumentUrl, infos.newsItemRefs[0].duid);
-
- this.FirstThumbnail = Utilities.LoadBinaryDocumentToBase64(uri);
- }
-
- if (String.IsNullOrEmpty(infos.newsItemRefs[0].description) == false)
- this.TopicDescription = infos.newsItemRefs[0].description;
- }
- }
- }
-
- }
- catch (Exception)
- {
- nameLabel = localName;
- }
-
- return nameLabel;
- }
-
- virtual public Utilities.XmlDocumentCache TopicIndex(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
- {
- XmlDocument remoteTopic = new XmlDocument();
- Uri remoteDocumentUrl = this.RemoteTopicIndexUrl;
- Utilities.XmlDocumentCache docCache = Utilities.LoadXmlDocument(remoteDocumentUrl, out remoteTopic, ref lastModified, RequestCacheLevel.Revalidate);
-
- if (docCache != Utilities.XmlDocumentCache.DocumentNotModified)
- {
- if (this.NewsItemFormat == Site.NewsFormat.eFormatNewsML)
- {
- NewsMLTopicInfos infos;
-
- infos.checkedComponents = new List<NewsItemDocument>();
- infos.newsItemRefs = null;
- infos.newsItemId = String.Empty;
- infos.topicName = String.Empty;
- infos.firstCreated = String.Empty;
- infos.revisionDate = String.Empty;
- infos.topicSource = String.Empty;
-
- infos.firstCreated = String.Empty;
- infos.revisionDate = String.Empty;
-
- DownloadNewsMLIndex(remoteTopic, ref infos, false, false);
- WriteNewsMLContent(wr, dc, infos);
- }
- else
- {
- remoteTopic.WriteContentTo(wr);
- }
- }
-
- return docCache;
- }
-
- private List<NewsItemDocument> ListHearthedItems(DataCenter dc)
- {
- IList<DataCenter.DataCenterResponse> responses = dc.ListMostHearthed(this, this.Parent.Parent.MaxNumberOfItems);
- List<NewsItemDocument> checkedComponents = new List<NewsItemDocument>();
-
- foreach (DataCenter.DataCenterResponse response in responses)
- {
- String NewsItemRef = String.Format("{0}.xml", response.parent);
- NewsItemDocument remoteItem = null;
-
- try
- {
- TopicItem ownerTopic = this.Parent.GetTopicItem(response.topic);
-
- if (ownerTopic != null)
- {
- Uri remoteDocumentUrl = ownerTopic.RemoteTopicIndexUrl;
-
- remoteItem = new NewsItemDocument(ownerTopic, remoteDocumentUrl, NewsItemRef, DateTime.MinValue);
-
- checkedComponents.Add(remoteItem);
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
- }
- }
-
- return checkedComponents;
- }
-
- private List<NewsItemDocument> ListRatedItems(DataCenter dc)
- {
- IList<DataCenter.DataCenterResponse> responses = dc.ListMostRated(this, this.Parent.Parent.MaxNumberOfItems);
- List<NewsItemDocument> checkedComponents = new List<NewsItemDocument>();
-
- foreach (DataCenter.DataCenterResponse response in responses)
- {
- String NewsItemRef = response.uno;
- NewsItemDocument remoteItem = null;
-
- try
- {
- TopicItem ownerTopic = this.Parent.GetTopicItem(response.topic);
-
- if (ownerTopic != null)
- {
- Uri remoteDocumentUrl = ownerTopic.RemoteTopicIndexUrl;
-
- remoteItem = new NewsItemDocument(ownerTopic, remoteDocumentUrl, String.Format("{0}.xml", NewsItemRef), DateTime.MinValue);
-
- checkedComponents.Add(remoteItem);
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine("Exception occured:", ex.ToString());
- }
- }
-
- return checkedComponents;
- }
-
- public Utilities.XmlDocumentCache HearthTopic(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
- {
- List<NewsItemDocument> checkedComponents = ListHearthedItems(dc);
-
- lastModified = DateTime.Now;
-
- #region Index Xml document
- wr.WriteStartElement("Xafp");
- {
- wr.WriteAttributeString("type", "collection");
- wr.WriteAttributeString("uno", this.Uno);
- wr.WriteAttributeString("newsItemId", String.Format("mmd--{0}", this.FullName));
- wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
-
- {
- wr.WriteStartElement("Head");
- wr.WriteElementString("Name", this.FullName);
- wr.WriteElementString("DateCreated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
- wr.WriteElementString("DateUpdated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
- wr.WriteElementString("Source", "AFP");
- wr.WriteElementString("NumberOfItems", checkedComponents.Count.ToString());
- wr.WriteEndElement();
-
- {
- wr.WriteStartElement("Bag");
-
- foreach (NewsItemDocument remoteItem in checkedComponents)
- {
- remoteItem.AppendDocumentToIndex(wr, remoteItem.OwnerTopic.Uno, dc);
- }
-
- wr.WriteEndElement();
- }
- }
- }
- wr.WriteEndElement();
- #endregion
-
- return Utilities.XmlDocumentCache.DocumentModified;
- }
-
- public Utilities.XmlDocumentCache RatedTopic(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
- {
- List<NewsItemDocument> checkedComponents = ListRatedItems(dc);
-
- lastModified = DateTime.Now;
-
- #region Index Xml document
- wr.WriteStartElement("Xafp");
- {
- wr.WriteAttributeString("type", "collection");
- wr.WriteAttributeString("uno", this.Uno);
- wr.WriteAttributeString("newsItemId", String.Format("mmd--{0}", this.FullName));
- wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
-
- {
- wr.WriteStartElement("Head");
- wr.WriteElementString("Name", this.FullName);
- wr.WriteElementString("DateCreated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
- wr.WriteElementString("DateUpdated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
- wr.WriteElementString("Source", "AFP");
- wr.WriteElementString("NumberOfItems", checkedComponents.Count.ToString());
- wr.WriteEndElement();
-
- {
- wr.WriteStartElement("Bag");
-
- foreach (NewsItemDocument remoteItem in checkedComponents)
- {
- remoteItem.AppendDocumentToIndex(wr, remoteItem.OwnerTopic.Uno, dc);
- }
-
- wr.WriteEndElement();
- }
- }
- }
- wr.WriteEndElement();
- #endregion
-
- return Utilities.XmlDocumentCache.DocumentModified;
- }
-
- public Utilities.XmlDocumentCache FavoritesTopic(XmlWriter wr, DataCenter dc, ref DateTime lastModified)
- {
- lastModified = DateTime.Now;
-
- #region Index Xml document
- wr.WriteStartElement("Xafp");
- {
- wr.WriteAttributeString("type", "collection");
- wr.WriteAttributeString("uno", this.Uno);
- wr.WriteAttributeString("newsItemId", String.Format("mmd--{0}", this.FullName));
- wr.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", Utilities.NormalizedLangue(this.Parent.Langue));
-
- {
- wr.WriteStartElement("Head");
- wr.WriteElementString("Name", this.FullName);
- wr.WriteElementString("DateCreated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
- wr.WriteElementString("DateUpdated", DateTime.Now.ToString("yyyyMMddTHHmmssZ"));
- wr.WriteElementString("Source", "AFP");
- wr.WriteElementString("NumberOfItems", "0");
- wr.WriteEndElement();
-
- {
- wr.WriteStartElement("Bag");
- wr.WriteEndElement();
- }
- }
- }
- wr.WriteEndElement();
- #endregion
-
- return Utilities.XmlDocumentCache.DocumentModified;
- }
-
- public TopicItem(TopicItems parent,
- TopicType topicType,
- int numOrder,
- String topicID,
- String uno,
- String fullName,
- String shortName,
- String local,
- 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
- )
- {
- mvar_NumOrder = numOrder;
- mvar_topicID = topicID;
- mvar_Uno = uno;
- mvar_Startup = startup;
- mvar_Preferred = preferred;
- mvar_FullName = fullName;
- mvar_ShortName = shortName;
- mvar_IconName = icon;
- mvar_Diaporama = diaporama;
- mvar_LocalHref = local;
- mvar_Video = video;
- mvar_Parent = parent;
- mvar_TypeOfTopic = topicType;
- mvar_Href = href;
- mvar_Root = root;
- mvar_Format = newsFormat;
- mvar_HTMLTag = htmltag;
- mvar_TidyEncoding = tidyEncoding;
- mvar_XsltFileName = xsltFileName;
- mvar_TopicDescription = description;
- }
-
- public DateTime CollectIcons(SortedList<String, IIconElement> icons)
- {
- DateTime lastModified = DateTime.MinValue;
-
- if (String.IsNullOrEmpty(this.IconName) == false)
- {
- String key = String.Format("topic/{0}", this.IconName);
-
- if (icons.ContainsKey(key) == false)
- icons.Add(key, this);
-
- if (String.IsNullOrEmpty(this.FirstThumbnail) == false)
- {
- key = String.Format("{0}@{1}", this.Parent.Langue, this.IconName);
-
- if (icons.ContainsKey(key) == false)
- icons.Add(key, new Thumbnail(key, this.FirstThumbnail, lastModified));
- }
- }
-
- foreach (SubTopicItem item in this)
- lastModified = Utilities.MaxDate(lastModified, item.CollectIcons(icons));
-
- return lastModified;
- }
-
- public DateTime LastModifiedIcons
- {
- get
- {
- DateTime dt = DateTime.MinValue;
- if (String.IsNullOrEmpty(this.IconName) == false)
- {
- String fName = HttpContext.Current.Server.MapPath(String.Format("images/topics/big/{0}.png", this.IconName));
-
- if (System.IO.File.Exists(fName))
- dt = Utilities.GetLastWriteTime(fName);
- }
- return dt;
- }
- }
-
- public void WriteIcons(HttpRequest currentRequest, XmlWriter wr)
- {
- if (String.IsNullOrEmpty(this.IconName) == false)
- {
- wr.WriteStartElement("icons");
- wr.WriteAttributeString("name", this.IconName);
- wr.WriteAttributeString("class", "topic");
- Site.WriteIconDatas(wr, currentRequest.MapPath(String.Format("images/topics/big/{0}.png", this.IconName)), false);
- Site.WriteIconDatas(wr, currentRequest.MapPath(String.Format("images/topics/small/{0}.png", this.IconName)), true);
- wr.WriteEndElement();
- }
- }
-
- public void WriteTo(HttpRequest currentRequest, XmlWriter wr, String nodeName, String referrer)
- {
- //<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=""/>
- wr.WriteStartElement(nodeName);
-
- wr.WriteAttributeString("uno", this.Uno);
- wr.WriteAttributeString("fullName", this.FullName);
- wr.WriteAttributeString("shortName", String.IsNullOrEmpty(this.ShortName) ? this.FullName : this.ShortName);
-
- if (this.TypeOfTopic != TopicType.eStandardTopic)
- {
- if (this.TypeOfTopic == TopicType.eCollectedVideo)
- wr.WriteAttributeString("type", Convert.ToInt16(TopicType.eVideoramaTopic).ToString());
- else
- wr.WriteAttributeString("type", Convert.ToInt16(this.TypeOfTopic).ToString());
- }
-
- if (this.Startup)
- wr.WriteAttributeString("startup", Utilities.BoolToString(this.Startup));
-
- if (this.Preferred)
- wr.WriteAttributeString("preferred", Utilities.BoolToString(this.Preferred));
-
- if (this.Diaporama)
- {
- wr.WriteAttributeString("diaporama", Utilities.BoolToString(this.Diaporama));
- }
- else if (this.TypeOfTopic == TopicType.eCollectedVideo)
- {
- wr.WriteAttributeString("diaporama", "1");
- wr.WriteAttributeString("video", "1");
- }
- else if (this.Video)
- {
- wr.WriteAttributeString("video", Utilities.BoolToString(this.Video));
- }
-
- if (String.IsNullOrEmpty(this.HTMLTag) == false)
- wr.WriteAttributeString("htmltag", this.HTMLTag);
-
- if (String.IsNullOrEmpty(this.TidyEncoding) == false)
- wr.WriteAttributeString("tidyEncoding", this.TidyEncoding);
-
- if (this.Count == 0)
- {
- String href;
-
- if (this.NewsItemFormat == Site.NewsFormat.eFormatRss)
- {
- Uri uri = new Uri(new Uri(this.Parent.Parent.Href, this.Parent.Root), this.LocalHref);
-
- wr.WriteAttributeString("format", "rss");
- href = uri.ToString();
- }
- else
- {
- if (Settings.WriteFullURL)
- {
- if (this.TypeOfTopic == TopicType.eCollectedVideo)
- href = String.Format("{0}/Diaporama.ashx?uno={1}&site={2}", referrer, this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
- else
- href = String.Format("{0}/Topic.ashx?uno={1}&site={2}", referrer, this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
- }
- else
- {
- if (this.TypeOfTopic == TopicType.eCollectedVideo)
- href = String.Format("Diaporama.ashx?uno={0}&site={1}", this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
- else
- href = String.Format("Topic.ashx?uno={0}&site={1}", this.Uno, HttpUtility.UrlEncode(this.Parent.Parent.Name));
- }
- }
-
- //href = "maintenance.htm";
-
- wr.WriteAttributeString("href", href);
- }
-
- if (Settings.SeparateIcons == false)
- WriteIcons(currentRequest, wr);
- else if (String.IsNullOrEmpty(this.IconName) == false)
- wr.WriteAttributeString("icon", this.IconName);
-
- foreach (KeyValuePair<String, String> attribute in this.foreignAttributes)
- {
- wr.WriteAttributeString(attribute.Key, attribute.Value);
- }
-
- if (mvar_Advisories != null && mvar_Advisories.Count > 0)
- {
- wr.WriteStartElement("advisories");
- foreach (Advisory ads in mvar_Advisories)
- ads.WriteTo(wr);
- wr.WriteEndElement();
- }
-
- if (this.Count > 0)
- {
- if (mvar_Advisories != null && mvar_Advisories.Count > 0)
- {
- wr.WriteStartElement("advisories");
- foreach (Advisory ads in mvar_Advisories)
- ads.WriteTo(wr);
- wr.WriteEndElement();
- }
-
- foreach (SubTopicItem item in this)
- item.WriteTo(currentRequest, wr, referrer);
- }
-
- if (String.IsNullOrEmpty(this.TopicDescription) == false)
- wr.WriteString(this.TopicDescription);
-
- wr.WriteEndElement();
- }
-
- public virtual void WriteTo(HttpRequest currentRequest, XmlWriter wr, String referrer)
- {
- this.WriteTo(currentRequest, wr, "topic", referrer);
- }
-
- public virtual void SaveForAirship(AirshipCenter ac)
- {
- Uri remoteIndexUrl = this.RemoteTopicIndexUrl;
- String queryPart = remoteIndexUrl.PathAndQuery;
- String viewUrl = String.Format("{0}/view.ashx?uno={1}&item={2}", Utilities.getRootPath(), this.Uno, "{0}");
-
- queryPart = queryPart.Substring(0, queryPart.LastIndexOf("/"));
-
- 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);
-
- foreach (SubTopicItem item in this)
- {
- switch (item.TypeOfTopic)
- {
- case TopicItem.TopicType.eAlertTopic:
- case TopicItem.TopicType.eCollectedVideo:
- case TopicItem.TopicType.eDiaporamaTopic:
- case TopicItem.TopicType.eDocumentationTopic:
- case TopicItem.TopicType.eMagazinTopic:
- case TopicItem.TopicType.eStandardTopic:
- case TopicItem.TopicType.eVideoramaTopic:
- item.SaveForAirship(ac);
- break;
- }
- }
- }
-
- virtual public SubTopicItem createSubTopicItem(TopicType topicType, int numOrder, String topicID, String uno, String fullName, String shortName, String local,
- 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)
- {
- return new SubTopicItem(this, topicType, numOrder, topicID, uno, fullName, shortName,
- local, icon, startup, preferred, diaporama, video, href, root, newsFormat, htmltag, tidyEncoding, xsltFileName, description);
- }
-
- }