Exemplo n.º 1
0
 // 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, DefaultStatisticsDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.ActivityDate))
     {
         ActivityDate = reader.GetString(ordinals.ActivityDate);
     }
     if (!reader.IsDBNull(ordinals.DayCount))
     {
         DayCount = reader.GetInt32(ordinals.DayCount);
     }
 }
Exemplo n.º 2
0
        /// <summary>Get default statistics</summary>
        /// <cardinality>Many</cardinality>
        public List <DefaultStatisticsData> DefaultStatistics()
        {
            var ret = new List <DefaultStatisticsData>();

            string sql = @" 
                    select top 50 
	                     convert(nvarchar(30), date_time, 2) as activity_date
	                    ,count(*) as day_count
                    from default_user_activity as ua
                    group by convert(nvarchar(30), date_time, 2)
                    order by convert(nvarchar(30), date_time, 2) desc
                ";

            // where 1=1

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

            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 DefaultStatisticsDataOrdinals(reader);
                        while (reader.Read())
                        {
                            var data = new DefaultStatisticsData();
                            data.Populate(reader, ordinals);
                            ret.Add(data);
                        }

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