/// <summary> /// Load activities from DB /// </summary> public static SiteActivityCollection Load(SiteActivityFilter filter) { SiteActivityCollection activities = new SiteActivityCollection(); SiteActivity a; Data.Sql db = new Data.Sql(); Data.SqlReader reader; BuildCommand(db, filter); try { reader = db.GetReader(); } catch (System.Exception ex) { Idaho.Exception.Log(ex); return(null); } while (reader.Read()) { a = new SiteActivity(); a.Type = (SiteActivity.Types)reader.GetInt32("Type"); a.IpAddress = reader.GetIpAddress("IpAddress"); a.Note = reader.GetString("Note"); a.On = reader.GetDateTime("HappenedOn"); activities.Add(a); } reader.Close(); db.Finish(true); return(activities); }
/// <summary> /// Construct sorted dictionary from SQL object and key/value field names /// </summary> public static SortedDictionary <K, V> Load(Data.Sql sql, string keyField, string valueField) { SortedDictionary <K, V> sorted = new SortedDictionary <K, V>(); SqlReader reader = sql.GetReader(true); while (reader.Read()) { sorted.Add(reader.GetValue <K>(keyField), reader.GetValue <V>(valueField)); } return(sorted); }
//private Int64 Save() { return this.Save(this); } /// <summary> /// Persist exception data /// </summary> /// <returns>Log number</returns> private Int64 Save() { _recurseCount += 1; // recursively save inner exceptions if (_inner != null) { _innerID = _inner.Save(); _recurseCount -= 1; } Data.Sql sql = new Data.Sql(); sql.ProcedureName = "SaveException"; sql.Parameters.IgnoreNull = true; sql.Parameters.Add("type", (int)_type, SqlDbType.Int); sql.Parameters.Add("message", _message, SqlDbType.VarChar); sql.Parameters.Add("stack", _stack, SqlDbType.VarChar); sql.Parameters.Add("machine", _machineName, SqlDbType.VarChar); sql.Parameters.Add("process", _process, SqlDbType.VarChar); if (_recurseCount == 0 && !string.IsNullOrEmpty(_note)) { // only save note for outermost exception sql.Parameters.Add("note", _note.SafeForWeb(500), SqlDbType.VarChar); } // client if (_user != null) { sql.Parameters.Add("userID", _user.ID, SqlDbType.UniqueIdentifier); } if (_userIP != null) { sql.Parameters.Add("ipAddress", _userIP.ToInt32(), SqlDbType.Int); } sql.Parameters.Add("browser", _browser, SqlDbType.VarChar); sql.Parameters.Add("cookies", _cookies, SqlDbType.VarChar); // meta sql.Parameters.Add("innerID", _innerID, SqlDbType.BigInt); //sql.Parameters.Add("emailed", ex); // page sql.Parameters.Add("context", _pageName, SqlDbType.VarChar); sql.Parameters.Add("queryString", _queryString, SqlDbType.VarChar); try { _id = sql.GetReturn(); } catch { _id = 0; } finally { sql.Finish(true); } return(_id); }
/// <summary> /// Load indicators using SQL object (assumes standard column names) /// </summary> public static IndicatorCollection <T> Load(Data.Sql sql) { IndicatorCollection <T> list = new IndicatorCollection <T>(); T i; SqlReader reader = sql.GetReader(true); while (reader.Read()) { i = new T(); i.Level = reader.GetInt32("Level"); i.Name = reader.GetString("Name"); i.Description = reader.GetString("Description"); i.Tag = reader.GetString("Abbreviation"); list.Add(i); } sql.Finish(); return(list); }
/// <summary> /// Build command best suiting filter /// </summary> private static void BuildCommand(Idaho.Data.Sql db, ExceptionFilter filter) { if (filter.ID != 0) { db.ProcedureName = "ExceptionByID"; db.Parameters.Add("id", filter.ID); } else { db.ProcedureName = "ExceptionByAny"; if (filter.Type != Idaho.Exception.Types.Unknown) { db.Parameters.Add("type", filter.Type); } if (filter.After != DateTime.MinValue) { db.Parameters.Add("after", filter.After); } if (filter.Before != DateTime.MaxValue) { db.Parameters.Add("before", filter.Before); } if (filter.IpAddress != null) { db.Parameters.Add("ipAddress", filter.IpAddress.ToInt32()); } if (filter.User != null) { db.Parameters.Add("userID", filter.User.ID); } if (!string.IsNullOrEmpty(filter.Page)) { db.Parameters.Add("page", filter.Page); } if (!string.IsNullOrEmpty(filter.Browser)) { db.Parameters.Add("browser", filter.Browser); } } }
/// <summary> /// Construct sorted dictionary from SQL object and key/value field name /// </summary> public static SortedDictionary <K, V> Load(Data.Sql sql, string field) { return(Load(sql, field, field)); }