// clsWebReportListener.cs
// Copyright (C) 2008 Karel Jordaan karel_jordaan@yahoo.com.au
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Diagnostics;
using ZANZI.localhost;

namespace GUIControlLogic.Error
{
    /// <summary>
    /// clsEmailListener is a trace listener that sends email.
    /// </summary>
    /// <remarks>None</remarks>
    public class clsWebReportListener : TraceListener
    {
        #region Variable declaration

        //
        /// <summary>
        /// log the bug to the ZANZIBug tracker web service for analysis
        /// </summary>
        /// <remarks>None</remarks>
        private readonly ZANZIBugTracker bugtracker; // = new ZANZI.localhost.ZANZIBugTracker();

        #endregion

        #region Functions

        /// <summary>
        /// Constructor for sending errors to web
        /// </summary>
        /// <remarks>None</remarks>
        public clsWebReportListener()
        {
            try
            {
                //log the bug to the ZANZIBug tracker web service for analysis
                bugtracker = new ZANZIBugTracker();
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        /// Write string to file
        /// </summary>
        /// <param name="str">String to write</param>
        /// <remarks>None</remarks>
        public override void Write(string str)
        {
            try
            {
                //base.Write (str);
                ReportBug(str);
            }
            catch (Exception ex)
            {
                 new clsExeption(ex);
            }
        }

        /// <summary>
        /// Writes line to file
        /// </summary>
        /// <param name="str">String to write</param>
        /// <remarks>None</remarks>
        public override void WriteLine(string str)

    {
            try
            {
                //base.Write (str);
                ReportBug(str);
            }
            catch (Exception ex)
            {
                 new clsExeption(ex);
            }
        }

        /// <summary>
        /// Reports the bug to webservice
        /// </summary>
        /// <param name="str">Error string</param>
        /// <remarks>None</remarks>
        private void ReportBug(string str)
        {
            //if there is no connection this will generate another error
            try
            {
                //bugtracker.BugEntry(str, null, null, null);
            }
            catch (Exception)
            {
            }
        }

        #endregion
    }
}