⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobs.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.StaticHtml
{
    using PowerEasy.Common;
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Threading;
    using System.Web;
    using System.Xml;

    public class Jobs
    {
        private DateTime _completed;
        private DateTime _created = DateTime.Now;
        private static int _instancesOfParent;
        private bool _isRunning;
        private static readonly Jobs _jobs = new Jobs();
        private DateTime _started;
        private int Interval = 0xdbba0;
        private Hashtable jobList = new Hashtable();
        private Timer singleTimer;

        private Jobs()
        {
        }

        private void call_back(object state)
        {
            this._isRunning = true;
            this._started = DateTime.Now;
            this.singleTimer.Change(-1, -1);
            foreach (Job job in this.jobList.Values)
            {
                if (job.Enabled && job.SingleThreaded)
                {
                    job.ExecuteJob();
                }
            }
            this.singleTimer.Change(this.Interval, this.Interval);
            this._isRunning = false;
            this._completed = DateTime.Now;
        }

        public static Jobs Instance()
        {
            return _jobs;
        }

        public bool IsJobEnabled(string jobName)
        {
            if (!this.jobList.Contains(jobName))
            {
                return false;
            }
            return ((Job) this.jobList[jobName]).Enabled;
        }

        public void Start()
        {
            Interlocked.Increment(ref _instancesOfParent);
            lock (this.jobList.SyncRoot)
            {
                if (this.jobList.Count == 0)
                {
                    string filename = HttpContext.Current.Server.MapPath("~/Config/AutoCreate.config");
                    XmlDocument document = new XmlDocument();
                    document.Load(filename);
                    XmlNode node = document.SelectSingleNode("Jobs");
                    if (node != null)
                    {
                        bool flag = true;
                        XmlAttribute attribute1 = node.Attributes["singleThread"];
                        XmlAttribute attribute = node.Attributes["minutes"];
                        this.Interval = DataConverter.CLng(attribute.Value) * 0xea60;
                        string str2 = HttpContext.Current.Request.Url.Authority + VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Request.ApplicationPath);
                        string physicalApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath;
                        foreach (XmlNode node2 in node.ChildNodes)
                        {
                            XmlAttribute attribute2 = node2.Attributes["type"];
                            XmlAttribute attribute3 = node2.Attributes["name"];
                            XmlElement element = (XmlElement) node2;
                            element.SetAttribute("siteMap", physicalApplicationPath);
                            element.SetAttribute("siteUrl", str2);
                            Type ijob = Type.GetType(attribute2.Value);
                            if ((ijob != null) && !this.jobList.Contains(attribute3.Value))
                            {
                                Job job = new Job(ijob, node2);
                                this.jobList[attribute3.Value] = job;
                                if (!flag || !job.SingleThreaded)
                                {
                                    job.InitializeTimer();
                                }
                            }
                        }
                        if (flag)
                        {
                            this.singleTimer = new Timer(new TimerCallback(this.call_back), null, this.Interval, this.Interval);
                        }
                    }
                }
            }
        }

        public void Stop()
        {
            Interlocked.Decrement(ref _instancesOfParent);
            if ((_instancesOfParent <= 0) && (this.jobList != null))
            {
                lock (this.jobList.SyncRoot)
                {
                    foreach (Job job in this.jobList.Values)
                    {
                        job.Dispose();
                    }
                    this.jobList.Clear();
                    if (this.singleTimer != null)
                    {
                        this.singleTimer.Dispose();
                        this.singleTimer = null;
                    }
                }
            }
        }

        public override string ToString()
        {
            return string.Format("Created: {0}, LastStart: {1}, LastStop: {2}, IsRunning: {3}, Minutes: {4}", new object[] { this._created, this._started, this._completed, this._isRunning, this.Interval / 0xea60 });
        }

        public Hashtable CurrentJobs
        {
            get
            {
                return this.jobList;
            }
        }

        public ListDictionary CurrentStats
        {
            get
            {
                ListDictionary dictionary = new ListDictionary();
                dictionary.Add("Created", this._created);
                dictionary.Add("LastStart", this._started);
                dictionary.Add("LastStop", this._completed);
                dictionary.Add("IsRunning", this._isRunning);
                dictionary.Add("Minutes", this.Interval / 0xea60);
                return dictionary;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -