// use ordinals to speed up access to DataReader
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497
 // parameters:
 //  reader: IDataReader from SQLClient
 public void Populate(IDataReader reader, DefaultUserActivityByHourDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.HourNumber))
     {
         HourNumber = reader.GetString(ordinals.HourNumber);
     }
     if (!reader.IsDBNull(ordinals.HourCount))
     {
         HourCount = reader.GetInt32(ordinals.HourCount);
     }
 }
Ejemplo n.º 2
0
        /// <summary>Get default User Activity By Hour</summary>
        /// <cardinality>Many</cardinality>
        public List <DefaultUserActivityByHourData> DefaultUserActivityByHour()
        {
            var ret = new List <DefaultUserActivityByHourData>();

            string sql = @" 
                select 
	                 convert(varchar(2), datepart(dd, date_time)) + '.' + convert(varchar(2), datepart(hh, date_time)) as hour_number
	                ,count(1) as hour_count
                from default_user_activity
                where date_time > dateadd(hh, -24, getutcdate())
                group by     
	                 datepart(dd, date_time)
	                ,datepart(hh, date_time)
                order by     
	                 datepart(dd, date_time)
	                ,datepart(hh, date_time)
                ";

            Logging log = Logging.PerformanceTimeStart("Default", "DataAccessLayer", "DefaultSearch", "DefaultUserActivityByHour");

            try {
                using (var conn = new SqlConnection(Conn.ConnectionString)) {
                    conn.Open();
                    conn.BeginTransaction(IsolationLevel.ReadUncommitted).Commit();

                    using (var command = new SqlCommand(sql, conn)) {
                        log.PerformanceTimePrepare(command);
                        IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);
                        log.PerformanceTimeCheck();

                        var ordinals = new DefaultUserActivityByHourDataOrdinals(reader);
                        while (reader.Read())
                        {
                            var data = new DefaultUserActivityByHourData();
                            data.Populate(reader, ordinals);
                            ret.Add(data);
                        }

                        reader.Close();
                    }
                }
            } catch (Exception ex) {
                log.Error(ex);
            }
            return(ret);
        }