Config.cs
using System;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace PacMon
{
/// <summary>Represents an xml root ApplicationSettings document element.</summary>
[XmlRoot("ApplicationSettings")]
public class ApplicationSettings
{
private XmlSerializerNamespaces attribute_xmlns;
private System.String element_mailserver;
private System.String element_mailuser;
private System.String element_mailpass;
private System.String element_mailsender;
private System.String element_mailreceiver;
private bool element_monitoronstart;
private decimal element_monitordelay;
private List<Window> element_servicewindows;
/// <summary>XmlSerializerNamespaces attribute.</summary>
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces xmlns
{
get { return this.attribute_xmlns; }
set { this.attribute_xmlns = value; }
}
/// <summary>String mailServer element.</summary>
[XmlElement("mailServer", Namespace = "")]
public System.String MailServer
{
get { return this.element_mailserver; }
set { this.element_mailserver = value; }
}
/// <summary>String mailUser element.</summary>
[XmlElement("mailUser", Namespace = "")]
public System.String MailUser
{
get { return this.element_mailuser; }
set { this.element_mailuser = value; }
}
/// <summary>String mailPass element.</summary>
[XmlElement("mailPass", Namespace = "")]
public System.String MailPass
{
get { return this.element_mailpass; }
set { this.element_mailpass = value; }
}
/// <summary>String mailSender element.</summary>
[XmlElement("mailSender", Namespace = "")]
public System.String MailSender
{
get { return this.element_mailsender; }
set { this.element_mailsender = value; }
}
/// <summary>String mailReceiver element.</summary>
[XmlElement("mailReceiver", Namespace = "")]
public System.String MailReceiver
{
get { return this.element_mailreceiver; }
set { this.element_mailreceiver = value; }
}
/// <summary>String monitorOnStart element.</summary>
[XmlElement("monitorOnStart", Namespace = "")]
public bool MonitorOnStart
{
get { return this.element_monitoronstart; }
set { this.element_monitoronstart = value; }
}
/// <summary>String monitorDelay element.</summary>
[XmlElement("monitorDelay", Namespace = "")]
public decimal MonitorDelay
{
get { return this.element_monitordelay; }
set { this.element_monitordelay = value; }
}
/// <summary>Window[] serviceWindows xml array element.</summary>
[XmlArrayItem("window", typeof(Window))]
[XmlArray("serviceWindows", Namespace = "")]
public List<Window> ServiceWindows
{
get { return this.element_servicewindows; }
set { this.element_servicewindows = value; }
}
}
/// <summary>Represents a serviceWindows.window node.</summary>
public class Window
{
private string attribute_start;
private string attribute_stop;
private System.String attribute_mail;
//private List<System.String> element_mail;
public Window() { }
public Window(string start, string stop, string mail)
{
this.attribute_start = start;
this.attribute_stop = stop;
this.attribute_mail = mail;
}
/// <summary>System.DateTime start attribute.</summary>
[XmlAttribute("start")]
public string Start
{
get { return this.attribute_start; }
set { this.attribute_start = value; Debug.Write("window.Start <- " + value); }
}
/// <summary>System.DateTime stop attribute.</summary>
[XmlAttribute("stop")]
public string Stop
{
get { return this.attribute_stop; }
set { this.attribute_stop = value; Debug.Write("window.Stop <- " + value); }
}
// <summary>System.String mail attribute.</summary>
[XmlAttribute("mail")]
public System.String Mail
{
get { return this.attribute_mail; }
set { this.attribute_mail = value; Debug.Write("window.Mail <- " + value); }
}
/*
/// <summary>String mail element.</summary>
[XmlElement("mail")]
public List<System.String> Mail
{
get { return this.element_mail; }
set { this.element_mail = value; }
}
*/
public bool WindowActive()
{
try
{
DateTime mStart = DateTime.Parse(Start);
DateTime mStop = DateTime.Parse(Stop);
DateTime mNow = DateTime.Now;
//DateTime mNow = new DateTime(2010, 06, 14, 15, 00, 01);
if (mStart >= mStop) // Start is less or equal to start - end next day
{
mStop += new TimeSpan(24, 0, 0);
}
Debug.Write("ServiceWindow: " + mStart + " -> " + mStop);
if (mStart <= mNow && mStop >= mNow)
{
return true;
}
}
catch (Exception ex) { return false; }
return false;
}
}
}