141 lines
3.5 KiB
C#
Executable File
141 lines
3.5 KiB
C#
Executable File
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.Xml.Schema;
|
|
|
|
namespace WoL_Manager
|
|
{
|
|
class ManagerSettings
|
|
{
|
|
private static int ping_timeout = 1000;
|
|
private static int ping_waittime = 3;
|
|
private static int wake_waittime = 5*60;
|
|
|
|
public static int PingTimeOut
|
|
{
|
|
set
|
|
{
|
|
ping_timeout = value;
|
|
}
|
|
get
|
|
{
|
|
return ping_timeout;
|
|
}
|
|
}
|
|
|
|
public static int PingWaitTime
|
|
{
|
|
set
|
|
{
|
|
ping_waittime = value;
|
|
}
|
|
get
|
|
{
|
|
return ping_waittime;
|
|
}
|
|
}
|
|
|
|
public static int WakeWaitTime
|
|
{
|
|
set
|
|
{
|
|
wake_waittime = value;
|
|
}
|
|
get
|
|
{
|
|
return wake_waittime;
|
|
}
|
|
}
|
|
|
|
public static void createDTD(string file)
|
|
{
|
|
string temp = "<?xml version='1.0' encoding='utf-8'?>\n\n<!ELEMENT settings (ping_timeout, ping_waittime, wake_waittime)>\n<!ELEMENT ping_timeout (#PCDATA)>\n<!ELEMENT ping_waittime (#PCDATA)>\n<!ELEMENT wake_waittime (#PCDATA)>";
|
|
System.IO.File.WriteAllText(file, temp);
|
|
}
|
|
|
|
public static void writeToFile(string file)
|
|
{
|
|
string temp = "<?xml version='1.0' encoding='utf-8'?>\n<!DOCTYPE settings SYSTEM 'settings.dtd'>\n\n<settings>";
|
|
temp = String.Concat(temp, "\n<ping_timeout>", ManagerSettings.PingTimeOut.ToString(), "</ping_timeout>");
|
|
temp = String.Concat(temp, "\n<ping_waittime>", ManagerSettings.PingWaitTime.ToString(), "</ping_waittime>");
|
|
temp = String.Concat(temp, "\n<wake_waittime>", ManagerSettings.WakeWaitTime.ToString(), "</wake_waittime>");
|
|
temp = String.Concat(temp, "\n</settings>");
|
|
System.IO.File.WriteAllText(file, temp);
|
|
}
|
|
|
|
|
|
private static void validationEventHandler(object sender, ValidationEventArgs args)
|
|
{
|
|
valitationResult = false;
|
|
}
|
|
|
|
private static bool valitationResult = true;
|
|
|
|
public static bool readFromFile(string file)
|
|
{
|
|
XmlReaderSettings settings = new XmlReaderSettings();
|
|
settings.IgnoreWhitespace = true;
|
|
settings.IgnoreComments = true;
|
|
settings.IgnoreProcessingInstructions = true;
|
|
settings.ProhibitDtd = false;
|
|
settings.ValidationType = ValidationType.DTD;
|
|
settings.ValidationEventHandler += new ValidationEventHandler(validationEventHandler);
|
|
XmlReader reader = XmlReader.Create(file, settings);
|
|
while (reader.Read())
|
|
{
|
|
if (reader.NodeType == XmlNodeType.Element && reader.LocalName.CompareTo("settings") == 0)
|
|
{
|
|
string p_timeout;
|
|
string p_waittime;
|
|
string w_waittime;
|
|
int temp1, temp2, temp3;
|
|
reader.Read();
|
|
p_timeout = reader.ReadString();
|
|
reader.Read();
|
|
p_waittime = reader.ReadString();
|
|
reader.Read();
|
|
w_waittime = reader.ReadString();
|
|
|
|
try
|
|
{
|
|
temp1 = Int32.Parse(p_timeout);
|
|
temp2 = Int32.Parse(p_waittime);
|
|
temp3 = Int32.Parse(w_waittime);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
reader.Close();
|
|
return false;
|
|
}
|
|
if (temp1 < 1 || temp1 > 30000)
|
|
{
|
|
reader.Close();
|
|
return false;
|
|
}
|
|
if (temp2 < 1 || temp2 > 30000)
|
|
{
|
|
reader.Close();
|
|
return false;
|
|
}
|
|
if (temp3 < 1 || temp3 > 30000)
|
|
{
|
|
reader.Close();
|
|
return false;
|
|
}
|
|
if (valitationResult == false)
|
|
{
|
|
reader.Close();
|
|
return false;
|
|
}
|
|
ping_timeout = temp1;
|
|
ping_waittime = temp2;
|
|
wake_waittime = temp3;
|
|
}
|
|
}
|
|
reader.Close();
|
|
return true;
|
|
}
|
|
}
|
|
}
|