<commit_before>#region Disclaimer/Info
///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at <EMAIL> 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////
#endregion

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Net;
using Subtext.Extensibility;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;

//Need to remove Global.X calls ...just seems unclean
//Maybe create a another class formatter ...Format.Entry(ref Entry entry) 
//or, Instead of Globals.PostUrl(int id) --> Globals.PostUrl(ref Entry entry)
//...

namespace Subtext.Framework.Data
{
    /// <summary>
    /// Contains helper methods for getting blog entries from the database 
    /// into objects such as <see cref="Entry" />
    /// </summary>
    public static class DataHelper
    {
        public static DateTime? NullIfEmpty(this DateTime dateTime)
        {
            if (NullValue.IsNull(dateTime))
            {
                return null;
            }
            return dateTime;
        }

        public static Referrer LoadReferrer(IDataReader reader, Blog blog)
        {
            Referrer refer = reader.LoadObject<Referrer>();
            refer.BlogId = blog.Id;
            return refer;
        }

        private static bool IsNewDay(DateTime dtCurrent, DateTime dtDay)
        {
            return !(dtCurrent.DayOfYear == dtDay.DayOfYear && dtCurrent.Year == dtDay.Year);
        }

        public static ICollection<EntryDay> LoadEntryDayCollection(IDataReader reader)
        {
            DateTime dt = new DateTime(1900, 1, 1);
            List<EntryDay> edc = new List<EntryDay>();
            EntryDay day = null;

            while (reader.Read())
            {
                DateTime dateCreated = (DateTime)reader["DateCreated"];
                if (IsNewDay(dt, dateCreated))
                {
                    dt = dateCreated;
                    day = new EntryDay(dateCreated);
                    edc.Add(day);
                }
                day.Add(LoadEntry(reader));
            }
            return edc;
        }

        internal static ICollection<Entry> LoadEntryCollectionFromDataReader(this IDataReader reader)
        {
            return reader.LoadEntryCollectionFromDataReader(true /* buildLinks */);
        }

        internal static ICollection<Entry> LoadEntryCollectionFromDataReader(this IDataReader reader, bool buildLinks)
        {
            var entries = new Dictionary<int, Entry>();
            while (reader.Read())
            {
                var entry = reader.LoadEntry(buildLinks);
                entries.Add(entry.Id, entry);
            }

            if (entries.Count > 0 && reader.NextResult())
            {
                //Categories...
                while (reader.Read())
                {
                    int entryId = ReadInt32(reader, "Id");
                    string categoryTitle = ReadString(reader, "Title");
                    Entry entry;
                    if (entries.TryGetValue(entryId, out entry))
                    {
                        entry.Categories.Add(categoryTitle);
                    }
                }
            }
            return entries.Values;
        }

        //Crappy. Need to clean up all of the entry references
        public static EntryStatsView LoadEntryStatsView(this IDataReader reader)
        {
            EntryStatsView entry = new EntryStatsView();

            entry.PostType = ((PostType)ReadInt32(reader, "PostType"));
            entry.WebCount = reader.ReadInt32("WebCount");
            entry.AggCount = reader.ReadInt32("AggCount");
            entry.WebLastUpdated = reader.ReadDate("WebLastUpdated");
            entry.AggLastUpdated = reader.ReadDate("AggLastUpdated");
            entry.Author = reader.ReadString("Author");
            entry.Email = reader.ReadString("Email");
            entry.DateCreated = reader.ReadDate("DateCreated");
            entry.DateModified = reader.ReadDate("DateUpdated");
            entry.Id = reader.ReadInt32("ID");
            entry.Description = reader.ReadString("Description");
            entry.EntryName = reader.ReadString("EntryName");
            entry.FeedBackCount = reader.ReadInt32("FeedBackCount");
            entry.Body = reader.ReadString("Text");
            entry.Title = reader.ReadString("Title");
            entry.PostConfig = (PostConfig)(reader.ReadInt32("PostConfig"));
            entry.DateSyndicated = reader.ReadDate("DateSyndicated");<commit_msg>issue #93: with SQLServer 2008 the null value was not detected correctly. Added the default as 0 in the mapping method.<commit_after>#region Disclaimer/Info
///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at <EMAIL> 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////
#endregion

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Net;
using Subtext.Extensibility;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;

//Need to remove Global.X calls ...just seems unclean
//Maybe create a another class formatter ...Format.Entry(ref Entry entry) 
//or, Instead of Globals.PostUrl(int id) --> Globals.PostUrl(ref Entry entry)
//...

namespace Subtext.Framework.Data
{
    /// <summary>
    /// Contains helper methods for getting blog entries from the database 
    /// into objects such as <see cref="Entry" />
    /// </summary>
    public static class DataHelper
    {
        public static DateTime? NullIfEmpty(this DateTime dateTime)
        {
            if (NullValue.IsNull(dateTime))
            {
                return null;
            }
            return dateTime;
        }

        public static Referrer LoadReferrer(IDataReader reader, Blog blog)
        {
            Referrer refer = reader.LoadObject<Referrer>();
            refer.BlogId = blog.Id;
            return refer;
        }

        private static bool IsNewDay(DateTime dtCurrent, DateTime dtDay)
        {
            return !(dtCurrent.DayOfYear == dtDay.DayOfYear && dtCurrent.Year == dtDay.Year);
        }

        public static ICollection<EntryDay> LoadEntryDayCollection(IDataReader reader)
        {
            DateTime dt = new DateTime(1900, 1, 1);
            List<EntryDay> edc = new List<EntryDay>();
            EntryDay day = null;

            while (reader.Read())
            {
                DateTime dateCreated = (DateTime)reader["DateCreated"];
                if (IsNewDay(dt, dateCreated))
                {
                    dt = dateCreated;
                    day = new EntryDay(dateCreated);
                    edc.Add(day);
                }
                day.Add(LoadEntry(reader));
            }
            return edc;
        }

        internal static ICollection<Entry> LoadEntryCollectionFromDataReader(this IDataReader reader)
        {
            return reader.LoadEntryCollectionFromDataReader(true /* buildLinks */);
        }

        internal static ICollection<Entry> LoadEntryCollectionFromDataReader(this IDataReader reader, bool buildLinks)
        {
            var entries = new Dictionary<int, Entry>();
            while (reader.Read())
            {
                var entry = reader.LoadEntry(buildLinks);
                entries.Add(entry.Id, entry);
            }

            if (entries.Count > 0 && reader.NextResult())
            {
                //Categories...
                while (reader.Read())
                {
                    int entryId = ReadInt32(reader, "Id");
                    string categoryTitle = ReadString(reader, "Title");
                    Entry entry;
                    if (entries.TryGetValue(entryId, out entry))
                    {
                        entry.Categories.Add(categoryTitle);
                    }
                }
            }
            return entries.Values;
        }

        //Crappy. Need to clean up all of the entry references
        public static EntryStatsView LoadEntryStatsView(this IDataReader reader)
        {
            EntryStatsView entry = new EntryStatsView();

            entry.PostType = ((PostType)ReadInt32(reader, "PostType"));
            entry.WebCount = reader.ReadInt32("WebCount",0);
            entry.AggCount = reader.ReadInt32("AggCount",0);
            entry.WebLastUpdated = reader.ReadDate("WebLastUpdated");
            entry.AggLastUpdated = reader.ReadDate("AggLastUpdated");
            entry.Author = reader.ReadString("Author");
            entry.Email = reader.ReadString("Email");
            entry.DateCreated = reader.ReadDate("DateCreated");
            entry.DateModified = reader.ReadDate("DateUpdated");
            entry.Id = reader.ReadInt32("ID");
            entry.Description = reader.ReadString("Description");
            entry.EntryName = reader.ReadString("EntryName");
            entry.FeedBackCount = reader.ReadInt32("FeedBackCount");
            entry.Body = reader.ReadString("Text");
            entry.Title = reader.ReadString("Title");
            entry.PostConfig = (PostConfig)(reader.ReadInt32("PostConfig"));
            entry.DateSyndicated = reader.ReadDate("DateSyndicated");
{'fraction_non_alphanumeric': 0.133937174792831, 'fraction_numerical': 0.004914241665060705, 'mean_word_length': 1.7743918738305267, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5102294', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2470, 'n_words': 641}