/Server/IServV2/IPhone/Plugins/Content/AFP.IPhone.Content.Plugins.JournalInternet/Plugin.cs
C# | 3180 lines | 2278 code | 446 blank | 456 comment | 372 complexity | 89b288cb6c243a771e0dbf16bfc6be8c MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0, LGPL-2.1, MIT, BSD-3-Clause, 0BSD, AGPL-3.0
- using AFP.IPhone.Application;
- using AFP.IPhone.Extensions;
- using AFP.IPhone.Storage;
- using AFP.IPhone.Processor.Plugins.JournalInternet.Documents;
-
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Xml;
- using System.Xml.Xsl;
- using System.Web.Services;
- using System.Globalization;
-
- #if SERVICE
- using AFP.IPhone.Plugins.GetCourseId;
- #endif
-
- namespace AFP.IPhone.Processor.Plugins.JournalInternet
- {
- class ExXmlTextWriter : XmlTextWriter
- {
- private StringWriter mvar_Writer;
-
- private ExXmlTextWriter(StringWriter w)
- : base(w)
- {
- mvar_Writer = w;
- // Indentation
- this.Formatting = Formatting.Indented;
- this.Indentation = 2;
- }
-
- public ExXmlTextWriter()
- : this(new StringWriter())
- {
- }
-
- public override string ToString()
- {
- return mvar_Writer.ToString();
- }
- }
- /// <summary>
- /// Class to handle JI AFP iPhone Content
- /// </summary>
- ///
- public class Plugin : ProcessorPluginBase
- {
-
-
- private const string _storagePhotosFormatName = "Photos";
- private const string _storageVideosFormatName = "Videos";
- private const string _storageDocumentFormatName = "Documents";
-
- private readonly List<SqlProcessor> _sqlProcessorList;
- private readonly List<SqlProcessor> _sqlProcessorList2;
- private readonly List<string> _dynamicTopicList;
- private XmlDocument _sites;
-
- private ProcessorServer.TTrace _levelTrace;
-
- private int _Version =1;
- private string _ImageActive ="true";
- private string _PreviewRole ="HighDef";
-
- private Boolean _UseUri = false;
-
- private System.Collections.Hashtable _Xslt;
-
-
- private static XmlWriter createXmlWriter()
- {
- return new ExXmlTextWriter();
- }
-
- public struct RatingEntry
- {
- public readonly string Lang;
- public readonly string NewsId;
- public readonly string TopicId;
-
- public RatingEntry(string topicId, string newsId, string lang)
- {
- Lang = lang;
- NewsId = newsId;
- TopicId = topicId;
- }
- }
-
- public struct HitEntry
- {
- public readonly string Lang;
- public readonly string NewsId;
- public readonly string TopicId;
- public readonly int Hits;
-
- public HitEntry(string topicId, string newsId, string lang, int hits)
- {
- Lang = lang;
- NewsId = newsId;
- TopicId = topicId;
- Hits = hits;
- }
- }
-
- public struct RatingEntryKey : IComparable<RatingEntryKey>
- {
- private readonly string _value;
-
- public RatingEntryKey(DateTime newsDate, DataRow row)
- {
- _value = string.Format("{0}{1}", (((double)row["averageRating"] * 1000) / (1 + (Math.Truncate(DateTime.Now.Subtract(newsDate).TotalDays) * 10))).ToString("0000"), ((int)row["votes"]).ToString("0000000000"));
- }
-
- public int CompareTo(RatingEntryKey other)
- {
- var cmp = other._value.CompareTo(_value);
- return (cmp == 0) ? -1 : cmp;
- }
- }
-
-
- private enum ComponentType
- {
- photo,
- video,
- text,
- unsupported
- }
-
- private enum MessageSection
- {
- Alimentation,
- Database,
- Processing
- }
-
- private enum NewsMediaFilter
- {
- all,
- photoOnly,
- videoOnly
- }
-
-
- private static Object GBLock = new Object();
-
- /// <summary>
- /// Creates a new instance of Plugin
- /// </summary>
- ///
- public Plugin()
- {
- // Initialisations
- _dynamicTopicList = new List<string>();
- _sqlProcessorList = new List<SqlProcessor>();
- _sites = new XmlDocument();
- _Xslt = new System.Collections.Hashtable();
-
-
- // Chargement sites
- _sites.LoadXml("<sites/>");
-
- // Initialisation des bases rating
- try
- {
- foreach (var connection in Configuration.GetAttribute("ratingConnection").Split('|'))
- {
- if (string.IsNullOrEmpty(connection) == false)
- _sqlProcessorList.Add(new SqlProcessor(connection));
- }
- foreach (var connection in Configuration.GetAttribute("alertConnection").Split('|'))
- {
- if (string.IsNullOrEmpty(connection) == false)
- _sqlProcessorList2.Add(new SqlProcessor(connection));
- }
-
- }
- catch (Exception e)
- {
- Process.Trace(e, System.Diagnostics.EventLogEntryType.Error);
- throw;
- }
-
-
- }
-
-
-
-
-
- /// <summary>
- /// Gets the plugin key name.
- /// </summary>
- ///
- public override string Key
- {
- get { return "JI"; }
- }
-
- /// <summary>
- /// Get or Set Leveltrace
- /// </summary>
- public override ProcessorServer.TTrace levelTrace
- {
- get
- {
- return _levelTrace;
- }
- set
- {
- _levelTrace = value;
- }
- }
-
- public override int Version
- {
- get
- {
- return _Version;
- }
- set
- {
- _Version = value;
- }
- }
-
- public override string ImageActive
- {
- get
- {
- return _ImageActive;
- }
- set
- {
- _ImageActive = value;
- }
- }
-
- public override bool UseUri
- {
- get
- {
- return _UseUri;
- }
- set
- {
- _UseUri = value;
- }
- }
-
- public override string PreviewRole
- {
- get
- {
- return _PreviewRole;
- }
- set
- {
- _PreviewRole = value;
- }
- }
- public override void MakeTopic(string topicId)
- {
- TopicImplementation topic;
- topic = TopicImplementation.Load(topicId);
- MakeTopic(topic, false, null);
- }
-
- /// <summary>
- /// Process the defined topics.
- /// </summary>
- /// <param name="content">The content configuration.</param>
- /// <param name="refresh">Flag for refreshing content.</param>
- ///
- public override void MakeTopics(XmlElement content, bool refresh, Boolean multiThread, int maxThreads)
- {
- var doneTopics = new List<ManualResetEvent>();
-
- //note : Traitement de tous les topics et subtopics du site
- try
- {
- foreach (XmlNode item in content.ChildNodes)
- {
- if (item is XmlElement)
- {
- if (item.HasChildNodes)
- MakeTopics((XmlElement)item, refresh, Boolean.Parse(item.GetAttributeValue("multiThread", multiThread.ToString())), maxThreads);
-
- // Traitement d'un topic
- if (item.Name.Equals("topic") || item.Name.Equals("subtopic"))
- {
- // dans le cadre du Touch il faut passer l'id et non l'item...
- var topic = new TopicImplementation((XmlElement)item);
-
- // note: Tout ce passe ici pour la synchro
- if (multiThread == false)
- {
- MakeTopic(topic, refresh, null);
- }
- else
- {
- if (topic.DynamicDelay.Equals(TimeSpan.Zero))
- {
- doneTopics.Add(new ManualResetEvent(false));
- ThreadPool.QueueUserWorkItem
- (
- MakeTopic, new object[]
- {
- topic,
- refresh,
- doneTopics[doneTopics.Count - 1]
- });
-
- // Limitation WaitAll à 64
- if (doneTopics.Count == maxThreads)
- {
- WaitHandle.WaitAll(doneTopics.ToArray());
- doneTopics.Clear();
- }
- }
- else if (_dynamicTopicList.Contains(topic.Id) == false)
- {
- var dynamicMakeTopicThread = new Thread(MakeTopicFromThread);
-
- dynamicMakeTopicThread.IsBackground = true;
- dynamicMakeTopicThread.Name = String.Format("MakeTopics:{0}", topic.Id);
- dynamicMakeTopicThread.Start(topic);
- _dynamicTopicList.Add(topic.Id);
- }
- }
- }
- }
- }
- }
- finally
- {
- // Attente fin de traitement de tous les topics d'un même niveau
- if (doneTopics.Count > 0)
- WaitHandle.WaitAll(doneTopics.ToArray());
- }
- }
-
- /// <summary>
- /// Rate a media.
- /// </summary>
- /// <param name="topicImplementation">Topic implementation.</param>
- /// <param name="newsId">Id of the owner news.</param>
- /// <param name="mediaId">Id of the media.</param>
- /// <param name="rate">Rate value.</param>
- ///
- public override string Rate(TopicImplementation topicImplementation, string productId, string newsId, string mediaId, float rate, string device)
- {
- //en cours
- double realRate = rate;
- int votes;
-
- // Vérification site
- if (_sites == null)
- new Rating(rate, "Invalid site value.", 1).ToString();
-
- lock (_sites)
- {
- // Récupération des votes
- GetRating(string.Format("SELECT SUM(votes) AS votes, SUM(rating) AS rating FROM Ratings2 WHERE mediaId='{0}' and productId='{1}' GROUP BY mediaId", mediaId, productId), ref realRate, out votes);
-
- // Vote
- foreach (var sqlProcessor in _sqlProcessorList)
- sqlProcessor.Add(new SqlMediaRateRequest(productId, topicImplementation.Id, newsId, mediaId, topicImplementation.Lang, rate, device));
- }
-
- return new Rating(rate, realRate, votes).ToString();
- }
-
- /// <summary>
- /// Rate a media.
- /// </summary>
- /// <param name="topicImplementation">Topic implementation</param>
- /// <param name="topicId">Id of the owner topic.</param>
- /// <param name="newsId">Id of the owner news.</param>
- /// <param name="rate">Rate value.</param>
- ///
- public override string Rate(TopicImplementation topicImplementation, string productId, string newsId, float rate, string device)
- {
- double realRate = rate;
- int votes;
-
- // Vérification site
- if (_sites == null)
- new Rating(rate, "Invalid site value.", 1).ToString();
-
- lock (_sites)
- {
- // Récupération des votes
- GetRating(string.Format("SELECT SUM(votes) AS votes, SUM(rating) AS rating FROM Ratings2 WHERE newsId='{0}' AND mediaId IS NULL AND producId='{1}' GROUP BY newsId", newsId, productId), ref realRate, out votes);
-
- // Vote
- foreach (var sqlProcessor in _sqlProcessorList)
- {
- sqlProcessor.Add(new SqlNewsRateRequest(productId, topicImplementation.Id, newsId, topicImplementation.Lang, rate, device));
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format(" productId {0} topicId {1} newsId {2} lang {3} rating {4} device {5} ", productId, topicImplementation.Id, newsId, topicImplementation.Lang, rate, device), System.Diagnostics.EventLogEntryType.Information);
- #endif
-
- }
- }
-
- return new Rating(rate, realRate, votes).ToString();
- }
-
-
-
- /// <summary>
- /// Appel via WCF pour connaitre le vote sur un article ou une photo
- /// </summary>
- /// <param name="productId"></param>
- /// <param name="topicId"></param>
- /// <param name="newsId"></param>
- /// <param name="mediaId"></param>
- /// <param name="lang"></param>
- /// <param name="rate"></param>
- /// <param name="vote"></param>
- public override void getRated(string productId, string topicId, string newsId, string mediaId, string lang, out double rate, out int vote)
- {
- if (_sites == null)
- throw new Exception("Invalid Site value");
- double realRate = 0;
- //int votes;
- if (string.IsNullOrEmpty(mediaId) == false)
- GetRating(string.Format("SELECT SUM(votes) AS votes, SUM(rating) AS rating FROM Ratings2 WHERE mediaId='{0}' and productId='{1}' GROUP BY mediaId", newsId, productId), ref realRate, out vote);
- else
- GetRating(string.Format("SELECT SUM(votes) AS votes, SUM(rating) AS rating FROM Ratings2 WHERE newsId='{0}' AND mediaId IS NULL AND productId='{1}' GROUP BY newsId", newsId, productId), ref realRate, out vote);
- rate = realRate;
-
- //return realRate;
- }
- //Encours GetMostViewed
- /// <summary>
- /// donne la liste des plus vus pour ce serveur...
- /// </summary>
- /// <param name="lstId"></param>
- /// <param name="productId"></param>
- /// <returns></returns>
- public override string GetMostViewed(string lstId, string productId, string topicId, TimeSpan MaxAge, int MaxEntries)
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// Donne la listes des medias les plus votés
- /// </summary>
- /// <param name="lstId"></param>
- /// <param name="productId"></param>
- /// <returns></returns>
- public override string GetHeartRatedList(string lstId, string productId, string topicId, TimeSpan MaxAge, int MaxEntries, string lang )
- {
- string sqlLang;
-
- if (string.IsNullOrEmpty(lang))
- {
- sqlLang = "";
- }
- else
- {
- sqlLang = string.Format(" AND [lang] = '{0}' ", lang);
- }
-
- string query = string.Format(
- "SELECT lang, topicId, newsId, MAX([rating]/[votes]) AS averageRating, SUM([votes]) AS votes " +
- "FROM [Ratings2] WHERE NOT [mediaId] IS NULL AND [dateUpdated] > CONVERT(datetime, '{0}', 120) " +
- "AND [productId]='{1}' {2} GROUP BY lang, topicId, newsId ORDER BY [averageRating] DESC, [votes] DESC",
- DateTime.UtcNow.Subtract(MaxAge).ToString("yyyy-MM-dd"), productId, sqlLang );
- //en cours
- #if DEBUG && TRACE_REQUEST
- Process.Trace(query, "GetHeartRatedList", System.Diagnostics.EventLogEntryType.Information);
- #endif
-
- return TopicBuildRated(query, topicId, MaxEntries, new StorageServer(), false);
- }
- /// <summary>
- /// Donne la liste les Articles les mieux votés
- /// </summary>
- /// <param name="lstId"></param>
- /// <param name="productId"></param>
- /// <returns></returns>
- public override string GetArticleRatedList(string lstId, string productId, string topicId, TimeSpan MaxAge, int MaxEntries, string lang )
- {
- #if DEBUG && DEBUGRATEDLIST
- System.Diagnostics.Debugger.Break();
- #endif
- string sqlLang ;
-
- if (string.IsNullOrEmpty(lang))
- {
- sqlLang = "";
- }
- else
- {
- sqlLang = string.Format(" AND [lang] = '{0}' ", lang);
- }
-
- string query = string.Format(
- "SELECT lang, topicId, newsId, MAX([rating]/[votes]) AS averageRating, SUM([votes]) AS votes " +
- "FROM [Ratings2] WHERE [mediaId] IS NULL AND [dateUpdated] > CONVERT(datetime, '{0}', 120) " +
- "AND [productId]='{1}' {2} GROUP BY lang, topicId, newsId ORDER BY [averageRating] DESC, [votes] DESC"
- , DateTime.UtcNow.Subtract(MaxAge).ToString("yyyy-MM-dd"), productId ,sqlLang );
- //en cours
- #if DEBUG && TRACE_REQUEST
- Process.Trace(query, "GetArticleRatedList", System.Diagnostics.EventLogEntryType.Information);
- #endif
- return TopicBuildRated(query, topicId, MaxEntries, new StorageServer(), false);
- }
-
-
- private void getDegMinSec(string value, ref int deg ,ref int min , ref int sec)
- {
- float Valeur = value.toFloat(0f) ;
-
- deg = (int) Math.Truncate(Valeur);
- Valeur = (Valeur - (float) deg ) * 60f;
-
- min = (int)Math.Truncate(Valeur);
- Valeur = (Valeur - (float)min) * 60f;
-
- sec = (int)Math.Truncate(Valeur);
-
- }
-
- public override string GetAroundMe(string latitude, string longitude, string range ,int MaxEntries, string lang )
- {
-
- //ttot
-
- // Determination de la plage
- /* int degLat = 0;
- int minLat = 0;
- int secLat = 0;
-
- int degLong = 0;
- int minLong = 0;
- int secLong = 0;
- */
-
- string sWhere = " where ";
- string sWhereLatitudeSup ="" ;
- string sWhereLatitudeInf ="" ;
- string sWhereLongitudeSup ="" ;
- string sWhereLongitudeInf ="" ;
-
- Decimal oLat = latitude.toDecimal(0m);
- Decimal oLong = longitude.toDecimal(0m);
- Sexagesimal sRange = new Sexagesimal (range, true);
- Decimal Valeur = range.toDecimal(0m) / 111.195m;
-
- Decimal latitudeBornesup ;
- Decimal latitudeBorneInf ;
-
- latitudeBornesup = oLat + Valeur ;
- if( latitudeBornesup > 90m)
- {
- // il faut découper
- sWhereLatitudeSup = string.Format(" latitude < 90 or ( latitude > {0:0.########} and latitude <90 and longitude >-180 and longitude <180) ", 90m - (latitudeBornesup - 90m));
- }
- else
- {
- sWhereLatitudeSup = string.Format(" latitude < {0:0.########} ", latitudeBornesup.ToString("G",CultureInfo.InvariantCulture) );
- }
-
- latitudeBorneInf = oLat - Valeur ;
- if ( latitudeBorneInf <-90m)
- {
- // il faut découper
- sWhereLatitudeInf = string.Format (" latitude > -90 or ( latitude < {1} and latitude >-90 and longitude >-180 and longitude <180) ", -90m +(latitudeBornesup -90m) );
- }
- else
- {
- sWhereLatitudeInf = string.Format(" latitude > {0:0.########}", latitudeBorneInf.ToString("G", CultureInfo.InvariantCulture));
- }
-
- Decimal longitudeBordSup ;
- Decimal longitudeBordInf;
-
- longitudeBordSup = oLong + Valeur ;
- longitudeBordInf = oLong - Valeur ;
-
- if( longitudeBordSup > 180m )
- {
- // on a dépasser le bord de la terre on tombe... ha non c'est rond.
- sWhereLongitudeSup = string.Format(" (longitude < {0:0.########} or (longitude > -180 and longitude < {1:0.########} ) ", longitudeBordSup.ToString("G", CultureInfo.InvariantCulture), -180m + (longitudeBordSup - 180m));
-
- }
- else
- {
- sWhereLongitudeSup = string.Format(" longitude < {0:0.########} ", longitudeBordSup.ToString("G", CultureInfo.InvariantCulture));
- }
-
- if(longitudeBordInf <-180m )
- {
- sWhereLongitudeSup = string.Format(" (longitude > {0:0.########} or (longitude > {1:0.########} and longitude < 180 ) ", longitudeBordSup.ToString("G", CultureInfo.InvariantCulture), 180m - (longitudeBordInf - 180m));
- }
- else
- {
- sWhereLongitudeInf = string.Format(" longitude > {0:0.########}", longitudeBordInf.ToString("G", CultureInfo.InvariantCulture));
- }
-
- sWhere = string.Format ("{4} {0} and {1} and {2} and {3}" , sWhereLatitudeInf , sWhereLatitudeSup , sWhereLongitudeInf ,sWhereLongitudeSup , sWhere );
-
- string query = string.Format(
- "SELECT * from Localization {0} ", sWhere );
- if (!string.IsNullOrEmpty(lang))
- {
- query = string.Format("{0} and lang='{1}'", query, lang);
- }
- #if DEBUG && TRACEAROUND
- Process.Trace(query, System.Diagnostics.EventLogEntryType.Information);
- #endif
-
- return TopicBuildAround(query,new StorageServer() , MaxEntries );
-
- }
-
- /// <summary>
- /// Trace viewed.
- /// </summary>
- /// <param name="topicImplementation"></param>
- /// <param name="productId"></param>
- /// <param name="newsId"></param>
- /// <param name="mediaId"></param>
- /// <param name="device"></param>
- public override void InsertViewed(TopicImplementation topicImplementation, string productId, string newsId, string mediaId, string device)
- {
- #if DEBUG && DEBUGINSERT
- System.Diagnostics.Debugger.Break();
-
- #endif
- // Insert viewed
- foreach (var sqlProcessor in _sqlProcessorList)
- sqlProcessor.Add(new SqlNewsViewed(productId, topicImplementation.Id, newsId, mediaId, topicImplementation.Lang, device));
-
- }
-
-
-
-
- private XslCompiledTransform GetXsltCT(string path)
- {
- lock (_Xslt)
- {
- if (!_Xslt.ContainsKey(path))
- {
- XslCompiledTransform newX = new XslCompiledTransform(System.Diagnostics.Debugger.IsAttached);
- newX.Load(path);
- _Xslt.Add(path, newX);
-
- }
- }
-
- return (XslCompiledTransform)_Xslt[path];
- }
-
- private string GetMediaName(string href, TopicImplementation topic)
- {
- var pattern = topic["mediaNamePattern"];
- var regEx = new Regex((string.IsNullOrEmpty(pattern)) ? "(.)*" : pattern);
-
- return regEx.Match(Path.GetFileNameWithoutExtension(href)).ToString();
- }
-
- public void GetRating(string query, ref double rate, out int votes)
- {
- // Valeur par défaut
- votes = 0;
-
- // Ajout du rating
- foreach (var processor in _sqlProcessorList)
- using (var sqlRatingReader = new SqlDataAdapter(query, processor.ConnectionString))
- {
- using (var sqlRatingTable = new DataTable())
- {
- try
- {
- sqlRatingReader.Fill(sqlRatingTable);
- }
- catch
- {
- continue;
- }
-
- if (sqlRatingTable.Rows.Count == 0)
- votes = 0;
- else
- {
- votes = ((int)sqlRatingTable.Rows[0]["votes"] + 1);
- rate = ((double)sqlRatingTable.Rows[0]["rating"] + rate) / votes;
- }
-
- break;
- }
- }
- }
-
- private void MakeTopic(object stateInfo)
- {
- MakeTopic((TopicImplementation)((object[])stateInfo)[0], (bool)((object[])stateInfo)[1], (ManualResetEvent)((object[])stateInfo)[2]);
- }
-
- private void MakeTopic(TopicImplementation topic, bool refresh, ManualResetEvent doneEvent)
- {
- var storage = new StorageServer();
- #if DBG_PERFORMANCE_TRACE
- var timer = new System.Diagnostics.Stopwatch();
-
- // Démarage compteur
- timer.Start();
-
- if (_levelTrace.TraceTimeMakeTopic == true )
- {
- Process.Trace(string.Format(" Start Processing {0} at {1}", topic.Id, DateTime.Now), System.Diagnostics.EventLogEntryType.Information);
- }
- #endif
- try
- {
- // Traitement des différents type de topic
- switch (topic.Type)
- {
- case TopicImplementation.TopicType.heart:
- case TopicImplementation.TopicType.rated:
- // Construction du topic et stockage
- // TO DO a reprendre et a tester...
- XmlDocument topicRated = new XmlDocument();
- topicRated.LoadXml(TopicBuildRated(topic, storage, refresh));
- using (var storageTopicFile = storage.Store(Constants._storageTopicFormatName, Key, string.Format("{0}.xml", topic.Id)))
- topicRated.Save(storageTopicFile);
-
- break;
-
- case TopicImplementation.TopicType.videorama:
- case TopicImplementation.TopicType.standard:
- // Récupération du fichier index NewsML
- NewsML index = TopicLoadDocument(topic, storage);
- #if DBG_PERFORMANCE_TRACE
-
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("TopicLoadDocument for topicId '{0}' processed after {1} seconds.", topic.Id, timer.ElapsedMilliseconds / 1000), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- // Transformation du document et stockage
- if (index != null)
- {
- String topicContent = TopicBuildStandard(index, topic, storage, topic.MaxEntries, refresh);
-
- #if DBG_PERFORMANCE_TRACE
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("TopicBuildStandard for topicId '{0}' processed after {1} seconds.", topic.Id, timer.ElapsedMilliseconds / 1000), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- if (String.IsNullOrEmpty(topicContent) == false)
- {
- Stream output = storage.Store(Constants._storageTopicFormatName, Key, string.Format("{0}.xml", topic.Id));
-
- if (output != null)
- {
- TextWriter wr = new StreamWriter(output, Encoding.UTF8);
-
- wr.Write(topicContent);
-
- wr.Flush();
- output.Close();
- }
- }
- }
-
- break;
-
- case TopicImplementation.TopicType.buildedvideorama:
- // Construction du topic et stockage
- var topicVideorama = TopicBuildVideorama(topic, storage, refresh);
- using (var storageTopicFile = storage.Store(Constants._storageTopicFormatName, Key, string.Format("{0}.xml", topic.Id)))
- topicVideorama.Save(storageTopicFile);
-
- break;
-
- /* case TopicImplementation.TopicType.magazin:
- case TopicImplementation.TopicType.diaporama:
- var indexd = TopicLoadDocument(topic, storage);
- if (indexd != null)
- {
- String topicContent = TopicBuildMagazin(indexd, topic, storage, topic.MaxEntries, refresh,"");
-
- #if DBG_PERFORMANCE_TRACE
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("TopicBuildStandard for topicId '{0}' processed after {1} seconds.", topic.Id, timer.ElapsedMilliseconds / 1000), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- if (String.IsNullOrEmpty(topicContent) == false)
- {
- Stream output = storage.Store(Constants._storageTopicFormatName, Key, string.Format("{0}.xml", topic.Id));
-
- if (output != null)
- {
- TextWriter wr = new StreamWriter(output, Encoding.UTF8);
-
- wr.Write(topicContent);
-
- wr.Flush();
- output.Close();
- }
- }
- }
- break;*/
- case TopicImplementation.TopicType.alert:
- //TODO implementer fonction alert
- break;
-
- case TopicImplementation.TopicType.diaporama:
- case TopicImplementation.TopicType.magazin:
- if (topic.IsSubTopic() == false)
- TopicLoadTableAndDoneTopics(topic, storage);
- else
- {
- // cas de l'update d'un topic spé Ipad de merde...
-
- NewsML index1 = TopicLoadDocument(topic, storage);
- // Transformation du document et stockage
- if (index1 != null)
- {
- String topicContent = TopicBuildStandard(index1, topic, storage, topic.MaxEntries, refresh);
- if (String.IsNullOrEmpty(topicContent) == false)
- {
- Stream output = storage.Store(Constants._storageTopicFormatName, Key, string.Format("{0}.xml", topic.Id));
- if (output != null)
- {
- TextWriter wr = new StreamWriter(output, Encoding.UTF8);
- wr.Write(topicContent);
- wr.Flush();
- output.Close();
- }
- }
- }
- }
-
- break;
-
- }
- }
- catch (ThreadAbortException)
- {
- }
- catch (Exception e)
- {
- Process.Trace(string.Format("Can't process topic {0}", topic.Id), e.ToString(), System.Diagnostics.EventLogEntryType.Error);
- this.Set("Topic process error", MessageSection.Processing.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- }
- finally
- {
- #if DBG_PERFORMANCE_TRACE
- timer.Stop();
-
-
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("Topic '{0}' processed in {1} seconds.", topic.Id, timer.ElapsedMilliseconds / 1000), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- }
- // Attente fin des traitements
- if (doneEvent != null)
- doneEvent.Set();
- }
-
- private void MakeTopicFromThread(object state)
- {
- while (true)
- try
- {
- // Traitement
- MakeTopic((TopicImplementation)state, false, null);
-
- // Pause dynamique
- Thread.Sleep(((TopicImplementation)state).DynamicDelay);
- }
- catch (ThreadAbortException)
- {
- }
- }
-
- private void NewsBuildHtml(XmlElement extensions, XmlDocument news, TopicImplementation topic, string uno, StorageServer storage)
- {
- // Stockage et transformation de la news au format html
- if (String.IsNullOrEmpty((string)topic["htmlModel"]) == false)
- {
- using (var storageHtmlNews = storage.Store(Constants._storageNewsFormatName, Key, string.Format("{0}.htm", uno)))
- {
- XslCompiledTransform transform = GetXsltCT((string)topic["htmlModel"]);
- XsltArgumentList arguments = new XsltArgumentList();
-
- arguments.AddParam("NewsExtension", String.Empty, extensions);
- arguments.AddParam("Version", string.Empty, Version);
- arguments.AddParam("ImageActive", string.Empty, Convert.ToBoolean ( ImageActive )) ;
-
- transform.Transform(news, arguments, storageHtmlNews);
- }
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="doc">Noeud ou on rajoute l'attribut</param>
- /// <param name="name">Nom de l'attribut</param>
- /// <param name="value">Valeur </param>
- /// <returns></returns>
- public XmlAttribute createAttribute(XmlDocument doc, String name, String value)
- {
- XmlAttribute attr = doc.CreateAttribute(name);
-
- attr.Value = value;
-
- return attr;
- }
-
- void appendXmlDateAttribute(XmlElement element, XmlDocument doc, String name, DateTime? dt)
- {
- if (dt != null && dt.HasValue)
- {
- String dtStr = XmlConvert.ToString(dt.Value, XmlDateTimeSerializationMode.RoundtripKind);
-
- element.Attributes.Append(createAttribute(doc, name, dtStr));
- }
- }
-
- private XmlElement NewsExtendDocument(XmlDocument news, List<Media> photoList, List<Media> documentsList, TopicImplementation topic, string uno, StorageServer storage, int XsltVersion)
- {
- XmlElement NewsExtension;
-
- Int16 pos = 0;
- Int16 previewB = 0;
-
- NewsExtension = news.CreateElement("NewsExtension");
- //NewsExtension.Attributes.Append(createAttribute(news, "id", topic.Id));
- if (topic.Id.Contains("__"))
- NewsExtension.Attributes.Append(createAttribute(news, "id", string.Format("{0:X}", topic.Id.Substring(topic.Id.IndexOf("__") + 2).MyGetHashCode())));
- else
- NewsExtension.Attributes.Append(createAttribute(news, "id", string.Format("{0:X}",topic.Id.MyGetHashCode())));
- //BUG le bon id commence par topic.Id.Substring(topic.Id.IndexOf("__")+2).MyGetHashCode()
- NewsExtension.Attributes.Append(createAttribute(news, "uno", uno));
- if (topic.UseBase64 == false)
- {
- NewsExtension.Attributes.Append(createAttribute(news, "DontUseDataUrl", "1"));
- }
-
- //NewsExtension.Attributes.Append(createAttribute(news, "Version", XsltVersion.ToString() ));
-
- // Traitement des dates
- if (XsltVersion == 1)
- {
- // on reste avec l'ancien traitement on ne sait jamais
- appendXmlDateAttribute(NewsExtension, news, "dateAndTime", news.DocumentElement.FindDate("/NewsML/NewsEnvelope/DateAndTime"));
- appendXmlDateAttribute(NewsExtension, news, "firstCreated", news.DocumentElement.FindDate("/NewsML/NewsItem/NewsManagement/FirstCreated"));
- appendXmlDateAttribute(NewsExtension, news, "thisRevisionCreated", news.DocumentElement.FindDate("/NewsML/NewsItem/NewsManagement/ThisRevisionCreated"));
- }
- else
- {
- NewsExtension.Attributes.Append(createAttribute(news, "dateAndTime", news.DocumentElement.FindDateToXmlUtcString("/NewsML/NewsEnvelope/DateAndTime")));
- NewsExtension.Attributes.Append(createAttribute(news, "firstCreated", news.DocumentElement.FindDateToXmlUtcString("/NewsML/NewsItem/NewsManagement/FirstCreated")));
- NewsExtension.Attributes.Append(createAttribute(news, "thisRevisionCreated", news.DocumentElement.FindDateToXmlUtcString("/NewsML/NewsItem/NewsManagement/ThisRevisionCreated")));
- }
- // Traitement des photos
-
- XmlElement ContainerNewsComponent = null ;
-
- string mediaCurrentId ="";
- Boolean newMediaId = false;
-
- foreach (Media media in photoList)
- {
- //XmlElement NewsComponent1 = news.CreateElement("NewsComponent");
- if (mediaCurrentId != media.Duid)
- {
- newMediaId = true;
- mediaCurrentId = media.Duid;
- }
-
-
- if (XsltVersion > 1 && newMediaId == true )
- {
- ContainerNewsComponent = news.CreateElement("NewsComponent");
- NewsExtension.AppendChild(ContainerNewsComponent);
- pos = 0; previewB = 0;
- newMediaId = false;
- }
-
-
- XmlElement NewsComponent;
- NewsComponent = news.CreateElement("NewsComponent");
- if (XsltVersion > 1)
- {
- ContainerNewsComponent.AppendChild(NewsComponent);
- }
- else
- {
- NewsExtension.AppendChild(NewsComponent);
- }
-
- //favori : Ici sont passées les Parametres...
- //NewsExtension.Attributes.Append(createAttribute(news, "uno", uno));
-
- if (XsltVersion == 1)
- {
- NewsComponent.Attributes.Append(createAttribute(news, "duid", media.Duid));
- NewsComponent.Attributes.Append(createAttribute(news, "hduid", string.Format("#{0}", media.Duid)));
-
- }
- else
- {
- if (pos == 0)
- {
- ContainerNewsComponent.Attributes.Append(createAttribute(news, "duid", media.Duid));
- ContainerNewsComponent.Attributes.Append(createAttribute(news, "huid", string.Format("#{0}", media.AbsoluteWebPath)));
- }
- pos += 1;
- }
-
- // insertion de la preview
- if (media.Role.Equals( _PreviewRole, StringComparison.InvariantCultureIgnoreCase ))
- {
- ContainerNewsComponent.Attributes.Append(createAttribute(news, "preview", string.Format("{0}", media.AbsoluteWebPath)));
-
- previewB += 1;
- }
-
- NewsComponent.Attributes.Append(createAttribute(news, "role", media.Role));
- // est-ce une video
- Boolean video= false;
- if (media.Role.ToLower() == "iformat" || media.Role.ToLower() == "video" || media.AbsoluteWebPath.EndsWith("mp4"))
- {
- NewsComponent.Attributes.Append(createAttribute(news, "video", "1"));
- video = true;
- }
- else
- {
- NewsComponent.Attributes.Append(createAttribute(news, "video", "0"));
- video = false;
- }
-
-
- if (topic.UseBase64 == true )
- {
- NewsComponent.Attributes.Append(createAttribute(news, "href", string.Format("{0}/{1}/{2}/{3}/{4}",
- topic.ProductServiceName,
- _storagePhotosFormatName,
- Key,
- Storage.StorageServer.GetHashFolder(media.Name),
- media.Name.UrlEncode()
- )
- ));
-
- }
- else
- {
- NewsComponent.Attributes.Append(createAttribute(news, "href", media.AbsoluteWebPath));
- }
- NewsComponent.Attributes.Append(createAttribute(news, "width", media.Width));
- NewsComponent.Attributes.Append(createAttribute(news, "height", media.Height));
-
- // Ecriture fichier encodé
- if (topic.UseBase64 && video == false)
- {
- if (storage.Exists(_storagePhotosFormatName, Key, media.Name))
- {
- using (var file = storage.Restore("Photos", Key, media.Name, true))
- {
- NewsComponent.InnerText = StorageServer.FileToBase64(file);
- }
- }
- }
- else
- {
- // NewsComponent.InnerText = media.AbsoluteWebPath;
- }
- }
-
-
-
- // on va maintenant prendre la liste des documents
- if (XsltVersion > 1)
- {
- XmlElement NewsComponent1 = news.CreateElement("NewsComponent");
- ((XmlElement)NewsComponent1).SetAttribute("role", "document");
- foreach (Media media in documentsList)
- {
- XmlElement docNewsComponent = news.CreateElement("NewsComponent");
- // NewsExtension.AppendChild(docNewsComponent);
- docNewsComponent.Attributes.Append(createAttribute(news, "duid", media.Duid));
- docNewsComponent.Attributes.Append(createAttribute(news, "role", "document"));
- docNewsComponent.Attributes.Append(createAttribute(news, "href", media.AbsoluteWebPath));
- NewsComponent1.AppendChild(docNewsComponent);
- }
-
- NewsExtension.AppendChild(NewsComponent1);
- }
-
- /* Process.Trace(" News Extension ",
- string.Format("version {0} ", XsltVersion),
- System.Diagnostics.EventLogEntryType.Information);
- */
- return NewsExtension;
- }
-
- private News NewsLoadDocument(NewsComponent newsComponent, TopicImplementation topic, StorageServer storage, DateTime dateReference)
- {
- return NewsLoadDocument(((NewsItemRef)newsComponent.Items[0]).NewsItem, topic, storage, dateReference);
- }
-
- private News NewsLoadDocument(String newsItemRef, TopicImplementation topic, StorageServer storage, DateTime dateReference)
- {
- String fileName = Path.GetFileName(newsItemRef);
- StorageFileInfo storedNewsInfo = storage.Info(Constants._storageNewsFormatName, Key, fileName);
- News news = new News(Path.GetFileNameWithoutExtension(fileName));
- Boolean srcNewsExists = false;
- String livraisonNewsPath = string.Empty;
- DateTime? ThisRevisionCreated;
- news.State = News.NewsState.New;
-
- try
- {
- // Recherche de la news
- foreach (var directoryName in topic.Folders)
- {
- livraisonNewsPath = Path.Combine(directoryName, newsItemRef);
- srcNewsExists = StorageServer.FileExists(livraisonNewsPath);
-
- if (srcNewsExists)
- {
- news.LastModificationDate = File.GetLastWriteTime(livraisonNewsPath);
- break;
- }
- }
-
- // Détermination de l'état de la news
- // News locale présente
- if (srcNewsExists)
- {
- // Ancienne news stockée existe ?
- using (var localNewsFile = StorageServer.FileOpen(livraisonNewsPath))
- {
- if (storedNewsInfo == null)
- {
- // Nouvelle news
- news.Document.Load(localNewsFile);
-
- news.Path = livraisonNewsPath;
- news.State = News.NewsState.New;
- #if SERVICE
-
- lock (GBLock)
- {
- AFP.IPhone.Plugins.GetCourseId.GetRefIdSoapClient Client = new AFP.IPhone.Plugins.GetCourseId.GetRefIdSoapClient();
- Client.ClientCredentials.Windows.AllowNtlm = true;
-
- news.Uid = Client.GetCourseId(topic.Id, news.Uno);
- };
- #endif
- }
- else
- {
- // La news a-t-elle été modifiée ? et la feuille de style a elle été modifiée?
- if (storedNewsInfo.LastModified >= news.LastModificationDate && topic.XsltDate <= storedNewsInfo.LastModified)
- {
- // La news est ancienne
- news.Document.Load(storedNewsInfo.Path);
- news.State = News.NewsState.Stored;
- try
- {
- news.Uid = Convert.ToInt64(news.Document.SelectSingleNode("NewsML").Attributes["absoluteindex"].Value);
- }
- finally
- {
- }
- }
- else
- {
- // Nouvelle version de la news
- news.Document.Load(localNewsFile);
- news.Path = livraisonNewsPath;
- #if SERVICE
- lock (GBLock)
- {
- /*TO DO appel au service WEB !!! */
- // TO DO a voir à factoriser le client
- AFP.IPhone.Plugins.GetCourseId.GetRefIdSoapClient Client = new AFP.IPhone.Plugins.GetCourseId.GetRefIdSoapClient();
- Client.ClientCredentials.Windows.AllowNtlm = true;
- news.Uid = Client.GetCourseId(topic.Id, news.Uno);
- };
-
- #endif
- news.State = News.NewsState.New;
- }
- }
- }
- // La news est ancienne
- }
- else
- {
- if (storedNewsInfo == null)
- {
-
- String Folders = "";
- foreach (string cFolder in topic.Folders)
- {
- Folders = string.Format("{0} ; {1}", cFolder, Folders);
- }
-
- Process.Trace("Bug Store", string.Format("NO DOCUMENT FOUND {0}-{1}. Folder : {2}", topic.Id, newsItemRef, Folders), System.Diagnostics.EventLogEntryType.Information);
-
- // La news n'est pas archivée
- news.State = News.NewsState.Invalid;
- }
- else
- {
- //Process.Trace("Bug Store", string.Format("REUSE STORED DOCUMENT {0}-{1}", topic.Id, newsItemRef), System.Diagnostics.EventLogEntryType.Information);
-
- // La news est archivée
- if (topic.XsltDate <= storedNewsInfo.LastModified)
- {
- news.Document.Load(storedNewsInfo.Path);
- try
- {
- news.Uid = Convert.ToInt64(news.Document.SelectSingleNode("NewsML").Attributes["absoluteindex"].Value);
- }
- finally
- {
- }
- news.State = News.NewsState.Stored;
- }
- else
- {
- // la feuille de style a été modifiée on force le recalcul
- news.Document.Load(storedNewsInfo.Path);
- news.State = News.NewsState.New;
- }
- }
- }
-
-
- // Vérification date de validité et transformation éventuelle
- if (news.State != News.NewsState.Invalid)
- {
- if (string.IsNullOrEmpty(topic.NewsXslt) == false)
- {
- using (var newsStream = new MemoryStream())
- {
- // Transformation de la news
- GetXsltCT(topic.NewsXslt).Transform(news.Document, null, newsStream);
- // Récupération
- newsStream.Position = 0;
- news.Document.Load(newsStream);
- }
- }
-
- //ENCOURS si message alert on la prépare
- if (topic.CanBeAlert)
- {
- // si le document comporte le flag alerte
- // on le rajoute dans la base alerte...
- // avec topicId siteIdn UrlDocument? on l'a ici?
- //
- TopicDeclaration topicDeclaration = new TopicDeclaration(topic.Topic);
- AddAlert(topicDeclaration.Uno, news.Uno, news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine"));
-
- }
- ThisRevisionCreated = news.Document.FindDate("/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
-
- if (ThisRevisionCreated.HasValue == false)
- ThisRevisionCreated = news.Document.FindDate("/NewsML/NewsItem/NewsManagement/FirstCreated");
-
- // Vérification date de validité et transformation éventuelle
- if (ThisRevisionCreated.Value > dateReference)
- {
- #if DEBUG
- Process.Trace("Bug Delivery", string.Format("DOCUMENT IN FUTURE {0}-{1} Date:{2} --> {3}", topic.Id, newsItemRef, ThisRevisionCreated.Value, dateReference), System.Diagnostics.EventLogEntryType.Information);
- #endif
- }
- else
- {
- if (topic.IsDaily == false)
- {
- if (dateReference.ToUniversalTime().Subtract(ThisRevisionCreated.Value).CompareTo(topic.MaxAge) > 0)
- {
- news.State = News.NewsState.Invalid;
- }
- }
- }
- }
- else
- {
- }
- }
- catch (Exception e)
- {
- Process.Trace(string.Format("Can't load news document {0}", newsItemRef), e.ToString(), System.Diagnostics.EventLogEntryType.Error);
- this.Set("News load error", MessageSection.Processing.ToString(), System.Diagnostics.EventLogEntryType.Warning);
-
- // La news est invalide
- news.State = News.NewsState.Invalid;
- }
-
- return news;
- }
-
- private News AnnounceLoadDocument(string Path, TopicImplementation topic, StorageServer storage, DateTime ThisRevisionCreated)
- {
- String FileName = System.IO.Path.GetFileName(Path);
- String NewsItemRef = String.Format("{0}_{1}", topic.Id, FileName);
- StorageFileInfo storedNewsInfo = storage.Info(Constants._storageNewsFormatName, Key, FileName);
-
- News news = new News(NewsItemRef);
-
- if (System.IO.File.Exists(Path))
- {
- // on a une annonce a faire !!
- if (storedNewsInfo == null)
- {
- // first !!!
- news.Document.Load(Path);
- news.Path = Path;
- news.State = News.NewsState.New;
-
- }
- else
- {
- // Stored
- if (File.GetLastWriteTime(storedNewsInfo.Path) >= File.GetLastWriteTime(Path))
- {
- //
- news.Document.Load(storedNewsInfo.Path);
- news.State = News.NewsState.Stored;
- }
- else
- {
- // une mise à jour de l'annonce a été faite !
- news.Document.Load(Path);
- news.Path = Path;
- news.State = News.NewsState.New;
-
- }
- }
-
- // on applique eventuellement la XSLT !
-
- if (string.IsNullOrEmpty(topic.NewsXslt) != true)
- {
- using (var newsStream = new MemoryStream())
- {
- // Transformation de la news
- GetXsltCT(topic.NewsXslt).Transform(news.Document, null, newsStream);
- // Récupération
- newsStream.Position = 0;
- news.Document.Load(newsStream);
- }
- }
-
- news.LastModificationDate = ThisRevisionCreated;
- news.Document.SelectSingleNode("/NewsML/NewsItem/NewsManagement/FirstCreated").SetDateToXmlUtcString(ThisRevisionCreated);
- news.Document.SelectSingleNode("/NewsML/NewsItem/NewsManagement/ThisRevisionCreated").SetDateToXmlUtcString(ThisRevisionCreated);
- // /NewsML/NewsItem/NewsManagement/FirstCreated
- // /NewsML/NewsItem/NewsManagement/ThisRevisionCreated
-
- }
- else
- {
- if (storedNewsInfo != null)
- {
- // on supprimer le fichier reference... il faut supprimer du stockage
- try
- {
- System.IO.File.Delete(storedNewsInfo.Path);
- }
- catch
- {
- ;
- }
- news.State = News.NewsState.Invalid;
- }
- }
-
- return news;
-
- }
- // calcul des votes...
- public void NewsWriteRating(string query, XmlWriter xmlTopic)
- {
- // Ajout du rating
- if (_sqlProcessorList.Count > 0)
- {
- foreach (var processor in _sqlProcessorList)
- using (var sqlRatingReader = new SqlDataAdapter(query, processor.ConnectionString))
- {
- using (var sqlRatingTable = new DataTable())
- {
- try
- {
- sqlRatingReader.Fill(sqlRatingTable);
- }
- catch
- {
- continue;
- }
-
- if (sqlRatingTable.Rows.Count == 0)
- {
- xmlTopic.WriteAttributeString("globalRate", "0");
- xmlTopic.WriteAttributeString("numberOfVote", "0");
- }
- else
- {
- xmlTopic.WriteAttributeString("globalRate", Convert.ToString((double)sqlRatingTable.Rows[0]["rating"] / (int)sqlRatingTable.Rows[0]["votes"], System.Globalization.CultureInfo.InvariantCulture));
- xmlTopic.WriteAttributeString("numberOfVote", Convert.ToString(sqlRatingTable.Rows[0]["votes"]));
- }
-
- break;
- }
- }
- }
- }
-
- private void AddAlert(string topicUno, string newsId, string Headline)
- {
- // productId, topicId, newsId, mediaId, lang, hit,longitude, lattidute)
-
- foreach (var sqlProcessor in _sqlProcessorList2)
- {
-
- sqlProcessor.Add(new SqlAlertServiceProduction(topicUno , newsId, Headline )) ;
- }
-
- }
-
-
- private bool NewsWriteBySubject(News news, NewsML topicDocument, TopicImplementation topic, XmlWriter xmlTopic, StorageServer storage, NewsMediaFilter mediaFilter, int index, bool writeId, bool refresh, int nbHits, ref string rcatchLine)
- {
- // Traitement de la news
- var mediaPhotoList = new List<Media>();
-
- var processedComponent = new List<string>();
- var firstComponent = true;
- var textOnly = news.Document.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent/p/a[@class='videoSet']").Count == 0 && news.Document.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid]").Count == 0;
-
-
- String FirstCreated = news.Document.FindDateToXmlUtcString("/NewsML/NewsItem/NewsManagement/FirstCreated");
- String DatePublished = news.Document.FindDateToXmlUtcString("/NewsML/NewsItem/NewsManagement/ThisRevisionCreated");
- if (string.IsNullOrEmpty(FirstCreated) || String.IsNullOrEmpty(DatePublished))
- {
- //TO do une log peut être?
- Process.Trace(string.Format("Empty Date on {0} uno : {1} path : {2}", topic.Id, news.Uno, news.Path), System.Diagnostics.EventLogEntryType.Warning);
- this.Set(string.Format("Empty Date on {0} uno : {1} path : {2}", topic.Id, news.Uno, news.Path), MessageSection.Processing.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- return false;
- }
-
- // Gestion d'un sujet
- float latitude = 0;
- float longitude = 0;
- string city = "";
- string country = "";
-
- XmlNode selNode = null;
-
-
- selNode = news.Document.SelectSingleNode("/NewsML/NewsItem/NewsComponent/DescriptiveMetadata/Location[@HowPresent='Origin']/Property[@FormalName='Latitude']");
- if ( selNode != null )
- latitude =float.Parse( selNode.GetAttributeValue("Value", "0"), CultureInfo.InvariantCulture) ;
- selNode = news.Document.SelectSingleNode("/NewsML/NewsItem/NewsComponent/DescriptiveMetadata/Location[@HowPresent='Origin']/Property[@FormalName='Longitude']");
- if (selNode != null)
- longitude = float.Parse(selNode.GetAttributeValue("Value", "0"), CultureInfo.InvariantCulture) ;
-
- selNode = news.Document.SelectSingleNode("/NewsML/NewsItem/NewsComponent/DescriptiveMetadata/Location[@HowPresent='Origin']/Property[@FormalName='City']");
- if (selNode != null)
- city = selNode.GetAttributeValue("City", "" ) ;
- selNode = news.Document.SelectSingleNode("/NewsML/NewsItem/NewsComponent/DescriptiveMetadata/Location[@HowPresent='Origin']/Property[@FormalName='Country']");
- if (selNode != null)
- country = selNode.GetAttributeValue("Country", "");
-
-
-
- // TO do enregistrement de la latitude longitude dans la base ;
- AddDocumentInLocalizedDatabase(topic.ProductServiceName , topic.Id, news.Uno, "", topic.Lang ,latitude, longitude);
- xmlTopic.WriteStartElement("Item");
- {
- // Xafp/Bag/Item
- xmlTopic.WriteAttributeString("type", "multimedia");
- xmlTopic.WriteAttributeString("uno", news.Uno);
- xmlTopic.WriteAttributeString("parentId", topic.Id);
- if (latitude != 0.0 )
- xmlTopic.WriteAttributeString("latitude", latitude.ToString( new CultureInfo(""))) ;
- if (longitude != 0.0)
- xmlTopic.WriteAttributeString("longitude", longitude.ToString ( new CultureInfo("") ) );
- if ( ! string.IsNullOrEmpty(city ))
- xmlTopic.WriteAttributeString("city", city);
- if (!string.IsNullOrEmpty(country ))
- xmlTopic.WriteAttributeString("country",country );
-
- string pPath ="";
-
- if (_UseUri )// AbsolutePath or not
- {
-
- string WebFilePAth = string.Format("{0}/{1}/{2}/{3}.htm",
- Constants._storageNewsFormatName,
- Key,
- AFP.IPhone.Storage.StorageServer.GetHashFolder(string.Format("{0}{1}", news.Uno, ".htm")),
- news.Uno);
- if (topic.UrlWebRacine.EndsWith ("/"))
- pPath = string.Format(@"{0}{1}/{2}", topic.UrlWebRacine, topic.ProductServiceName, WebFilePAth);
- else
- pPath = string.Format(@"{0}/{1}/{2}", topic.UrlWebRacine, topic.ProductServiceName, WebFilePAth);
-
- //pPath = pPath.Replace("//", "/");
-
- xmlTopic.WriteAttributeString("href", pPath);
- }
- else
- {
- pPath = String.Format("{0}/{1}/{2}/{3}/{4}{5}",
- topic.ProductServiceName,
- Constants._storageNewsFormatName,
- Key,
- AFP.IPhone.Storage.StorageServer.GetHashFolder(string.Format("{0}{1}", news.Uno, ".htm")),
- news.Uno,
- ".htm");
-
- xmlTopic.WriteAttributeString("href", pPath );
-
-
- }
-
- //Encours c'est ici qu'on va traiter les alertes
- xmlTopic.WriteAttributeString("revision", news.Document.FindInnerText("/NewsML/NewsItem/Identification/NewsIdentifier/RevisionId"));
- xmlTopic.WriteAttributeString("index", index.ToString());
- xmlTopic.WriteAttributeString("absoluteindex", news.Uid.ToString());
- if (nbHits != -1)
- xmlTopic.WriteAttributeString("numberOfHits", nbHits.ToString());
-
- // TopicId
- if (writeId)
- xmlTopic.WriteAttributeString("topicId", topic.Id);
-
- // Ajout du rating
- try
- {
- NewsWriteRating(string.Format("SELECT SUM(votes) AS votes, SUM(rating) AS rating FROM Ratings2 WHERE newsId='{0}' AND mediaId IS NULL GROUP BY newsId", news.Uno), xmlTopic);
- }
- catch (Exception e)
- {
- Process.Trace(string.Format("Can't get rating info for news {0} (source : {1})", news.Uno, topic.Id), e.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- this.Set("Rating access error", MessageSection.Database.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- }
-
- // Gestion NewsLine
- xmlTopic.WriteStartElement("NewsLines");
- {
- // Xafp/Bag/Item/NewsLines
- xmlTopic.WriteElementString("HeadLine", news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine"));
- xmlTopic.WriteElementString("SubHeadLine", news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/SubHeadLine"));
- xmlTopic.WriteElementString("SlugLine", news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/SlugLine"));
- xmlTopic.WriteElementString("DateCreated", FirstCreated);
- xmlTopic.WriteElementString("DatePublished", DatePublished);
- xmlTopic.WriteElementString("DateLine", news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/DateLine"));
- xmlTopic.WriteElementString("CopyRightLine", news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/CopyrightLine"));
- }
- xmlTopic.WriteEndElement();
- // Xafp/Bag/Item/NewsLines
- foreach (XmlElement element in news.Document.SelectNodes("/NewsML/NewsItem/NewsComponent/NewsComponent"))
- {
- XmlElement componentRelative = null;
- ComponentType componentType;
- string photoRef = null;
- string headLine = "";
- // Détermination du type de composante
- if (element.SelectSingleNode("ContentItem/DataContent/p/a[@class='videoSet']") != null)
- {
- componentType = ComponentType.video;
- photoRef = element.FindValue("ContentItem/DataContent/p/a[@class='videoSet']/a[@class='photo']/@href").Substring(1);
- componentRelative = (XmlElement)news.Document.SelectSingleNode(string.Format("/NewsML/NewsItem/NewsComponent/NewsComponent[@Duid='{0}']", photoRef));
- }
- else if (element.HasAttribute("Duid"))
- {
- componentType = ComponentType.photo;
- photoRef = element.GetAttribute("Duid");
- componentRelative = element;
- if (element.SelectSingleNode("NewsLines/HeadLine") != null)
- headLine = element.SelectSingleNode("NewsLines/HeadLine").InnerText;
-
- }
- else
- componentType = (textOnly) ? ComponentType.text : ComponentType.unsupported;
-
- // Traitement des composantes supportées
-
- switch (componentType)
- {
- case ComponentType.text:
- // Traitement d'un bag
- using (var xmlBag = createXmlWriter())
- {
- // Ecriture du bag
- xmlBag.WriteStartElement("Bag");
- {
- // Xafp/Bag/Item/Bag
- var titleLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
- var catchLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
- //var OotherC = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
-
-
- // TitleLine alternatif
- if (String.IsNullOrEmpty(titleLine))
- titleLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/HeadLine");
-
- // CatchLine alternatif
- if (String.IsNullOrEmpty(catchLine))
- catchLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsComponent[1]/ContentItem/DataContent/p[1]");
-
-
- rcatchLine = catchLine;
- // Gestion TitleLine
- if (!String.IsNullOrEmpty(titleLine))
- {
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Text");
- xmlBag.WriteAttributeString("role", "Title");
- xmlBag.WriteElementString("p", titleLine.ConvertWhitespacesToSingleSpaces().Trim());
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- }
-
- // Gestion CatchLine
- if (!String.IsNullOrEmpty(catchLine))
- {
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Text");
- xmlBag.WriteAttributeString("role", "News");
- xmlBag.WriteElementString("p", catchLine.ConvertWhitespacesToSingleSpaces().Trim());
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- }
-
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag
- //Ecriture du bag dans la news
- xmlTopic.WriteRaw(xmlBag.ToString());
- }
-
- break;
-
- case ComponentType.photo:
- case ComponentType.video:
- // Vérification de traitement déjà effectué (pb video liée à une photo)
- if (!processedComponent.Contains(photoRef))
- {
- var photoName = GetMediaName(componentRelative.FindValue("NewsComponent/ContentItem/MediaType[@FormalName='Photo']/parent::*/@Href"), topic);
- var provider = componentRelative.FindValue("AdministrativeMetadata/Provider/Party/@FormalName");
- var creator = componentRelative.FindValue("AdministrativeMetadata/Creator/Party/@FormalName");
- var bagDefined = false;
-
- // Photo traitée
- processedComponent.Add(photoRef);
-
- // Traitement creator
- if (string.IsNullOrEmpty(creator) && componentRelative.SelectNodes("AdministrativeMetadata/Provider/Party").Count > 1)
- creator = componentRelative.FindValue("AdministrativeMetadata/Provider/Party[2]/@FormalName");
-
- // Traitement d'un bag
- using (var xmlBag = createXmlWriter())
- {
- // Ecriture du bag
- xmlBag.WriteStartElement("Bag");
- {
- // Xafp/Bag/Item/Bag
- // Ecriture du uno
- xmlBag.WriteAttributeString("uno", photoName);
-
- // Ajout du rating
- try
- {
- NewsWriteRating(string.Format("SELECT SUM(votes) AS votes, SUM(rating) AS rating FROM Ratings2 WHERE mediaId='{0}' GROUP BY mediaId", photoName), xmlBag);
- }
- catch (Exception e)
- {
- Process.Trace(string.Format("Can't get rating info for media {0} (source : {1})", photoName, topic.Id), e.ToString(), System.Diagnostics.EventLogEntryType.Information);
- this.Set("Rating access error", MessageSection.Database.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- }
-
- // Traitement de la première composante
- if (firstComponent)
- {
- var titleLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='MobileShortTitle']]");
- var catchLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsLines/NewsLine/NewsLineText[preceding-sibling::NewsLineType[@FormalName='CatchLine']]");
-
- // CatchLine alternatif
- if (String.IsNullOrEmpty(catchLine))
- catchLine = news.Document.FindInnerText("/NewsML/NewsItem/NewsComponent/NewsComponent[1]/ContentItem/DataContent/p[1]");
-
- // Gestion TitleLine
- if (!String.IsNullOrEmpty(titleLine))
- {
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Text");
- xmlBag.WriteAttributeString("role", "Title");
- xmlBag.WriteElementString("p", titleLine.ConvertWhitespacesToSingleSpaces().Trim());
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- }
- rcatchLine = catchLine;
- // Gestion CatchLine
- if (!String.IsNullOrEmpty(catchLine ))
- {
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Text");
- xmlBag.WriteAttributeString("role", "News");
- xmlBag.WriteElementString("p", catchLine.ConvertWhitespacesToSingleSpaces().Trim());
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- }
-
- }
- // Gestion HeadLine (Rajout de fonctionnalité 02/2011)
- if (!String.IsNullOrEmpty(headLine))
- {
- xmlBag.WriteStartElement("Content");
- {
- xmlBag.WriteAttributeString("type", "Text");
- xmlBag.WriteAttributeString("role", "Headline");
- xmlBag.WriteElementString("p", headLine.ConvertWhitespacesToSingleSpaces());
- }
- xmlBag.WriteEndElement();
- }
-
- // Gestion Caption
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Text");
- xmlBag.WriteAttributeString("role", "Caption");
- xmlBag.WriteAttributeString("provider", provider);
- xmlBag.WriteAttributeString("creator", creator);
-
- // Caption ou HeadLine si vide
- var documentCaption = componentRelative.FindInnerText("NewsComponent/Role[@FormalName='Caption']/following::DataContent");
-
- if (string.IsNullOrEmpty(documentCaption))
- xmlBag.WriteElementString("p", componentRelative.FindInnerText("NewsLines/HeadLine"));
- else
- xmlBag.WriteElementString("p", documentCaption);
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- // Gestion des liens photos
- if (!String.IsNullOrEmpty(photoRef))
- foreach (XmlElement content in Configuration.SelectNodes("//contents/photo/content"))
- foreach (var role in content.GetAttributeValue("source", content.GetAttribute("role")).Split(';'))
- try
- {
- var media = (XmlElement)componentRelative.SelectSingleNode(string.Format("NewsComponent[Role[@FormalName='{0}']]", role));
-
- // Role trouvé ?
- if (media != null && media.FindValue("ContentItem/MediaType/@FormalName").Equals("Photo"))
- {
- String storageMediaName = string.Format("{0}-{1}.jpg", photoName, content.GetAttribute("role"));
- var sourceState = News.NewsState.Invalid;
- var mediaExists = false;
-
- // Traitement nouveau média
- if ((refresh && !string.IsNullOrEmpty(news.Path)) || news.State == News.NewsState.New)
- {
- mediaExists = StorageServer.FileExists(Path.Combine(Path.GetDirectoryName(news.Path), media.FindValue("ContentItem/@Href")));
-
- // Source fichier ?
- if (mediaExists)
- sourceState = News.NewsState.New;
- }
-
- // Média depuis stockage si media pas trouvé ?
- if (!mediaExists)
- {
- mediaExists = storage.Exists(_storagePhotosFormatName, Key, storageMediaName);
-
- // Source stockage ?
- if (mediaExists)
- sourceState = News.NewsState.Stored;
- else
- if (topic.UseBase64) sourceState = News.NewsState.TemporayInvalid;
- }
-
- // Traitement du media
- if (mediaExists)
- {
- var mediaWidth = 0;
- var mediaHeight = 0;
-
- // Transformations et stockage
- switch (sourceState)
- {
- case News.NewsState.New:
- var mediaPath = Path.Combine(Path.GetDirectoryName(news.Path), media.FindValue("ContentItem/@Href"));
-
- try
- {
- // Traitements
- using (Image photo = Transformations.Photo.Transform(mediaPath, content, role))
- {
- // Stockage du document
- /*using (Stream storageMedia = storage.Store(_storagePhotosFormatName, Key, storageMediaName))
- Transformations.Photo.Save(storageMedia, photo, content);
- */
- string StoragePath = "";
- using (Stream storageMedia = storage.CreateStoreAndGetPath(_storagePhotosFormatName, Key, storageMediaName, out StoragePath))
- Transformations.Photo.Save(storageMedia, photo, content);
-
- // Récupération height et width
- mediaHeight = photo.Height;
- mediaWidth = photo.Width;
-
- // Ajout de la photo à la liste pour extension
- string AbsoluteWebPath = "";
- AbsoluteWebPath = string.Format(@"{0}/{1}/{2}", topic.UrlWebRacine, topic.ProductServiceName, storage.Trunc(StoragePath));
-
- // note : emplacement HD
- mediaPhotoList.Add(
- new Media(
- photoRef,
- content.GetAttribute("role"),
- storageMediaName,
- photo.Width.ToString(),
- photo.Height.ToString(),
- AbsoluteWebPath
- )
- );
- }
- }
- catch (Exception e)
- {
- throw new Exception(string.Format("Photo {0} process error.", mediaPath), e);
- }
-
- break;
-
- case News.NewsState.Stored:
-
- using (Stream storageMedia = storage.Restore(_storagePhotosFormatName, Key, storageMediaName, true))
- {
- using (Image storageMediaImage = Image.FromStream(storageMedia))
- {
- string WebFilePAth = "";
- // Récupération height et width
- string AbsoluteWebPath = "";
-
- mediaHeight = storageMediaImage.Height;
- mediaWidth = storageMediaImage.Width;
- if (topic.UseBase64 == false)
- {
- WebFilePAth = storage.GetStorageFilePath(_storagePhotosFormatName, Key, storageMediaName);
- AbsoluteWebPath = string.Format(@"{0}/{1}/{2}", topic.UrlWebRacine, topic.ProductServiceName, WebFilePAth);
- }
- // Ajout de la photo à la liste pour extension
- // note emplacement HD
- mediaPhotoList.Add(
- new Media
- (
- photoRef,
- content.GetAttribute("role"),
- storageMediaName,
- storageMediaImage.Width.ToString(),
- storageMediaImage.Height.ToString(),
- AbsoluteWebPath
- ));
- }
- }
-
-
-
- break;
- }
-
- // Ecriture de l'élément Content
- if (mediaFilter != NewsMediaFilter.videoOnly || componentType == ComponentType.video)
- {
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Photo");
- xmlBag.WriteAttributeString("role", content.GetAttribute("role"));
- /*
- if (topic.UseBase64)
- xmlBag.WriteAttributeString("href", String.Format("{0}/{1}/{2}", _storagePhotosFormatName, Key, storageMediaName.UrlEncode()));
- else
- {*/
- //xmlBag.WriteAttributeString("href", string.Format(@"{0}\{1}\{2}\{3}\{4}", topic.ProductServiceName, _storagePhotosFormatName, Key, storage.GetHashFolder2(storageMediaName), storageMediaName));
-
- // V .11 on passe en URL absolue pour les bags (cache à plein régime)
- if (_UseUri)
- {
- string WebFilePAth = storage.GetStorageFilePath(_storagePhotosFormatName, Key, storageMediaName);
- string AbsoluteWebPath = string.Format(@"{0}/{1}/{2}", topic.UrlWebRacine, topic.ProductServiceName, WebFilePAth);
- xmlBag.WriteAttributeString("href", AbsoluteWebPath );
-
- }
- else
- {
- xmlBag.WriteAttributeString("href", string.Format(@"{0}\{1}\{2}\{3}\{4}", topic.ProductServiceName, _storagePhotosFormatName, Key, storage.GetHashFolder2(storageMediaName), storageMediaName));
- }
-
- /*
- }
- */
-
- xmlBag.WriteAttributeString("height", mediaHeight.ToString());
- xmlBag.WriteAttributeString("width", mediaWidth.ToString());
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- // Ecriture du bag autorisée
- bagDefined = true;
- }
-
- break;
- }
-
- // Media non trouvé
- Process.Trace(string.Format("Can't find photo key {0} and id {1}.", Key, storageMediaName), System.Diagnostics.EventLogEntryType.FailureAudit);
- }
- }
- catch (Exception e)
- {
- Process.Trace(string.Format("Can't process media {0} for role {1} in news {2} of topic {3} (source : {4})", photoName, role, news.Uno, topic.Id, topic.Id), e.ToString(), System.Diagnostics.EventLogEntryType.FailureAudit);
- }
-
- // Gestion des liens videos
-
-
- foreach (XmlElement content in Configuration.SelectNodes("//contents/video/content"))
- foreach (var title in content.GetAttributeValue("source", content.GetAttribute("role")).Split(';'))
- {
- var media = (XmlElement)element.SelectSingleNode(string.Format("ContentItem/DataContent/p/a[@class='videoSet']/a[@title='{0}']", title));
- string StoragemediaPath = "";
-
- // Traitement de la video
- if (media != null)
- {
- var mediaName = Path.GetFileName(media.GetAttribute("href").Replace("/", @"\"));
- var mediaExists = false;
-
- // Traitement nouvelle vidéo
- if (news.State == News.NewsState.New)
- {
- var mediaPath = Path.Combine(Path.GetDirectoryName(news.Path), media.GetAttribute("href").Replace("/", @"\"));
- mediaExists = StorageServer.FileExists(mediaPath);
-
- // Stockage de la vidéo
- if (mediaExists)
- StoragemediaPath = storage.Store(mediaPath, _storageVideosFormatName, Key, mediaName);
-
- // TO Do se servir de StoragemediaPath
- }
-
- // Traitement du media
- if ((news.State == News.NewsState.Stored || mediaExists))
- // Ecriture de l'élément Content
- if (mediaFilter != NewsMediaFilter.photoOnly && componentType == ComponentType.video)
- {
- xmlBag.WriteStartElement("Content");
- {
- // Xafp/Bag/Item/Bag/Content
- xmlBag.WriteAttributeString("type", "Video");
- xmlBag.WriteAttributeString("role", content.GetAttribute("role"));
- xmlBag.WriteAttributeString("href", String.Format("{0}/{1}/{2}/{3}/{4}/{5}",
- topic.UrlWebRacine,
- topic.ProductServiceName,
- _storageVideosFormatName,
- Key,
- StorageServer.GetHashFolder(mediaName),
- mediaName.UrlEncode()
- ));
-
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag/Content
- // Ecriture du bag autorisée
- bagDefined = true;
- }
- else
- Process.Trace(string.Format("Can't find video {0} in news {1} of topic {2} (source : {3})", media.GetAttribute("href"), news.Uno, topic.Id, topic.Id), System.Diagnostics.EventLogEntryType.FailureAudit);
-
- break;
- }
- }
- }
- xmlBag.WriteEndElement();
- // Xafp/Bag/Item/Bag
- // Gestion du bag
- if (bagDefined)
- {
- // Première composante traitée
- firstComponent = false;
-
- //Ecriture du bag dans la news
- xmlTopic.WriteRaw(xmlBag.ToString());
- }
- }
-
- }
-
- break;
- }
- }
- }
- xmlTopic.WriteEndElement();
-
-
- var mediaDocList = new List<Media>();
-
-
- // Ajout de la photo à la liste pour extension
- string DocWebPath;
- string docmediaName = "";
-
- foreach (XmlNode xCurDocuments in news.Document.SelectNodes("//a[@class='document']"))
- {
- // determination docmediaName ;
- string href = "";
- if (((XmlElement)xCurDocuments).HasAttribute("href"))
- {
- href = xCurDocuments.Attributes["href"].Value;
- docmediaName = System.IO.Path.GetFileNameWithoutExtension(href);
-
- DocWebPath = String.Format("{5}/{0}/{1}/{2}/{3}/{4}.htm",
- topic.ProductServiceName,
- "News",
- Key,
- StorageServer.GetHashFolder(href),
- docmediaName.UrlEncode(),
- topic.UrlWebRacine
- );
-
- //note: Lien vers la DOC ( **DOCUMENTATION**)
- mediaDocList.Add(
- new Media(
- docmediaName,
- "document",
- docmediaName,
- "", "",
- DocWebPath
- ));
- } // si pas on oublie
-
- }
-
- // Xafp/Bag/Item
- // Sauvegarde d'une nouvelle news dans le stockage
- try
- {
- if (news.State == News.NewsState.New || refresh || topic.IsDaily == true)
- {
- // Traitement de la news en HTML
- XmlElement xEtend;
- xEtend = NewsExtendDocument(news.Document, mediaPhotoList, mediaDocList, topic, news.Uno, storage, _Version);
- NewsBuildHtml(xEtend, news.Document, topic, news.Uno, storage);
- #if DEBUG && TRACEINTER
- try
- {
-
- StreamWriter writer = File.CreateText(string.Format("{0}.ext.xml", System.IO.Path.Combine(@"C:\Trace", news.Uno)));
- writer.WriteLine(((XmlNode)xEtend).OuterXml);
- writer.Close();
- news.Document.Save(string.Format("{0}.xml", System.IO.Path.Combine(@"C:\Trace", news.Uno)));
- Process.Trace(string.Format("version ", _Version.ToString () ), System.Diagnostics.EventLogEntryType.Warning);
- }
- catch (Exception e)
- {
- int a = 0;
- Process.Trace(e, System.Diagnostics.EventLogEntryType.Warning);
- }
- #endif
-
- // Stockage de la news d'origine
- if (!string.IsNullOrEmpty(news.Path))
- {
- //Enregistrement du NewsML
- storage.Store(news.Path, Constants._storageNewsFormatName, Key, string.Format("{0}.xml", news.Uno), news.LastModificationDate, news.Uid);
- }
- }
- }
- catch (Exception e)
- {
- Process.Trace(e, System.Diagnostics.EventLogEntryType.Warning);
- this.Set(string.Format("Topic process error on {0}", topic.Id), MessageSection.Processing.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- }
-
- return true;
- }
-
- private void AddDocumentInLocalizedDatabase(string productId, string topicId, string newsId, string mediaId, string lang, float latitude, float longitude)
- {
- // productId, topicId, newsId, mediaId, lang, hit,longitude, lattidute)
-
- foreach (var sqlProcessor in _sqlProcessorList)
- {
-
- sqlProcessor.Add(new SqlLocation(productId, topicId, newsId, mediaId, lang, longitude, latitude));
- }
-
- }
-
- private XmlDocument TopicMostViewed(TopicImplementation topic, StorageServer storage, bool refresh)
- {
- var documentTopic = new XmlDocument();
- var nowDate = DateTime.Now.ToUniversalTime();
- string productId = "";
-
- var newsOrderedList = new SortedList<int, HitEntry>();
- var topicCountByLang = new Dictionary<string, int>();
- var query = (topic.Type == TopicImplementation.TopicType.mostviewed)
- ?
- string.Format("select Sum(hit) as hits , productId, topicId, newsId, lang from viewed where mediaid='' and productId='{0}' group by productid, topicid, newsid, hit, lang order by hits desc", productId)
- :
- string.Format("select Sum(hit) as hits , productId, topicId, newsId, lang from viewed where mediaid!='' and productId='{0}' group by productid, topicid, newsid, hit, lang order by hits desc", productId);
-
- // Récupération des sujets
- foreach (var processor in _sqlProcessorList)
- using (var sqlRatingReader = new SqlDataAdapter(query, processor.ConnectionString))
- {
- using (var sqlRatingTable = new DataTable())
- {
- try
- {
- sqlRatingReader.Fill(sqlRatingTable);
- }
- catch
- {
- continue;
- }
-
- // Création document final
- using (var xmlTopic = createXmlWriter())
- {
- // Création du document XAfp
- xmlTopic.WriteStartElement("Xafp");
- {
- // Xafp
- xmlTopic.WriteAttributeString("type", "collection");
- xmlTopic.WriteAttributeString("id", topic.Id);
-
- xmlTopic.WriteStartElement("Head");
- {
- // Xafp/Head
- xmlTopic.WriteElementString("DateCreated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("DateUpdated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("NumberOfItems", string.Empty);
- }
- xmlTopic.WriteEndElement();
- // Xafp/Head
- xmlTopic.WriteStartElement("Bag");
- {
- // Xafp/Bag
- foreach (DataRow row in sqlRatingTable.Rows)
- {
- try
- {
- var topicSource = TopicImplementation.Load((string)row["topicId"]);
- var topicRated = TopicLoadDocument(topicSource, storage);
-
- if (topicRated == null)
- Process.Trace(string.Format("Can't load topic {0} for rated news {1}", row["topicId"], row["newsId"]), System.Diagnostics.EventLogEntryType.FailureAudit);
- else
- {
- var news = NewsLoadDocument(string.Format("{0}.xml", row["newsId"]), topicSource, storage, DateTime.Now);
-
- // Ecriture de la news
- if (news == null)
- Process.Trace(string.Format("Can't load rated news {0}.", row["newsId"]), System.Diagnostics.EventLogEntryType.FailureAudit);
- else
- newsOrderedList.Add((int)row["hits"], new HitEntry((string)row["topicId"], (string)row["newsId"], (string)row["lang"], (int)row["hits"]));
- }
- }
- catch
- {
- }
- }
-
- foreach (var ratingEntry in newsOrderedList.Values)
- {
- var topicSource = TopicImplementation.Load(ratingEntry.TopicId);
- var topicRated = TopicLoadDocument(topicSource, storage);
- var news = NewsLoadDocument(string.Format("{0}.xml", ratingEntry.NewsId), topicSource, storage, DateTime.Now);
-
-
- if (!topicCountByLang.ContainsKey(ratingEntry.Lang))
- topicCountByLang.Add(ratingEntry.Lang, 0);
-
- // Création du sujet
- string tmv ="" ;
- if (topicCountByLang[ratingEntry.Lang] <= topic.MaxEntries)
- if (NewsWriteBySubject(news, topicRated, topicSource, xmlTopic, storage, NewsMediaFilter.all, topicCountByLang[ratingEntry.Lang], true, refresh, ratingEntry.Hits, ref tmv))
- topicCountByLang[ratingEntry.Lang]++;
- }
- }
- xmlTopic.WriteEndElement();
- // Xafp/Bag
- }
- xmlTopic.WriteEndElement();
- // Xafp
- // Chargement du document
- documentTopic.LoadXml(xmlTopic.ToString());
-
- // Mise à jour du nombre de news
- documentTopic.DocumentElement.SelectSingleNode("//Head/NumberOfItems").InnerText = topicCountByLang.Values.Sum().ToString();
- }
-
- break;
- }
- }
-
- return documentTopic;
- }
- private string TopicBuildRated(TopicImplementation topic, StorageServer storage, bool refresh)
- {
- string productId = "";
- string query = (topic.Type == TopicImplementation.TopicType.rated)
- ?
- string.Format("SELECT lang, topicId, newsId, MAX([rating]/[votes]) AS averageRating, SUM([votes]) AS votes FROM [Ratings2] WHERE [mediaId] IS NULL AND [dateUpdated] > CONVERT(datetime, '{0}', 120) AND [productId]='{1}' GROUP BY lang, topicId, newsId ORDER BY [averageRating] DESC, [votes] DESC", DateTime.Now.Subtract(topic.MaxAge).ToString("yyyy-MM-dd"), productId)
- :
- string.Format("SELECT lang, topicId, newsId, MAX([rating]/[votes]) AS averageRating, SUM([votes]) AS votes FROM [Ratings2] WHERE NOT [mediaId] IS NULL AND [dateUpdated] > CONVERT(datetime, '{0}', 120) AND [productId]='{1}' GROUP BY lang, topicId, newsId ORDER BY [averageRating] DESC, [votes] DESC", DateTime.Now.Subtract(topic.MaxAge).ToString("yyyy-MM-dd"), productId);
- return TopicBuildRated(query, topic.Id, topic.MaxEntries, storage, refresh);
- }
-
- private string TopicBuildAround(string query, StorageServer storage , int MaxEntries)
- {
- var documentTopic = new XmlDocument();
- var nowDate = DateTime.Now.ToUniversalTime();
- var newsOrderedList = new List<News>();
- var topicCountByLang = new Dictionary<string, int>();
- int index =0 ;
-
- // Récupération des sujets
- foreach (var processor in _sqlProcessorList)
- {
- using (var sqlRatingReader = new SqlDataAdapter(query, processor.ConnectionString))
- {
- using (var sqlRatingTable = new DataTable())
- {
- try
- {
- sqlRatingReader.Fill(sqlRatingTable);
- }
- catch(Exception e )
- {
- #if DEBUG
- Process.Trace(e, System.Diagnostics.EventLogEntryType.Error);
- #endif
- continue;
- }
- // Création document final
- using (var xmlTopic = createXmlWriter())
- {
- // Création du document XAfp
- xmlTopic.WriteStartElement("Xafp");
- {
- // Xafp
- xmlTopic.WriteAttributeString("type", "collection");
- xmlTopic.WriteAttributeString("id", "none" );
-
- xmlTopic.WriteStartElement("Head");
- {
- // Xafp/Head
- xmlTopic.WriteElementString("DateCreated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("DateUpdated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("NumberOfItems", string.Empty);
- }
- xmlTopic.WriteEndElement();
- // Xafp/Head
- xmlTopic.WriteStartElement("Bag");
- {
- // Xafp/Bag
- foreach (DataRow row in sqlRatingTable.Rows)
- {
- try
- {
- var topicSource = TopicImplementation.Load((string)row["topicId"]);
- var topicRated = TopicLoadDocument(topicSource, storage);
-
- if (topicRated == null)
- Process.Trace(string.Format("Can't load topic {0} for rated news {1}", row["topicId"], row["newsId"]), System.Diagnostics.EventLogEntryType.FailureAudit);
- else
- {
- var news = NewsLoadDocument(string.Format("{0}.xml", row["newsId"]), topicSource, storage, DateTime.Now);
- // Ecriture de la news
- if (news == null)
- Process.Trace(string.Format("Can't load rated news {0}.", row["newsId"]), System.Diagnostics.EventLogEntryType.FailureAudit);
- else
- {
- index++;
- string Tvc ="";
-
- NewsWriteBySubject(news, topicRated, topicSource, xmlTopic, storage, NewsMediaFilter.all,index,true, false, -1, ref Tvc);
- }
- if (index > MaxEntries)
- break;
- }
- }
- catch
- {
-
- }
- }
-
-
-
- }
- xmlTopic.WriteEndElement();
- // Xafp/Bag
- }
- xmlTopic.WriteEndElement();
- // Xafp
- // Chargement du document
- string res = xmlTopic.ToString();
- #if DEBUG && DEBUGAROUND
- Process.Trace(string.Format(" calcul et renvoit du document BuildAround query {0} : res {1} ", query , res), System.Diagnostics.EventLogEntryType.Error);
- #endif
- documentTopic.LoadXml(res);
-
- // Mise à jour du nombre de news
- documentTopic.DocumentElement.SelectSingleNode("//Head/NumberOfItems").InnerText = index.ToString();
- }
-
- break;
- }
- }
- }
-
- return documentTopic.OuterXml;
- }
-
-
- private string TopicBuildRated(string query, string topicId, int MaxEntries, StorageServer storage, bool refresh)
- {
- var documentTopic = new XmlDocument();
- var nowDate = DateTime.Now.ToUniversalTime();
- var newsOrderedList = new SortedList<RatingEntryKey, RatingEntry>();
- var topicCountByLang = new Dictionary<string, int>();
-
- // Récupération des sujets
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("TopicBuildRated processor nb ProcessorList {0}", _sqlProcessorList.Count ), System.Diagnostics.EventLogEntryType.Error);
- #endif
- foreach (var processor in _sqlProcessorList)
- {
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("TopicBuildRated processor Processor {0}", processor.ConnectionString ), System.Diagnostics.EventLogEntryType.Error);
- #endif
- using (var sqlRatingReader = new SqlDataAdapter(query, processor.ConnectionString))
- {
- using (var sqlRatingTable = new DataTable())
- {
- try
- {
- sqlRatingReader.Fill(sqlRatingTable);
- }
- catch
- {
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("Can't Fill table {0} ", processor.ConnectionString), System.Diagnostics.EventLogEntryType.Error);
- #endif
- continue;
- }
-
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("Creation document {0} nombre releve {1} ", processor.ConnectionString, sqlRatingTable.Rows.Count), System.Diagnostics.EventLogEntryType.Error);
- #endif
- // Création document final
- using (var xmlTopic = createXmlWriter())
- {
- // Création du document XAfp
- xmlTopic.WriteStartElement("Xafp");
- {
- // Xafp
- xmlTopic.WriteAttributeString("type", "collection");
- xmlTopic.WriteAttributeString("id", topicId);
-
- xmlTopic.WriteStartElement("Head");
- {
- // Xafp/Head
- xmlTopic.WriteElementString("DateCreated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("DateUpdated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("NumberOfItems", string.Empty);
- }
- xmlTopic.WriteEndElement();
- // Xafp/Head
- xmlTopic.WriteStartElement("Bag");
- {
- // Xafp/Bag
- foreach (DataRow row in sqlRatingTable.Rows)
- {
- try
- {
- var topicSource = TopicImplementation.Load((string)row["topicId"]);
- var topicRated = TopicLoadDocument(topicSource, storage);
-
- if (topicRated == null)
- Process.Trace(string.Format("Can't load topic {0} for rated news {1}", row["topicId"], row["newsId"]), System.Diagnostics.EventLogEntryType.FailureAudit);
- else
- {
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("NewsLoadDocument NewsDocument row[newsId] {0} (string)row[topicId] ", row["newsId"], (string)row["topicId"]), System.Diagnostics.EventLogEntryType.Warning);
- #endif
-
- var news = NewsLoadDocument(string.Format("{0}.xml", row["newsId"]), topicSource, storage, DateTime.Now);
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("NewsLoadDocument NewsDocument {0} ", news.Document.OuterXml ), System.Diagnostics.EventLogEntryType.Warning);
- #endif
-
- // Ecriture de la news
- if (news == null)
- Process.Trace(string.Format("Can't load rated news {0}.", row["newsId"]), System.Diagnostics.EventLogEntryType.FailureAudit);
- else
- {
- // if (news.State != News.NewsState.Invalid )
- newsOrderedList.Add(new RatingEntryKey(news.Document.FindDate("/NewsML/NewsItem/NewsManagement/ThisRevisionCreated").Value, row), new RatingEntry((string)row["topicId"], (string)row["newsId"], (string)row["lang"]));
- #if DEBUG && TRACE_REQUEST
- /*else
- {
- Process.Trace(string.Format(" le document {0} est invalid ", row["newsId"]), System.Diagnostics.EventLogEntryType.Information);
- }
- * */
- #endif
- }
-
- }
- }
- catch (Exception ErreuLoad)
- {
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("NewsLoadDocument Error {0} ",ErreuLoad.ToString() ), System.Diagnostics.EventLogEntryType.Information);
- #endif
-
- }
- }
-
- foreach (var ratingEntry in newsOrderedList.Values)
- {
- var topicSource = TopicImplementation.Load(ratingEntry.TopicId);
- var topicRated = TopicLoadDocument(topicSource, storage);
- var news = NewsLoadDocument(string.Format("{0}.xml", ratingEntry.NewsId), topicSource, storage, DateTime.Now);
-
- if (!topicCountByLang.ContainsKey(ratingEntry.Lang))
- topicCountByLang.Add(ratingEntry.Lang, 0);
-
- // Création du sujet
- string Tvc= "";
- if (topicCountByLang[ratingEntry.Lang] <= MaxEntries)
- if (NewsWriteBySubject(news, topicRated, topicSource, xmlTopic, storage, NewsMediaFilter.all, topicCountByLang[ratingEntry.Lang], true, refresh, -1, ref Tvc))
- topicCountByLang[ratingEntry.Lang]++;
- }
- }
- xmlTopic.WriteEndElement();
- // Xafp/Bag
- }
- xmlTopic.WriteEndElement();
- // Xafp
- // Chargement du document
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("Return TopicBuildRated xmlTopic ", xmlTopic.ToString()), System.Diagnostics.EventLogEntryType.Information);
- #endif
- documentTopic.LoadXml(xmlTopic.ToString());
-
- // Mise à jour du nombre de news
- documentTopic.DocumentElement.SelectSingleNode("//Head/NumberOfItems").InnerText = topicCountByLang.Values.Sum().ToString();
- }
-
- break;
- }
- }
- }
- #if DEBUG && TRACE_REQUEST
- Process.Trace(string.Format("Return TopicBuildRated ", documentTopic.OuterXml), System.Diagnostics.EventLogEntryType.Error);
- #endif
-
- return documentTopic.OuterXml;
- }
- /// <summary>
- /// magazin ou special diaporama (special Ipad)
- /// </summary>
- /// <param name="topicDocument"></param>
- /// <param name="topic"></param>
- /// <param name="storage"></param>
- /// <param name="maxNews"></param>
- /// <param name="refresh"></param>
- /// <returns></returns>
- private String TopicBuildMagazin(NewsML topicDocument, TopicImplementation topic, StorageServer storage, int maxNews, bool refresh, string idTopic, string catchLine)
- {
- String result = null;
-
- // il faut extraire la premiere image...
-
- #if DEBUG && TRACE_TIME_TOPIC
- System.Diagnostics.Stopwatch timer =null;
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- timer = new System.Diagnostics.Stopwatch();
- timer.Start();
- }
- #endif
- using (var xmlTopic = createXmlWriter())
- {
- var numberOfItems = 0;
- var numberOfNews = 0;
-
- DateTime ThisRevisionCreated =DateTime.UtcNow;
- String sDateTimeRev;
-
- sDateTimeRev = topicDocument.NewsItem.NewsManagement.ThisRevisionCreated;
-
- if (string.IsNullOrEmpty(topic.Announces) == false)
- {
- if (System.IO.File.Exists(topic.Announces))
- {
- ThisRevisionCreated = DateTime.UtcNow.AddMinutes(1);
-
- sDateTimeRev = ThisRevisionCreated.ToString().FromDateToXmlUTCString();
-
- }
- }
-
- // Création du document XAfp
- xmlTopic.WriteStartElement("Xafp");
- {
- // Xafp
- xmlTopic.WriteAttributeString("type", "collection");
- xmlTopic.WriteAttributeString("id", (string.IsNullOrEmpty(idTopic) ? topic.Id : idTopic));
- xmlTopic.WriteAttributeString("newsItemId", topicDocument.NewsItem.Identification.NewsIdentifier.NewsItemId);
- xmlTopic.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", topic.Lang.Split('_')[0]);
-
- xmlTopic.WriteStartElement("Head");
- {
- // Xafp/Head
- //xmlTopic.WriteElementString("Name", "__TEMPORAIRE__");
- xmlTopic.WriteElementString("Name", topicDocument.NewsItem.Identification.NameLabel);
- xmlTopic.WriteElementString("DateCreated", topicDocument.NewsItem.NewsManagement.FirstCreated);
- xmlTopic.WriteElementString("DateUpdated", sDateTimeRev);
- xmlTopic.WriteElementString("Source", topicDocument.NewsItem.Identification.NewsIdentifier.ProviderId);
- xmlTopic.WriteElementString("NumberOfItems", "__NumberOfItems__");
- // xmlTopic.WriteElementString("CatchLine", catchLine );
- }
- xmlTopic.WriteEndElement();
- // Xafp/Head
-
-
- xmlTopic.WriteStartElement("Bag");
- {
- Boolean removeIt = false;
- NewsItemComponent newsItemComponent = topicDocument.NewsItem.NewsComponent;
-
-
- if (string.IsNullOrEmpty(topic.Announces) == false)
- {
-
- // TO DO rajouter le document induit s'il existe...
- NewsComponent newsComponent = newsItemComponent.NewsComponent[numberOfItems];
- var news = AnnounceLoadDocument(topic.Announces, topic, storage, ThisRevisionCreated );
- string tCatchLine ="";
- if (NewsWriteBySubject(news, topicDocument, topic, xmlTopic, storage, NewsMediaFilter.all, numberOfNews++, false, refresh, -1, ref tCatchLine) == false)
- {
- topicDocument.NewsItem.NewsComponent.NewsComponent.Remove(newsComponent);
- }
- //numberOfItems++;
-
-
- }
- // Xafp/Bag
- // Traitement des news
-
- while (numberOfItems < topicDocument.NewsItem.NewsComponent.NewsComponent.Count && numberOfItems < maxNews)
- {
- NewsComponent newsComponent = newsItemComponent.NewsComponent[numberOfItems];
- String newsItemRef = ((NewsItemRef)newsComponent.Items[0]).NewsItem;
-
-
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("********"), System.Diagnostics.EventLogEntryType.Information );
- Process.Trace(string.Format("Start Load Component for topicId '{0}' newsItemRef {2} processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds, newsItemRef), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- var news = NewsLoadDocument(newsComponent, topic, storage, topicDocument.NewsItem.NewsManagement.ThisRevisionCreated.FromXmlUTCStringToDate());
-
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("End load Component for topicId '{0}' newsItemRef{2} processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds, newsItemRef), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- // Suppression du document newsml si invalide
- string tC2 ="";
- if (news.State == News.NewsState.Invalid)
- {
- removeIt = true;
- // Process.Trace("RemoveTopic", String.Format("Invalid state:{0}-{1}", topic.Id, newsItemRef), System.Diagnostics.EventLogEntryType.Warning);
- }
- else if (NewsWriteBySubject(news, topicDocument, topic, xmlTopic, storage, NewsMediaFilter.all, numberOfNews++, false, refresh, -1, ref tC2) == false)
- {
- removeIt = true;
- Process.Trace("RemoveTopic", String.Format("Can't save:{0}-{1}", topic.Id, newsItemRef), System.Diagnostics.EventLogEntryType.Warning);
- }
- else
- {
- numberOfItems++;
- removeIt = false;
- }
-
-
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("End NewsWriteBySubject for topicId '{0}' newsItemRef {2} processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds, newsItemRef), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
-
- if (removeIt)
- {
- topicDocument.NewsItem.NewsComponent.NewsComponent.Remove(newsComponent);
- }
- }
- }
- xmlTopic.WriteEndElement();
- // Xafp/Bag
- }
- xmlTopic.WriteElementString("CatchLine", catchLine);
- xmlTopic.WriteEndElement();
- // Xafp
- // Trace pour absence de document
- if (numberOfItems == 0)
- {
- Process.Trace(string.Format("Empty topic error for topic id {0}", topic.Id), System.Diagnostics.EventLogEntryType.Information);
- this.Set(string.Format("Empty topic error for topic id {0}", topic.Id), MessageSection.Alimentation.ToString(), System.Diagnostics.EventLogEntryType.Information);
- }
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- timer.Stop();
- Process.Trace(string.Format("End TopicBuildStandard for topicId '{0}' processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- // Chargement du document & Mise à jour du nombre de news
- if (string.IsNullOrEmpty(topic.Announces) == false)
- {
- numberOfItems++;
- }
- result = xmlTopic.ToString().Replace("__NumberOfItems__", numberOfItems.ToString());
- //result = result.Replace("__TEMPORAIRE__", );
- }
-
- return result;
- }
-
- //private XmlDocument TopicBuildStandard(NewsML topicDocument, TopicImplementation topic, StorageServer storage, int maxNews, bool refresh)
- private String TopicBuildStandard(NewsML topicDocument, TopicImplementation topic, StorageServer storage, int maxNews, bool refresh)
- {
- String result = null;
-
- #if DEBUG && TRACE_TIME_TOPIC
- System.Diagnostics.Stopwatch timer =null;
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- timer = new System.Diagnostics.Stopwatch();
- timer.Start();
- }
- #endif
- string catchLine="";
- string otherC = "";
- using (var xmlTopic = createXmlWriter())
- {
- var numberOfItems = 0;
- var numberOfNews = 0;
- DateTime ThisRevisionCreated = DateTime.UtcNow.AddMinutes(1);
-
- // Création du document XAfp
- xmlTopic.WriteStartElement("Xafp");
- {
- // Xafp
- xmlTopic.WriteAttributeString("type", "collection");
- xmlTopic.WriteAttributeString("id", topic.Id);
- xmlTopic.WriteAttributeString("newsItemId", topicDocument.NewsItem.Identification.NewsIdentifier.NewsItemId);
- xmlTopic.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", topic.Lang.Split('_')[0]);
-
- xmlTopic.WriteStartElement("Head");
- {
- // Xafp/Head
- xmlTopic.WriteElementString("Name", topicDocument.NewsItem.Identification.NameLabel);
- xmlTopic.WriteElementString("DateCreated", topicDocument.NewsItem.NewsManagement.FirstCreated);
- xmlTopic.WriteElementString("DateUpdated", topicDocument.NewsItem.NewsManagement.ThisRevisionCreated);
- xmlTopic.WriteElementString("Source", topicDocument.NewsItem.Identification.NewsIdentifier.ProviderId);
- xmlTopic.WriteElementString("NumberOfItems", "__NumberOfItems__");
-
-
- }
- xmlTopic.WriteEndElement();
- // Xafp/Head
-
-
- xmlTopic.WriteStartElement("Bag");
- {
- Boolean removeIt = false;
- NewsItemComponent newsItemComponent = topicDocument.NewsItem.NewsComponent;
-
-
- if (string.IsNullOrEmpty(topic.Announces) == false)
- {
- NewsComponent newsComponent = newsItemComponent.NewsComponent[numberOfItems];
- var news = AnnounceLoadDocument(topic.Announces, topic, storage, ThisRevisionCreated);
-
- string tA ="";
- if (NewsWriteBySubject(news, topicDocument, topic, xmlTopic, storage, NewsMediaFilter.all, numberOfNews++, false, refresh, -1, ref tA) == false)
- {
- topicDocument.NewsItem.NewsComponent.NewsComponent.Remove(newsComponent);
- }
- }
- // Xafp/Bag
- // Traitement des news
-
- while (numberOfItems < topicDocument.NewsItem.NewsComponent.NewsComponent.Count && numberOfItems < maxNews)
- {
- NewsComponent newsComponent = newsItemComponent.NewsComponent[numberOfItems];
- try
- {
-
- String newsItemRef = ((NewsItemRef)newsComponent.Items[0]).NewsItem;
-
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("********"), System.Diagnostics.EventLogEntryType.Information );
- Process.Trace(string.Format("Start Load Component for topicId '{0}' newsItemRef {2} processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds, newsItemRef), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- News news = NewsLoadDocument(newsComponent, topic, storage, topicDocument.NewsItem.NewsManagement.ThisRevisionCreated.FromXmlUTCStringToDate());
-
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("End load Component for topicId '{0}' newsItemRef{2} processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds, newsItemRef), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- // Suppression du document newsml si invalide
- string tCatchLine="";
- string tOtherC ="";
- if (news.State == News.NewsState.Invalid)
- {
- removeIt = true;
- // Process.Trace("RemoveTopic", String.Format("Invalid state:{0}-{1}", topic.Id, newsItemRef), System.Diagnostics.EventLogEntryType.Warning);
- }
- else if (NewsWriteBySubject(news, topicDocument, topic, xmlTopic, storage, NewsMediaFilter.all, numberOfNews++, false, refresh, -1, ref tCatchLine ) == false)
- {
- removeIt = true;
- Process.Trace("RemoveTopic", String.Format("Can't save:{0}-{1}", topic.Id, newsItemRef), System.Diagnostics.EventLogEntryType.Warning);
- }
- else
- {
- numberOfItems++;
- removeIt = false;
- }
- if (numberOfItems == 1)
- {
- catchLine = tCatchLine;
- otherC = tOtherC;
- }
-
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- Process.Trace(string.Format("End NewsWriteBySubject for topicId '{0}' newsItemRef {2} processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds, newsItemRef), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- }
- catch (Exception e)
- {
- Process.Trace(string.Format("Error topicId : {0} NameLabel : {1} Message : {2}", topic.Id, topicDocument.NewsItem.Identification.NameLabel, e.Message), System.Diagnostics.EventLogEntryType.Warning);
- this.Set("Topic process error", MessageSection.Processing.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- removeIt = true;
- }
-
- if (removeIt)
- {
- try
- {
- topicDocument.NewsItem.NewsComponent.NewsComponent.Remove(newsComponent);
- }
- catch
- { }
- }
- }
- }
-
- xmlTopic.WriteEndElement();
- // Xafp/Bag
- if (topic.MustShowCatchLine())
- {
- xmlTopic.WriteElementString("CatchLine", catchLine);
- }
- }
-
- xmlTopic.WriteEndElement();
- // Xafp
- // Trace pour absence de document
- if (numberOfItems == 0)
- {
- Process.Trace(string.Format("Empty topic error for topic id {0}", topic.Id), System.Diagnostics.EventLogEntryType.Information);
- this.Set(string.Format("Empty topic error for topic id {0}", topic.Id), MessageSection.Alimentation.ToString(), System.Diagnostics.EventLogEntryType.Information);
- }
- #if DEBUG && TRACE_TIME_TOPIC
- if (_levelTrace.TraceTimeMakeTopic == true)
- {
- timer.Stop();
- Process.Trace(string.Format("End TopicBuildStandard for topicId '{0}' processed after {1} milliseconds.", topic.Id, timer.ElapsedMilliseconds), System.Diagnostics.EventLogEntryType.SuccessAudit);
- }
- #endif
- // Chargement du document & Mise à jour du nombre de news
- if (string.IsNullOrEmpty(topic.Announces) == false)
- {
- numberOfItems++;
- }
- result = xmlTopic.ToString().Replace("__NumberOfItems__", numberOfItems.ToString());
- }
-
- return result;
- }
-
- private XmlDocument TopicBuildVideorama(TopicImplementation topic, StorageServer storage, bool refresh)
- {
-
- var documentTopic = new XmlDocument();
- string catchLine ="";
-
-
-
- using (var xmlTopic = createXmlWriter())
- {
- var nowDate = DateTime.Now.ToUniversalTime();
- var newsList = new List<SortedList<News, TopicImplementation>>();
- var numberOfItems = 0;
-
- // Création du document XAfp
- xmlTopic.WriteStartElement("Xafp");
- {
- // Xafp
- xmlTopic.WriteAttributeString("type", "collection");
- xmlTopic.WriteAttributeString("id", topic.Id);
- xmlTopic.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", topic.Lang.Split('_')[0]);
-
- xmlTopic.WriteStartElement("Head");
- {
- // Xafp/Head
- xmlTopic.WriteElementString("Name", topic["name"]);
- xmlTopic.WriteElementString("DateCreated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("DateUpdated", nowDate.ToXmlElementString());
- xmlTopic.WriteElementString("Source", topic["source"]);
- xmlTopic.WriteElementString("NumberOfItems", string.Empty);
- }
- xmlTopic.WriteEndElement();
- // Xafp/Head
- xmlTopic.WriteStartElement("Bag");
- {
- // Xafp/Bag
- // Traitement de tous les topics du topic parent
- foreach (var referencedTopic in topic.Childs())
- // Traitement des topic standard
- if (referencedTopic.Type == TopicImplementation.TopicType.standard)
- {
- var topicDocument = TopicLoadDocument(referencedTopic, storage);
-
- // Chargement des news
- if (topicDocument != null)
- {
- // Nouveau sujet
- newsList.Add(new SortedList<News, TopicImplementation>());
-
- // Traitement des news
- foreach (var newsComponent in topicDocument.NewsItem.NewsComponent.NewsComponent)
- {
- var news = NewsLoadDocument(newsComponent, referencedTopic, storage, topicDocument.NewsItem.NewsManagement.ThisRevisionCreated.FromXmlUTCStringToDate());
- var exists = false;
-
- // Selection et tri de la news en mode video only si contient au moins une vidéo
- if (news.State != News.NewsState.Invalid && news.Document.SelectSingleNode("/NewsML/NewsItem/NewsComponent/NewsComponent/ContentItem/DataContent/p/a[@class='videoSet']") != null)
- {
- foreach (var newsInnerList in newsList)
- exists |= newsInnerList.ContainsKey(news);
- if (!exists)
- newsList[newsList.Count - 1].Add(news, referencedTopic);
- }
- }
- }
- }
-
- // Ecriture des news par ordre chronologique
- foreach (var newsInnerList in newsList)
- for (var i = 0; i < newsInnerList.Count; i++)
- {
- var news = newsInnerList.ElementAt(i).Key;
- var topicImplementation = newsInnerList.ElementAt(i).Value;
- var topicDocument = TopicLoadDocument(topicImplementation, storage);
-
- // Ecriture de la news
- string tcatchLine ="";
-
- if (topicDocument != null && NewsWriteBySubject(news, topicDocument, topicImplementation, xmlTopic, storage, NewsMediaFilter.videoOnly, i, false, refresh, -1, ref tcatchLine ))
- numberOfItems++;
- if (numberOfItems == 1)
- {
- catchLine = tcatchLine;
- }
- }
- }
-
- xmlTopic.WriteEndElement();
- // Xafp/Bag
- if (topic.MustShowCatchLine())
- {
- xmlTopic.WriteElementString("CatchLine", catchLine);
- }
- }
-
- xmlTopic.WriteEndElement();
- // Xafp
- // Trace pour absence de document
- if (numberOfItems == 0)
- {
- Process.Trace(string.Format("Empty topic error for topic id {0}", topic.Id), System.Diagnostics.EventLogEntryType.Warning);
- this.Set("Empty topic error", MessageSection.Alimentation.ToString(), System.Diagnostics.EventLogEntryType.Warning);
- }
-
- // Chargement du document
- documentTopic.LoadXml(xmlTopic.ToString());
-
- // Mise à jour du nombre de news
- documentTopic.DocumentElement.SelectSingleNode("//Head/NumberOfItems").InnerText = numberOfItems.ToString();
- }
-
- return documentTopic;
- }
-
- private NewsML TopicLoadDocument(TopicImplementation topic, StorageServer storage)
- {
- NewsML indexNew = null;
- DateTime IndexCompiledDateTime = DateTime.MinValue;
- String topicFileNameAll = String.Format("{0}.all", topic.Id);
- String topicFileNameRef = String.Format("{0}.ref", topic.Id);
-
- // Création du fichier topic de référence
- foreach (var file in topic.Files)
- {
- if (StorageServer.FileExists(file))
- {
- // Présence d'un fichier index ?
- using (var topicFile = StorageServer.FileOpen(file))
- {
- // Ouverture du fichier en lecture avec attente de lock
- if (indexNew == null)
- {
- indexNew = NewsML.Load(topicFile);
- }
- else
- {
- var indexConcat = NewsML.Load(topicFile);
-
- // Consolidation avec index supplémentaire
- indexNew.NewsItem.NewsComponent.NewsComponent = new List<NewsComponent>(indexNew.NewsItem.NewsComponent.NewsComponent.Union(indexConcat.NewsItem.NewsComponent.NewsComponent, new NewsComponentComparer()));
- }
-
- if (StorageServer.GetLastModifiedDate(file).CompareTo(IndexCompiledDateTime) > 0)
- IndexCompiledDateTime = StorageServer.GetLastModifiedDate(file);
- }
- }
- }
-
- // Présence d'un fichier index ?
- if (indexNew != null)
- {
- // Sauvegarde du document index concaténés
- bool supportSeek;
- var indexNewStream = new MemoryStream();
- // En cours codage du daily
- indexNew.Save(indexNewStream);
-
- StorageFileInfo storedTopicInfo = null;
- if (topic.IsDaily == false)
- storedTopicInfo = storage.Info(Constants._storageTopicFormatName, Key, topicFileNameRef);
- // si on est en daily on ne regarde pas ce qui était sauvegardé
-
- // Nouveau dépot ?
- // Process.Trace(string.Format("## id topic {0} CompiledDateTime {1} storedTopicInfo : path {3} Date Time {2} ", topic.Id, IndexCompiledDateTime, storedTopicInfo.LastModified , storedTopicInfo.Path ), System.Diagnostics.EventLogEntryType.Information);
- //Ex Checksum
-
- if (storedTopicInfo == null || (IndexCompiledDateTime.CompareTo(storedTopicInfo.LastModified) >= 0))
- {
- NewsML indexOld = null;
-
- // Chargement de l'état précedent du topic
- if (topic.IsDaily == false)
- if (storage.Exists(Constants._storageTopicFormatName, Key, topicFileNameAll))
- using (var indexOldStream = storage.Restore(Constants._storageTopicFormatName, Key, topicFileNameAll, true))
- indexOld = NewsML.Load(indexOldStream);
-
- // Consolidation si ancien index existe
- if (indexOld != null)
- indexNew.NewsItem.NewsComponent.NewsComponent = new List<NewsComponent>(
- indexNew.NewsItem.NewsComponent.NewsComponent.Union(indexOld.NewsItem.NewsComponent.NewsComponent, new NewsComponentComparer()).Take(topic.MaxEntries)
- );
-
- // Sauvegarde du document de référence
- storage.Store(indexNewStream, Constants._storageTopicFormatName, Key, topicFileNameRef, out supportSeek);
-
- // Sauvegarde du document mergé
- using (var storageFile = storage.Store(Constants._storageTopicFormatName, Key, topicFileNameAll))
- indexNew.Save(storageFile);
- }
-
- // Restauration depuis le stockage
- if (topic.IsDaily == false)
- if (storage.Exists(Constants._storageTopicFormatName, Key, topicFileNameAll))
- using (var indexOldStream = storage.Restore(Constants._storageTopicFormatName, Key, topicFileNameAll, true))
- return NewsML.Load(indexOldStream);
-
- return indexNew;
- }
-
- // Restauration depuis le stockage
- if (storage.Exists(Constants._storageTopicFormatName, Key, topicFileNameAll))
- using (var indexOldStream = storage.Restore(Constants._storageTopicFormatName, Key, topicFileNameAll, true))
- return NewsML.Load(indexOldStream);
-
- return null;
- }
-
- private NewsML TopicLoadTableAndDoneTopics(TopicImplementation topic, StorageServer storage)
- {
- NewsML indexNew = null;
- DateTime IndexCompiledDateTime = DateTime.MinValue;
- String topicFileNameAll = String.Format("{0}.all", topic.Id);
- String topicFileNameRef = String.Format("{0}.ref", topic.Id);
- string CatchLine = "";
- string iop = "";
-
- #if DEBUG && DEBUG_IPAD
- Process.Trace(string.Format(" TopicLoadTableAndDoneTopics with topicID : {0}" , topic.Id) , System.Diagnostics.EventLogEntryType.Information);
- #endif
- // Création du fichier topic de référence
- foreach (var file in topic.Files)
- {
- if (StorageServer.FileExists(file))
- {
- // Présence d'un fichier index ?
- using (var topicFile = StorageServer.FileOpen(file))
- {
- // Ouverture du fichier en lecture avec attente de lock
- if (indexNew == null)
- {
- indexNew = NewsML.Load(topicFile);
- }
- else
- {
- var indexConcat = NewsML.Load(topicFile);
-
- // Consolidation avec index supplémentaire
- indexNew.NewsItem.NewsComponent.NewsComponent = new List<NewsComponent>(indexNew.NewsItem.NewsComponent.NewsComponent.Union(indexConcat.NewsItem.NewsComponent.NewsComponent, new NewsComponentComparer()));
- }
- //BRUTDECOFFRAGE: Brut de coffrage si un jour on en a deux il faudra collectionner...
- iop = System.IO.Path.GetDirectoryName(file);
-
- if (StorageServer.GetLastModifiedDate(file).CompareTo(IndexCompiledDateTime) > 0)
- IndexCompiledDateTime = StorageServer.GetLastModifiedDate(file);
- }
- }
- }
-
- // Présence d'un fichier index ?
- if (indexNew != null)
- {
- // on a le news ML
- #if DEBUG && DEBUG_IPAD
- #if DEBUGMACHINE
- System.Diagnostics.Debugger.Break();
- #endif
-
- Process.Trace(string.Format(" fichier Index trouvé "), System.Diagnostics.EventLogEntryType.Information);
- #endif
-
-
-
- foreach (NewsComponent topicpath in indexNew.NewsItem.NewsComponent.NewsComponent)
- {
- string topicID = topicpath.NewsLines.HeadLine;// ca ne va pas poser un souci?
- try
- {
-
- //Determination du catchLine pour chaque subTopic
- string FileName = ((NewsItemRef)(topicpath.Items[0])).NewsItem ;
- CatchLine = "";
- if (string.IsNullOrEmpty(iop) == false)
- {
- FileStream Fs = new FileStream(System.IO.Path.Combine(iop, FileName), FileMode.Open);
- NewsML CatchLineUp = NewsML.Load(Fs);
- //CatchLine = CatchLineUp.NewsItem.NewsComponent.NewsLines.NewsLine[""]
- // il est parfois dans MobileShortTitle...
- foreach (NewsLine Nl in CatchLineUp.NewsItem.NewsComponent.NewsLines.NewsLine)
- {
- if (string.IsNullOrEmpty(Nl.NewsLineText) == false)
- {
- CatchLine = Nl.NewsLineText;
- break;
- }
- }
- }
-
- //string.Format("{0}__{1}", _ProductServiceName, _topic.GetAttribute("id"));
- topicID = string.Format("{0}__{1}", topic.ProductServiceName, topicID);
-
- TopicImplementation curtopic;
- curtopic = TopicImplementation.Load(topicID);
- NewsML indexd = TopicLoadDocument(curtopic, storage);
- String topicContent = TopicBuildMagazin(indexd, curtopic, storage, topic.MaxEntries, true, topicID, CatchLine);
-
- if (String.IsNullOrEmpty(topicContent) == false)
- {
- Stream output = storage.Store(Constants._storageTopicFormatName, Key, string.Format("{0}.xml", topicID));
- if (output != null)
- {
- TextWriter wr = new StreamWriter(output, Encoding.UTF8);
- wr.Write(topicContent);
- wr.Flush();
- output.Close();
- }
- }
- }
- catch (Exception ErrorTopic)
- {
- Process.Trace(string.Format(" Error with topic {0} {1}", topicID, ErrorTopic.Message), System.Diagnostics.EventLogEntryType.Error);
- }
-
- }
- // on parcours tous les items et on fait un MakeTopic avec le headLine
-
- }
-
- return indexNew;
-
- }
-
-
- }
- }