
using System;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Reflection;

using Legalsoft.Workflow.Engine;

public partial class Settings : System.Web.HttpApplication
{
    public static System.Threading.Timer stateTimer = null;

    protected void Application_Start(Object sender, EventArgs e)
    {
        #region 以下代码使得DateTime.Now的默认时间格式为yyyy-MM-dd HH:mm:ss
        if (DateTimeFormatInfo.CurrentInfo != null)
        {
            var type = DateTimeFormatInfo.CurrentInfo.GetType();
            var field = type.GetField("generalLongTimePattern", BindingFlags.NonPublic | BindingFlags.Instance);
            if (field != null)
            {
                field.SetValue(DateTimeFormatInfo.CurrentInfo, "yyyy-MM-dd HH:mm:ss");
            }
        }
        #endregion

        CSS.Load(Server.MapPath("/app_resource/") + "/css.js");
        Flows.LoadPath(Server.MapPath("/app_resource/flows/"));
        Flows.LoadInstances(Server.MapPath("/app_resource/") + "/instance.js");

        System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false);
        System.Threading.TimerCallback timerDelegate = new System.Threading.TimerCallback(timerCall);
        stateTimer = new System.Threading.Timer(timerDelegate, autoEvent, 0, 1979);
    }

    private void timerCall(object arts)
    {
        Commands.Sending();
    }

    //每个请求开始时
    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
    }
    //每个请求结束时
    protected void Application_EndRequest(Object sender, EventArgs e)
    {
    }
    //用来对调用者进行验证
    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {
    }
    //引发未处理的异常时激发
    protected void Application_Error(Object sender, EventArgs e)
    {
    }
    //程序结束时激发(或应用程序已经有20分钟没有请求)
    protected void Application_End(Object sender, EventArgs e)
    {
    }
    //会话开始时激发
    protected void Session_Start(Object sender, EventArgs e)
    {
    }
    //会话结束时激发
    protected void Session_End(Object sender, EventArgs e)
    {
    }
}
