Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
sheychen | b46e11e2c6 | |
sheychen | f7880dd6e0 | |
sheychen | f4480b684a | |
sheychen | 1c991d37b2 | |
sheychen | aaca034ba8 |
|
@ -6,6 +6,7 @@ namespace MyCommon
|
|||
/// <summary>
|
||||
/// Manager Console with Async I/O
|
||||
/// </summary>
|
||||
/// <remarks>No Mono Proof</remarks>
|
||||
public class ConsoleIO
|
||||
{
|
||||
private static string inputBuffer = "";
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace MyCommon.Generic
|
||||
{
|
||||
/// <summary>
|
||||
/// Two way dictionary
|
||||
/// </summary>
|
||||
public class LinkTable<TMain, TSecond>
|
||||
{
|
||||
private Dictionary<TMain, TSecond> mainTable;
|
||||
private Dictionary<TSecond, TMain> secondTable;
|
||||
public Dictionary<TMain, TSecond> Main { get { return mainTable; } }
|
||||
public Dictionary<TSecond, TMain> Second { get { return secondTable; } }
|
||||
public int Count { get { return mainTable.Count; } }
|
||||
|
||||
public LinkTable()
|
||||
{
|
||||
mainTable = new Dictionary<TMain, TSecond>();
|
||||
secondTable = new Dictionary<TSecond, TMain>();
|
||||
}
|
||||
|
||||
public void Add(TMain main, TSecond second)
|
||||
{
|
||||
mainTable.Add(main, second);
|
||||
secondTable.Add(second, main);
|
||||
}
|
||||
|
||||
public bool TryAdd(TMain main, TSecond second)
|
||||
{
|
||||
try
|
||||
{
|
||||
Add(main, second);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
mainTable.Clear();
|
||||
secondTable.Clear();
|
||||
}
|
||||
|
||||
public bool ContainsMain(TMain main)
|
||||
{
|
||||
return mainTable.ContainsKey(main);
|
||||
}
|
||||
|
||||
public bool ContainsSecond(TSecond second)
|
||||
{
|
||||
return secondTable.ContainsKey(second);
|
||||
}
|
||||
|
||||
public TMain GetMain(TSecond second)
|
||||
{
|
||||
return secondTable[second];
|
||||
}
|
||||
|
||||
public TSecond GetSecond(TMain main)
|
||||
{
|
||||
return mainTable[main];
|
||||
}
|
||||
|
||||
public bool TryGetMain(TSecond second, out TMain main)
|
||||
{
|
||||
return secondTable.TryGetValue(second, out main);
|
||||
}
|
||||
|
||||
public bool TryGetSecond(TMain main, out TSecond second)
|
||||
{
|
||||
return mainTable.TryGetValue(main, out second);
|
||||
}
|
||||
|
||||
public void RemoveMain(TMain main)
|
||||
{
|
||||
secondTable.Remove(mainTable[main]);
|
||||
mainTable.Remove(main);
|
||||
}
|
||||
|
||||
public void RemoveSecond(TSecond second)
|
||||
{
|
||||
mainTable.Remove(secondTable[second]);
|
||||
secondTable.Remove(second);
|
||||
}
|
||||
|
||||
public bool TryRemoveMain(TMain main)
|
||||
{
|
||||
if (!mainTable.ContainsKey(main))
|
||||
return false;
|
||||
|
||||
if (!secondTable.ContainsKey(mainTable[main]))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
RemoveMain(main);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryRemoveSecond(TSecond second)
|
||||
{
|
||||
if (!secondTable.ContainsKey(second))
|
||||
return false;
|
||||
|
||||
if (!mainTable.ContainsKey(secondTable[second]))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
RemoveSecond(second);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<TMain, TSecond>.Enumerator GetEnumerator()
|
||||
{
|
||||
return mainTable.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,169 +8,230 @@ using System.Threading;
|
|||
|
||||
namespace MyCommon
|
||||
{
|
||||
public class Logger
|
||||
{
|
||||
public enum logType { dev, debug, info, warm, error, fatal }
|
||||
public class Logger
|
||||
{
|
||||
public enum logType { dev = 0, debug, info, warm, error, fatal }
|
||||
|
||||
public enum logConsole { normal, show, hide }
|
||||
public enum logDisplay { normal, show, hide }
|
||||
|
||||
public struct Log
|
||||
{
|
||||
public string text;
|
||||
public logType type;
|
||||
public logConsole console;
|
||||
public struct Log
|
||||
{
|
||||
public string text;
|
||||
public logType type;
|
||||
public logDisplay display;
|
||||
|
||||
public Log(string p1, logType p2, logConsole p3 = logConsole.normal)
|
||||
{
|
||||
text = p1;
|
||||
type = p2;
|
||||
console = p3;
|
||||
}
|
||||
}
|
||||
public Log(string p1, logType p2, logDisplay p3 = logDisplay.normal)
|
||||
{
|
||||
text = p1;
|
||||
type = p2;
|
||||
display = p3;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Log> toWriteLogs = new List<Log>();
|
||||
private string logPath;
|
||||
private ConsoleColor[] logBackColor;
|
||||
private ConsoleColor[] logForeColor;
|
||||
private Thread Updater;
|
||||
private logType logLevel = logType.info;
|
||||
private bool _run = true;
|
||||
public bool run { get { return _run; } }
|
||||
private static bool _debug = false;
|
||||
private static bool _dev = false;
|
||||
private bool haveConsole = false;
|
||||
List<Log> toWriteLogs = new List<Log>();
|
||||
string logPath;
|
||||
ConsoleColor[] logBackColor;
|
||||
ConsoleColor[] logForeColor;
|
||||
Thread Updater;
|
||||
logType logLevel = logType.info;
|
||||
bool _run = true;
|
||||
public bool run { get { return _run; } }
|
||||
static bool _debug = false;
|
||||
static bool _dev = false;
|
||||
|
||||
/// <summary>
|
||||
/// Create log file and start logger thread
|
||||
/// </summary>
|
||||
/// <param name="LogPath">Absolute path to logs directory</param>
|
||||
public void Initialise(string LogPath, ConsoleColor[] backColor, ConsoleColor[] foreColor, logType LogLevel, bool debug, bool dev, bool haveconsole = true)
|
||||
{
|
||||
haveConsole = haveconsole;
|
||||
logPath = LogPath;
|
||||
logBackColor = backColor;
|
||||
logForeColor = foreColor;
|
||||
logLevel = LogLevel;
|
||||
_debug = debug;
|
||||
_dev = dev;
|
||||
if (!Directory.Exists(logPath))
|
||||
{
|
||||
Directory.CreateDirectory(logPath);
|
||||
Write("Log Directory Created", logType.info);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sort old logs
|
||||
string[] files = Directory.GetFiles(logPath);
|
||||
List<string> _outList;
|
||||
public List<string> outList { get { return _outList; } }
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (Path.GetExtension(file) == ".log")
|
||||
{
|
||||
string name = Path.GetFileName(file);
|
||||
name = name.Substring(0, Math.Min(name.Length, 10));
|
||||
if (name.Length == 10)
|
||||
{
|
||||
if (name != DateTime.UtcNow.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture))
|
||||
{
|
||||
int y;
|
||||
int m;
|
||||
int d;
|
||||
string _outText;
|
||||
public string outText { get { return _outText; } }
|
||||
|
||||
if (int.TryParse(new string(name.Take(4).ToArray()), out y) && int.TryParse(new string(name.Skip(5).Take(2).ToArray()), out m) && int.TryParse(new string(name.Skip(8).Take(2).ToArray()), out d))
|
||||
{
|
||||
if (!Directory.Exists(logPath + "/" + y + "/" + m + "/" + d))
|
||||
{
|
||||
Directory.CreateDirectory(logPath + "/" + y + "/" + m + "/" + d);
|
||||
}
|
||||
File.Move(file, logPath + "/" + y + "/" + m + "/" + d + "/" + Path.GetFileName(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public struct Outputs
|
||||
{
|
||||
public bool File;
|
||||
public bool Console;
|
||||
public bool ConsoleIO;
|
||||
public bool List;
|
||||
public bool Text;
|
||||
|
||||
int i = 0;
|
||||
while (File.Exists(logPath + "/" + DateTime.UtcNow.ToString("yyyy-MM-dd-", CultureInfo.InvariantCulture) + i + ".log")) { i++; }
|
||||
logPath = logPath + "/" + DateTime.UtcNow.ToString("yyyy-MM-dd-", CultureInfo.InvariantCulture) + i + ".log";
|
||||
Write("Log path:" + logPath, logType.debug);
|
||||
Updater = new Thread(new ThreadStart(UpdaterLoop));
|
||||
Updater.Start();
|
||||
}
|
||||
public Outputs(bool file = true, bool console = false, bool consoleIO = true, bool stringList = false, bool text = false )
|
||||
{
|
||||
File = file;
|
||||
Console = console;
|
||||
ConsoleIO = consoleIO;
|
||||
List = stringList;
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public void Join()
|
||||
{
|
||||
_run = false;
|
||||
Updater.Join();
|
||||
}
|
||||
Outputs outputs;
|
||||
|
||||
public void ChangeLevel(logType level)
|
||||
{
|
||||
logLevel = level;
|
||||
Write("Change to " + logLevel.ToString(), logType.info, logConsole.show);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create log file and start logger thread
|
||||
/// </summary>
|
||||
/// <param name="LogPath">Absolute path to logs directory</param>
|
||||
public void Initialise(string LogPath, ConsoleColor[] backColor, ConsoleColor[] foreColor, logType LogLevel = logType.info, bool debug = false, bool dev = false, Outputs output = new Outputs())
|
||||
{
|
||||
outputs = output;
|
||||
logPath = LogPath;
|
||||
logBackColor = backColor;
|
||||
logForeColor = foreColor;
|
||||
logLevel = LogLevel;
|
||||
_debug = debug;
|
||||
_dev = dev;
|
||||
|
||||
/// <summary>
|
||||
/// Add log to log pile
|
||||
/// </summary>
|
||||
/// <param name="text">Log text</param>
|
||||
/// <param name="type">Log status</param>
|
||||
/// <param name="console">Server display modifier</param>
|
||||
public void Write(string text, logType type, logConsole console = logConsole.normal)
|
||||
{
|
||||
Write(new Log(text, type, console));
|
||||
}
|
||||
if (outputs.File)
|
||||
{
|
||||
if (!Directory.Exists(logPath))
|
||||
{
|
||||
Directory.CreateDirectory(logPath);
|
||||
Write("Log Directory Created", logType.info);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sort old logs
|
||||
string[] files = Directory.GetFiles(logPath);
|
||||
|
||||
/// <summary>
|
||||
/// Add log to log pile
|
||||
/// </summary>
|
||||
/// <param name="log">Log struct</param>
|
||||
private void Write(Log log)
|
||||
{
|
||||
if (_debug || _dev)
|
||||
{
|
||||
//Add Source Method
|
||||
log.text = "[" + new StackTrace().GetFrame(2).GetMethod().Name + "]: " + log.text;
|
||||
}
|
||||
toWriteLogs.Add(log);
|
||||
}
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (Path.GetExtension(file) == ".log")
|
||||
{
|
||||
string name = Path.GetFileName(file);
|
||||
name = name.Substring(0, Math.Min(name.Length, 10));
|
||||
if (name.Length == 10)
|
||||
{
|
||||
if (name != DateTime.UtcNow.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture))
|
||||
{
|
||||
int y;
|
||||
int m;
|
||||
int d;
|
||||
|
||||
/// <summary>
|
||||
/// Write log pile to logfile and console
|
||||
/// </summary>
|
||||
public void UpdaterLoop()
|
||||
{
|
||||
while (_run || toWriteLogs.Count > 0)
|
||||
{
|
||||
while (toWriteLogs.Count > 0)
|
||||
{
|
||||
Log log = toWriteLogs[0]; //Saved log -> any lock need
|
||||
if (int.TryParse(new string(name.Take(4).ToArray()), out y) && int.TryParse(new string(name.Skip(5).Take(2).ToArray()), out m) && int.TryParse(new string(name.Skip(8).Take(2).ToArray()), out d))
|
||||
{
|
||||
if (!Directory.Exists(logPath + "/" + y + "/" + m + "/" + d))
|
||||
{
|
||||
Directory.CreateDirectory(logPath + "/" + y + "/" + m + "/" + d);
|
||||
}
|
||||
File.Move(file, logPath + "/" + y + "/" + m + "/" + d + "/" + Path.GetFileName(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (log.type >= logLevel)
|
||||
{
|
||||
File.AppendAllText(logPath, DateTime.UtcNow.ToString("[yyyy-MM-dd]", CultureInfo.InvariantCulture) + " [" + log.type.ToString().ToUpper() + "]: " + log.text + Environment.NewLine);
|
||||
if (log.console != logConsole.hide)
|
||||
{
|
||||
ConsoleWrite(log);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (log.console == logConsole.show)
|
||||
{
|
||||
ConsoleWrite(log);
|
||||
}
|
||||
}
|
||||
toWriteLogs.Remove(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
while (File.Exists(logPath + "/" + DateTime.UtcNow.ToString("yyyy-MM-dd-", CultureInfo.InvariantCulture) + i + ".log")) { i++; }
|
||||
logPath = logPath + "/" + DateTime.UtcNow.ToString("yyyy-MM-dd-", CultureInfo.InvariantCulture) + i + ".log";
|
||||
Write("Log path:" + logPath, logType.debug);
|
||||
}
|
||||
|
||||
private void ConsoleWrite(Log log)
|
||||
{
|
||||
if (haveConsole)
|
||||
ConsoleIO.Write(new ColorStrings(new ColorString(DateTime.UtcNow.ToString("[yyyy-MM-dd]", CultureInfo.InvariantCulture) + ": " + log.text, logForeColor[(int)log.type], logBackColor[(int)log.type])));
|
||||
}
|
||||
}
|
||||
if (outputs.Console || outputs.ConsoleIO)
|
||||
{
|
||||
Console.BackgroundColor = logBackColor[0];
|
||||
Console.ForegroundColor = logForeColor[0];
|
||||
Console.Clear();
|
||||
}
|
||||
|
||||
if (outputs.Text)
|
||||
{
|
||||
_outText = "";
|
||||
}
|
||||
|
||||
if (outputs.List)
|
||||
{
|
||||
_outList = new List<string>();
|
||||
}
|
||||
|
||||
Updater = new Thread(new ThreadStart(UpdaterLoop));
|
||||
Updater.Start();
|
||||
}
|
||||
|
||||
public void Join()
|
||||
{
|
||||
_run = false;
|
||||
Updater.Join();
|
||||
}
|
||||
|
||||
public void ChangeLevel(logType level)
|
||||
{
|
||||
logLevel = level;
|
||||
Write("Change to " + logLevel, logType.info, logDisplay.show);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add log to log pile
|
||||
/// </summary>
|
||||
/// <param name="text">Log text</param>
|
||||
/// <param name="type">Log status</param>
|
||||
/// <param name="console">Server display modifier</param>
|
||||
public void Write(string text, logType type, logDisplay console = logDisplay.normal)
|
||||
{
|
||||
Write(new Log(text, type, console));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add log to log pile
|
||||
/// </summary>
|
||||
/// <param name="log">Log struct</param>
|
||||
void Write(Log log)
|
||||
{
|
||||
if (_debug || _dev)
|
||||
{
|
||||
//Add Source Method
|
||||
log.text = "[" + new StackTrace().GetFrame(2).GetMethod().Name + "]: " + log.text;
|
||||
}
|
||||
toWriteLogs.Add(log);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write log pile to logfile and console
|
||||
/// </summary>
|
||||
public void UpdaterLoop()
|
||||
{
|
||||
while (_run || toWriteLogs.Count > 0)
|
||||
{
|
||||
while (toWriteLogs.Count > 0)
|
||||
{
|
||||
Log log = toWriteLogs[0]; //Saved log -> any lock need
|
||||
|
||||
if (log.type >= logLevel || log.display == logDisplay.show)
|
||||
{
|
||||
string datetime = DateTime.UtcNow.ToString("[yyyy-MM-dd]", CultureInfo.InvariantCulture);
|
||||
string text = datetime + " [" + log.type.ToString().ToUpper() + "]: " + log.text;
|
||||
string textfull = datetime + ": " + log.text;
|
||||
|
||||
if (outputs.File && log.type >= logLevel)
|
||||
{
|
||||
File.AppendAllText(logPath, textfull + Environment.NewLine);
|
||||
}
|
||||
|
||||
if (outputs.Console)
|
||||
{
|
||||
Console.ResetColor();
|
||||
Console.ForegroundColor = logForeColor[(int)log.type];
|
||||
Console.BackgroundColor = logBackColor[(int)log.type];
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
|
||||
if (outputs.ConsoleIO)
|
||||
{
|
||||
ConsoleIO.Write(new ColorStrings(new ColorString(text, logForeColor[(int)log.type], logBackColor[(int)log.type])));
|
||||
}
|
||||
|
||||
if (outputs.List)
|
||||
{
|
||||
_outList.Add(textfull);
|
||||
}
|
||||
|
||||
if (outputs.Text)
|
||||
{
|
||||
_outText += textfull + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
|
||||
toWriteLogs.Remove(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,10 +47,15 @@
|
|||
<Compile Include="MultiLang.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Strings.cs" />
|
||||
<Compile Include="XmlManager.cs" />
|
||||
<Compile Include="Generic\LinkTable.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Lang.csv" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Generic\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
||||
// en utilisant '*', comme indiqué ci-dessous :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
[assembly: AssemblyVersion("1.2.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.0.0")]
|
|
@ -0,0 +1,122 @@
|
|||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace MyCommon
|
||||
{
|
||||
public static class XmlManager
|
||||
{
|
||||
public enum LoadMode { ReadOnly, ReadOrCreate, ReadCreateOrReplace };
|
||||
/// <summary>
|
||||
/// Load class from xml file
|
||||
/// </summary>
|
||||
/// <param name="filepath">Path to xml file</param>
|
||||
/// <param name="schema">null disable Correct check (unsafe)</param>
|
||||
/// <returns>Loaded class</returns>
|
||||
/// <remarks>App.config is too easy</remarks>
|
||||
public static T Load<T>(string filepath, LoadMode mode, XmlReader schema, Logger logger = null) where T : new()
|
||||
{
|
||||
T file = new T();
|
||||
if (logger != null) { logger.Write("Loading " + file.GetType().Name, Logger.logType.info); }
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
bool correct = false;
|
||||
if(schema != null)
|
||||
{
|
||||
correct = Correct<T>(file, filepath, schema, logger);
|
||||
}
|
||||
else
|
||||
{
|
||||
correct = true;
|
||||
}
|
||||
if (correct)
|
||||
{
|
||||
XmlSerializer xs = new XmlSerializer(typeof(T));
|
||||
using (StreamReader re = new StreamReader(filepath))
|
||||
{
|
||||
file = (T)xs.Deserialize(re);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mode == LoadMode.ReadCreateOrReplace)
|
||||
{
|
||||
if (logger != null) { logger.Write("Old " + file.GetType().Name + " in .old", Logger.logType.warm); }
|
||||
File.Delete(filepath + ".old");
|
||||
File.Move(filepath, filepath + ".old");
|
||||
Save<T>(file, filepath, logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger != null) { logger.Write("Any config file", Logger.logType.error); }
|
||||
if (mode != LoadMode.ReadOnly)
|
||||
{
|
||||
Save<T>(file, filepath, logger);
|
||||
}
|
||||
}
|
||||
if (logger != null) { logger.Write(file.GetType().Name + " loaded", Logger.logType.debug); }
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write class in xml file
|
||||
/// </summary>
|
||||
public static void Save<T>(T file, string path, Logger logger = null)
|
||||
{
|
||||
XmlSerializer xs = new XmlSerializer(typeof(T));
|
||||
using (StreamWriter st = new StreamWriter(path))
|
||||
{
|
||||
xs.Serialize(st, file);
|
||||
};
|
||||
if (logger != null) { logger.Write(file.GetType().Name + " saved", Logger.logType.debug); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check file format using Schema
|
||||
/// </summary>
|
||||
public static bool Correct<T>(T file, string filepath, XmlReader schema, Logger logger = null)
|
||||
{
|
||||
bool isCorrect = false;
|
||||
|
||||
using (Stream fs = new FileStream(filepath, FileMode.Open))
|
||||
{
|
||||
XmlReader re = new XmlTextReader(fs);
|
||||
XmlSerializer xs = new XmlSerializer(typeof(T));
|
||||
try
|
||||
{
|
||||
isCorrect = xs.CanDeserialize(re);
|
||||
}
|
||||
catch (XmlException e)
|
||||
{
|
||||
isCorrect = false;
|
||||
if (logger != null) { logger.Write("Format check error: " + e.Message, Logger.logType.error); }
|
||||
}
|
||||
}
|
||||
|
||||
if (isCorrect)
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlDocument d = new XmlDocument();
|
||||
d.Load(filepath);
|
||||
d.Schemas.Add("", schema);
|
||||
|
||||
d.Validate((o, e) =>
|
||||
{
|
||||
if (logger != null) { logger.Write("Format check error: " + e.Message, Logger.logType.error); }
|
||||
isCorrect = false;
|
||||
});
|
||||
}
|
||||
catch (XmlException e)
|
||||
{
|
||||
isCorrect = false;
|
||||
if (logger != null) { logger.Write("Format check error: " + e.Message, Logger.logType.error); }
|
||||
}
|
||||
}
|
||||
|
||||
return isCorrect;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue