parent
aaca034ba8
commit
1c991d37b2
|
@ -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,127 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/// <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)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,10 +48,14 @@
|
|||
<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.
|
||||
|
|
Loading…
Reference in New Issue