Example #1
0
    internal long?AddRasadNews(RasadNews rasadNews, string folder, int line)
    {
        try
        {
            long rasadNewsSourceId;
            long rasadNewsTypeId;
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            if (rasadNews.SourceId == null && defaultNewsSource == null)
            {
                logger.LogInformation("XML file and defual News SOURCE have not value!");
                return(null);
            }
            else
            {
                if (rasadNews.SourceId != null)
                {
                    rasadNewsSourceId = GetSourceIdWithCode(rasadNews.SourceId, conn);
                    if (rasadNewsSourceId == 0 && defaultNewsSource == null)
                    {
                        logger.LogInformation("XML file and defual News SOURCE have not value!");
                        return(null);
                    }
                }
            }

            if (rasadNews.CategoryType == null && defaultNewsType == null)
            {
                logger.LogInformation("XML file and defual News TYPE have not value!");
                return(null);
            }
            else
            {
                if (rasadNews.CategoryType != null)
                {
                    rasadNewsTypeId = GetTypeIdWithCode(rasadNews.CategoryType, conn);
                    if (rasadNewsTypeId == 0 && defaultNewsType == null)
                    {
                        logger.LogInformation("XML file and defual News TYPE have not value!");
                        return(null);
                    }
                }
            }

            long forignSourceId = InsertForignSource(rasadNews, folder, line);
            return(InsertNews(rasadNews, forignSourceId));
        }
        catch (Exception ex)
        {
            logger.LogError("Error on insert news, ex:" + ex.Message);
            return(null);
        }
        finally
        {
            conn.Close();
        }
    }
Example #2
0
    private long InsertNews(RasadNews rasadNews, long forignSourceId)
    {
        var strInsertNewsCommand = @"INSERT INTO news.news(
            news_id, bst_suggestion_register, consideration, realtime, news_content, 
            declarationdate_time, news_lead, news_level_type, news_number, 
            occurrence_time, register_date, register_news_type, title, approvedorganizationalposition, 
            bst_accuracy_degree_id, bst_confidential_id, bst_refer_level_id, 
            forignsource_forign_source_id, newspic_news_pic_id, organizationalposition_id, 
            news_sources_str, news_types_str, bst_news_type_id)
    VALUES (nextval('log_seq'), null, null, false, '" + rasadNews.Content + @"', 
            '" + rasadNews.PubTime + @"', '" + rasadNews.Description + @"', null, '" + GetStationNumber() + "-" + DateTime.Now.ToString("yyyyMMddHHss") + @"', 
            '" + rasadNews.PubTime + @"', '" + rasadNews.PubTime + @"', 10, '" + rasadNews.Title + @"', null, 
            950, 218, 1, 
            '" + forignSourceId + @"', null, null, 
            null, null, null);";
        var cmd = new Npgsql.NpgsqlCommand(strInsertNewsCommand, conn);

        return((long)cmd.ExecuteScalar());
    }
Example #3
0
    private long InsertForignSource(RasadNews rasadNews, string folder, long line)
    {
        var strInsertForignCommand = @"INSERT INTO news.forign_source(
            forign_source_id, author, category_type, content, description, 
            fetch_time, folder, id, insert_on, line, mesbahdocid, page_url, 
            pub_time, source_id, title, news_id)
    VALUES (nextval('log_seq'), @autor, @CategoryType, @Content, @Description, 
            '" + new DateTime(long.Parse(rasadNews.FetchTime)) + "', '" + folder + "', " + rasadNews.Id + @", '" + DateTime.Now + "', " + line + ", " + rasadNews.mesbahdocid + ", '" + rasadNews.PageUrl + @"', 
            '" + new DateTime(long.Parse(rasadNews.PubTime)) + @"', '" + rasadNews.SourceId + "', @Title, null) RETURNING forign_source_id;";

        var cmd = new Npgsql.NpgsqlCommand(strInsertForignCommand, conn);

        cmd.Parameters.AddWithValue("autor", rasadNews.Author);
        cmd.Parameters.AddWithValue("CategoryType", rasadNews.CategoryType);
        cmd.Parameters.AddWithValue("Content", (rasadNews.Content.Length > 10000) ? rasadNews.Content.Substring(0, 9999) : rasadNews.Content);
        cmd.Parameters.AddWithValue("Description", rasadNews.Description);
        cmd.Parameters.AddWithValue("Title", rasadNews.Title);

        var a = cmd.ExecuteScalar();

        return((long)a);
    }
Example #4
0
    internal void AddRasadNews(RasadNews rasadNews, Dictionary <string, byte[]> attachments, string folder, int line)
    {
        try
        {
            long rasadNewsSourceId;
            long rasadNewsTypeId;
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            if (rasadNews.SourceId == null && defaultNewsSource == null)
            {
                logger.LogInformation("XML file and defual News SOURCE have not value!");
                return;
            }
            else
            {
                if (rasadNews.SourceId != null)
                {
                    rasadNewsSourceId = GetSourceIdWithCode(rasadNews.SourceId, conn);
                    if (rasadNewsSourceId == 0 && defaultNewsSource == null)
                    {
                        logger.LogInformation("XML file and defual News SOURCE have not value!");
                        return;
                    }
                }
            }

            if (rasadNews.CategoryType == null && defaultNewsType == null)
            {
                logger.LogInformation("XML file and defual News TYPE have not value!");
                return;
            }
            else
            {
                if (rasadNews.CategoryType != null)
                {
                    rasadNewsTypeId = GetTypeIdWithCode(rasadNews.CategoryType, conn);
                    if (rasadNewsTypeId == 0 && defaultNewsType == null)
                    {
                        logger.LogInformation("XML file and defual News TYPE have not value!");
                        return;
                    }
                }
            }

            long forignSourceId = InsertForignSource(rasadNews, folder, line);
            long newsId         = InsertNews(rasadNews, forignSourceId);
            if (attachments != null && attachments.Count > 0)
            {
                foreach (var item in attachments)
                {
                    InsertAttachment(newsId, item.Key, item.Value);
                }
            }
        }
        catch (Exception ex)
        {
            logger.LogError("Error on insert news, ex:" + ex.Message);
            return;
        }
        finally
        {
            conn.Close();
        }
    }