/// <summary> /// Selects the archive content not in index to list. /// </summary> /// <returns>The archive content not in index to list.</returns> /// <param name="contentLang">Content lang.</param> /// <param name="limit">Limit.</param> public IList<ArchiveContent> SelectArchiveContentNotInIndexToList(int contentLang, long limit) { try { var sbQuery = new StringBuilder(); sbQuery.Append("SELECT * FROM archivecontent "); sbQuery.Append("WHERE ContentLang = @ContentLang "); sbQuery.Append("AND Id NOT IN "); sbQuery.Append("(SELECT ContentId FROM archiveindex "); sbQuery.Append("WHERE archiveindex.ContentId = archivecontent.Id) "); sbQuery.Append("LIMIT @Limit "); string query = sbQuery.ToString(); var contentList = new List<ArchiveContent>(); if (this.Connection.State != ConnectionState.Open) { this.OpenConnection(); } MySqlCommand cmd = new MySqlCommand(query, this.Connection); cmd.Parameters.AddWithValue("@ContentLang", contentLang); cmd.Parameters.AddWithValue("@Limit", limit); MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { var content = new ArchiveContent(); content.GetArchiveContent(dataReader); contentList.Add(content); } } dataReader.Close(); this.CloseConnection(); return contentList; } catch (Exception) { throw; } }
/// <summary> /// Updates the lucene document. /// </summary> /// <returns>The lucene document.</returns> /// <param name="archiveContent">Archive content.</param> private Document UpdateLuceneDocument(ArchiveContent archiveContent) { var doc = new Lucene.Net.Documents.Document(); try { doc.Add(new Field("content_id", Convert.ToString(archiveContent.Id), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("content_title", archiveContent.ContentTitle, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("content_text", archiveContent.ContentText, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("source_name", archiveContent.ArchiveSource.SourceName, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("source_link", archiveContent.ArchiveSource.SourceLink, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("source_id", Convert.ToString(archiveContent.ContentSourceId), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("language_id", Convert.ToString(archiveContent.ContentLangId), Field.Store.YES, Field.Index.ANALYZED)); } catch (Exception ex) { throw ex; } return doc; }
/// <summary> /// Gets the content of the archive. /// </summary> /// <returns>The archive content.</returns> /// <param name="paramTitle">Parameter title.</param> /// <param name="paramDesc">Parameter desc.</param> /// <param name="paramLink">Parameter link.</param> /// <param name="paramPubDate">Parameter pub date.</param> /// <param name="paramSourceId">Parameter source identifier.</param> public ArchiveContent GetArchiveContent(string paramTitle, string paramDesc, string paramLink, string paramPubDate, string paramSourceId) { var content = new ArchiveContent(); content.ContentSourceId = Convert.ToInt64(paramSourceId); content.ArchiveSource = mad.SelectArchiveSourceById(content.ContentSourceId); if (content.ArchiveSource.SourceEncoding.ToLower().Contains("utf-8")) { content.ContentTitle = paramTitle; content.ContentText = paramDesc; content.ContentLink = paramLink; } else if (content.ArchiveSource.SourceEncoding.ToLower().Contains("8859-1")) { content.ContentTitle = this.DecodeFromUtf8ToLatin1(paramTitle); content.ContentText = this.DecodeFromUtf8ToLatin1(paramDesc); content.ContentLink = paramLink; } try { content.ContentOriginDateTime = ConverterHelper.NormalizeDate(paramPubDate); } catch (Exception ex) { if (log.IsDebugEnabled) { content.ContentOriginDateTime = DateTime.Now; log.InfoFormat("Error while Normalize Date in SourceId {0}", paramSourceId); log.ErrorFormat("{0}", ex); } } content.ContentCreationDateTime = DateTime.Now; content.ContentModifiedTimeStamp = DateTime.Now; content.ContentLangId = Convert.ToInt32(content.ArchiveSource.SourceLang); content.ContentType = 1; content.ContentVersion = 1; content.IsArchive = false; content.IsDelete = false; return content; }
/// <summary> /// Checks the is article new. /// </summary> /// <returns><c>true</c>, if is article new was checked, <c>false</c> otherwise.</returns> /// <param name="archiveContent">Archive content.</param> public bool CheckIsArticleNew(ArchiveContent archiveContent) { bool isNew = false; try { isNew = mad.ArchiveContentExist(archiveContent.ContentSourceId, archiveContent.ContentLink); } catch (Exception) { throw; } return isNew; }
/// <summary> /// Inserts the content of the archive. /// </summary> /// <returns><c>true</c>, if archive content was inserted, <c>false</c> otherwise.</returns> /// <param name="paramContent">Parameter content.</param> public bool InsertArchiveContent(ArchiveContent paramContent) { try { if (this.Connection.State != ConnectionState.Open) { this.OpenConnection(); } StringBuilder sbQuery = new StringBuilder(); sbQuery.Append("INSERT INTO archivecontent "); sbQuery.Append("( ContentCreationDateTime, "); sbQuery.Append("ContentLang, "); sbQuery.Append("ContentLink, "); sbQuery.Append("ContentOriginDateTime, "); sbQuery.Append("ContentSource, "); sbQuery.Append("ContentText, "); sbQuery.Append("ContentTitle, "); sbQuery.Append("ContentType, "); sbQuery.Append("ContentVersion )"); sbQuery.Append("VALUES ( @ContentCreationDateTime, "); sbQuery.Append("@ContentLang, "); sbQuery.Append("@ContentLink, "); sbQuery.Append("@ContentOriginDateTime, "); sbQuery.Append("@ContentSource, "); sbQuery.Append("@ContentText, "); sbQuery.Append("@ContentTitle, "); sbQuery.Append("@ContentType, "); sbQuery.Append("@ContentVersion )"); string query = sbQuery.ToString(); using (var insCommand = new MySqlCommand(query, this.Connection)) { insCommand.Parameters.AddWithValue("@ContentCreationDateTime", paramContent.ContentCreationDateTime); insCommand.Parameters.AddWithValue("@ContentLang", paramContent.ContentLangId); insCommand.Parameters.AddWithValue("@ContentLink", paramContent.ContentLink); insCommand.Parameters.AddWithValue("@ContentOriginDateTime", paramContent.ContentOriginDateTime); insCommand.Parameters.AddWithValue("@ContentSource", paramContent.ContentSourceId); insCommand.Parameters.AddWithValue("@ContentType", paramContent.ContentType); insCommand.Parameters.AddWithValue("@ContentVersion", paramContent.ContentVersion); var endodedText = this.HtmlEncode(paramContent.ContentText); insCommand.Parameters.AddWithValue("@ContentText", endodedText); var endodedTitle = this.HtmlEncode(paramContent.ContentTitle); insCommand.Parameters.AddWithValue("@ContentTitle", endodedTitle); char isArchive = '0'; if (!paramContent.IsArchive) { insCommand.Parameters.AddWithValue("@IsArchive", isArchive); } else { isArchive = '1'; insCommand.Parameters.AddWithValue("@IsArchive", isArchive); } char isDelete = '0'; if (!paramContent.IsArchive) { insCommand.Parameters.AddWithValue("@IsDelete", isDelete); } else { isDelete = '1'; insCommand.Parameters.AddWithValue("@IsDelete", isDelete); } insCommand.ExecuteNonQuery(); } this.CloseConnection(); return true; } catch (Exception) { throw; } }
/// <summary> /// Selects the archive content by language to list. /// </summary> /// <returns>The archive content by language to list.</returns> /// <param name="contentLang">Content lang.</param> /// <param name="contentCountMin">Content count minimum.</param> /// <param name="contentCountMax">Content count max.</param> public IList<ArchiveContent> SelectArchiveContentByLanguageToList(int contentLang, long contentCountMin, long contentCountMax) { try { var sbQuery = new StringBuilder(); sbQuery.Append("SELECT * FROM archivecontent "); sbQuery.Append("WHERE ContentLang = @ContentLang "); sbQuery.Append("AND Id < @ContentCountMax "); sbQuery.Append("AND Id > @ContentCountMin "); sbQuery.Append("ORDER BY Id DESC"); string query = sbQuery.ToString(); var contentList = new List<ArchiveContent>(); if (this.Connection.State != ConnectionState.Open) { this.OpenConnection(); } MySqlCommand cmd = new MySqlCommand(query, this.Connection); cmd.Parameters.AddWithValue("@ContentLang", contentLang); cmd.Parameters.AddWithValue("@ContentCountMax", contentCountMax); cmd.Parameters.AddWithValue("@ContentCountMin", contentCountMin); MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { var content = new ArchiveContent(); content.GetArchiveContent(dataReader); contentList.Add(content); } } dataReader.Close(); this.CloseConnection(); return contentList; } catch (Exception) { throw; } }