📄 job.cs
字号:
namespace PowerEasy.StaticHtml
{
using PowerEasy.Common;
using PowerEasy.Enumerations;
using System;
using System.Threading;
using System.Xml;
public class Job : IDisposable
{
private bool _enabled = true;
private bool _enableShutDown;
private HtmlContent _ijob;
private bool _isRunning;
private Type _jobType;
private DateTime _lastEnd;
private DateTime _lastStart;
private DateTime _lastSucess;
private int _minutes = 15;
private string _name;
private XmlNode _node;
private int _seconds = -1;
private bool _singleThread = true;
private Timer _timer;
private bool createIndexPage;
private bool createNodePage;
private bool disposed;
private string nodeArry;
private int number;
private string siteMapth;
private string siteUrl;
public Job(Type ijob, XmlNode node)
{
this._node = node;
this._jobType = ijob;
XmlAttribute attribute = node.Attributes["enabled"];
if (attribute != null)
{
this._enabled = DataConverter.CBool(attribute.Value);
}
attribute = node.Attributes["enableShutDown"];
if (attribute != null)
{
this._enableShutDown = DataConverter.CBool(attribute.Value);
}
attribute = node.Attributes["name"];
if (attribute != null)
{
this._name = attribute.Value;
}
attribute = node.Attributes["seconds"];
if (attribute != null)
{
this._seconds = DataConverter.CLng(attribute.Value);
}
attribute = node.Attributes["createNodePage"];
if (attribute != null)
{
this.createNodePage = DataConverter.CBool(attribute.Value);
}
attribute = node.Attributes["createIndexPage"];
if (attribute != null)
{
this.createIndexPage = DataConverter.CBool(attribute.Value);
}
attribute = node.Attributes["siteUrl"];
if (attribute != null)
{
this.siteUrl = attribute.Value;
}
attribute = node.Attributes["siteMap"];
if (attribute != null)
{
this.siteMapth = attribute.Value;
}
attribute = node.Attributes["minutes"];
if (attribute != null)
{
try
{
this._minutes = DataConverter.CLng(attribute.Value);
}
catch
{
this._minutes = 15;
}
}
attribute = node.Attributes["number"];
if (attribute != null)
{
this.number = DataConverter.CLng(attribute.Value);
}
attribute = node.Attributes["nodeIdArray"];
if (attribute != null)
{
this.nodeArry = attribute.Value;
}
attribute = node.Attributes["singleThread"];
if ((attribute != null) && (string.Compare(attribute.Value, "false", true) == 0))
{
this._singleThread = false;
}
}
public HtmlContent CreateJobInstance()
{
if (this.Enabled && (this._ijob == null))
{
if (this._jobType != null)
{
this._ijob = Activator.CreateInstance(this._jobType) as HtmlContent;
}
this._enabled = this._ijob != null;
if (!this._enabled)
{
this.Dispose();
}
}
return this._ijob;
}
public void Dispose()
{
if ((this._timer != null) && !this.disposed)
{
lock (this)
{
this._timer.Dispose();
this._timer = null;
this.disposed = true;
}
}
}
public void ExecuteJob()
{
this._isRunning = true;
HtmlContent content = this.CreateJobInstance();
if (content != null)
{
this._lastStart = DateTime.Now;
try
{
content.CreateMethod = CreateContentType.CreateAuto;
content.NodeIdArray = this.nodeArry;
content.SiteUrl = this.siteUrl;
content.PhysicalApplicationPath = this.siteMapth;
content.EnableCreateNodePage = this.createNodePage;
content.EnableCreateIndexPage = this.createIndexPage;
content.Work();
this._lastEnd = this._lastSucess = DateTime.Now;
}
catch (Exception)
{
this._enabled = !this.EnableShutDown;
this._lastEnd = DateTime.Now;
}
}
this._isRunning = false;
}
public void InitializeTimer()
{
if ((this._timer == null) && this.Enabled)
{
this._timer = new Timer(new TimerCallback(this.timer_Callback), null, this.Interval, this.Interval);
}
}
private void timer_Callback(object state)
{
if (this.Enabled)
{
this._timer.Change(-1, -1);
this.ExecuteJob();
if (this.Enabled)
{
this._timer.Change(this.Interval, this.Interval);
}
else
{
this.Dispose();
}
}
}
public bool Enabled
{
get
{
return this._enabled;
}
}
public bool EnableShutDown
{
get
{
return this._enableShutDown;
}
}
protected int Interval
{
get
{
if (this._seconds > 0)
{
return (this._seconds * 0x3e8);
}
return (this.Minutes * 0xea60);
}
}
public bool IsRunning
{
get
{
return this._isRunning;
}
}
public Type JobType
{
get
{
return this._jobType;
}
}
public DateTime LastEnd
{
get
{
return this._lastEnd;
}
}
public DateTime LastStarted
{
get
{
return this._lastStart;
}
}
public DateTime LastSuccess
{
get
{
return this._lastSucess;
}
}
public int Minutes
{
get
{
return this._minutes;
}
set
{
this._minutes = value;
}
}
public string Name
{
get
{
return this._name;
}
}
public bool SingleThreaded
{
get
{
return this._singleThread;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -