diff --git a/.gitattributes b/.gitattributes old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/License.md b/License.md old mode 100644 new mode 100755 diff --git a/MyCommon.sln b/MyCommon.sln old mode 100644 new mode 100755 diff --git a/MyCommon/Binary.cs b/MyCommon/Binary.cs old mode 100644 new mode 100755 diff --git a/MyCommon/ConsoleIO.cs b/MyCommon/ConsoleIO.cs old mode 100644 new mode 100755 index 4f41e1a..80b4d2f --- a/MyCommon/ConsoleIO.cs +++ b/MyCommon/ConsoleIO.cs @@ -6,6 +6,7 @@ namespace MyCommon /// /// Manager Console with Async I/O /// + /// No Mono Proof public class ConsoleIO { private static string inputBuffer = ""; diff --git a/MyCommon/Generic/LinkTable.cs b/MyCommon/Generic/LinkTable.cs new file mode 100644 index 0000000..c5431dc --- /dev/null +++ b/MyCommon/Generic/LinkTable.cs @@ -0,0 +1,127 @@ +using System.Collections.Generic; + +namespace MyCommon.Generic +{ + /// + /// Two way dictionary + /// + public class LinkTable + { + private Dictionary mainTable; + private Dictionary secondTable; + public Dictionary Main { get { return mainTable; } } + public Dictionary Second { get { return secondTable; } } + public int Count { get { return mainTable.Count; } } + + public LinkTable() + { + mainTable = new Dictionary(); + secondTable = new Dictionary(); + } + + 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; + } + } + } +} diff --git a/MyCommon/Lang.csv b/MyCommon/Lang.csv old mode 100644 new mode 100755 diff --git a/MyCommon/Logger.cs b/MyCommon/Logger.cs old mode 100644 new mode 100755 index 6017cb6..69a059d --- a/MyCommon/Logger.cs +++ b/MyCommon/Logger.cs @@ -38,15 +38,17 @@ namespace MyCommon public bool run { get { return _run; } } private static bool _debug = false; private static bool _dev = false; - private bool haveConsole = false; + + public enum ConsoleTypes { Any, System, IO }; + private ConsoleTypes consoleType = ConsoleTypes.Any; /// /// Create log file and start logger thread /// /// Absolute path to logs directory - public void Initialise(string LogPath, ConsoleColor[] backColor, ConsoleColor[] foreColor, logType LogLevel, bool debug, bool dev, bool haveconsole = true) + public void Initialise(string LogPath, ConsoleColor[] backColor, ConsoleColor[] foreColor, logType LogLevel, bool debug, bool dev, ConsoleTypes consoletype = ConsoleTypes.Any) { - haveConsole = haveconsole; + consoleType = consoletype; logPath = LogPath; logBackColor = backColor; logForeColor = foreColor; @@ -169,8 +171,20 @@ namespace MyCommon 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]))); + string text = DateTime.UtcNow.ToString("[yyyy-MM-dd]", CultureInfo.InvariantCulture) + ": " + log.text; + switch (consoleType) + { + case ConsoleTypes.System: + Console.ResetColor(); + Console.ForegroundColor = logForeColor[(int)log.type]; + Console.BackgroundColor = logBackColor[(int)log.type]; + Console.WriteLine(text); + break; + + case ConsoleTypes.IO: + ConsoleIO.Write(new ColorStrings(new ColorString(text, logForeColor[(int)log.type], logBackColor[(int)log.type]))); + break; + } } } } \ No newline at end of file diff --git a/MyCommon/MultiLang.cs b/MyCommon/MultiLang.cs old mode 100644 new mode 100755 diff --git a/MyCommon/MyCommon.csproj b/MyCommon/MyCommon.csproj index 5524b0c..1197250 100644 --- a/MyCommon/MyCommon.csproj +++ b/MyCommon/MyCommon.csproj @@ -48,10 +48,14 @@ + + + +