/// <summary>
        /// Sort exceptions according to given field
        /// </summary>
        public int Compare(Idaho.Exception e1, Idaho.Exception e2)
        {
            int result = 0;

            switch (_field)
            {
            case Fields.Machine:
                result = e1.MachineName.CompareTo(e2.MachineName);
                if (result == 0)
                {
                    result = e1.On.CompareTo(e2.On);
                }
                break;

            case Fields.User:
                //result = e1.User.CompareTo(e2.User);
                if (result == 0)
                {
                    result = e1.On.CompareTo(e2.On);
                }
                break;

            case Fields.Date:
                result = e1.On.CompareTo(e2.On);
                break;

            case Fields.UserIP:
                result = e1.IpAddress.CompareTo(e2.IpAddress);
                if (result == 0)
                {
                    result = e1.On.CompareTo(e2.On);
                }
                break;

            case Fields.Page:
                result = e1.Page.CompareTo(e2.Page);
                if (result == 0)
                {
                    result = e1.On.CompareTo(e2.On);
                }
                break;
            }

            if (_direction == Entity.SortDirections.Descending)
            {
                result *= -1;
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Load exceptions from DB
        /// </summary>
        public static ExceptionCollection Load(ExceptionFilter filter)
        {
            ExceptionCollection exceptions = new ExceptionCollection();

            Idaho.Exception e;
            Sql             db = new Sql();
            SqlReader       reader;

            BuildCommand(db, filter);

            try {
                reader = db.GetReader();
            } catch (System.Exception ex) {
                db.Finish(true);
                Idaho.Exception.Log(ex);
                return(null);
            }

            while (reader.Read())
            {
                e             = new Idaho.Exception();
                e.MachineName = reader.GetString("Machine");
                e.On          = reader.GetDateTime("HappenedOn");
                e.Page        = reader.GetString("Page");
                e.QueryString = reader.GetString("QueryString");
                e.Browser     = reader.GetString("Browser");
                e.IpAddress   = reader.GetIpAddress("IpAddress");
                e.Stack       = reader.GetString("Stack");
                e.ID          = reader.GetInt64("ID");
                e.InnerID     = reader.GetInt64("InnerID");
                e.Message     = reader.GetString("Message");
                e.Note        = reader.GetString("Note");

                exceptions.Add(e);
            }
            reader.Close();
            db.Finish(true);

            foreach (Exception ex in exceptions)
            {
                // To be more thorough, could load missing inner exception
                ex.Inner = exceptions[ex.InnerID];
            }
            return(exceptions);
        }
Beispiel #3
0
        /// <summary>
        /// Log an error and return the error number
        /// </summary>
        /// <param name="redirect">Redirect after logging?</param>
        /// <returns>Error number</returns>
        public static Int64 Log(System.Exception ex, Types type, bool redirect, string note)
        {
            Idaho.Exception exception = new Idaho.Exception(ex, redirect, note, type);
            Int64           id        = exception.Save();

            if (type.Contains(Types.SendEmail))
            {
                Assert.NoNull(_emailTo, "NullMailTo");
                string key = ex.Message;
                if (!_occurrences.ContainsKey(key))
                {
                    _occurrences.Add(key, new Stack <DateTime>());
                }
                Stack <DateTime> oc = _occurrences[key];

                if (oc.Count == 0 || TimeSpan.Compare(
                        DateTime.Now.Subtract(oc.Peek()), _queueTime) >= 0)
                {
                    // at least frequency number of minutes have passed since last mail

                    Idaho.Web.Email    mail      = new Idaho.Web.Email();
                    List <MailAddress> addresses = new List <MailAddress>();

                    addresses.Add(_emailTo);

                    if (type.Contains(Types.HostEmail) && _hostMailTo != null &&
                        !addresses.Contains(_hostMailTo))
                    {
                        addresses.Add(_hostMailTo);
                    }

                    mail.Error(exception, addresses, oc.Count);

                    // reset the stack
                    if (oc.Count > 0)
                    {
                        oc.Clear();
                    }
                }
                oc.Push(DateTime.Now);
            }
            return(id);
        }
Beispiel #4
0
 public bool Equals(Idaho.Exception other)
 {
     return(_id == other.ID);
 }