using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Timers;

namespace Stat.web
{
    /// <summary>
    /// 
    ///</summary>
    public class Global : System.Web.HttpApplication
    {
        /// <summary>
        /// 
        ///</summary>
        protected void Application_Start(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        protected void Session_Start(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 
        ///</summary>
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception objErr = this.Server.GetLastError().GetBaseException();
            string errContent = "异常路径：" + this.Request.Url.ToString();
            errContent += "异常实例：" + objErr.InnerException;
            errContent += "当前实例Message：" + objErr.Message;
            errContent += "当前实例Source：" + objErr.Source;
            errContent += "当前实例TargetSite：" + objErr.TargetSite;
            errContent += "当前实例StackTrace：" + objErr.StackTrace;
            errContent += "异常发生时间：" + DateTime.Now;
            BLL.Log.InsertUpdateDelete(new Model.Log("Insert", "Application_Err", errContent, 3));
        }
        /// <summary>
        /// 
        ///</summary>
        protected void Session_End(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 
        ///</summary>
        protected void Application_End(object sender, EventArgs e)
        {
            BLL.Log.InsertUpdateDelete(new Model.Log("Insert", "Application_End", 1));
            Stat.Cache.IConfig config = Stat.Cache.CacheFatory.CreateConfig();
            Thread.Sleep(1000);
            string url = config.GetWebConfig_Str("IISPostUrl");
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            Stream receiveStream = myHttpWebResponse.GetResponseStream();
        }
    }
}
