// 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, DefaultUserActivityRecentDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.DateTime))
     {
         DateTime = reader.GetDateTime(ordinals.DateTime);
     }
     if (!reader.IsDBNull(ordinals.UserActivityTypeName))
     {
         UserActivityTypeName = reader.GetString(ordinals.UserActivityTypeName);
     }
     if (!reader.IsDBNull(ordinals.OriginatingAddress))
     {
         OriginatingAddress = reader.GetString(ordinals.OriginatingAddress);
     }
     if (!reader.IsDBNull(ordinals.Referrer))
     {
         Referrer = reader.GetString(ordinals.Referrer);
     }
     if (!reader.IsDBNull(ordinals.UserActivityNote))
     {
         UserActivityNote = reader.GetString(ordinals.UserActivityNote);
     }
 }
예제 #2
0
        /// <summary>Get recent user activities</summary>
        /// <summary>Filters out activities with rule in default_rule ( Type 'Hide' ) </summary>
        /// <cardinality>Many</cardinality>
        public List <DefaultUserActivityRecentData> DefaultUserActivityRecent(
            Guid defaultUserId
            )
        {
            var ret = new List <DefaultUserActivityRecentData>();

            string sql = @" 
                    select top 50
	                     ua.date_time
	                    ,uatr.default_user_activity_type_name   as user_activity_type_name
	                    ,ua.originating_address
						,ua.referrer
	                    ,ua.user_activity_note
					from default_user_activity                  as ua
                    inner join default_user_activity_type_ref   as uatr on uatr.default_user_activity_type_rcd = ua.default_user_activity_type_rcd
            ";

            if (defaultUserId == Guid.Empty)
            {
                sql += @"
					 left join default_rule						as der	on der.address = ua.originating_address
																	   and der.default_rule_type_rcd = @default_rule_type_rcd
					where der.default_rule_id is null
                   ";
            }

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

            try {
                using (var conn = new SqlConnection(ConfigurationManager.AppSettings["Conn"])) {
                    conn.Open();
                    conn.BeginTransaction(IsolationLevel.ReadUncommitted).Commit();

                    using (var command = new SqlCommand(sql, conn)) {
                        if (defaultUserId == Guid.Empty)
                        {
                            command.Parameters.Add("@default_rule_type_rcd", SqlDbType.NVarChar).Value = DefaultRuleTypeRef.HideLayerAddress;
                        }
                        else
                        {
                            sql += " where ua.default_user_id = @default_user_id\r\n";
                            command.Parameters.Add("@default_user_id", SqlDbType.UniqueIdentifier).Value = defaultUserId;
                        }

                        sql += "                    order by ua.date_time desc";
                        log.PerformanceTimePrepare(command);

                        command.CommandText = sql;

                        IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);
                        log.PerformanceTimeCheck();

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

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