|
using System;
using System.Xml;
using System.Xml.XPath;
namespace Schedule
{
/// <summary>
/// Local event strorage keeps the last time in memory so that skipped events are not recovered.
/// </summary>
public class LocalEventStorage : IEventStorage
{
public LocalEventStorage()
{
_LastTime = DateTime.MaxValue;
}
public void RecordLastTime(DateTime Time)
{
_LastTime = Time;
}
public DateTime ReadLastTime()
{
if (_LastTime == DateTime.MaxValue)
_LastTime = DateTime.Now;
return _LastTime;
}
DateTime _LastTime;
}
/// <summary>
/// FileEventStorage saves the last time in an XmlDocument so that recovery will include periods that the
/// process is shutdown.
/// </summary>
public class FileEventStorage : IEventStorage
{
public FileEventStorage(string FileName, string XPath)
{
_FileName = FileName;
_XPath = XPath;
}
public void RecordLastTime(DateTime Time)
{
_Doc.SelectSingleNode(_XPath).Value = Time.ToString();
_Doc.Save(_FileName);
}
public DateTime ReadLastTime()
{
_Doc.Load(_FileName);
string Value = _Doc.SelectSingleNode(_XPath).Value;
if (Value == null || Value == string.Empty)
return DateTime.Now;
return DateTime.Parse(Value);
}
string _FileName;
string _XPath;
XmlDocument _Doc = new XmlDocument();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I co-founded Standard Beagle Studio, a software development consulting service in Austin Texas with my wife Cindy Brummer. We focus mostly on web projects, but have built some react native mobile apps, and even a windows screen saver or two.
I started my career back when ASP pages were state of the art, and IE3 was considered a web browser. I've worked with Microsoft technologies for most of that time, and have recently branched out into node, wordpress, and react native applications.
I'm a web developer, math and physics enthusiast, father of 2, and all around great guy. I live in Austin TX and love using technology to change people's lives for the better. When I manage scrape together some spare time, I build generative art at curvature of the mind.