Beispiel #1
0
        /// <summary>Get default resource statistics</summary>
        /// <cardinality>Many</cardinality>
        public List <DefaultResourceStatisticsData> DefaultResourceStatistics()
        {
            var ret = new List <DefaultResourceStatisticsData>();

            string sql = @" 
select top 20 
	 convert(varchar(2), datepart(day, date_time)) 
		+ '.' + convert(varchar(2), datepart(hour, date_time)) 
		+ '.' + convert(varchar(2), datepart(minute, date_time)) as hour_number
	,drm.client_workingset_bytes
	,drm.business_workingset_bytes
	,drm.database_size_bytes
from default_resource_measurement as drm
order by date_time desc
                ";

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

            try {
                using (var conn = new SqlConnection(ConfigurationManager.AppSettings["Conn"])) {
                    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 DefaultResourceStatisticsDataOrdinals(reader);
                        while (reader.Read())
                        {
                            var data = new DefaultResourceStatisticsData();
                            data.Populate(reader, ordinals);
                            ret.Add(data);
                        }

                        reader.Close();
                    }
                }
            } catch (Exception ex) {
                log.Error(ex);
            }
            return(ret);
        }
 // use ordinals to speed up access to DataReader
 // links:
 //  docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497
 // parameters:
 //  reader: IDataReader from SQLClient
 public void Populate(IDataReader reader, DefaultResourceStatisticsDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.HourNumber))
     {
         HourNumber = reader.GetString(ordinals.HourNumber);
     }
     if (!reader.IsDBNull(ordinals.ClientWorkingsetBytes))
     {
         ClientWorkingsetBytes = reader.GetInt32(ordinals.ClientWorkingsetBytes);
     }
     if (!reader.IsDBNull(ordinals.BusinessWorkingsetBytes))
     {
         BusinessWorkingsetBytes = reader.GetInt32(ordinals.BusinessWorkingsetBytes);
     }
     if (!reader.IsDBNull(ordinals.DatabaseSizeBytes))
     {
         DatabaseSizeBytes = reader.GetInt32(ordinals.DatabaseSizeBytes);
     }
 }